Underwater Transport

- Mechanical Belts can now be waterlogged
This commit is contained in:
simibubi 2023-04-22 13:18:55 +02:00
parent af2c40c27d
commit c2c37da442
7 changed files with 851 additions and 184 deletions

View file

@ -17,7 +17,7 @@ a07a73251d26e8b38bce295838c2fef246f9885d assets/create/blockstates/andesite_scaf
aefe4cd5fdb50b2ffe89f43acac4206c5adfad3f assets/create/blockstates/asurine.json aefe4cd5fdb50b2ffe89f43acac4206c5adfad3f assets/create/blockstates/asurine.json
bb61f3f336ebe0ff08d84cb6a83e86a823dac7aa assets/create/blockstates/asurine_pillar.json bb61f3f336ebe0ff08d84cb6a83e86a823dac7aa assets/create/blockstates/asurine_pillar.json
e555e3c2b2d3f01440e48db4ba88f7e00fd99b6f assets/create/blockstates/basin.json e555e3c2b2d3f01440e48db4ba88f7e00fd99b6f assets/create/blockstates/basin.json
f25693a9429f6337149ff24f27900dc4eb82a7c2 assets/create/blockstates/belt.json af4a0f1ad88334ed96b839a9d7f6dca1778b7410 assets/create/blockstates/belt.json
cf9045eb16e5299a1d917c4cb536289f49411276 assets/create/blockstates/birch_window.json cf9045eb16e5299a1d917c4cb536289f49411276 assets/create/blockstates/birch_window.json
94a1a91403eb4b035fec48071e7fcae57a8a6abd assets/create/blockstates/birch_window_pane.json 94a1a91403eb4b035fec48071e7fcae57a8a6abd assets/create/blockstates/birch_window_pane.json
95bada2b3bf55536f85e82bc6f9d16501b6e1a95 assets/create/blockstates/black_nixie_tube.json 95bada2b3bf55536f85e82bc6f9d16501b6e1a95 assets/create/blockstates/black_nixie_tube.json

File diff suppressed because it is too large Load diff

View file

