From da27a63447eb2125146d30bef306c91621fe19fc Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sat, 7 Dec 2019 00:07:49 +0100 Subject: [PATCH] Family reunion - Mechanical Bearings now use Contraption Entities for their structures - Fixed Mounted Contraptions being slightly offset --- .../java/com/simibubi/create/AllBlocks.java | 16 +- .../java/com/simibubi/create/AllEntities.java | 4 +- .../java/com/simibubi/create/AllPackets.java | 2 +- .../com/simibubi/create/AllTileEntities.java | 10 +- .../com/simibubi/create/CreateClient.java | 2 +- .../create/ResourceReloadHandler.java | 2 - .../contraptions/receivers/DrillBlock.java | 2 +- .../receivers/DrillTileEntityRenderer.java | 2 +- .../receivers/HarvesterBlock.java | 2 +- .../HarvesterTileEntityRenderer.java | 2 +- .../contraptions/receivers/SawBlock.java | 2 +- .../MechanicalBearingTileEntityRenderer.java | 108 --------- .../constructs/bearing/RotationConstruct.java | 212 ------------------ .../RotationConstructVertexBuffer.java | 42 ---- .../Contraption.java | 17 +- .../ContraptionEntity.java | 109 ++++++--- .../ContraptionEntityRenderer.java | 13 +- .../ContraptionRenderer.java | 4 +- .../IControlContraption.java | 2 +- .../IHaveMovementBehavior.java | 4 +- .../bearing/BearingContraption.java | 53 +++++ .../bearing/MechanicalBearingBlock.java | 2 +- .../bearing/MechanicalBearingTileEntity.java | 95 ++++---- .../MechanicalBearingTileEntityRenderer.java | 38 ++++ .../chassis}/AbstractChassisBlock.java | 2 +- .../chassis}/ChassisTileEntity.java | 2 +- .../chassis}/ConfigureChassisPacket.java | 2 +- .../chassis}/LinearChassisBlock.java | 2 +- .../chassis}/RadialChassisBlock.java | 2 +- .../mounted/CartAssemblerBlock.java | 17 +- .../mounted/MountedContraption.java | 21 +- .../piston/MechanicalPistonBlock.java | 2 +- .../piston/MechanicalPistonHeadBlock.java | 4 +- .../piston/MechanicalPistonTileEntity.java | 26 +-- .../MechanicalPistonTileEntityRenderer.java | 2 +- .../piston/MovingConstructHandler.java | 1 + .../piston/PistonContraption.java | 6 +- .../piston/PistonPoleBlock.java | 4 +- .../contraptions/redstone/ContactBlock.java | 2 +- 39 files changed, 301 insertions(+), 539 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/MechanicalBearingTileEntityRenderer.java delete mode 100644 src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/RotationConstruct.java delete mode 100644 src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/RotationConstructVertexBuffer.java rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/Contraption.java (94%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs/mounted => contraptions}/ContraptionEntity.java (74%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs/mounted => contraptions}/ContraptionEntityRenderer.java (87%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/ContraptionRenderer.java (94%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs/mounted => contraptions}/IControlContraption.java (55%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/IHaveMovementBehavior.java (92%) create mode 100644 src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/BearingContraption.java rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/bearing/MechanicalBearingBlock.java (94%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/bearing/MechanicalBearingTileEntity.java (59%) create mode 100644 src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/MechanicalBearingTileEntityRenderer.java rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions/chassis}/AbstractChassisBlock.java (98%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions/chassis}/ChassisTileEntity.java (95%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions/chassis}/ConfigureChassisPacket.java (90%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions/chassis}/LinearChassisBlock.java (97%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions/chassis}/RadialChassisBlock.java (96%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/mounted/CartAssemblerBlock.java (89%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/mounted/MountedContraption.java (77%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/piston/MechanicalPistonBlock.java (98%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/piston/MechanicalPistonHeadBlock.java (95%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/piston/MechanicalPistonTileEntity.java (90%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/piston/MechanicalPistonTileEntityRenderer.java (92%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/piston/MovingConstructHandler.java (98%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/piston/PistonContraption.java (95%) rename src/main/java/com/simibubi/create/modules/contraptions/receivers/{constructs => contraptions}/piston/PistonPoleBlock.java (94%) diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index 656dc417d..3be50cf72 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -20,17 +20,17 @@ import com.simibubi.create.modules.contraptions.receivers.HarvesterBlock; import com.simibubi.create.modules.contraptions.receivers.HarvesterBlock.HarvesterBladeBlock; import com.simibubi.create.modules.contraptions.receivers.MechanicalMixerBlock; import com.simibubi.create.modules.contraptions.receivers.MechanicalMixerBlock.MechanicalMixerBlockItem; +import com.simibubi.create.modules.contraptions.receivers.contraptions.bearing.MechanicalBearingBlock; +import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.LinearChassisBlock; +import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.RadialChassisBlock; +import com.simibubi.create.modules.contraptions.receivers.contraptions.mounted.CartAssemblerBlock; +import com.simibubi.create.modules.contraptions.receivers.contraptions.mounted.CartAssemblerBlock.MinecartAnchorBlock; +import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonBlock; +import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonHeadBlock; +import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.PistonPoleBlock; import com.simibubi.create.modules.contraptions.receivers.MechanicalPressBlock; import com.simibubi.create.modules.contraptions.receivers.SawBlock; import com.simibubi.create.modules.contraptions.receivers.TurntableBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.LinearChassisBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.RadialChassisBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.bearing.MechanicalBearingBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.CartAssemblerBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.CartAssemblerBlock.MinecartAnchorBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonHeadBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.piston.PistonPoleBlock; import com.simibubi.create.modules.contraptions.receivers.crafter.MechanicalCrafterBlock; import com.simibubi.create.modules.contraptions.redstone.ContactBlock; import com.simibubi.create.modules.contraptions.relays.ClutchBlock; diff --git a/src/main/java/com/simibubi/create/AllEntities.java b/src/main/java/com/simibubi/create/AllEntities.java index d4095dc29..20947c48c 100644 --- a/src/main/java/com/simibubi/create/AllEntities.java +++ b/src/main/java/com/simibubi/create/AllEntities.java @@ -2,8 +2,8 @@ package com.simibubi.create; import java.util.function.Function; -import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.ContraptionEntity; -import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.ContraptionEntityRenderer; +import com.simibubi.create.modules.contraptions.receivers.contraptions.ContraptionEntity; +import com.simibubi.create.modules.contraptions.receivers.contraptions.ContraptionEntityRenderer; import com.simibubi.create.modules.logistics.transport.CardboardBoxEntity; import com.simibubi.create.modules.logistics.transport.CardboardBoxEntityRenderer; diff --git a/src/main/java/com/simibubi/create/AllPackets.java b/src/main/java/com/simibubi/create/AllPackets.java index 57f3b8c6d..5bf40dabd 100644 --- a/src/main/java/com/simibubi/create/AllPackets.java +++ b/src/main/java/com/simibubi/create/AllPackets.java @@ -8,7 +8,7 @@ import com.simibubi.create.foundation.packet.NbtPacket; import com.simibubi.create.foundation.packet.SimplePacketBase; import com.simibubi.create.modules.contraptions.generators.ConfigureMotorPacket; import com.simibubi.create.modules.contraptions.receivers.ConfigureMixerPacket; -import com.simibubi.create.modules.contraptions.receivers.constructs.ConfigureChassisPacket; +import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.ConfigureChassisPacket; import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunBeamPacket; import com.simibubi.create.modules.curiosities.symmetry.SymmetryEffectPacket; import com.simibubi.create.modules.logistics.block.diodes.ConfigureFlexpeaterPacket; diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 00651bd74..3da5e42b8 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -24,11 +24,11 @@ import com.simibubi.create.modules.contraptions.receivers.MechanicalPressTileEnt import com.simibubi.create.modules.contraptions.receivers.SawTileEntity; import com.simibubi.create.modules.contraptions.receivers.SawTileEntityRenderer; import com.simibubi.create.modules.contraptions.receivers.TurntableTileEntity; -import com.simibubi.create.modules.contraptions.receivers.constructs.ChassisTileEntity; -import com.simibubi.create.modules.contraptions.receivers.constructs.bearing.MechanicalBearingTileEntity; -import com.simibubi.create.modules.contraptions.receivers.constructs.bearing.MechanicalBearingTileEntityRenderer; -import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonTileEntity; -import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonTileEntityRenderer; +import com.simibubi.create.modules.contraptions.receivers.contraptions.bearing.MechanicalBearingTileEntity; +import com.simibubi.create.modules.contraptions.receivers.contraptions.bearing.MechanicalBearingTileEntityRenderer; +import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.ChassisTileEntity; +import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonTileEntity; +import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonTileEntityRenderer; import com.simibubi.create.modules.contraptions.receivers.crafter.MechanicalCrafterTileEntity; import com.simibubi.create.modules.contraptions.receivers.crafter.MechanicalCrafterTileEntityRenderer; import com.simibubi.create.modules.contraptions.relays.ClutchTileEntity; diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 4ab00aca4..121ec50d4 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -14,7 +14,7 @@ import com.simibubi.create.foundation.utility.SuperByteBufferCache; import com.simibubi.create.modules.contraptions.WrenchModel; import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.modules.contraptions.receivers.EncasedFanParticleHandler; -import com.simibubi.create.modules.contraptions.receivers.constructs.ContraptionRenderer; +import com.simibubi.create.modules.contraptions.receivers.contraptions.ContraptionRenderer; import com.simibubi.create.modules.curiosities.deforester.DeforesterModel; import com.simibubi.create.modules.curiosities.partialWindows.WindowInABlockModel; import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunModel; diff --git a/src/main/java/com/simibubi/create/ResourceReloadHandler.java b/src/main/java/com/simibubi/create/ResourceReloadHandler.java index be9478bab..2823618d3 100644 --- a/src/main/java/com/simibubi/create/ResourceReloadHandler.java +++ b/src/main/java/com/simibubi/create/ResourceReloadHandler.java @@ -1,7 +1,6 @@ package com.simibubi.create; import com.simibubi.create.foundation.block.SpriteShifter; -import com.simibubi.create.modules.contraptions.receivers.constructs.bearing.MechanicalBearingTileEntityRenderer; import net.minecraft.client.resources.ReloadListener; import net.minecraft.profiler.IProfiler; @@ -16,7 +15,6 @@ public class ResourceReloadHandler extends ReloadListener { @Override protected void apply(String splashList, IResourceManager resourceManagerIn, IProfiler profilerIn) { - MechanicalBearingTileEntityRenderer.invalidateCache(); SpriteShifter.reloadUVs(); CreateClient.bufferCache.invalidate(); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java index 82157de60..59d612dd9 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java @@ -7,7 +7,7 @@ import com.simibubi.create.foundation.block.IWithTileEntity; import com.simibubi.create.foundation.utility.SuperByteBuffer; import com.simibubi.create.foundation.utility.VoxelShapers; import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior; import net.minecraft.block.Block; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillTileEntityRenderer.java index bd10f7a1d..e82bca1f7 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillTileEntityRenderer.java @@ -9,7 +9,7 @@ import com.simibubi.create.foundation.utility.SuperByteBuffer; import com.simibubi.create.modules.contraptions.base.IRotate; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext; import net.minecraft.block.BlockState; import net.minecraft.util.Direction.Axis; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/HarvesterBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/HarvesterBlock.java index e8b06b775..9184a67b6 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/HarvesterBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/HarvesterBlock.java @@ -6,7 +6,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.IRenderUtilityBlock; import com.simibubi.create.foundation.utility.SuperByteBuffer; import com.simibubi.create.foundation.utility.VoxelShaper; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior; import net.minecraft.block.Block; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/HarvesterTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/HarvesterTileEntityRenderer.java index cca73f0ff..25f1744f6 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/HarvesterTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/HarvesterTileEntityRenderer.java @@ -7,7 +7,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.SuperByteBuffer; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.BufferBuilder; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java index c4015e7b8..7cbdb48cb 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java @@ -3,7 +3,7 @@ package com.simibubi.create.modules.contraptions.receivers; import com.simibubi.create.foundation.block.IWithTileEntity; import com.simibubi.create.foundation.utility.VoxelShapers; import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior; import com.simibubi.create.modules.logistics.block.IBlockWithFilter; import net.minecraft.block.Block; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/MechanicalBearingTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/MechanicalBearingTileEntityRenderer.java deleted file mode 100644 index 96e4f5dcf..000000000 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/MechanicalBearingTileEntityRenderer.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.bearing; - -import java.util.Random; -import java.util.concurrent.TimeUnit; - -import org.lwjgl.opengl.GL11; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.simibubi.create.AllBlocks; -import com.simibubi.create.CreateClient; -import com.simibubi.create.foundation.utility.PlacementSimulationWorld; -import com.simibubi.create.foundation.utility.SuperByteBuffer; -import com.simibubi.create.modules.contraptions.base.KineticTileEntity; -import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer; - -import net.minecraft.block.BlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BlockModelRenderer; -import net.minecraft.client.renderer.BlockRendererDispatcher; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.model.IBakedModel; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.util.Direction; -import net.minecraft.util.math.Vec3i; -import net.minecraft.world.gen.feature.template.Template.BlockInfo; -import net.minecraftforge.client.model.data.EmptyModelData; - -public class MechanicalBearingTileEntityRenderer extends KineticTileEntityRenderer { - - protected static Cache cachedConstructs; - protected static PlacementSimulationWorld renderWorld; - - @Override - public void renderTileEntityFast(KineticTileEntity te, double x, double y, double z, float partialTicks, - int destroyStage, BufferBuilder buffer) { - super.renderTileEntityFast(te, x, y, z, partialTicks, destroyStage, buffer); - - MechanicalBearingTileEntity bearingTe = (MechanicalBearingTileEntity) te; - final Direction facing = te.getBlockState().get(BlockStateProperties.FACING); - BlockState capState = AllBlocks.MECHANICAL_BEARING_TOP.get().getDefaultState().with(BlockStateProperties.FACING, - facing); - - SuperByteBuffer superBuffer = CreateClient.bufferCache.renderBlockState(KINETIC_TILE, capState); - float interpolatedAngle = bearingTe.getInterpolatedAngle(partialTicks); - kineticRotationTransform(superBuffer, bearingTe, facing.getAxis(), interpolatedAngle, getWorld()); - superBuffer.translate(x, y, z).renderInto(buffer); - - if (!bearingTe.running) - return; - - cacheConstructIfMissing(bearingTe.movingConstruct); - renderConstructFromCache(bearingTe.movingConstruct, bearingTe, x, y, z, partialTicks, buffer); - } - - protected void cacheConstructIfMissing(RotationConstruct c) { - if (cachedConstructs == null) - cachedConstructs = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.SECONDS).build(); - if (cachedConstructs.getIfPresent(c) != null) - return; - if (renderWorld == null || renderWorld.getWorld() != Minecraft.getInstance().world) - renderWorld = new PlacementSimulationWorld(Minecraft.getInstance().world); - - BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher(); - BlockModelRenderer blockRenderer = dispatcher.getBlockModelRenderer(); - Random random = new Random(); - BufferBuilder builder = new BufferBuilder(0); - builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); - builder.setTranslation(0, 0, 0); - - for (BlockInfo info : c.blocks.values()) { - renderWorld.setBlockState(info.pos, info.state); - } - - for (BlockInfo info : c.blocks.values()) { - IBakedModel originalModel = dispatcher.getModelForState(info.state); - blockRenderer.renderModel(renderWorld, originalModel, info.state, info.pos, builder, true, random, 42, - EmptyModelData.INSTANCE); - } - - builder.finishDrawing(); - renderWorld.clear(); - cachedConstructs.put(c, new RotationConstructVertexBuffer(builder.getByteBuffer())); - } - - protected void renderConstructFromCache(RotationConstruct c, MechanicalBearingTileEntity te, double x, double y, - double z, float partialTicks, BufferBuilder buffer) { - float zfightBonus = 1 / 128f; - Direction direction = te.getBlockState().get(BlockStateProperties.FACING); - Vec3i vec = direction.getDirectionVec(); - buffer.putBulkData(cachedConstructs.getIfPresent(c).getTransformed(te, (float) (x) + vec.getX() * zfightBonus, - (float) (y) + vec.getY() * zfightBonus, (float) (z) + vec.getZ() * zfightBonus, - te.getInterpolatedAngle(partialTicks), direction.getAxis())); - } - - @Override - protected BlockState getRenderedBlockState(KineticTileEntity te) { - return AllBlocks.SHAFT_HALF.get().getDefaultState().with(BlockStateProperties.FACING, - te.getBlockState().get(BlockStateProperties.FACING).getOpposite()); - } - - public static void invalidateCache() { - if (cachedConstructs != null) - cachedConstructs.invalidateAll(); - } - -} diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/RotationConstruct.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/RotationConstruct.java deleted file mode 100644 index 6df9082d2..000000000 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/RotationConstruct.java +++ /dev/null @@ -1,212 +0,0 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.bearing; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.simibubi.create.AllBlockTags; -import com.simibubi.create.AllBlocks; -import com.simibubi.create.CreateConfig; -import com.simibubi.create.modules.contraptions.receivers.constructs.ChassisTileEntity; -import com.simibubi.create.modules.contraptions.receivers.constructs.RadialChassisBlock; - -import net.minecraft.block.BlockState; -import net.minecraft.block.PistonBlock; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.ListNBT; -import net.minecraft.nbt.NBTUtil; -import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.gen.feature.template.Template.BlockInfo; - -public class RotationConstruct { - - protected Map blocks; - protected int sailBlocks; - - public RotationConstruct() { - blocks = new HashMap<>(); - sailBlocks = 0; - } - - public static RotationConstruct getAttachedForRotating(World world, BlockPos pos, Direction direction) { - RotationConstruct construct = new RotationConstruct(); - - if (!construct.collectAttached(world, pos, direction)) - return null; - - return construct; - } - - public int getSailBlocks() { - return sailBlocks; - } - - protected boolean collectAttached(World world, BlockPos pos, Direction direction) { - if (isFrozen()) - return false; - - // Find chassis - List chassis = collectChassis(world, pos, direction); - if (chassis == null) - return false; - - // Get single block - if (chassis.isEmpty()) { - BlockPos blockPos = pos.offset(direction); - BlockState state = world.getBlockState(pos.offset(direction)); - - if (state.getMaterial().isReplaceable() || state.isAir(world, blockPos)) - return true; - if (state.getCollisionShape(world, blockPos).isEmpty()) - return true; - if (!canRotate(world, blockPos, direction)) - return false; - - blocks.put(blockPos, new BlockInfo(blockPos.subtract(pos), state, null)); - - // Get attached blocks by chassis - } else { - List attachedBlocksByChassis = getAttachedBlocksByChassis(world, direction, chassis); - if (attachedBlocksByChassis == null) - return false; - attachedBlocksByChassis.forEach(info -> { - if (isSailBlock(info.state)) - sailBlocks++; - blocks.put(info.pos, new BlockInfo(info.pos.subtract(pos), info.state, info.nbt)); - }); - } - - return true; - } - - private List getAttachedBlocksByChassis(World world, Direction direction, List chassis) { - List blocks = new ArrayList<>(); - RadialChassisBlock def = (RadialChassisBlock) AllBlocks.ROTATION_CHASSIS.block; - - for (BlockInfo chassisBlock : chassis) { - blocks.add(chassisBlock); - BlockState state = chassisBlock.state; - BlockPos currentPos = chassisBlock.pos; - TileEntity tileEntity = world.getTileEntity(currentPos); - - if (!(tileEntity instanceof ChassisTileEntity)) - return null; - - int chassisRange = ((ChassisTileEntity) tileEntity).getRange(); - Set visited = new HashSet<>(); - - for (Direction facing : Direction.values()) { - if (facing.getAxis() == direction.getAxis()) - continue; - if (!state.get(def.getGlueableSide(state, facing))) - continue; - - BlockPos startPos = currentPos.offset(facing); - List frontier = new LinkedList<>(); - frontier.add(startPos); - CompoundNBT nbt = new CompoundNBT(); - nbt.putInt("Range", chassisRange); - - while (!frontier.isEmpty()) { - BlockPos searchPos = frontier.remove(0); - BlockState searchedState = world.getBlockState(searchPos); - - if (visited.contains(searchPos)) - continue; - if (!searchPos.withinDistance(currentPos, chassisRange + .5f)) - continue; - if (searchedState.getMaterial().isReplaceable() || state.isAir(world, searchPos)) - continue; - if (searchedState.getCollisionShape(world, searchPos).isEmpty()) - continue; - if (!canRotate(world, searchPos, direction)) - return null; - - visited.add(searchPos); - - blocks.add(new BlockInfo(searchPos, searchedState, - AllBlocks.ROTATION_CHASSIS.typeOf(searchedState) ? nbt : null)); - - for (Direction offset : Direction.values()) { - if (offset.getAxis() == direction.getAxis()) - continue; - if (searchPos.equals(currentPos) && offset != facing) - continue; - - frontier.add(searchPos.offset(offset)); - } - } - } - } - return blocks; - } - - private List collectChassis(World world, BlockPos pos, Direction direction) { - List chassis = new ArrayList<>(); - for (int distance = 1; distance <= CreateConfig.parameters.maxChassisForRotation.get(); distance++) { - BlockPos currentPos = pos.offset(direction, distance); - if (!world.isBlockPresent(currentPos)) - return chassis; - - BlockState state = world.getBlockState(currentPos); - if (!AllBlocks.ROTATION_CHASSIS.typeOf(state)) - return chassis; - if (direction.getAxis() != state.get(BlockStateProperties.AXIS)) - return chassis; - - chassis.add(new BlockInfo(currentPos, state, null)); - } - return chassis; - } - - private static boolean isSailBlock(BlockState state) { - return AllBlockTags.WINDMILL_SAILS.matches(state); - } - - public CompoundNBT writeNBT() { - CompoundNBT nbt = new CompoundNBT(); - ListNBT blocks = new ListNBT(); - for (BlockInfo block : this.blocks.values()) { - CompoundNBT c = new CompoundNBT(); - c.put("Block", NBTUtil.writeBlockState(block.state)); - c.put("Pos", NBTUtil.writeBlockPos(block.pos)); - if (block.nbt != null) - c.put("Data", block.nbt); - blocks.add(c); - } - - nbt.put("Blocks", blocks); - return nbt; - } - - public static RotationConstruct fromNBT(CompoundNBT nbt) { - RotationConstruct construct = new RotationConstruct(); - nbt.getList("Blocks", 10).forEach(c -> { - CompoundNBT comp = (CompoundNBT) c; - BlockInfo info = new BlockInfo(NBTUtil.readBlockPos(comp.getCompound("Pos")), - NBTUtil.readBlockState(comp.getCompound("Block")), - comp.contains("Data") ? comp.getCompound("Data") : null); - construct.blocks.put(info.pos, info); - }); - - return construct; - } - - private static boolean canRotate(World world, BlockPos pos, Direction direction) { - return PistonBlock.canPush(world.getBlockState(pos), world, pos, direction, true, direction) - || AllBlocks.ROTATION_CHASSIS.typeOf(world.getBlockState(pos)); - } - - public static boolean isFrozen() { - return CreateConfig.parameters.freezeRotationConstructs.get(); - } - -} diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/RotationConstructVertexBuffer.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/RotationConstructVertexBuffer.java deleted file mode 100644 index f2b459bd6..000000000 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/RotationConstructVertexBuffer.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.bearing; - -import java.nio.ByteBuffer; - -import com.simibubi.create.foundation.utility.BufferManipulator; - -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction.Axis; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; - -public class RotationConstructVertexBuffer extends BufferManipulator { - - public RotationConstructVertexBuffer(ByteBuffer original) { - super(original); - } - - public ByteBuffer getTransformed(TileEntity te, float x, float y, float z, float angle, Axis axis) { - original.rewind(); - mutable.rewind(); - - float cos = MathHelper.cos(angle); - float sin = MathHelper.sin(angle); - - for (int vertex = 0; vertex < vertexCount(original); vertex++) { - float xL = getX(original, vertex) -.5f; - float yL = getY(original, vertex) -.5f; - float zL = getZ(original, vertex) -.5f; - - float xL2 = rotateX(xL, yL, zL, sin, cos, axis) + .5f; - float yL2 = rotateY(xL, yL, zL, sin, cos, axis) + .5f; - float zL2 = rotateZ(xL, yL, zL, sin, cos, axis) + .5f; - - putPos(mutable, vertex, xL2 + x, yL2 + y, zL2 + z); - BlockPos pos = new BlockPos(te.getPos().getX() + xL2, te.getPos().getY() + yL2, te.getPos().getZ() + zL2); - putLight(mutable, vertex, te.getWorld().getCombinedLight(pos, 0)); - } - - return mutable; - } - -} diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/Contraption.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/Contraption.java similarity index 94% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/Contraption.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/Contraption.java index c8f31b615..5f5393fdc 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/Contraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/Contraption.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs; +package com.simibubi.create.modules.contraptions.receivers.contraptions; import static com.simibubi.create.CreateConfig.parameters; import static net.minecraft.state.properties.BlockStateProperties.AXIS; @@ -19,9 +19,14 @@ import org.apache.commons.lang3.tuple.MutablePair; import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateConfig; import com.simibubi.create.modules.contraptions.receivers.SawBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext; -import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.MountedContraption; -import com.simibubi.create.modules.contraptions.receivers.constructs.piston.PistonContraption; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext; +import com.simibubi.create.modules.contraptions.receivers.contraptions.bearing.BearingContraption; +import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.AbstractChassisBlock; +import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.ChassisTileEntity; +import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.LinearChassisBlock; +import com.simibubi.create.modules.contraptions.receivers.contraptions.chassis.RadialChassisBlock; +import com.simibubi.create.modules.contraptions.receivers.contraptions.mounted.MountedContraption; +import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.PistonContraption; import net.minecraft.block.BlockState; import net.minecraft.block.FallingBlock; @@ -451,6 +456,8 @@ public class Contraption { contraption = new PistonContraption(); if (type.equals("Mounted")) contraption = new MountedContraption(); + if (type.equals("Bearing")) + contraption = new BearingContraption(); contraption.readNBT(nbt); return contraption; } @@ -488,6 +495,8 @@ public class Contraption { nbt.putString("Type", "Piston"); if (this instanceof MountedContraption) nbt.putString("Type", "Mounted"); + if (this instanceof BearingContraption) + nbt.putString("Type", "Bearing"); ListNBT blocks = new ListNBT(); for (BlockInfo block : this.blocks.values()) { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/ContraptionEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/ContraptionEntity.java similarity index 74% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/ContraptionEntity.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/ContraptionEntity.java index eb71d5b38..c83a9b0d7 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/ContraptionEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/ContraptionEntity.java @@ -1,13 +1,12 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.mounted; +package com.simibubi.create.modules.contraptions.receivers.contraptions; import com.simibubi.create.AllEntities; import com.simibubi.create.foundation.utility.VecHelper; -import com.simibubi.create.modules.contraptions.receivers.constructs.Contraption; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; +import net.minecraft.entity.item.minecart.AbstractMinecartEntity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.NBTUtil; import net.minecraft.network.IPacket; @@ -31,11 +30,17 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD protected BlockPos controllerPos; protected IControlContraption controllerTE; - // Not synchronizing any of these yet + public float prevYaw; + public float prevPitch; + public float prevRoll; + + public float yaw; + public float pitch; + public float roll; + + // Mounted Contraptions public float targetYaw; public float targetPitch; - public float contraptionYaw; - public float contraptionPitch; public ContraptionEntity(EntityType entityTypeIn, World worldIn) { super(entityTypeIn, worldIn); @@ -49,8 +54,8 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD this(world); this.contraption = contraption; this.initialAngle = initialAngle; - this.prevRotationYaw = initialAngle; - this.contraptionYaw = initialAngle; + this.prevYaw = initialAngle; + this.yaw = initialAngle; this.targetYaw = initialAngle; } @@ -64,10 +69,9 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD public void tick() { super.tick(); attachToController(); + Entity e = getRidingEntity(); - if (e == null) - return; - else { + if (e != null) { Vec3d movementVector = e.getMotion(); Vec3d motion = movementVector.normalize(); if (motion.length() > 0) { @@ -75,24 +79,29 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD targetPitch = (float) ((Math.atan(motion.y) * 73.0D) / Math.PI * 180); if (targetYaw < 0) targetYaw += 360; - if (contraptionYaw < 0) - contraptionYaw += 360; + if (yaw < 0) + yaw += 360; } float speed = 0.2f; - prevRotationYaw = contraptionYaw; - contraptionYaw = angleLerp(speed, contraptionYaw, targetYaw); - prevRotationPitch = contraptionPitch; - contraptionPitch = angleLerp(speed, contraptionPitch, targetPitch); + prevYaw = yaw; + yaw = angleLerp(speed, yaw, targetYaw); + prevPitch = pitch; + pitch = angleLerp(speed, pitch, targetPitch); tickActors(movementVector); + return; } + + prevYaw = yaw; + prevPitch = pitch; + prevRoll = roll; } public void tickActors(Vec3d movementVector) { getContraption().getActors().forEach(pair -> { MovementContext context = pair.right; - float deg = -contraptionYaw + initialAngle; + float deg = -yaw + initialAngle; context.motion = VecHelper.rotate(movementVector, deg, Axis.Y); if (context.world == null) @@ -120,8 +129,39 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD }); } + public void moveTo(double x, double y, double z) { + move(x - posX, y - posY, z - posZ); + } + + public void move(double x, double y, double z) { + + // Collision and stuff + + setPosition(posX + x, posY + y, posZ + z); + } + + public void rotateTo(double roll, double yaw, double pitch) { + rotate(getShortestAngleDiff(this.roll, roll), getShortestAngleDiff(this.yaw, yaw), + getShortestAngleDiff(this.pitch, pitch)); + } + + public void rotate(double roll, double yaw, double pitch) { + + // Collision and stuff + + this.yaw += yaw; + this.pitch += pitch; + this.roll += roll; + } + @Override public void setPosition(double x, double y, double z) { + Entity e = getRidingEntity(); + if (e != null && e instanceof AbstractMinecartEntity) { + x -= .5; + z -= .5; + } + this.posX = x; this.posY = y; this.posZ = z; @@ -134,25 +174,37 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD } } + @Override + public void stopRiding() { + super.stopRiding(); + if (!world.isRemote) + disassemble(); + } + public static float yawFromMotion(Vec3d motion) { return (float) ((Math.PI / 2 - Math.atan2(motion.z, motion.x)) / Math.PI * 180); } public float getYaw(float partialTicks) { - float yaw = contraptionYaw; - return (partialTicks == 1.0F ? yaw : angleLerp(partialTicks, this.prevRotationYaw, yaw)) - initialAngle; + return (partialTicks == 1.0F ? yaw : angleLerp(partialTicks, prevYaw, yaw)) - initialAngle; } public float getPitch(float partialTicks) { - float pitch = contraptionPitch; - return partialTicks == 1.0F ? pitch : angleLerp(partialTicks, this.prevRotationPitch, pitch); + return partialTicks == 1.0F ? pitch : angleLerp(partialTicks, prevPitch, pitch); + } + + public float getRoll(float partialTicks) { + return partialTicks == 1.0F ? roll : angleLerp(partialTicks, prevRoll, roll); } private float angleLerp(float pct, float current, float target) { + return current + getShortestAngleDiff(current, target) * pct; + } + + private float getShortestAngleDiff(double current, double target) { current = current % 360; target = target % 360; - float shortest_angle = ((((target - current) % 360) + 540) % 360) - 180; - return current + shortest_angle * pct; + return (float) (((((target - current) % 360) + 540) % 360) - 180); } public static EntityType.Builder build(EntityType.Builder builder) { @@ -171,8 +223,8 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD initialAngle = compound.getFloat("InitialAngle"); if (compound.contains("Controller")) controllerPos = NBTUtil.readBlockPos(compound.getCompound("Controller")); - prevRotationYaw = initialAngle; - contraptionYaw = initialAngle; + prevYaw = initialAngle; + yaw = initialAngle; targetYaw = initialAngle; } @@ -216,8 +268,7 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD public void disassemble() { if (getContraption() != null) - getContraption().disassemble(world, new BlockPos(getPositionVec().add(.5, .5, .5)), contraptionYaw, - contraptionPitch); + getContraption().disassemble(world, new BlockPos(getPositionVec().add(.5, .5, .5)), yaw, pitch); remove(); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/ContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/ContraptionEntityRenderer.java similarity index 87% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/ContraptionEntityRenderer.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/ContraptionEntityRenderer.java index 173efc49f..630080cdb 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/ContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/ContraptionEntityRenderer.java @@ -1,8 +1,8 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.mounted; +package com.simibubi.create.modules.contraptions.receivers.contraptions; import com.mojang.blaze3d.platform.GlStateManager; import com.simibubi.create.foundation.utility.TessellatorHelper; -import com.simibubi.create.modules.contraptions.receivers.constructs.ContraptionRenderer; +import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; @@ -13,6 +13,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.item.minecart.AbstractMinecartEntity; import net.minecraft.util.Direction.Axis; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; @@ -37,11 +38,11 @@ public class ContraptionEntityRenderer extends EntityRenderer GlStateManager.pushMatrix(); float angleYaw = (float) (entity.getYaw(partialTicks) / 180 * Math.PI); float anglePitch = (float) (entity.getPitch(partialTicks) / 180 * Math.PI); + float angleRoll = (float) (entity.getRoll(partialTicks) / 180 * Math.PI); Entity ridingEntity = entity.getRidingEntity(); if (ridingEntity != null && ridingEntity instanceof AbstractMinecartEntity) { AbstractMinecartEntity cart = (AbstractMinecartEntity) ridingEntity; - GlStateManager.translated(0, .5, 0); long i = (long) entity.getEntityId() * 493286711L; i = i * i * 4392167121L + i * 98761L; @@ -73,15 +74,17 @@ public class ContraptionEntityRenderer extends EntityRenderer } // BlockPos anchor = entity.getContraption().getAnchor(); -// Vec3d rotationOffset = VecHelper.getCenterOf(anchor); + Vec3d rotationOffset = VecHelper.getCenterOf(BlockPos.ZERO); // Vec3d offset = VecHelper.getCenterOf(anchor).scale(-1); TessellatorHelper.prepareFastRender(); TessellatorHelper.begin(DefaultVertexFormats.BLOCK); ContraptionRenderer.render(entity.world, entity.getContraption(), superByteBuffer -> { -// superByteBuffer.translate(-rotationOffset.x, -rotationOffset.y, -rotationOffset.z); + superByteBuffer.translate(-rotationOffset.x, -rotationOffset.y, -rotationOffset.z); + superByteBuffer.rotate(Axis.X, angleRoll); superByteBuffer.rotate(Axis.Y, angleYaw); superByteBuffer.rotate(Axis.Z, anglePitch); + superByteBuffer.translate(rotationOffset.x, rotationOffset.y, rotationOffset.z); superByteBuffer.translate(x, y, z); superByteBuffer.offsetLighting(-x + entity.posX, -y + entity.posY, -z + entity.posZ); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/ContraptionRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/ContraptionRenderer.java similarity index 94% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/ContraptionRenderer.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/ContraptionRenderer.java index 595024393..2925346f7 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/ContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/ContraptionRenderer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs; +package com.simibubi.create.modules.contraptions.receivers.contraptions; import java.util.Random; import java.util.function.Consumer; @@ -10,7 +10,7 @@ import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.utility.PlacementSimulationWorld; import com.simibubi.create.foundation.utility.SuperByteBuffer; import com.simibubi.create.foundation.utility.SuperByteBufferCache.Compartment; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockModelRenderer; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/IControlContraption.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/IControlContraption.java similarity index 55% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/IControlContraption.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/IControlContraption.java index edc1602b7..1a1d45799 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/IControlContraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/IControlContraption.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.mounted; +package com.simibubi.create.modules.contraptions.receivers.contraptions; public interface IControlContraption { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/IHaveMovementBehavior.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/IHaveMovementBehavior.java similarity index 92% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/IHaveMovementBehavior.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/IHaveMovementBehavior.java index 50362a879..09c441b18 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/IHaveMovementBehavior.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/IHaveMovementBehavior.java @@ -1,8 +1,8 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs; +package com.simibubi.create.modules.contraptions.receivers.contraptions; import com.simibubi.create.foundation.utility.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; -import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonTileEntity; +import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonTileEntity; import net.minecraft.block.BlockState; import net.minecraft.nbt.CompoundNBT; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/BearingContraption.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/BearingContraption.java new file mode 100644 index 000000000..d86c6776c --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/BearingContraption.java @@ -0,0 +1,53 @@ +package com.simibubi.create.modules.contraptions.receivers.contraptions.bearing; + +import com.simibubi.create.AllBlockTags; +import com.simibubi.create.modules.contraptions.receivers.contraptions.Contraption; + +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.template.Template.BlockInfo; + +public class BearingContraption extends Contraption { + + protected int sailBlocks; + protected Direction facing; + + public static BearingContraption assembleBearingAt(World world, BlockPos pos, Direction direction) { + if (isFrozen()) + return null; + BearingContraption construct = new BearingContraption(); + construct.facing = direction; + if (!construct.searchMovedStructure(world, pos.offset(direction), direction)) + return null; + return construct; + } + + @Override + public void add(BlockPos pos, BlockInfo block) { + if (AllBlockTags.WINDMILL_SAILS.matches(block.state)) + sailBlocks++; + super.add(pos, block); + } + + @Override + public CompoundNBT writeNBT() { + CompoundNBT tag = super.writeNBT(); + tag.putInt("Sails", sailBlocks); + tag.putInt("facing", facing.getIndex()); + return tag; + } + + @Override + public void readNBT(CompoundNBT tag) { + sailBlocks = tag.getInt("Sails"); + facing = Direction.byIndex(tag.getInt("Facing")); + super.readNBT(tag); + } + + public int getSailBlocks() { + return sailBlocks; + } + +} diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/MechanicalBearingBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/MechanicalBearingBlock.java similarity index 94% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/MechanicalBearingBlock.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/MechanicalBearingBlock.java index 62ae7d5d0..79693e585 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/MechanicalBearingBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/MechanicalBearingBlock.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.bearing; +package com.simibubi.create.modules.contraptions.receivers.contraptions.bearing; import com.simibubi.create.foundation.block.IWithTileEntity; import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/MechanicalBearingTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/MechanicalBearingTileEntity.java similarity index 59% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/MechanicalBearingTileEntity.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/MechanicalBearingTileEntity.java index d1c6f969c..85efc3924 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/bearing/MechanicalBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/MechanicalBearingTileEntity.java @@ -1,25 +1,23 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.bearing; +package com.simibubi.create.modules.contraptions.receivers.contraptions.bearing; import com.simibubi.create.AllTileEntities; import com.simibubi.create.modules.contraptions.base.GeneratingKineticTileEntity; -import com.simibubi.create.modules.contraptions.receivers.constructs.ChassisTileEntity; +import com.simibubi.create.modules.contraptions.receivers.contraptions.Contraption; +import com.simibubi.create.modules.contraptions.receivers.contraptions.ContraptionEntity; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IControlContraption; -import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.nbt.CompoundNBT; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.gen.feature.template.Template.BlockInfo; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity { +public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity implements IControlContraption { - protected RotationConstruct movingConstruct; + protected ContraptionEntity movedContraption; protected float angle; protected boolean running; protected boolean assembleNextTick; @@ -30,17 +28,6 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity { isWindmill = false; } - @Override - public AxisAlignedBB getRenderBoundingBox() { - return INFINITE_EXTENT_AABB; - } - - @Override - @OnlyIn(Dist.CLIENT) - public double getMaxRenderDistanceSquared() { - return super.getMaxRenderDistanceSquared() * 16; - } - @Override public float getAddedStressCapacity() { return isWindmill ? super.getAddedStressCapacity() : 0; @@ -77,7 +64,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity { public float getGeneratedSpeed() { if (!running || !isWindmill) return 0; - int sails = movingConstruct.getSailBlocks(); + int sails = ((BearingContraption) movedContraption.getContraption()).getSailBlocks(); return MathHelper.clamp(sails, 0, 128); } @@ -86,9 +73,6 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity { tag.putBoolean("Running", running); tag.putBoolean("Windmill", isWindmill); tag.putFloat("Angle", angle); - if (running && !RotationConstruct.isFrozen()) - tag.put("Construct", movingConstruct.writeNBT()); - return super.write(tag); } @@ -97,15 +81,10 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity { running = tag.getBoolean("Running"); isWindmill = tag.getBoolean("Windmill"); angle = tag.getFloat("Angle"); - if (running && !RotationConstruct.isFrozen()) - movingConstruct = RotationConstruct.fromNBT(tag.getCompound("Construct")); - super.read(tag); } public float getInterpolatedAngle(float partialTicks) { - if (RotationConstruct.isFrozen()) - return 0; return MathHelper.lerp(partialTicks, angle, angle + getAngularSpeed()); } @@ -123,19 +102,23 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity { Direction direction = getBlockState().get(BlockStateProperties.FACING); // Collect Construct - movingConstruct = RotationConstruct.getAttachedForRotating(getWorld(), getPos(), direction); - if (movingConstruct == null) + BearingContraption contraption = BearingContraption.assembleBearingAt(world, pos, direction); + if (contraption == null) return; - if (isWindmill && movingConstruct.getSailBlocks() == 0) + if (isWindmill && contraption.getSailBlocks() == 0) return; + movedContraption = new ContraptionEntity(world, contraption, 0).controlledBy(this); + BlockPos anchor = pos.offset(direction); + movedContraption.setPosition(anchor.getX(), anchor.getY(), anchor.getZ()); + world.addEntity(movedContraption); // Run running = true; angle = 0; sendData(); - for (BlockInfo info : movingConstruct.blocks.values()) { - getWorld().setBlockState(info.pos.add(pos), Blocks.AIR.getDefaultState(), 67); + for (BlockInfo info : contraption.blocks.values()) { + getWorld().setBlockState(info.pos.add(contraption.getAnchor()), Blocks.AIR.getDefaultState(), 67); } updateGeneratedRotation(); @@ -145,24 +128,9 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity { if (!running) return; - for (BlockInfo block : movingConstruct.blocks.values()) { - BlockPos targetPos = block.pos.add(pos); - BlockState state = block.state; - - for (Direction face : Direction.values()) - state = state.updatePostPlacement(face, world.getBlockState(targetPos.offset(face)), world, targetPos, - targetPos.offset(face)); - - world.destroyBlock(targetPos, world.getBlockState(targetPos).getCollisionShape(world, targetPos).isEmpty()); - getWorld().setBlockState(targetPos, state, 3); - TileEntity tileEntity = world.getTileEntity(targetPos); - if (tileEntity != null && block.nbt != null) { - ((ChassisTileEntity) tileEntity).setRange(block.nbt.getInt("Range")); - } - } - + movedContraption.disassemble(); + movedContraption = null; running = false; - movingConstruct = null; angle = 0; updateGeneratedRotation(); sendData(); @@ -172,14 +140,15 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity { public void tick() { super.tick(); - if (running && RotationConstruct.isFrozen()) + if (running && Contraption.isFrozen()) disassembleConstruct(); if (!world.isRemote && assembleNextTick) { assembleNextTick = false; if (running) { boolean canDisassemble = Math.abs(angle) < Math.PI / 4f || Math.abs(angle) > 7 * Math.PI / 4f; - if (speed == 0 && (canDisassemble || movingConstruct == null || movingConstruct.blocks.isEmpty())) { + if (speed == 0 && (canDisassemble || movedContraption == null + || movedContraption.getContraption().blocks.isEmpty())) { disassembleConstruct(); } return; @@ -197,6 +166,26 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity { float angularSpeed = getAngularSpeed(); float newAngle = angle + angularSpeed; angle = (float) (newAngle % (2 * Math.PI)); + applyRotation(); + } + + private void applyRotation() { + if (movedContraption != null) { + Direction direction = getBlockState().get(BlockStateProperties.FACING); + Vec3d vec = new Vec3d(1, 1, 1).scale(angle * 180 / Math.PI).mul(new Vec3d(direction.getDirectionVec())); + movedContraption.rotateTo(-vec.x, vec.y, -vec.z); + } + } + + @Override + public void attach(ContraptionEntity contraption) { + if (contraption.getContraption() instanceof BearingContraption) { + this.movedContraption = contraption; + BlockPos anchor = pos.offset(getBlockState().get(BlockStateProperties.FACING)); + movedContraption.setPosition(anchor.getX(), anchor.getY(), anchor.getZ()); + if (!world.isRemote) + sendData(); + } } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/MechanicalBearingTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/MechanicalBearingTileEntityRenderer.java new file mode 100644 index 000000000..8ecfcb176 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/bearing/MechanicalBearingTileEntityRenderer.java @@ -0,0 +1,38 @@ +package com.simibubi.create.modules.contraptions.receivers.contraptions.bearing; + +import com.simibubi.create.AllBlocks; +import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.utility.SuperByteBuffer; +import com.simibubi.create.modules.contraptions.base.KineticTileEntity; +import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer; + +import net.minecraft.block.BlockState; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.util.Direction; + +public class MechanicalBearingTileEntityRenderer extends KineticTileEntityRenderer { + + @Override + public void renderTileEntityFast(KineticTileEntity te, double x, double y, double z, float partialTicks, + int destroyStage, BufferBuilder buffer) { + super.renderTileEntityFast(te, x, y, z, partialTicks, destroyStage, buffer); + + MechanicalBearingTileEntity bearingTe = (MechanicalBearingTileEntity) te; + final Direction facing = te.getBlockState().get(BlockStateProperties.FACING); + BlockState capState = AllBlocks.MECHANICAL_BEARING_TOP.get().getDefaultState().with(BlockStateProperties.FACING, + facing); + + SuperByteBuffer superBuffer = CreateClient.bufferCache.renderBlockState(KINETIC_TILE, capState); + float interpolatedAngle = bearingTe.getInterpolatedAngle(partialTicks); + kineticRotationTransform(superBuffer, bearingTe, facing.getAxis(), interpolatedAngle, getWorld()); + superBuffer.translate(x, y, z).renderInto(buffer); + } + + @Override + protected BlockState getRenderedBlockState(KineticTileEntity te) { + return AllBlocks.SHAFT_HALF.get().getDefaultState().with(BlockStateProperties.FACING, + te.getBlockState().get(BlockStateProperties.FACING).getOpposite()); + } + +} diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/AbstractChassisBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/AbstractChassisBlock.java similarity index 98% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/AbstractChassisBlock.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/AbstractChassisBlock.java index 1f5159003..8644b0115 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/AbstractChassisBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/AbstractChassisBlock.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs; +package com.simibubi.create.modules.contraptions.receivers.contraptions.chassis; import java.util.List; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/ChassisTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/ChassisTileEntity.java similarity index 95% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/ChassisTileEntity.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/ChassisTileEntity.java index dfa3d0707..ba83c3e7d 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/ChassisTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/ChassisTileEntity.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs; +package com.simibubi.create.modules.contraptions.receivers.contraptions.chassis; import static com.simibubi.create.CreateConfig.parameters; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/ConfigureChassisPacket.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/ConfigureChassisPacket.java similarity index 90% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/ConfigureChassisPacket.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/ConfigureChassisPacket.java index c9425f831..23939a858 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/ConfigureChassisPacket.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/ConfigureChassisPacket.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs; +package com.simibubi.create.modules.contraptions.receivers.contraptions.chassis; import com.simibubi.create.foundation.packet.TileEntityConfigurationPacket; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/LinearChassisBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/LinearChassisBlock.java similarity index 97% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/LinearChassisBlock.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/LinearChassisBlock.java index 5eecafc86..c8c525134 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/LinearChassisBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/LinearChassisBlock.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs; +package com.simibubi.create.modules.contraptions.receivers.contraptions.chassis; import com.google.common.collect.ImmutableList; import com.simibubi.create.AllBlocks; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/RadialChassisBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/RadialChassisBlock.java similarity index 96% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/RadialChassisBlock.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/RadialChassisBlock.java index 38f54cd56..a7d6e4a6f 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/RadialChassisBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/chassis/RadialChassisBlock.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs; +package com.simibubi.create.modules.contraptions.receivers.contraptions.chassis; import com.simibubi.create.foundation.utility.Lang; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/CartAssemblerBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/mounted/CartAssemblerBlock.java similarity index 89% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/CartAssemblerBlock.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/mounted/CartAssemblerBlock.java index b151ab13a..cb3a66bf1 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/CartAssemblerBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/mounted/CartAssemblerBlock.java @@ -1,15 +1,15 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.mounted; +package com.simibubi.create.modules.contraptions.receivers.contraptions.mounted; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.RenderUtilityBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.Contraption; +import com.simibubi.create.modules.contraptions.receivers.contraptions.Contraption; +import com.simibubi.create.modules.contraptions.receivers.contraptions.ContraptionEntity; import net.minecraft.block.AbstractRailBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.material.PushReaction; -import net.minecraft.entity.Entity; import net.minecraft.entity.item.minecart.AbstractMinecartEntity; import net.minecraft.item.BlockItemUseContext; import net.minecraft.state.BooleanProperty; @@ -84,17 +84,8 @@ public class CartAssemblerBlock extends AbstractRailBlock { protected void disassemble(World world, BlockPos pos, AbstractMinecartEntity cart) { if (cart.getPassengers().isEmpty()) return; - Entity entity = cart.getPassengers().get(0); - if (!(entity instanceof ContraptionEntity)) + if (!(cart.getPassengers().get(0) instanceof ContraptionEntity)) return; - Contraption contraption = ((ContraptionEntity) entity).getContraption(); - if (contraption == null) - return; - - contraption.disassemble(world, pos.subtract(contraption.getAnchor()), 0, 0, (targetPos, state) -> { - return targetPos.equals(pos); - }); - cart.removePassengers(); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/MountedContraption.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/mounted/MountedContraption.java similarity index 77% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/MountedContraption.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/mounted/MountedContraption.java index 8ba6f0d33..67e9096f7 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/MountedContraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/mounted/MountedContraption.java @@ -1,15 +1,15 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.mounted; +package com.simibubi.create.modules.contraptions.receivers.contraptions.mounted; -import static com.simibubi.create.modules.contraptions.receivers.constructs.mounted.CartAssemblerBlock.RAIL_SHAPE; +import static com.simibubi.create.modules.contraptions.receivers.contraptions.mounted.CartAssemblerBlock.RAIL_SHAPE; import java.util.List; import org.apache.commons.lang3.tuple.MutablePair; import com.simibubi.create.AllBlocks; -import com.simibubi.create.modules.contraptions.receivers.constructs.Contraption; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MoverType; +import com.simibubi.create.modules.contraptions.receivers.contraptions.Contraption; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MoverType; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -21,6 +21,7 @@ import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraft.world.gen.feature.template.Template.BlockInfo; @@ -45,10 +46,9 @@ public class MountedContraption extends Contraption { null)); for (BlockInfo block : contraption.blocks.values()) { - BlockPos startPos = pos; - if (startPos.equals(block.pos)) + if (BlockPos.ZERO.equals(block.pos)) continue; - world.setBlockState(block.pos, Blocks.AIR.getDefaultState(), 67); + world.setBlockState(block.pos.add(pos), Blocks.AIR.getDefaultState(), 67); } for (MutablePair pair : contraption.getActors()) { @@ -83,4 +83,9 @@ public class MountedContraption extends Contraption { return capture; } + @Override + public void disassemble(IWorld world, BlockPos offset, float yaw, float pitch) { + super.disassemble(world, offset, yaw, pitch, (pos, state) -> AllBlocks.MINECART_ANCHOR.typeOf(state)); + } + } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MechanicalPistonBlock.java similarity index 98% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonBlock.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MechanicalPistonBlock.java index 6dcf88bcb..65514fdaf 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MechanicalPistonBlock.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.piston; +package com.simibubi.create.modules.contraptions.receivers.contraptions.piston; import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateConfig; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonHeadBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MechanicalPistonHeadBlock.java similarity index 95% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonHeadBlock.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MechanicalPistonHeadBlock.java index 549b35823..5a299deb4 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonHeadBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MechanicalPistonHeadBlock.java @@ -1,10 +1,10 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.piston; +package com.simibubi.create.modules.contraptions.receivers.contraptions.piston; import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateConfig; import com.simibubi.create.foundation.block.IWithoutBlockItem; import com.simibubi.create.foundation.block.ProperDirectionalBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonBlock.PistonState; +import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonBlock.PistonState; import net.minecraft.block.Block; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MechanicalPistonTileEntity.java similarity index 90% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonTileEntity.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MechanicalPistonTileEntity.java index 037c452e5..8b73596e3 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MechanicalPistonTileEntity.java @@ -1,28 +1,25 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.piston; +package com.simibubi.create.modules.contraptions.receivers.contraptions.piston; import org.apache.commons.lang3.tuple.MutablePair; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllTileEntities; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MovementContext; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior.MoverType; -import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.ContraptionEntity; -import com.simibubi.create.modules.contraptions.receivers.constructs.mounted.IControlContraption; -import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonBlock.PistonState; +import com.simibubi.create.modules.contraptions.receivers.contraptions.ContraptionEntity; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IControlContraption; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MovementContext; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior.MoverType; +import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonBlock.PistonState; import net.minecraft.block.Blocks; import net.minecraft.nbt.CompoundNBT; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.gen.feature.template.Template.BlockInfo; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; public class MechanicalPistonTileEntity extends KineticTileEntity implements IControlContraption { @@ -52,17 +49,6 @@ public class MechanicalPistonTileEntity extends KineticTileEntity implements ICo super.remove(); } - @Override - public AxisAlignedBB getRenderBoundingBox() { - return INFINITE_EXTENT_AABB; - } - - @Override - @OnlyIn(Dist.CLIENT) - public double getMaxRenderDistanceSquared() { - return super.getMaxRenderDistanceSquared() * 16; - } - @Override public CompoundNBT write(CompoundNBT tag) { tag.putBoolean("Running", running); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MechanicalPistonTileEntityRenderer.java similarity index 92% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonTileEntityRenderer.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MechanicalPistonTileEntityRenderer.java index ef3eb9500..d3c5ab93e 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MechanicalPistonTileEntityRenderer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.piston; +package com.simibubi.create.modules.contraptions.receivers.contraptions.piston; import com.simibubi.create.AllBlocks; import com.simibubi.create.modules.contraptions.base.IRotate; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MovingConstructHandler.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MovingConstructHandler.java similarity index 98% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MovingConstructHandler.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MovingConstructHandler.java index 66d2f4c74..f61d02bbc 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MovingConstructHandler.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/MovingConstructHandler.java @@ -1,3 +1,4 @@ +package com.simibubi.create.modules.contraptions.receivers.contraptions.piston; /*package com.simibubi.create.modules.contraptions.receivers.constructs.piston; import java.util.ArrayList; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/PistonContraption.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/PistonContraption.java similarity index 95% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/PistonContraption.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/PistonContraption.java index 822a60751..c401f2ee8 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/PistonContraption.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/PistonContraption.java @@ -1,4 +1,4 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.piston; +package com.simibubi.create.modules.contraptions.receivers.contraptions.piston; import static com.simibubi.create.AllBlocks.MECHANICAL_PISTON_HEAD; import static com.simibubi.create.AllBlocks.PISTON_POLE; @@ -10,8 +10,8 @@ import java.util.ArrayList; import java.util.List; import com.simibubi.create.AllBlocks; -import com.simibubi.create.modules.contraptions.receivers.constructs.Contraption; -import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonBlock.PistonState; +import com.simibubi.create.modules.contraptions.receivers.contraptions.Contraption; +import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonBlock.PistonState; import net.minecraft.block.BlockState; import net.minecraft.nbt.CompoundNBT; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/PistonPoleBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/PistonPoleBlock.java similarity index 94% rename from src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/PistonPoleBlock.java rename to src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/PistonPoleBlock.java index 5a9cbb1be..fb9858dc3 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/PistonPoleBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/contraptions/piston/PistonPoleBlock.java @@ -1,9 +1,9 @@ -package com.simibubi.create.modules.contraptions.receivers.constructs.piston; +package com.simibubi.create.modules.contraptions.receivers.contraptions.piston; import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateConfig; import com.simibubi.create.foundation.block.ProperDirectionalBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonBlock.PistonState; +import com.simibubi.create.modules.contraptions.receivers.contraptions.piston.MechanicalPistonBlock.PistonState; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/redstone/ContactBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/redstone/ContactBlock.java index 93f076fcd..dba5d5b1c 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/redstone/ContactBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/redstone/ContactBlock.java @@ -4,7 +4,7 @@ import java.util.Random; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.ProperDirectionalBlock; -import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior; +import com.simibubi.create.modules.contraptions.receivers.contraptions.IHaveMovementBehavior; import net.minecraft.block.Block; import net.minecraft.block.BlockState;