|
21 | 21 |
|
22 | 22 | public class FluidVesselItem extends BlockItem {
|
23 | 23 |
|
24 |
| - public FluidVesselItem(Block p_i48527_1_, Properties p_i48527_2_) { |
25 |
| - super(p_i48527_1_, p_i48527_2_); |
26 |
| - } |
| 24 | + public FluidVesselItem(Block p_i48527_1_, Properties p_i48527_2_) { |
| 25 | + super(p_i48527_1_, p_i48527_2_); |
| 26 | + } |
27 | 27 |
|
28 |
| - @Override |
29 |
| - public InteractionResult place(BlockPlaceContext ctx) { |
30 |
| - InteractionResult initialResult = super.place(ctx); |
31 |
| - if (!initialResult.consumesAction()) |
32 |
| - return initialResult; |
33 |
| - tryMultiPlace(ctx); |
34 |
| - return initialResult; |
35 |
| - } |
| 28 | + @Override |
| 29 | + public InteractionResult place(BlockPlaceContext ctx) { |
| 30 | + InteractionResult initialResult = super.place(ctx); |
| 31 | + if (!initialResult.consumesAction()) |
| 32 | + return initialResult; |
| 33 | + tryMultiPlace(ctx); |
| 34 | + return initialResult; |
| 35 | + } |
36 | 36 |
|
37 |
| - @Override |
38 |
| - protected boolean updateCustomBlockEntityTag(BlockPos p_195943_1_, Level p_195943_2_, Player p_195943_3_, |
39 |
| - ItemStack p_195943_4_, BlockState p_195943_5_) { |
40 |
| - MinecraftServer minecraftserver = p_195943_2_.getServer(); |
41 |
| - if (minecraftserver == null) |
42 |
| - return false; |
43 |
| - CompoundTag nbt = p_195943_4_.getTagElement("BlockEntityTag"); |
44 |
| - if (nbt != null) { |
45 |
| - nbt.remove("Luminosity"); |
46 |
| - nbt.remove("Size"); |
47 |
| - nbt.remove("Height"); |
48 |
| - nbt.remove("Controller"); |
49 |
| - nbt.remove("LastKnownPos"); |
50 |
| - if (nbt.contains("TankContent")) { |
51 |
| - FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt.getCompound("TankContent")); |
52 |
| - if (!fluid.isEmpty()) { |
53 |
| - fluid.setAmount(Math.min(FluidVesselBlockEntity.getCapacityMultiplier(), fluid.getAmount())); |
54 |
| - nbt.put("TankContent", fluid.writeToNBT(new CompoundTag())); |
55 |
| - } |
56 |
| - } |
57 |
| - } |
58 |
| - return super.updateCustomBlockEntityTag(p_195943_1_, p_195943_2_, p_195943_3_, p_195943_4_, p_195943_5_); |
59 |
| - } |
| 37 | + @Override |
| 38 | + protected boolean updateCustomBlockEntityTag(BlockPos p_195943_1_, Level p_195943_2_, Player p_195943_3_, |
| 39 | + ItemStack p_195943_4_, BlockState p_195943_5_) { |
| 40 | + MinecraftServer minecraftserver = p_195943_2_.getServer(); |
| 41 | + if (minecraftserver == null) |
| 42 | + return false; |
| 43 | + CompoundTag nbt = p_195943_4_.getTagElement("BlockEntityTag"); |
| 44 | + if (nbt != null) { |
| 45 | + nbt.remove("Luminosity"); |
| 46 | + nbt.remove("Size"); |
| 47 | + nbt.remove("Height"); |
| 48 | + nbt.remove("Controller"); |
| 49 | + nbt.remove("LastKnownPos"); |
| 50 | + if (nbt.contains("TankContent")) { |
| 51 | + FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt.getCompound("TankContent")); |
| 52 | + if (!fluid.isEmpty()) { |
| 53 | + fluid.setAmount(Math.min(FluidVesselBlockEntity.getCapacityMultiplier(), fluid.getAmount())); |
| 54 | + nbt.put("TankContent", fluid.writeToNBT(new CompoundTag())); |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + return super.updateCustomBlockEntityTag(p_195943_1_, p_195943_2_, p_195943_3_, p_195943_4_, p_195943_5_); |
| 59 | + } |
60 | 60 |
|
61 |
| - private void tryMultiPlace(BlockPlaceContext ctx) { |
62 |
| - Player player = ctx.getPlayer(); |
63 |
| - if (player == null) |
64 |
| - return; |
65 |
| - if (player.isShiftKeyDown()) |
66 |
| - return; |
67 |
| - Direction face = ctx.getClickedFace(); |
68 |
| - if (!face.getAxis() |
69 |
| - .isHorizontal()) |
70 |
| - return; |
71 |
| - ItemStack stack = ctx.getItemInHand(); |
72 |
| - Level world = ctx.getLevel(); |
73 |
| - BlockPos pos = ctx.getClickedPos(); |
74 |
| - BlockPos placedOnPos = pos.relative(face.getOpposite()); |
75 |
| - BlockState placedOnState = world.getBlockState(placedOnPos); |
| 61 | + private void tryMultiPlace(BlockPlaceContext ctx) { |
| 62 | + Player player = ctx.getPlayer(); |
| 63 | + if (player == null) |
| 64 | + return; |
| 65 | + if (player.isShiftKeyDown()) |
| 66 | + return; |
| 67 | + Direction face = ctx.getClickedFace(); |
| 68 | + if (!face.getAxis() |
| 69 | + .isHorizontal()) |
| 70 | + return; |
| 71 | + ItemStack stack = ctx.getItemInHand(); |
| 72 | + Level world = ctx.getLevel(); |
| 73 | + BlockPos pos = ctx.getClickedPos(); |
| 74 | + BlockPos placedOnPos = pos.relative(face.getOpposite()); |
| 75 | + BlockState placedOnState = world.getBlockState(placedOnPos); |
76 | 76 |
|
77 |
| - if (!FluidVesselBlock.isVessel(placedOnState)) |
78 |
| - return; |
79 |
| - boolean creative = getBlock().equals(CCBlocks.CREATIVE_FLUID_VESSEL.get()); |
80 |
| - FluidVesselBlockEntity tankAt = ConnectivityHandler.partAt( |
81 |
| - creative ? CCBlockEntityTypes.CREATIVE_FLUID_VESSEL.get() : CCBlockEntityTypes.FLUID_VESSEL.get(), world, placedOnPos |
82 |
| - ); |
83 |
| - if (tankAt == null) |
84 |
| - return; |
85 |
| - FluidVesselBlockEntity controllerBE = tankAt.getControllerBE(); |
86 |
| - if (controllerBE == null) |
87 |
| - return; |
| 77 | + if (!FluidVesselBlock.isVessel(placedOnState)) |
| 78 | + return; |
| 79 | + boolean creative = getBlock().equals(CCBlocks.CREATIVE_FLUID_VESSEL.get()); |
| 80 | + FluidVesselBlockEntity tankAt = ConnectivityHandler.partAt( |
| 81 | + creative ? CCBlockEntityTypes.CREATIVE_FLUID_VESSEL.get() : CCBlockEntityTypes.FLUID_VESSEL.get(), world, placedOnPos |
| 82 | + ); |
| 83 | + if (tankAt == null) |
| 84 | + return; |
| 85 | + FluidVesselBlockEntity controllerBE = tankAt.getControllerBE(); |
| 86 | + if (controllerBE == null) |
| 87 | + return; |
88 | 88 |
|
89 |
| - int width = controllerBE.getWidth(); |
90 |
| - if (width == 1) |
91 |
| - return; |
| 89 | + int width = controllerBE.getWidth(); |
| 90 | + if (width == 1) |
| 91 | + return; |
92 | 92 |
|
93 |
| - int tanksToPlace = 0; |
94 |
| - Axis vesselAxis = placedOnState.getOptionalValue(FluidVesselBlock.AXIS).orElse(null); |
95 |
| - if (vesselAxis == null) |
96 |
| - return; |
97 |
| - if (face.getAxis() != vesselAxis) |
98 |
| - return; |
| 93 | + int tanksToPlace = 0; |
| 94 | + Axis vesselAxis = placedOnState.getOptionalValue(FluidVesselBlock.AXIS).orElse(null); |
| 95 | + if (vesselAxis == null) |
| 96 | + return; |
| 97 | + if (face.getAxis() != vesselAxis) |
| 98 | + return; |
99 | 99 |
|
100 |
| - Direction vesselFacing = Direction.fromAxisAndDirection(vesselAxis, Direction.AxisDirection.POSITIVE); |
101 |
| - BlockPos startPos = face == vesselFacing.getOpposite() |
102 |
| - ? controllerBE.getBlockPos().relative(vesselFacing.getOpposite()) |
103 |
| - : controllerBE.getBlockPos().relative(vesselFacing, controllerBE.getHeight()); |
| 100 | + Direction vesselFacing = Direction.fromAxisAndDirection(vesselAxis, Direction.AxisDirection.POSITIVE); |
| 101 | + BlockPos startPos = face == vesselFacing.getOpposite() |
| 102 | + ? controllerBE.getBlockPos().relative(vesselFacing.getOpposite()) |
| 103 | + : controllerBE.getBlockPos().relative(vesselFacing, controllerBE.getHeight()); |
104 | 104 |
|
105 |
| - if (VecHelper.getCoordinate(startPos, vesselAxis) != VecHelper.getCoordinate(pos, vesselAxis)) |
106 |
| - return; |
| 105 | + if (VecHelper.getCoordinate(startPos, vesselAxis) != VecHelper.getCoordinate(pos, vesselAxis)) |
| 106 | + return; |
107 | 107 |
|
108 |
| - for (int xOffset = 0; xOffset < width; xOffset++) { |
109 |
| - for (int zOffset = 0; zOffset < width; zOffset++) { |
110 |
| - BlockPos offsetPos = vesselAxis == Axis.X |
111 |
| - ? startPos.offset(0, xOffset, zOffset) |
112 |
| - : startPos.offset(xOffset, zOffset, 0); |
113 |
| - BlockState blockState = world.getBlockState(offsetPos); |
114 |
| - if (FluidVesselBlock.isVessel(blockState)) |
115 |
| - continue; |
116 |
| - if (!blockState.canBeReplaced()) |
117 |
| - return; |
118 |
| - tanksToPlace++; |
119 |
| - } |
120 |
| - } |
| 108 | + for (int xOffset = 0; xOffset < width; xOffset++) { |
| 109 | + for (int zOffset = 0; zOffset < width; zOffset++) { |
| 110 | + BlockPos offsetPos = vesselAxis == Axis.X |
| 111 | + ? startPos.offset(0, xOffset, zOffset) |
| 112 | + : startPos.offset(xOffset, zOffset, 0); |
| 113 | + BlockState blockState = world.getBlockState(offsetPos); |
| 114 | + if (FluidVesselBlock.isVessel(blockState)) |
| 115 | + continue; |
| 116 | + if (!blockState.getMaterial().isReplaceable()) |
| 117 | + return; |
| 118 | + tanksToPlace++; |
| 119 | + } |
| 120 | + } |
121 | 121 |
|
122 |
| - if (!player.isCreative() && stack.getCount() < tanksToPlace) |
123 |
| - return; |
| 122 | + if (!player.isCreative() && stack.getCount() < tanksToPlace) |
| 123 | + return; |
124 | 124 |
|
125 |
| - for (int xOffset = 0; xOffset < width; xOffset++) { |
126 |
| - for (int zOffset = 0; zOffset < width; zOffset++) { |
127 |
| - BlockPos offsetPos = vesselAxis == Axis.X |
128 |
| - ? startPos.offset(0, xOffset, zOffset) |
129 |
| - : startPos.offset(xOffset, zOffset, 0); |
130 |
| - BlockState blockState = world.getBlockState(offsetPos); |
131 |
| - if (FluidVesselBlock.isVessel(blockState)) |
132 |
| - continue; |
133 |
| - BlockPlaceContext context = BlockPlaceContext.at(ctx, offsetPos, face); |
134 |
| - player.getPersistentData() |
135 |
| - .putBoolean("SilenceVesselSound", true); |
136 |
| - super.place(context); |
137 |
| - player.getPersistentData().remove("SilenceVesselSound"); |
138 |
| - } |
139 |
| - } |
140 |
| - } |
| 125 | + for (int xOffset = 0; xOffset < width; xOffset++) { |
| 126 | + for (int zOffset = 0; zOffset < width; zOffset++) { |
| 127 | + BlockPos offsetPos = vesselAxis == Axis.X |
| 128 | + ? startPos.offset(0, xOffset, zOffset) |
| 129 | + : startPos.offset(xOffset, zOffset, 0); |
| 130 | + BlockState blockState = world.getBlockState(offsetPos); |
| 131 | + if (FluidVesselBlock.isVessel(blockState)) |
| 132 | + continue; |
| 133 | + BlockPlaceContext context = BlockPlaceContext.at(ctx, offsetPos, face); |
| 134 | + player.getPersistentData() |
| 135 | + .putBoolean("SilenceVesselSound", true); |
| 136 | + super.place(context); |
| 137 | + player.getPersistentData().remove("SilenceVesselSound"); |
| 138 | + } |
| 139 | + } |
| 140 | + } |
141 | 141 |
|
142 | 142 | }
|
0 commit comments