From 0bded6533817c963696500b29fa6e366012dc039 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Mon, 18 Nov 2019 11:49:50 +0100 Subject: [PATCH] The Belt is Lava - Belts are now being avoided by pathfinding - Fixed Belt observers not detecting items - Lowered spacing between moved entities - Tweaked initial collision shape for diagonal belts, fixes entities not being picked up at certain spots - Fixed Glass Panes being usable on Belts and Crushing wheels (wall tag) - Fixed Pulley sections not moving entities properly - Fixed belt UVs not updating when textureAtlas changes, addresses #24 --- .../contraptions/CachedBufferReloader.java | 2 ++ .../contraptions/relays/belt/BeltBlock.java | 26 ++++++++++++++++ .../relays/belt/BeltModelAnimator.java | 13 +++++--- .../relays/belt/BeltMovementHandler.java | 6 ++-- .../relays/belt/BeltTileEntityRenderer.java | 1 + .../block/belts/EntityDetectorBlock.java | 31 +++++++++++++++++++ .../data/minecraft/tags/blocks/walls.json | 2 -- 7 files changed, 71 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/CachedBufferReloader.java b/src/main/java/com/simibubi/create/modules/contraptions/CachedBufferReloader.java index 862496802..8b9633f93 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/CachedBufferReloader.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/CachedBufferReloader.java @@ -4,6 +4,7 @@ import com.simibubi.create.foundation.utility.ColoredIndicatorRenderer; import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.modules.contraptions.receivers.constructs.ContraptionRenderer; import com.simibubi.create.modules.contraptions.receivers.constructs.MechanicalBearingTileEntityRenderer; +import com.simibubi.create.modules.contraptions.relays.belt.BeltModelAnimator; import net.minecraft.client.resources.ReloadListener; import net.minecraft.profiler.IProfiler; @@ -22,6 +23,7 @@ public class CachedBufferReloader extends ReloadListener { ContraptionRenderer.invalidateCache(); MechanicalBearingTileEntityRenderer.invalidateCache(); ColoredIndicatorRenderer.invalidateCache(); + BeltModelAnimator.invalidateCache(); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java index 1563cc338..ca3d9c498 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java @@ -17,11 +17,13 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; +import net.minecraft.entity.MobEntity; import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.DyeColor; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUseContext; +import net.minecraft.pathfinding.PathNodeType; import net.minecraft.state.BooleanProperty; import net.minecraft.state.EnumProperty; import net.minecraft.state.IProperty; @@ -38,6 +40,7 @@ import net.minecraft.util.IStringSerializable; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.shapes.IBooleanFunction; import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; @@ -52,6 +55,7 @@ public class BeltBlock extends HorizontalKineticBlock implements IWithoutBlockIt public static final IProperty SLOPE = EnumProperty.create("slope", Slope.class); public static final IProperty PART = EnumProperty.create("part", Part.class); public static final BooleanProperty CASING = BooleanProperty.create("casing"); + private final VoxelShape collisionMask = makeCuboidShape(0, 0, 0, 16, 19, 16); public BeltBlock() { super(Properties.from(Blocks.BROWN_WOOL)); @@ -247,11 +251,33 @@ public class BeltBlock extends HorizontalKineticBlock implements IWithoutBlockIt return true; } + @Override + public PathNodeType getAiPathNodeType(BlockState state, IBlockReader world, BlockPos pos, MobEntity entity) { + return PathNodeType.DANGER_OTHER; + } + @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return VoxelShapes.or(BeltShapes.getShape(state), BeltShapes.getCasingShape(state)); } + @Override + public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, + ISelectionContext context) { + VoxelShape shape = getShape(state, worldIn, pos, context); + BeltTileEntity belt = (BeltTileEntity) worldIn.getTileEntity(pos); + if (belt == null || context.getEntity() == null) + return shape; + BeltTileEntity controller = (BeltTileEntity) worldIn.getTileEntity(belt.getController()); + if (controller == null) + return shape; + if (controller.passengers == null || !controller.passengers.containsKey(context.getEntity())) { + return VoxelShapes.combine(collisionMask, shape, IBooleanFunction.AND); + } + + return shape; + } + @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new BeltTileEntity(); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltModelAnimator.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltModelAnimator.java index 1ff634398..530ddb1ca 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltModelAnimator.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltModelAnimator.java @@ -14,14 +14,12 @@ import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; -class BeltModelAnimator extends BufferManipulator { +public class BeltModelAnimator extends BufferManipulator { protected static TextureAtlasSprite beltTextures; protected static TextureAtlasSprite originalTexture; public BeltModelAnimator(ByteBuffer template) { super(template); - if (beltTextures == null) - initSprites(); } private void initSprites() { @@ -46,6 +44,8 @@ class BeltModelAnimator extends BufferManipulator { if (textureIndex < 0) textureIndex += 16; + if (beltTextures == null) + initSprites(); textureOffsetX = beltTextures.getInterpolatedU((textureIndex % 4) * 4) - originalTexture.getMinU(); textureOffsetY = beltTextures.getInterpolatedV((textureIndex / 4) * 4) - originalTexture.getMinV(); } @@ -61,8 +61,7 @@ class BeltModelAnimator extends BufferManipulator { int r = defaultColor ? 128 : (color >> 16) & 0xFF; for (int vertex = 0; vertex < vertexCount(original); vertex++) { - putPos(mutable, vertex, getX(original, vertex) + x, getY(original, vertex) + y, - getZ(original, vertex) + z); + putPos(mutable, vertex, getX(original, vertex) + x, getY(original, vertex) + y, getZ(original, vertex) + z); putLight(mutable, vertex, packedLightCoords); int bufferPosition = getBufferPosition(vertex); @@ -80,4 +79,8 @@ class BeltModelAnimator extends BufferManipulator { return mutable; } + + public static void invalidateCache() { + beltTextures = null; + } } \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltMovementHandler.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltMovementHandler.java index f62d7ab5a..435dce9f6 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltMovementHandler.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltMovementHandler.java @@ -86,7 +86,7 @@ public class BeltMovementHandler { // Lock entities in place boolean isPlayer = entityIn instanceof PlayerEntity; if (entityIn instanceof LivingEntity && !isPlayer) { - ((LivingEntity) entityIn).addPotionEffect(new EffectInstance(Effects.SLOWNESS, 1, 9, false, false)); + ((LivingEntity) entityIn).addPotionEffect(new EffectInstance(Effects.SLOWNESS, 10, 1, false, false)); } BeltTileEntity belt = (BeltTileEntity) te; @@ -115,7 +115,7 @@ public class BeltMovementHandler { Part part = blockState.get(BeltBlock.PART); float top = 13 / 16f; - boolean onSlope = notHorizontal && (part == Part.MIDDLE + boolean onSlope = notHorizontal && (part == Part.MIDDLE || part == Part.PULLEY || part == (slope == Slope.UPWARD ? Part.END : Part.START) && entityIn.posY - pos.getY() < top || part == (slope == Slope.UPWARD ? Part.START : Part.END) && entityIn.posY - pos.getY() > top); @@ -142,7 +142,7 @@ public class BeltMovementHandler { // Entity Collisions if (Math.abs(movementSpeed) < .5f) { - Vec3d checkDistance = movement.scale(2f).add(movement.normalize()); + Vec3d checkDistance = movement.normalize().scale(0.5); AxisAlignedBB bb = entityIn.getBoundingBox(); AxisAlignedBB checkBB = new AxisAlignedBB(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ); if (!world diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntityRenderer.java index 4013390e2..6ff662825 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntityRenderer.java @@ -150,4 +150,5 @@ public class BeltTileEntityRenderer extends TileEntityRenderer { buffer.putBulkData(((BeltModelAnimator) KineticTileEntityRenderer.cachedBuffers .get(te.getBlockState().with(BeltBlock.CASING, false))).getTransformed(te, x, y, z, te.color)); } + } diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/belts/EntityDetectorBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/belts/EntityDetectorBlock.java index e24eff5d6..94884f53c 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/belts/EntityDetectorBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/belts/EntityDetectorBlock.java @@ -13,6 +13,7 @@ import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.I import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock; import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Part; import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope; +import com.simibubi.create.modules.contraptions.relays.belt.BeltInventory.TransportedItemStack; import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity; import com.simibubi.create.modules.logistics.block.IBlockWithFilter; @@ -180,6 +181,34 @@ public class EntityDetectorBlock extends HorizontalBlock onAttachmentPlaced(worldIn, pos, state); } + @Override + public boolean startProcessingItem(BeltTileEntity te, TransportedItemStack transported, BeltAttachmentState state) { + + state.processingDuration = 0; + withTileEntityDo(te.getWorld(), state.attachmentPos, detectorTE -> { + ItemStack filter = detectorTE.getFilter(); + if (filter.isEmpty()) + return; + + // Todo: Package filters + if (!ItemStack.areItemsEqual(transported.stack, filter)) { + state.processingDuration = -1; + return; + } + }); + + World world = te.getWorld(); + BlockState blockState = world.getBlockState(state.attachmentPos); + if (state.processingDuration == 0) { + world.setBlockState(state.attachmentPos, blockState.with(POWERED, true)); + world.getPendingBlockTicks().scheduleTick(state.attachmentPos, this, 6); + world.notifyNeighborsOfStateChange(state.attachmentPos, this); + return true; + } + + return false; + } + @Override public boolean processEntity(BeltTileEntity te, Entity entity, BeltAttachmentState state) { @@ -193,6 +222,8 @@ public class EntityDetectorBlock extends HorizontalBlock ItemStack filter = detectorTE.getFilter(); if (filter.isEmpty()) return; + + // Todo: Package filters if (!(entity instanceof ItemEntity) || !ItemStack.areItemsEqual(((ItemEntity) entity).getItem(), filter)) { state.processingDuration = -1; diff --git a/src/main/resources/data/minecraft/tags/blocks/walls.json b/src/main/resources/data/minecraft/tags/blocks/walls.json index 87e29446a..c9d6babae 100644 --- a/src/main/resources/data/minecraft/tags/blocks/walls.json +++ b/src/main/resources/data/minecraft/tags/blocks/walls.json @@ -1,8 +1,6 @@ { "replace": false, "values": [ - "create:belt", - "create:crushing_wheel", "create:limestone_wall", "create:limestone_bricks_wall", "create:weathered_limestone_wall",