From c5e783207f58667fad0f37edadc2967347e61c65 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sun, 7 Jun 2020 22:40:27 +0200 Subject: [PATCH] Bug Hunt - Fixed extractors looking for belt inventories too eagerly, adresses #327 - Slightly refactored Extendo Grip handlers - Fixed missing particle texture of Extendo Grips - Fixed crash when assembled minecarts pick up the block below their assembler - Ploughs no longer break blocks if farmland is below them, adresses #345 - Fixed Schematic tools placing lit furnaces, adresses #342 - Super glue can no longer be removed while inbetween two blocks, adresses #341 - Added a safety check in RotationPropagation, addresses #340 --- .../contraptions/RotationPropagator.java | 13 ++++- .../BlockBreakingMovementBehaviour.java | 2 +- .../actors/PloughMovementBehaviour.java | 16 ++++-- .../crafter/MechanicalCrafterTileEntity.java | 29 ++++++---- .../components/crafter/RecipeGridHandler.java | 18 +++--- .../glue/SuperGlueEntity.java | 57 ++++++++++++------- .../glue/SuperGlueRenderer.java | 13 +---- .../mounted/MountedContraption.java | 11 ++-- .../tools/ExtendoGripItemRenderer.java | 11 ++-- .../tools/ExtendoGripRenderHandler.java | 21 ++++--- .../block/extractor/ExtractorTileEntity.java | 6 +- .../content/schematics/SchematicWorld.java | 9 ++- .../create/models/item/extendo_grip/item.json | 2 +- 13 files changed, 119 insertions(+), 89 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/RotationPropagator.java b/src/main/java/com/simibubi/create/content/contraptions/RotationPropagator.java index 006127819..dd1a9350a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/RotationPropagator.java +++ b/src/main/java/com/simibubi/create/content/contraptions/RotationPropagator.java @@ -17,6 +17,7 @@ import com.simibubi.create.content.contraptions.relays.encased.SplitShaftTileEnt import com.simibubi.create.content.contraptions.relays.gearbox.GearboxTileEntity; import com.simibubi.create.foundation.config.AllConfigs; +import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; @@ -40,8 +41,14 @@ public class RotationPropagator { private static float getRotationSpeedModifier(KineticTileEntity from, KineticTileEntity to) { final BlockState stateFrom = from.getBlockState(); final BlockState stateTo = to.getBlockState(); - final IRotate definitionFrom = (IRotate) stateFrom.getBlock(); - final IRotate definitionTo = (IRotate) stateTo.getBlock(); + + Block fromBlock = stateFrom.getBlock(); + Block toBlock = stateTo.getBlock(); + if (!(fromBlock instanceof IRotate && toBlock instanceof IRotate)) + return 0; + + final IRotate definitionFrom = (IRotate) fromBlock; + final IRotate definitionTo = (IRotate) toBlock; final BlockPos diff = to.getPos() .subtract(from.getPos()); final Direction direction = Direction.getFacingFromVector(diff.getX(), diff.getY(), diff.getZ()); @@ -75,7 +82,7 @@ public class RotationPropagator { } // Attached Encased Belts - if (stateFrom.getBlock() instanceof EncasedBeltBlock && stateTo.getBlock() instanceof EncasedBeltBlock) { + if (fromBlock instanceof EncasedBeltBlock && toBlock instanceof EncasedBeltBlock) { boolean connected = EncasedBeltBlock.areBlocksConnected(stateFrom, stateTo, direction); return connected ? EncasedBeltBlock.getRotationSpeedModifier(from, to) : 0; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/BlockBreakingMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/BlockBreakingMovementBehaviour.java index 67d6b00c1..d562d43c9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/BlockBreakingMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/BlockBreakingMovementBehaviour.java @@ -155,9 +155,9 @@ public class BlockBreakingMovementBehaviour extends MovementBehaviour { data.remove("Progress"); data.remove("TicksUntilNextProgress"); data.remove("BreakingPos"); - context.stall = false; world.sendBlockBreakProgress(id, breakingPos, -1); } + context.stall = false; return; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PloughMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PloughMovementBehaviour.java index 4f02e6b4b..6f5216b79 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PloughMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PloughMovementBehaviour.java @@ -7,6 +7,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.BlockState; +import net.minecraft.block.FarmlandBlock; import net.minecraft.block.FlowingFluidBlock; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUseContext; @@ -26,8 +27,8 @@ public class PloughMovementBehaviour extends BlockBreakingMovementBehaviour { @Override public boolean isActive(MovementContext context) { - return !VecHelper - .isVecPointingTowards(context.relativeMotion, context.state.get(HORIZONTAL_FACING).getOpposite()); + return !VecHelper.isVecPointingTowards(context.relativeMotion, context.state.get(HORIZONTAL_FACING) + .getOpposite()); } @Override @@ -47,7 +48,7 @@ public class PloughMovementBehaviour extends BlockBreakingMovementBehaviour { return; BlockRayTraceResult ray = world - .rayTraceBlocks(new RayTraceContext(vec, vec.add(0, -1, 0), BlockMode.OUTLINE, FluidMode.NONE, player)); + .rayTraceBlocks(new RayTraceContext(vec, vec.add(0, -1, 0), BlockMode.OUTLINE, FluidMode.NONE, player)); if (ray == null || ray.getType() != Type.BLOCK) return; @@ -57,7 +58,8 @@ public class PloughMovementBehaviour extends BlockBreakingMovementBehaviour { @Override public Vec3d getActiveAreaOffset(MovementContext context) { - return new Vec3d(context.state.get(HORIZONTAL_FACING).getDirectionVec()).scale(.45); + return new Vec3d(context.state.get(HORIZONTAL_FACING) + .getDirectionVec()).scale(.45); } @Override @@ -67,8 +69,10 @@ public class PloughMovementBehaviour extends BlockBreakingMovementBehaviour { @Override public boolean canBreak(World world, BlockPos breakingPos, BlockState state) { - return state.getCollisionShape(world, breakingPos).isEmpty() - && !(state.getBlock() instanceof FlowingFluidBlock); + return state.getCollisionShape(world, breakingPos) + .isEmpty() && !(state.getBlock() instanceof FlowingFluidBlock) + && !(world.getBlockState(breakingPos.down()) + .getBlock() instanceof FarmlandBlock); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterTileEntity.java index 65e0cd38d..69a60b9b8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterTileEntity.java @@ -63,8 +63,6 @@ public class MechanicalCrafterTileEntity extends KineticTileEntity { return stack; return super.insertItem(slot, stack, simulate); }; - - protected void onContentsChanged(int slot) { if (!getStackInSlot(slot).isEmpty() && phase == Phase.IDLE) @@ -82,7 +80,7 @@ public class MechanicalCrafterTileEntity extends KineticTileEntity { protected Phase phase; protected int countDown; protected boolean covered; - private boolean wasPoweredBefore = true; + protected boolean wasPoweredBefore; protected GroupedItems groupedItemsBeforeCraft; // for rendering on client private InsertingBehaviour inserting; @@ -93,6 +91,9 @@ public class MechanicalCrafterTileEntity extends KineticTileEntity { setLazyTickRate(20); phase = Phase.IDLE; groupedItemsBeforeCraft = new GroupedItems(); + + // Does not get serialized due to active checking in tick + wasPoweredBefore = true; } @Override @@ -201,15 +202,15 @@ public class MechanicalCrafterTileEntity extends KineticTileEntity { } @Override - public void tick() { + public void tick() { super.tick(); if (phase == Phase.ACCEPTING) return; - - if(wasPoweredBefore != world.isBlockPowered(pos)) { + + if (wasPoweredBefore != world.isBlockPowered(pos)) { wasPoweredBefore = world.isBlockPowered(pos); - if(wasPoweredBefore) { + if (wasPoweredBefore) { if (world.isRemote) return; checkCompletedRecipe(true); @@ -422,11 +423,13 @@ public class MechanicalCrafterTileEntity extends KineticTileEntity { } public boolean craftingItemPresent() { - return !inventory.getStackInSlot(0).isEmpty(); + return !inventory.getStackInSlot(0) + .isEmpty(); } - + public boolean craftingItemOrCoverPresent() { - return !inventory.getStackInSlot(0).isEmpty() || covered; + return !inventory.getStackInSlot(0) + .isEmpty() || covered; } protected void checkCompletedRecipe(boolean poweredStart) { @@ -434,8 +437,10 @@ public class MechanicalCrafterTileEntity extends KineticTileEntity { return; if (world.isRemote) return; - List chain = - RecipeGridHandler.getAllCraftersOfChainIf(this, poweredStart ? MechanicalCrafterTileEntity::craftingItemPresent : MechanicalCrafterTileEntity::craftingItemOrCoverPresent, poweredStart); + List chain = RecipeGridHandler.getAllCraftersOfChainIf(this, + poweredStart ? MechanicalCrafterTileEntity::craftingItemPresent + : MechanicalCrafterTileEntity::craftingItemOrCoverPresent, + poweredStart); if (chain == null) return; chain.forEach(MechanicalCrafterTileEntity::begin); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/RecipeGridHandler.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/RecipeGridHandler.java index 185b51b34..775f21d05 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/RecipeGridHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/RecipeGridHandler.java @@ -33,12 +33,11 @@ public class RecipeGridHandler { public static List getAllCraftersOfChain(MechanicalCrafterTileEntity root) { return getAllCraftersOfChainIf(root, Predicates.alwaysTrue()); } - + public static List getAllCraftersOfChainIf(MechanicalCrafterTileEntity root, - Predicate test){ + Predicate test) { return getAllCraftersOfChainIf(root, test, false); } - public static List getAllCraftersOfChainIf(MechanicalCrafterTileEntity root, Predicate test, boolean poweredStart) { @@ -46,7 +45,7 @@ public class RecipeGridHandler { List> frontier = new ArrayList<>(); Set visited = new HashSet<>(); frontier.add(Pair.of(root, null)); - + boolean powered = false; boolean empty = false; boolean allEmpty = true; @@ -58,13 +57,14 @@ public class RecipeGridHandler { if (visited.contains(current)) return null; - if(!(test.test(current))) + if (!(test.test(current))) empty = true; else allEmpty = false; - if(poweredStart && current.getWorld().isBlockPowered(current.getPos())) - powered = true; - + if (poweredStart && current.getWorld() + .isBlockPowered(current.getPos())) + powered = true; + crafters.add(current); visited.add(current); @@ -76,7 +76,7 @@ public class RecipeGridHandler { frontier.add(Pair.of(preceding, current)); } - return empty && ! powered || allEmpty ? null : crafters; + return empty && !powered || allEmpty ? null : crafters; } public static MechanicalCrafterTileEntity getTargetingCrafter(MechanicalCrafterTileEntity crafter) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java index aedad7870..27b3a6cdc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java @@ -69,8 +69,7 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat } @Override - protected void registerData() { - } + protected void registerData() {} public int getWidthPixels() { return 12; @@ -84,7 +83,7 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat playSound(SoundEvents.ENTITY_SLIME_SQUISH_SMALL, 1.0F, 1.0F); if (onValidSurface()) { AllPackets.channel.send(PacketDistributor.TRACKING_ENTITY.with(() -> this), - new GlueEffectPacket(getHangingPosition(), getFacingDirection().getOpposite(), false)); + new GlueEffectPacket(getHangingPosition(), getFacingDirection().getOpposite(), false)); playSound(AllSoundEvents.SLIME_ADDED.get(), 0.5F, 0.5F); } } @@ -95,11 +94,13 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat protected void updateFacingWithBoundingBox() { Validate.notNull(getFacingDirection()); - if (getFacingDirection().getAxis().isHorizontal()) { + if (getFacingDirection().getAxis() + .isHorizontal()) { this.rotationPitch = 0.0F; this.rotationYaw = getFacingDirection().getHorizontalIndex() * 90; } else { - this.rotationPitch = -90 * getFacingDirection().getAxisDirection().getOffset(); + this.rotationPitch = -90 * getFacingDirection().getAxisDirection() + .getOffset(); this.rotationYaw = 0.0F; } @@ -118,7 +119,8 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat double w = getWidthPixels(); double h = getHeightPixels(); double l = getWidthPixels(); - Axis axis = this.getFacingDirection().getAxis(); + Axis axis = this.getFacingDirection() + .getAxis(); double depth = 2 - 1 / 128f; switch (axis) { @@ -151,14 +153,25 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat } + public boolean isVisible() { + if (!isAlive()) + return false; + BlockPos pos = hangingPosition; + BlockPos pos2 = pos.offset(getFacingDirection().getOpposite()); + return isValidFace(world, pos2, getFacingDirection()) != isValidFace(world, pos, + getFacingDirection().getOpposite()); + } + public boolean onValidSurface() { BlockPos pos = hangingPosition; BlockPos pos2 = hangingPosition.offset(getFacingDirection().getOpposite()); if (!world.isAreaLoaded(pos, 0) || !world.isAreaLoaded(pos2, 0)) return true; - if (!isValidFace(world, pos2, getFacingDirection()) && !isValidFace(world, pos, getFacingDirection().getOpposite())) + if (!isValidFace(world, pos2, getFacingDirection()) + && !isValidFace(world, pos, getFacingDirection().getOpposite())) return false; - return world.getEntitiesInAABBexcluding(this, getBoundingBox(), e -> e instanceof SuperGlueEntity).isEmpty(); + return world.getEntitiesInAABBexcluding(this, getBoundingBox(), e -> e instanceof SuperGlueEntity) + .isEmpty(); } public static boolean isValidFace(World world, BlockPos pos, Direction direction) { @@ -180,8 +193,8 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat @Override public boolean hitByEntity(Entity entity) { return entity instanceof PlayerEntity - ? attackEntityFrom(DamageSource.causePlayerDamage((PlayerEntity) entity), 0) - : false; + ? attackEntityFrom(DamageSource.causePlayerDamage((PlayerEntity) entity), 0) + : false; } @Override @@ -193,7 +206,7 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat public boolean attackEntityFrom(DamageSource source, float amount) { if (this.isInvulnerableTo(source)) return false; - if (isAlive() && !world.isRemote) { + if (isAlive() && !world.isRemote && isVisible()) { remove(); markVelocityChanged(); onBroken(source.getTrueSource()); @@ -253,11 +266,11 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat ItemStack itemstack = cPlayer.getHeldItem(handIn); int countBefore = itemstack.getCount(); ActionResultType actionResultType = mc.playerController.func_217292_a(cPlayer, - (ClientWorld) cPlayer.world, handIn, (BlockRayTraceResult) ray); + (ClientWorld) cPlayer.world, handIn, (BlockRayTraceResult) ray); if (actionResultType == ActionResultType.SUCCESS) { cPlayer.swingArm(handIn); if (!itemstack.isEmpty() - && (itemstack.getCount() != countBefore || mc.playerController.isInCreativeMode())) + && (itemstack.getCount() != countBefore || mc.playerController.isInCreativeMode())) mc.gameRenderer.itemRenderer.resetEquippedProgress(handIn); return; } @@ -268,7 +281,8 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat @Override public void writeAdditional(CompoundNBT compound) { - compound.putByte("Facing", (byte) this.getFacingDirection().getIndex()); + compound.putByte("Facing", (byte) this.getFacingDirection() + .getIndex()); BlockPos blockpos = this.getHangingPosition(); compound.putInt("TileX", blockpos.getX()); compound.putInt("TileY", blockpos.getY()); @@ -285,8 +299,10 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat @Override public ItemEntity entityDropItem(ItemStack stack, float yOffset) { - float xOffset = (float) this.getFacingDirection().getXOffset() * 0.15F; - float zOffset = (float) this.getFacingDirection().getZOffset() * 0.15F; + float xOffset = (float) this.getFacingDirection() + .getXOffset() * 0.15F; + float zOffset = (float) this.getFacingDirection() + .getZOffset() * 0.15F; ItemEntity itementity = new ItemEntity(this.world, this.getX() + xOffset, this.getY() + yOffset, this.getZ() + zOffset, stack); itementity.setDefaultPickupDelay(); @@ -308,7 +324,8 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat @Override public float getRotatedYaw(Rotation transformRotation) { - if (this.getFacingDirection().getAxis() != Direction.Axis.Y) { + if (this.getFacingDirection() + .getAxis() != Direction.Axis.Y) { switch (transformRotation) { case CLOCKWISE_180: facingDirection = facingDirection.getOpposite(); @@ -350,12 +367,10 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat } @Override - public void onStruckByLightning(LightningBoltEntity lightningBolt) { - } + public void onStruckByLightning(LightningBoltEntity lightningBolt) {} @Override - public void recalculateSize() { - } + public void recalculateSize() {} public static EntityType.Builder build(EntityType.Builder builder) { @SuppressWarnings("unchecked") diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueRenderer.java index eb7ca86cc..097daf419 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueRenderer.java @@ -51,7 +51,7 @@ public class SuperGlueRenderer extends EntityRenderer { super.render(entity, p_225623_2_, p_225623_3_, ms, buffer, light); PlayerEntity player = Minecraft.getInstance().player; - boolean visible = isVisible(entity); + boolean visible = entity.isVisible(); boolean holdingGlue = AllItems.SUPER_GLUE.isIn(player.getHeldItemMainhand()) || AllItems.SUPER_GLUE.isIn(player.getHeldItemOffhand()); @@ -83,17 +83,6 @@ public class SuperGlueRenderer extends EntityRenderer { ms.pop(); } - private boolean isVisible(SuperGlueEntity entity) { - if (!entity.isAlive()) - return false; - BlockPos pos = entity.hangingPosition; - BlockPos pos2 = pos.offset(entity.getFacingDirection() - .getOpposite()); - return SuperGlueEntity.isValidFace(entity.world, pos2, entity.getFacingDirection()) != SuperGlueEntity - .isValidFace(entity.world, pos, entity.getFacingDirection() - .getOpposite()); - } - private void initQuads() { Vec3d diff = new Vec3d(Direction.SOUTH.getDirectionVec()); Vec3d extension = diff.normalize() diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java index 66c619a54..6aa84ae26 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java @@ -29,6 +29,10 @@ public class MountedContraption extends Contraption { public CartMovementMode rotationMode; + public MountedContraption() { + rotationMode = CartMovementMode.ROTATE; + } + @Override protected AllContraptionTypes getType() { return AllContraptionTypes.MOUNTED; @@ -47,9 +51,8 @@ public class MountedContraption extends Contraption { return null; Axis axis = state.get(RAIL_SHAPE) == RailShape.EAST_WEST ? Axis.X : Axis.Z; - contraption.add(pos, Pair.of(new BlockInfo(pos, - AllBlocks.MINECART_ANCHOR.getDefaultState().with(BlockStateProperties.HORIZONTAL_AXIS, axis), - null), null)); + contraption.add(pos, Pair.of(new BlockInfo(pos, AllBlocks.MINECART_ANCHOR.getDefaultState() + .with(BlockStateProperties.HORIZONTAL_AXIS, axis), null), null)); contraption.removeBlocksFromWorld(world, BlockPos.ZERO); contraption.initActors(world); contraption.expandBoundsAroundAxis(Axis.Y); @@ -70,7 +73,7 @@ public class MountedContraption extends Contraption { BlockInfo capture = pair.getKey(); if (AllBlocks.CART_ASSEMBLER.has(capture.state)) return Pair.of(new BlockInfo(capture.pos, CartAssemblerBlock.createAnchor(capture.state), null), - pair.getValue()); + pair.getValue()); return pair; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java index b883c717e..3788d6000 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/ExtendoGripItemRenderer.java @@ -16,6 +16,9 @@ import net.minecraft.util.math.Vec3d; public class ExtendoGripItemRenderer extends CustomRenderedItemModelRenderer { + private static final Vec3d rotationOffset = new Vec3d(0, 1 / 2f, 1 / 2f); + private static final Vec3d cogRotationOffset = new Vec3d(0, 1 / 16f, 0); + @Override protected void render(ItemStack stack, ExtendoGripModel model, PartialItemModelRenderer renderer, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { @@ -30,8 +33,6 @@ public class ExtendoGripItemRenderer extends CustomRenderedItemModelRenderer