@ -29,6 +29,7 @@ import com.simibubi.create.content.schematics.ISpecialBlockItemRequirement;
import com.simibubi.create.content.schematics.ItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement;
import com.simibubi.create.content.schematics.ItemRequirement.ItemUseType; import com.simibubi.create.content.schematics.ItemRequirement.ItemUseType;
import com.simibubi.create.foundation.block.IBE; import com.simibubi.create.foundation.block.IBE;
import com.simibubi.create.foundation.block.ProperWaterloggedBlock;
import com.simibubi.create.foundation.block.render.MultiPosDestructionHandler; import com.simibubi.create.foundation.block.render.MultiPosDestructionHandler;
import com.simibubi.create.foundation.block.render.ReducedDestroyEffects; import com.simibubi.create.foundation.block.render.ReducedDestroyEffects;
import com.simibubi.create.foundation.blockEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult; import com.simibubi.create.foundation.blockEntity.behaviour.belt.TransportedItemStackHandlerBehaviour.TransportedResult;
@ -68,6 +69,7 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.levelgen.DebugLevelSource; import net.minecraft.world.level.levelgen.DebugLevelSource;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.pathfinder.BlockPathTypes; import net.minecraft.world.level.pathfinder.BlockPathTypes;
import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.level.pathfinder.PathComputationType;
@ -86,7 +88,8 @@ import net.minecraftforge.common.Tags;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
public class BeltBlock extends HorizontalKineticBlock implements IBE<BeltBlockEntity>, ISpecialBlockItemRequirement, ITransformableBlock { public class BeltBlock extends HorizontalKineticBlock
implements IBE<BeltBlockEntity>, ISpecialBlockItemRequirement, ITransformableBlock, ProperWaterloggedBlock {
public static final Property<BeltSlope> SLOPE = EnumProperty.create("slope", BeltSlope.class); public static final Property<BeltSlope> SLOPE = EnumProperty.create("slope", BeltSlope.class);
public static final Property<BeltPart> PART = EnumProperty.create("part", BeltPart.class); public static final Property<BeltPart> PART = EnumProperty.create("part", BeltPart.class);
@ -96,7 +99,8 @@ public class BeltBlock extends HorizontalKineticBlock implements IBE<BeltBlockEn
super(properties); super(properties);
registerDefaultState(defaultBlockState().setValue(SLOPE, BeltSlope.HORIZONTAL) registerDefaultState(defaultBlockState().setValue(SLOPE, BeltSlope.HORIZONTAL)
.setValue(PART, BeltPart.START) .setValue(PART, BeltPart.START)
.setValue(CASING, false)); .setValue(CASING, false)
.setValue(WATERLOGGED, false));
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
@ -254,11 +258,9 @@ public class BeltBlock extends HorizontalKineticBlock implements IBE<BeltBlockEn
.isSame(Fluids.WATER); .isSame(Fluids.WATER);
boolean isHand = heldItem.isEmpty() && handIn == InteractionHand.MAIN_HAND; boolean isHand = heldItem.isEmpty() && handIn == InteractionHand.MAIN_HAND;
if (isDye || hasWater) { if (isDye || hasWater)
if (!world.isClientSide) return onBlockEntityUse(world, pos,
withBlockEntityDo(world, pos, be -> be.applyColor(DyeColor.getColor(heldItem))); be -> be.applyColor(DyeColor.getColor(heldItem)) ? InteractionResult.SUCCESS : InteractionResult.PASS);
return InteractionResult.SUCCESS;
}
if (isConnector) if (isConnector)
return BeltSlicer.useConnector(state, world, pos, player, handIn, hit, new Feedback()); return BeltSlicer.useConnector(state, world, pos, player, handIn, hit, new Feedback());
@ -342,7 +344,7 @@ public class BeltBlock extends HorizontalKineticBlock implements IBE<BeltBlockEn
@Override @Override
protected void createBlockStateDefinition(Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(Builder<Block, BlockState> builder) {
builder.add(SLOPE, PART, CASING); builder.add(SLOPE, PART, CASING, WATERLOGGED);
super.createBlockStateDefinition(builder); super.createBlockStateDefinition(builder);
} }
@ -480,7 +482,8 @@ public class BeltBlock extends HorizontalKineticBlock implements IBE<BeltBlockEn
world.removeBlockEntity(currentPos); world.removeBlockEntity(currentPos);
BlockState shaftState = AllBlocks.SHAFT.getDefaultState() BlockState shaftState = AllBlocks.SHAFT.getDefaultState()
.setValue(BlockStateProperties.AXIS, getRotationAxis(currentState)); .setValue(BlockStateProperties.AXIS, getRotationAxis(currentState));
world.setBlock(currentPos, hasPulley ? shaftState : Blocks.AIR.defaultBlockState(), 3); world.setBlock(currentPos, ProperWaterloggedBlock.withWater(world,
hasPulley ? shaftState : Blocks.AIR.defaultBlockState(), currentPos), 3);
world.levelEvent(2001, currentPos, Block.getId(currentState)); world.levelEvent(2001, currentPos, Block.getId(currentState));
} }
} }
@ -488,6 +491,7 @@ public class BeltBlock extends HorizontalKineticBlock implements IBE<BeltBlockEn
@Override @Override
public BlockState updateShape(BlockState state, Direction side, BlockState p_196271_3_, LevelAccessor world, public BlockState updateShape(BlockState state, Direction side, BlockState p_196271_3_, LevelAccessor world,
BlockPos pos, BlockPos p_196271_6_) { BlockPos pos, BlockPos p_196271_6_) {
updateWater(world, state, pos);
if (side.getAxis() if (side.getAxis()
.isHorizontal()) .isHorizontal())
updateTunnelConnections(world, pos.above()); updateTunnelConnections(world, pos.above());
@ -707,6 +711,11 @@ public class BeltBlock extends HorizontalKineticBlock implements IBE<BeltBlockEn
return false; return false;
} }
@Override
public FluidState getFluidState(BlockState pState) {
return fluidState(pState);
}
public static class RenderProperties extends ReducedDestroyEffects implements MultiPosDestructionHandler { public static class RenderProperties extends ReducedDestroyEffects implements MultiPosDestructionHandler {
@Override @Override
public Set<BlockPos> getExtraPositions(ClientLevel level, BlockPos pos, BlockState blockState, int progress) { public Set<BlockPos> getExtraPositions(ClientLevel level, BlockPos pos, BlockState blockState, int progress) {

View file

@ -12,7 +12,6 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import com.jozufozu.flywheel.light.LightListener; import com.jozufozu.flywheel.light.LightListener;
import com.jozufozu.flywheel.light.LightUpdater; import com.jozufozu.flywheel.light.LightUpdater;
import com.jozufozu.flywheel.util.box.GridAlignedBB; import com.jozufozu.flywheel.util.box.GridAlignedBB;
@ -280,12 +279,14 @@ public class BeltBlockEntity extends KineticBlockEntity {
trackerUpdateTag = new CompoundTag(); trackerUpdateTag = new CompoundTag();
} }
public void applyColor(DyeColor colorIn) { public boolean applyColor(DyeColor colorIn) {
if (colorIn == null) { if (colorIn == null) {
if (!color.isPresent()) if (!color.isPresent())
return; return false;
} else if (color.isPresent() && color.get() == colorIn) } else if (color.isPresent() && color.get() == colorIn)
return; return false;
if (level.isClientSide())
return true;
for (BlockPos blockPos : BeltBlock.getBeltChain(level, getController())) { for (BlockPos blockPos : BeltBlock.getBeltChain(level, getController())) {
BeltBlockEntity belt = BeltHelper.getSegmentBE(level, blockPos); BeltBlockEntity belt = BeltHelper.getSegmentBE(level, blockPos);
@ -294,8 +295,9 @@ public class BeltBlockEntity extends KineticBlockEntity {
belt.color = Optional.ofNullable(colorIn); belt.color = Optional.ofNullable(colorIn);
belt.setChanged(); belt.setChanged();
belt.sendData(); belt.sendData();
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> InstancedRenderDispatcher.enqueueUpdate(belt));
} }
return true;
} }
public BeltBlockEntity getControllerBE() { public BeltBlockEntity getControllerBE() {

View file

@ -13,6 +13,7 @@ import com.simibubi.create.content.contraptions.relays.belt.BeltBlockEntity.Casi
import com.simibubi.create.content.contraptions.relays.belt.item.BeltConnectorItem; import com.simibubi.create.content.contraptions.relays.belt.item.BeltConnectorItem;
import com.simibubi.create.content.contraptions.relays.belt.transport.BeltInventory; import com.simibubi.create.content.contraptions.relays.belt.transport.BeltInventory;
import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack;
import com.simibubi.create.foundation.block.ProperWaterloggedBlock;
import com.simibubi.create.foundation.utility.Components; import com.simibubi.create.foundation.utility.Components;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.VecHelper;
@ -89,9 +90,10 @@ public class BeltSlicer {
BlockPos next = part == BeltPart.END ? pos.subtract(beltVector) : pos.offset(beltVector); BlockPos next = part == BeltPart.END ? pos.subtract(beltVector) : pos.offset(beltVector);
BlockState replacedState = world.getBlockState(next); BlockState replacedState = world.getBlockState(next);
BeltBlockEntity segmentBE = BeltHelper.getSegmentBE(world, next); BeltBlockEntity segmentBE = BeltHelper.getSegmentBE(world, next);
KineticBlockEntity.switchToBlockState(world, next, KineticBlockEntity.switchToBlockState(world, next, ProperWaterloggedBlock.withWater(world,
state.setValue(BeltBlock.CASING, segmentBE != null && segmentBE.casing != CasingType.NONE)); state.setValue(BeltBlock.CASING, segmentBE != null && segmentBE.casing != CasingType.NONE), next));
world.setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_ALL | Block.UPDATE_MOVE_BY_PISTON); world.setBlock(pos, ProperWaterloggedBlock.withWater(world, Blocks.AIR.defaultBlockState(), pos),
Block.UPDATE_ALL | Block.UPDATE_MOVE_BY_PISTON);
world.removeBlockEntity(pos); world.removeBlockEntity(pos);
world.levelEvent(2001, pos, Block.getId(state)); world.levelEvent(2001, pos, Block.getId(state));
@ -316,7 +318,9 @@ public class BeltSlicer {
if (mergedController == null) { if (mergedController == null) {
// Attach at end // Attach at end
world.setBlock(next, state.setValue(BeltBlock.CASING, false), Block.UPDATE_ALL | Block.UPDATE_MOVE_BY_PISTON); world.setBlock(next,
ProperWaterloggedBlock.withWater(world, state.setValue(BeltBlock.CASING, false), next),
Block.UPDATE_ALL | Block.UPDATE_MOVE_BY_PISTON);
BeltBlockEntity segmentBE = BeltHelper.getSegmentBE(world, next); BeltBlockEntity segmentBE = BeltHelper.getSegmentBE(world, next);
if (segmentBE != null) if (segmentBE != null)
segmentBE.color = controllerBE.color; segmentBE.color = controllerBE.color;

View file

@ -14,6 +14,7 @@ import com.simibubi.create.content.contraptions.relays.belt.BeltSlope;
import com.simibubi.create.content.contraptions.relays.elementary.AbstractSimpleShaftBlock; import com.simibubi.create.content.contraptions.relays.elementary.AbstractSimpleShaftBlock;
import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock; import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock;
import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.advancement.AllAdvancements;
import com.simibubi.create.foundation.block.ProperWaterloggedBlock;
import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.VecHelper;
@ -155,9 +156,10 @@ public class BeltConnectorItem extends BlockItem {
.isReplaceable()) .isReplaceable())
world.destroyBlock(pos, false); world.destroyBlock(pos, false);
KineticBlockEntity.switchToBlockState(world, pos, beltBlock.setValue(BeltBlock.SLOPE, slope) KineticBlockEntity.switchToBlockState(world, pos,
.setValue(BeltBlock.PART, part) ProperWaterloggedBlock.withWater(world, beltBlock.setValue(BeltBlock.SLOPE, slope)
.setValue(BeltBlock.HORIZONTAL_FACING, facing)); .setValue(BeltBlock.PART, part)
.setValue(BeltBlock.HORIZONTAL_FACING, facing), pos));
} }
if (!failed) if (!failed)

View file

@ -38,9 +38,11 @@ public interface ProperWaterloggedBlock extends SimpleWaterloggedBlock {
static BlockState withWater(LevelAccessor level, BlockState placementState, BlockPos pos) { static BlockState withWater(LevelAccessor level, BlockState placementState, BlockPos pos) {
if (placementState == null) if (placementState == null)
return null; return null;
FluidState ifluidstate = level.getFluidState(pos);
if (placementState.isAir())
return ifluidstate.getType() == Fluids.WATER ? ifluidstate.createLegacyBlock() : placementState;
if (!(placementState.getBlock() instanceof SimpleWaterloggedBlock)) if (!(placementState.getBlock() instanceof SimpleWaterloggedBlock))
return placementState; return placementState;
FluidState ifluidstate = level.getFluidState(pos);
return placementState.setValue(BlockStateProperties.WATERLOGGED, ifluidstate.getType() == Fluids.WATER); return placementState.setValue(BlockStateProperties.WATERLOGGED, ifluidstate.getType() == Fluids.WATER);
} }