From 2a56bb76be90c162596ca39cf0146847a777a063 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Thu, 3 Dec 2020 23:49:12 +0100 Subject: [PATCH] Casing case closed, Part II - Encasing fluid pipes now locks their configuration - Encased fluid pipes now join textures with adjacent casing blocks - Fixed windowed pipe not allowing to be encased - Fixed wrapped models not passing down model data in multi layered situations --- src/generated/resources/.cache/cache | 3 +- .../blockstates/encased_fluid_pipe.json | 117 ++++++++++++++++-- .../models/block/encased_fluid_pipe.json | 7 -- .../java/com/simibubi/create/AllBlocks.java | 7 +- .../com/simibubi/create/AllTileEntities.java | 4 +- .../fluids/FluidPipeAttachmentBehaviour.java | 4 + .../fluids/PipeAttachmentModel.java | 10 +- .../fluids/pipes/AxisPipeBlock.java | 20 ++- .../fluids/pipes/EncasedPipeBlock.java | 116 +++++++++++++++-- .../fluids/pipes/FluidPipeBlock.java | 9 +- .../fluids/pipes/FluidPipeTileEntity.java | 7 +- .../fluids/tank/FluidTankModel.java | 8 +- .../relays/encased/EncasedShaftBlock.java | 3 +- .../connected/BakedModelWrapperWithData.java | 29 +++++ .../foundation/block/connected/CTModel.java | 14 +-- .../block/render/CustomBlockModels.java | 17 ++- .../create/foundation/data/BlockStateGen.java | 21 ++++ .../block/encased_fluid_pipe/block_flat.json | 16 +++ .../block/encased_fluid_pipe/block_open.json | 16 +++ 19 files changed, 361 insertions(+), 67 deletions(-) delete mode 100644 src/generated/resources/assets/create/models/block/encased_fluid_pipe.json create mode 100644 src/main/java/com/simibubi/create/foundation/block/connected/BakedModelWrapperWithData.java create mode 100644 src/main/resources/assets/create/models/block/encased_fluid_pipe/block_flat.json create mode 100644 src/main/resources/assets/create/models/block/encased_fluid_pipe/block_open.json diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 7a8b08638..26114f7a6 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -103,7 +103,7 @@ f63a5816d4bfe643aa098d03c3b54462dd06fe19 assets/create/blockstates/dolomite_cobb f179202e59e449157f89efc37229b03bbfd391d7 assets/create/blockstates/dolomite_pillar.json 7b1c40891b07c8f3238537625d9e25c8627e7333 assets/create/blockstates/encased_belt.json 7b2b836649e729feafa60972bf95e3afb2143131 assets/create/blockstates/encased_fan.json -656813b75dd3b901bf34f24df785e4b0fbe11aa6 assets/create/blockstates/encased_fluid_pipe.json +d13940ed213d7acbc6ebe3bdd21175ef89e4d613 assets/create/blockstates/encased_fluid_pipe.json a774e815376a67e2a2de44e39af0a1a0b4406932 assets/create/blockstates/fancy_andesite_bricks.json 180be26a75834cf9cdb881f969f77906e91cc36a assets/create/blockstates/fancy_andesite_bricks_slab.json d5d7762b80952052d0a7adf3081967cac3f3ba6c assets/create/blockstates/fancy_andesite_bricks_stairs.json @@ -613,7 +613,6 @@ cc6d9300cd26f2323c653dbcc61b7a885be8fa3b assets/create/models/block/dolomite_cob a101974d906487326dc38916f828d12a278a49ae assets/create/models/block/dolomite_cobblestone_wall_post.json 9c497140dfe73abe1964479eaf1af8f1892de290 assets/create/models/block/dolomite_cobblestone_wall_side.json 999a7cd79a9dc80c47fd6103b65f006b55187402 assets/create/models/block/dolomite_pillar.json -1a8bac1e97a2a6c3cc362081568d2a7fce815ad5 assets/create/models/block/encased_fluid_pipe.json 17dae5fdc1a551d8ab1ab8a68cabf7a8c3848d86 assets/create/models/block/fancy_andesite_bricks.json cfb2cd84a1cbd9226a77ebc1f6c29e8eaa9c577f assets/create/models/block/fancy_andesite_bricks_slab.json 8ee27601996ab577991b6a0f7e9df27db0282cad assets/create/models/block/fancy_andesite_bricks_slab_top.json diff --git a/src/generated/resources/assets/create/blockstates/encased_fluid_pipe.json b/src/generated/resources/assets/create/blockstates/encased_fluid_pipe.json index 129e39baa..dc11492f3 100644 --- a/src/generated/resources/assets/create/blockstates/encased_fluid_pipe.json +++ b/src/generated/resources/assets/create/blockstates/encased_fluid_pipe.json @@ -1,17 +1,110 @@ { - "variants": { - "axis=x": { - "model": "create:block/encased_fluid_pipe", - "x": 90, - "y": 90 + "multipart": [ + { + "when": { + "down": "false" + }, + "apply": { + "model": "create:block/encased_fluid_pipe/block_flat", + "x": -90 + } }, - "axis=y": { - "model": "create:block/encased_fluid_pipe" + { + "when": { + "up": "false" + }, + "apply": { + "model": "create:block/encased_fluid_pipe/block_flat", + "x": 90 + } }, - "axis=z": { - "model": "create:block/encased_fluid_pipe", - "x": 90, - "y": 180 + { + "when": { + "north": "false" + }, + "apply": { + "model": "create:block/encased_fluid_pipe/block_flat", + "y": 180 + } + }, + { + "when": { + "south": "false" + }, + "apply": { + "model": "create:block/encased_fluid_pipe/block_flat" + } + }, + { + "when": { + "west": "false" + }, + "apply": { + "model": "create:block/encased_fluid_pipe/block_flat", + "y": 90 + } + }, + { + "when": { + "east": "false" + }, + "apply": { + "model": "create:block/encased_fluid_pipe/block_flat", + "y": 270 + } + }, + { + "when": { + "down": "true" + }, + "apply": { + "model": "create:block/encased_fluid_pipe/block_open", + "x": -90 + } + }, + { + "when": { + "up": "true" + }, + "apply": { + "model": "create:block/encased_fluid_pipe/block_open", + "x": 90 + } + }, + { + "when": { + "north": "true" + }, + "apply": { + "model": "create:block/encased_fluid_pipe/block_open", + "y": 180 + } + }, + { + "when": { + "south": "true" + }, + "apply": { + "model": "create:block/encased_fluid_pipe/block_open" + } + }, + { + "when": { + "west": "true" + }, + "apply": { + "model": "create:block/encased_fluid_pipe/block_open", + "y": 90 + } + }, + { + "when": { + "east": "true" + }, + "apply": { + "model": "create:block/encased_fluid_pipe/block_open", + "y": 270 + } } - } + ] } \ No newline at end of file diff --git a/src/generated/resources/assets/create/models/block/encased_fluid_pipe.json b/src/generated/resources/assets/create/models/block/encased_fluid_pipe.json deleted file mode 100644 index a8aad1994..000000000 --- a/src/generated/resources/assets/create/models/block/encased_fluid_pipe.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "parent": "block/cube_column", - "textures": { - "side": "create:block/copper_casing", - "end": "create:block/encased_pipe" - } -} \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index 7d35cd70b..d53d27bcc 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -519,8 +519,11 @@ public class AllBlocks { public static final BlockEntry ENCASED_FLUID_PIPE = REGISTRATE.block("encased_fluid_pipe", EncasedPipeBlock::new) .initialProperties(SharedProperties::softMetal) - .blockstate((c, p) -> BlockStateGen.axisBlock(c, p, state -> p.models() - .cubeColumn(c.getName(), p.modLoc("block/copper_casing"), p.modLoc("block/encased_pipe")))) + .properties(Block.Properties::nonOpaque) + .blockstate(BlockStateGen.encasedPipe()) + .onRegister(CreateRegistrate.connectedTextures(new EncasedCTBehaviour(AllSpriteShifts.COPPER_CASING))) + .onRegister(CreateRegistrate.casingConnectivity((block, cc) -> cc.make(block, AllSpriteShifts.COPPER_CASING, + (s, f) -> !s.get(EncasedPipeBlock.FACING_TO_PROPERTY_MAP.get(f))))) .onRegister(CreateRegistrate.blockModel(() -> PipeAttachmentModel::new)) .loot((p, b) -> p.registerDropping(b, FLUID_PIPE.get())) .register(); diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 3a92ad6fb..2d6f2513c 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -219,8 +219,8 @@ public class AllTileEntities { .validBlocks(AllBlocks.FLUID_PIPE) .register(); - public static final TileEntityEntry ENCASED_FLUID_PIPE = Create.registrate() - .tileEntity("encased_fluid_pipe", StraightPipeTileEntity::new) + public static final TileEntityEntry ENCASED_FLUID_PIPE = Create.registrate() + .tileEntity("encased_fluid_pipe", FluidPipeTileEntity::new) .validBlocks(AllBlocks.ENCASED_FLUID_PIPE) .register(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidPipeAttachmentBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidPipeAttachmentBehaviour.java index cdd3ef3d9..51d064588 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidPipeAttachmentBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidPipeAttachmentBehaviour.java @@ -26,6 +26,10 @@ public class FluidPipeAttachmentBehaviour extends BracketedTileEntityBehaviour { .getAxis() == direction.getAxis()) return AttachmentTypes.NONE; + if (AllBlocks.ENCASED_FLUID_PIPE.has(facingState) + && facingState.get(EncasedPipeBlock.FACING_TO_PROPERTY_MAP.get(direction.getOpposite()))) + return AttachmentTypes.NONE; + if (FluidPropagator.hasFluidCapability(facingState, world, offsetPos, direction) && !AllBlocks.HOSE_PULLEY.has(facingState)) return AttachmentTypes.DRAIN; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeAttachmentModel.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeAttachmentModel.java index b05ce97ac..1e7834771 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeAttachmentModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeAttachmentModel.java @@ -8,7 +8,7 @@ import java.util.Random; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.fluids.FluidPipeAttachmentBehaviour.AttachmentTypes; import com.simibubi.create.content.contraptions.fluids.pipes.FluidPipeBlock; -import com.simibubi.create.foundation.block.render.WrappedBakedModel; +import com.simibubi.create.foundation.block.connected.BakedModelWrapperWithData; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.Iterate; @@ -21,9 +21,10 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.ILightReader; import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.data.ModelDataMap; +import net.minecraftforge.client.model.data.ModelDataMap.Builder; import net.minecraftforge.client.model.data.ModelProperty; -public class PipeAttachmentModel extends WrappedBakedModel { +public class PipeAttachmentModel extends BakedModelWrapperWithData { private static ModelProperty PIPE_PROPERTY = new ModelProperty<>(); @@ -32,7 +33,7 @@ public class PipeAttachmentModel extends WrappedBakedModel { } @Override - public IModelData getModelData(ILightReader world, BlockPos pos, BlockState state, IModelData tileData) { + protected Builder gatherModelData(Builder builder, ILightReader world, BlockPos pos, BlockState state) { PipeModelData data = new PipeModelData(); FluidPipeAttachmentBehaviour attachmentBehaviour = TileEntityBehaviour.get(world, pos, FluidPipeAttachmentBehaviour.TYPE); @@ -44,8 +45,7 @@ public class PipeAttachmentModel extends WrappedBakedModel { } data.setEncased(FluidPipeBlock.shouldDrawCasing(world, pos, state)); - return new ModelDataMap.Builder().withInitial(PIPE_PROPERTY, data) - .build(); + return builder.withInitial(PIPE_PROPERTY, data); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/AxisPipeBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/AxisPipeBlock.java index 751ff1de4..a3570ee9a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/AxisPipeBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/AxisPipeBlock.java @@ -10,6 +10,7 @@ import com.simibubi.create.content.contraptions.fluids.FluidPipeAttachmentBehavi import com.simibubi.create.content.contraptions.fluids.FluidPropagator; import com.simibubi.create.content.contraptions.wrench.IWrenchableWithBracket; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; +import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -19,10 +20,13 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.network.DebugPacketSender; import net.minecraft.state.BooleanProperty; +import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; +import net.minecraft.util.Hand; import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; @@ -43,12 +47,26 @@ public class AxisPipeBlock extends RotatedPillarBlock implements IWrenchableWith boolean blockTypeChanged = state.getBlock() != newState.getBlock(); if (blockTypeChanged && !world.isRemote) FluidPropagator.propagateChangedPipe(world, pos, state); - if (state != newState && !isMoving) + if (state != newState && !isMoving) removeBracket(world, pos).ifPresent(stack -> Block.spawnAsEntity(world, pos, stack)); if (state.hasTileEntity() && (blockTypeChanged || !newState.hasTileEntity())) world.removeTileEntity(pos); } + @Override + public ActionResultType onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, + BlockRayTraceResult hit) { + if (!AllBlocks.COPPER_CASING.isIn(player.getHeldItem(hand))) + return ActionResultType.PASS; + if (!world.isRemote) { + BlockState newState = AllBlocks.ENCASED_FLUID_PIPE.getDefaultState(); + for (Direction d : Iterate.directionsInAxis(getAxis(state))) + newState = newState.with(EncasedPipeBlock.FACING_TO_PROPERTY_MAP.get(d), true); + world.setBlockState(pos, newState); + } + return ActionResultType.SUCCESS; + } + @Override public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean isMoving) { if (world.isRemote) diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/EncasedPipeBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/EncasedPipeBlock.java index 6d236427c..f74484b10 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/EncasedPipeBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/EncasedPipeBlock.java @@ -1,22 +1,58 @@ package com.simibubi.create.content.contraptions.fluids.pipes; -import com.simibubi.create.AllTileEntities; +import static net.minecraft.state.properties.BlockStateProperties.DOWN; +import static net.minecraft.state.properties.BlockStateProperties.EAST; +import static net.minecraft.state.properties.BlockStateProperties.NORTH; +import static net.minecraft.state.properties.BlockStateProperties.SOUTH; +import static net.minecraft.state.properties.BlockStateProperties.UP; +import static net.minecraft.state.properties.BlockStateProperties.WEST; +import java.util.Map; +import java.util.Random; + +import com.simibubi.create.AllBlocks; +import com.simibubi.create.AllTileEntities; +import com.simibubi.create.content.contraptions.fluids.FluidPropagator; +import com.simibubi.create.content.contraptions.wrench.IWrenchable; +import com.simibubi.create.foundation.utility.Iterate; + +import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.block.SixWayBlock; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUseContext; +import net.minecraft.network.DebugPacketSender; +import net.minecraft.state.BooleanProperty; +import net.minecraft.state.StateContainer.Builder; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResultType; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.shapes.ISelectionContext; -import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.util.math.shapes.VoxelShapes; +import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.IBlockReader; +import net.minecraft.world.TickPriority; import net.minecraft.world.World; +import net.minecraft.world.server.ServerWorld; -public class EncasedPipeBlock extends AxisPipeBlock { +public class EncasedPipeBlock extends Block implements IWrenchable { + + public static final Map FACING_TO_PROPERTY_MAP = SixWayBlock.FACING_TO_PROPERTY_MAP; public EncasedPipeBlock(Properties p_i48339_1_) { super(p_i48339_1_); + setDefaultState(getDefaultState().with(NORTH, false) + .with(SOUTH, false) + .with(DOWN, false) + .with(UP, false) + .with(WEST, false) + .with(EAST, false)); + } + + @Override + protected void fillStateContainer(Builder builder) { + builder.add(NORTH, EAST, SOUTH, WEST, UP, DOWN); + super.fillStateContainer(builder); } @Override @@ -25,22 +61,80 @@ public class EncasedPipeBlock extends AxisPipeBlock { } @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { - return AllTileEntities.ENCASED_FLUID_PIPE.create(); + public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) { + boolean blockTypeChanged = state.getBlock() != newState.getBlock(); + if (blockTypeChanged && !world.isRemote) + FluidPropagator.propagateChangedPipe(world, pos, state); + if (state.hasTileEntity() && (blockTypeChanged || !newState.hasTileEntity())) + world.removeTileEntity(pos); } @Override - public VoxelShape getShape(BlockState state, IBlockReader p_220053_2_, BlockPos p_220053_3_, - ISelectionContext p_220053_4_) { - return VoxelShapes.fullCube(); + public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean isMoving) { + if (!world.isRemote && state != oldState) + world.getPendingBlockTicks() + .scheduleTick(pos, this, 1, TickPriority.HIGH); + } + + @Override + public ItemStack getPickBlock(BlockState state, RayTraceResult target, IBlockReader world, BlockPos pos, + PlayerEntity player) { + return AllBlocks.FLUID_PIPE.asStack(); + } + + @Override + public void neighborChanged(BlockState state, World world, BlockPos pos, Block otherBlock, BlockPos neighborPos, + boolean isMoving) { + DebugPacketSender.func_218806_a(world, pos); + Direction d = FluidPropagator.validateNeighbourChange(state, world, pos, otherBlock, neighborPos, isMoving); + if (d == null) + return; + if (!state.get(FACING_TO_PROPERTY_MAP.get(d))) + return; + world.getPendingBlockTicks() + .scheduleTick(pos, this, 1, TickPriority.HIGH); + } + + @Override + public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random r) { + FluidPropagator.propagateChangedPipe(world, pos, state); + } + + @Override + public TileEntity createTileEntity(BlockState state, IBlockReader world) { + return AllTileEntities.ENCASED_FLUID_PIPE.create(); } @Override public ActionResultType onWrenched(BlockState state, ItemUseContext context) { World world = context.getWorld(); BlockPos pos = context.getPos(); - world.setBlockState(pos, toRegularPipe(world, pos, state), 3); + + if (world.isRemote) + return ActionResultType.SUCCESS; + + context.getWorld() + .playEvent(2001, context.getPos(), Block.getStateId(state)); + BlockState equivalentPipe = transferSixWayProperties(state, AllBlocks.FLUID_PIPE.getDefaultState()); + + Direction firstFound = Direction.UP; + for (Direction d : Iterate.directions) + if (state.get(FACING_TO_PROPERTY_MAP.get(d))) { + firstFound = d; + break; + } + + world.setBlockState(pos, AllBlocks.FLUID_PIPE.get() + .updateBlockState(equivalentPipe, firstFound, null, world, pos)); return ActionResultType.SUCCESS; } + public static BlockState transferSixWayProperties(BlockState from, BlockState to) { + for (Direction d : Iterate.directions) { + BooleanProperty property = FACING_TO_PROPERTY_MAP.get(d); + to = to.with(property, from.get(property)); + } + return to; + } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java index 56217071f..67a895eb2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java @@ -73,12 +73,9 @@ public class FluidPipeBlock extends SixWayBlock implements IWaterLoggable, IWren BlockRayTraceResult hit) { if (!AllBlocks.COPPER_CASING.isIn(player.getHeldItem(hand))) return ActionResultType.PASS; - Axis axis = getAxis(world, pos, state); - if (axis == null) - return ActionResultType.PASS; if (!world.isRemote) - world.setBlockState(pos, AllBlocks.ENCASED_FLUID_PIPE.getDefaultState() - .with(EncasedPipeBlock.AXIS, axis)); + world.setBlockState(pos, + EncasedPipeBlock.transferSixWayProperties(state, AllBlocks.ENCASED_FLUID_PIPE.getDefaultState())); return ActionResultType.SUCCESS; } @@ -149,7 +146,7 @@ public class FluidPipeBlock extends SixWayBlock implements IWaterLoggable, IWren || FluidPropagator.getStraightPipeAxis(neighbour) == blockFace.getAxis(); if (attachmentBehaviour == null) return false; - return attachmentBehaviour.isPipeConnectedTowards(neighbour, blockFace); + return attachmentBehaviour.isPipeConnectedTowards(neighbour, blockFace.getOpposite()); } public static boolean shouldDrawRim(ILightReader world, BlockPos pos, BlockState state, Direction direction) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeTileEntity.java index 5b0ca5222..a90f4c92d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeTileEntity.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.fluids.pipes; import java.util.List; +import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.fluids.FluidPipeAttachmentBehaviour; import com.simibubi.create.content.contraptions.fluids.FluidPipeBehaviour; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; @@ -33,7 +34,8 @@ public class FluidPipeTileEntity extends SmartTileEntity { @Override public boolean isConnectedTo(BlockState state, Direction direction) { - return FluidPipeBlock.isPipe(state) && state.get(FluidPipeBlock.FACING_TO_PROPERTY_MAP.get(direction)); + return (FluidPipeBlock.isPipe(state) || state.getBlock() instanceof EncasedPipeBlock) + && state.get(FluidPipeBlock.FACING_TO_PROPERTY_MAP.get(direction)); } } @@ -48,6 +50,9 @@ public class FluidPipeTileEntity extends SmartTileEntity { public AttachmentTypes getAttachment(ILightReader world, BlockPos pos, BlockState state, Direction direction) { AttachmentTypes attachment = super.getAttachment(world, pos, state, direction); + if (attachment == AttachmentTypes.RIM && AllBlocks.ENCASED_FLUID_PIPE.has(state)) + return AttachmentTypes.RIM; + BlockPos offsetPos = pos.offset(direction); if (!FluidPipeBlock.isPipe(world.getBlockState(offsetPos))) { FluidPipeAttachmentBehaviour attachmentBehaviour = diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankModel.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankModel.java index 0411e7edf..802f39e49 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankModel.java @@ -18,6 +18,7 @@ import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.ILightReader; import net.minecraftforge.client.model.data.IModelData; +import net.minecraftforge.client.model.data.ModelDataMap.Builder; import net.minecraftforge.client.model.data.ModelProperty; public class FluidTankModel extends CTModel { @@ -35,14 +36,13 @@ public class FluidTankModel extends CTModel { private FluidTankModel(IBakedModel originalModel, CTSpriteShiftEntry side, CTSpriteShiftEntry top) { super(originalModel, new FluidTankCTBehaviour(side, top)); } - + @Override - public IModelData getModelData(ILightReader world, BlockPos pos, BlockState state, IModelData tileData) { + protected Builder gatherModelData(Builder builder, ILightReader world, BlockPos pos, BlockState state) { CullData cullData = new CullData(); for (Direction d : Iterate.horizontalDirections) cullData.setCulled(d, FluidTankConnectivityHandler.isConnected(world, pos, pos.offset(d))); - return getCTDataMapBuilder(world, pos, state).withInitial(CULL_PROPERTY, cullData) - .build(); + return super.gatherModelData(builder, world, pos, state).withInitial(CULL_PROPERTY, cullData); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedShaftBlock.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedShaftBlock.java index 57b284045..1592b93cf 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedShaftBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/EncasedShaftBlock.java @@ -6,6 +6,7 @@ import com.simibubi.create.content.contraptions.base.CasingBlock; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.tterrag.registrate.util.entry.BlockEntry; +import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.item.ItemUseContext; import net.minecraft.tileentity.TileEntity; @@ -42,7 +43,7 @@ public class EncasedShaftBlock extends AbstractEncasedShaftBlock { public ActionResultType onSneakWrenched(BlockState state, ItemUseContext context) { if (context.getWorld().isRemote) return ActionResultType.SUCCESS; - + context.getWorld().playEvent(2001, context.getPos(), Block.getStateId(state)); KineticTileEntity.switchToBlockState(context.getWorld(), context.getPos(), AllBlocks.SHAFT.getDefaultState().with(AXIS, state.get(AXIS))); return ActionResultType.SUCCESS; } diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/BakedModelWrapperWithData.java b/src/main/java/com/simibubi/create/foundation/block/connected/BakedModelWrapperWithData.java new file mode 100644 index 000000000..d012d0588 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/block/connected/BakedModelWrapperWithData.java @@ -0,0 +1,29 @@ +package com.simibubi.create.foundation.block.connected; + +import net.minecraft.block.BlockState; +import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.ILightReader; +import net.minecraftforge.client.model.BakedModelWrapper; +import net.minecraftforge.client.model.data.IModelData; +import net.minecraftforge.client.model.data.ModelDataMap; +import net.minecraftforge.client.model.data.ModelDataMap.Builder; + +public abstract class BakedModelWrapperWithData extends BakedModelWrapper { + + public BakedModelWrapperWithData(IBakedModel originalModel) { + super(originalModel); + } + + @Override + public final IModelData getModelData(ILightReader world, BlockPos pos, BlockState state, IModelData tileData) { + Builder builder = new ModelDataMap.Builder(); + if (originalModel instanceof BakedModelWrapperWithData) + ((BakedModelWrapperWithData) originalModel).gatherModelData(builder, world, pos, state); + return gatherModelData(builder, world, pos, state).build(); + } + + protected abstract ModelDataMap.Builder gatherModelData(ModelDataMap.Builder builder, ILightReader world, + BlockPos pos, BlockState state); + +} diff --git a/src/main/java/com/simibubi/create/foundation/block/connected/CTModel.java b/src/main/java/com/simibubi/create/foundation/block/connected/CTModel.java index 6a76326b2..60c26a070 100644 --- a/src/main/java/com/simibubi/create/foundation/block/connected/CTModel.java +++ b/src/main/java/com/simibubi/create/foundation/block/connected/CTModel.java @@ -16,13 +16,11 @@ import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.ILightReader; -import net.minecraftforge.client.model.BakedModelWrapper; import net.minecraftforge.client.model.data.IModelData; -import net.minecraftforge.client.model.data.ModelDataMap; import net.minecraftforge.client.model.data.ModelDataMap.Builder; import net.minecraftforge.client.model.data.ModelProperty; -public class CTModel extends BakedModelWrapper { +public class CTModel extends BakedModelWrapperWithData { protected static ModelProperty CT_PROPERTY = new ModelProperty<>(); private ConnectedTextureBehaviour behaviour; @@ -43,19 +41,15 @@ public class CTModel extends BakedModelWrapper { return indices[face.getIndex()]; } } - + public CTModel(IBakedModel originalModel, ConnectedTextureBehaviour behaviour) { super(originalModel); this.behaviour = behaviour; } @Override - public IModelData getModelData(ILightReader world, BlockPos pos, BlockState state, IModelData tileData) { - return getCTDataMapBuilder(world, pos, state).build(); - } - - protected Builder getCTDataMapBuilder(ILightReader world, BlockPos pos, BlockState state) { - return new ModelDataMap.Builder().withInitial(CT_PROPERTY, createCTData(world, pos, state)); + protected Builder gatherModelData(Builder builder, ILightReader world, BlockPos pos, BlockState state) { + return builder.withInitial(CT_PROPERTY, createCTData(world, pos, state)); } protected CTData createCTData(ILightReader world, BlockPos pos, BlockState state) { diff --git a/src/main/java/com/simibubi/create/foundation/block/render/CustomBlockModels.java b/src/main/java/com/simibubi/create/foundation/block/render/CustomBlockModels.java index 0f3efbd4a..3653f4615 100644 --- a/src/main/java/com/simibubi/create/foundation/block/render/CustomBlockModels.java +++ b/src/main/java/com/simibubi/create/foundation/block/render/CustomBlockModels.java @@ -28,7 +28,7 @@ public class CustomBlockModels { NonNullFunction behaviour) { registered.add(Pair.of(entry, behaviour)); } - + public void foreach(NonNullBiConsumer> consumer) { loadEntriesIfMissing(); customModels.forEach(consumer); @@ -41,8 +41,19 @@ public class CustomBlockModels { private void loadEntries() { customModels.clear(); - registered.forEach(p -> customModels.put(p.getKey() - .get(), p.getValue())); + registered.forEach(p -> { + Block key = p.getKey() + .get(); + + NonNullFunction existingModel = customModels.get(key); + if (existingModel != null) { + customModels.put(key, p.getValue() + .andThen(existingModel)); + return; + } + + customModels.put(key, p.getValue()); + }); } } diff --git a/src/main/java/com/simibubi/create/foundation/data/BlockStateGen.java b/src/main/java/com/simibubi/create/foundation/data/BlockStateGen.java index 76874dc7c..ca4c81c04 100644 --- a/src/main/java/com/simibubi/create/foundation/data/BlockStateGen.java +++ b/src/main/java/com/simibubi/create/foundation/data/BlockStateGen.java @@ -19,6 +19,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.cha import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssembleRailType; import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerBlock; import com.simibubi.create.content.contraptions.components.tracks.ReinforcedRailBlock; +import com.simibubi.create.content.contraptions.fluids.pipes.EncasedPipeBlock; import com.simibubi.create.content.contraptions.fluids.pipes.FluidPipeBlock; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock; import com.simibubi.create.content.palettes.PavedBlock; @@ -340,6 +341,26 @@ public class BlockStateGen { }; } + public static

NonNullBiConsumer, RegistrateBlockstateProvider> encasedPipe() { + return (c, p) -> { + ModelFile open = AssetLookup.partialBaseModel(c, p, "open"); + ModelFile flat = AssetLookup.partialBaseModel(c, p, "flat"); + MultiPartBlockStateBuilder builder = p.getMultipartBuilder(c.get()); + for (boolean flatPass : Iterate.trueAndFalse) + for (Direction d : Iterate.directions) { + int verticalAngle = d == Direction.UP ? 90 : d == Direction.DOWN ? -90 : 0; + builder.part() + .modelFile(flatPass ? flat : open) + .rotationX(verticalAngle) + .rotationY((int) (d.getHorizontalAngle() + (d.getAxis() + .isVertical() ? 90 : 0)) % 360) + .addModel() + .condition(EncasedPipeBlock.FACING_TO_PROPERTY_MAP.get(d), !flatPass) + .end(); + } + }; + } + public static

NonNullBiConsumer, RegistrateBlockstateProvider> pipe() { return (c, p) -> { String path = "block/" + c.getName(); diff --git a/src/main/resources/assets/create/models/block/encased_fluid_pipe/block_flat.json b/src/main/resources/assets/create/models/block/encased_fluid_pipe/block_flat.json new file mode 100644 index 000000000..d084586f1 --- /dev/null +++ b/src/main/resources/assets/create/models/block/encased_fluid_pipe/block_flat.json @@ -0,0 +1,16 @@ +{ + "credit": "Made with Blockbench", + "textures": { + "0": "create:block/copper_casing", + "particle": "create:block/copper_casing" + }, + "elements": [ + { + "from": [0, 0, 15], + "to": [16, 16, 16], + "faces": { + "south": {"uv": [0, 0, 16, 16], "texture": "#0"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/create/models/block/encased_fluid_pipe/block_open.json b/src/main/resources/assets/create/models/block/encased_fluid_pipe/block_open.json new file mode 100644 index 000000000..0d555e7e4 --- /dev/null +++ b/src/main/resources/assets/create/models/block/encased_fluid_pipe/block_open.json @@ -0,0 +1,16 @@ +{ + "credit": "Made with Blockbench", + "textures": { + "0": "create:block/encased_pipe", + "particle": "create:block/encased_pipe" + }, + "elements": [ + { + "from": [0, 0, 15], + "to": [16, 16, 16], + "faces": { + "south": {"uv": [0, 0, 16, 16], "texture": "#0"} + } + } + ] +} \ No newline at end of file