aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/level/block/TripWireBlock.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/level/block/TripWireBlock.java.patch')
-rw-r--r--patch-remap/mache-vineflower/net/minecraft/world/level/block/TripWireBlock.java.patch332
1 files changed, 332 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/level/block/TripWireBlock.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/level/block/TripWireBlock.java.patch
new file mode 100644
index 0000000000..8cf6f75c90
--- /dev/null
+++ b/patch-remap/mache-vineflower/net/minecraft/world/level/block/TripWireBlock.java.patch
@@ -0,0 +1,332 @@
+--- a/net/minecraft/world/level/block/TripWireBlock.java
++++ b/net/minecraft/world/level/block/TripWireBlock.java
+@@ -2,7 +2,7 @@
+
+ import com.mojang.serialization.MapCodec;
+ import com.mojang.serialization.codecs.RecordCodecBuilder;
+-import com.mojang.serialization.codecs.RecordCodecBuilder.Instance;
++import java.util.Iterator;
+ import java.util.List;
+ import java.util.Map;
+ import net.minecraft.core.BlockPos;
+@@ -18,19 +18,23 @@
+ import net.minecraft.world.level.Level;
+ import net.minecraft.world.level.LevelAccessor;
+ import net.minecraft.world.level.block.state.BlockBehaviour;
+-import net.minecraft.world.level.block.state.BlockState;
++import net.minecraft.world.level.block.state.IBlockData;
+ import net.minecraft.world.level.block.state.StateDefinition;
+ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+ import net.minecraft.world.level.block.state.properties.BooleanProperty;
++import net.minecraft.world.level.block.state.properties.Property;
+ import net.minecraft.world.level.gameevent.GameEvent;
+ import net.minecraft.world.phys.shapes.CollisionContext;
+ import net.minecraft.world.phys.shapes.VoxelShape;
++import org.bukkit.event.entity.EntityInteractEvent; // CraftBukkit
+
+ public class TripWireBlock extends Block {
+- public static final MapCodec<TripWireBlock> CODEC = RecordCodecBuilder.mapCodec(
+- instance -> instance.group(BuiltInRegistries.BLOCK.byNameCodec().fieldOf("hook").forGetter(tripWireBlock -> tripWireBlock.hook), propertiesCodec())
+- .apply(instance, TripWireBlock::new)
+- );
++
++ public static final MapCodec<TripWireBlock> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
++ return instance.group(BuiltInRegistries.BLOCK.byNameCodec().fieldOf("hook").forGetter((blocktripwire) -> {
++ return blocktripwire.hook;
++ }), propertiesCodec()).apply(instance, TripWireBlock::new);
++ });
+ public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
+ public static final BooleanProperty ATTACHED = BlockStateProperties.ATTACHED;
+ public static final BooleanProperty DISARMED = BlockStateProperties.DISARMED;
+@@ -39,121 +43,123 @@
+ public static final BooleanProperty SOUTH = PipeBlock.SOUTH;
+ public static final BooleanProperty WEST = PipeBlock.WEST;
+ private static final Map<Direction, BooleanProperty> PROPERTY_BY_DIRECTION = CrossCollisionBlock.PROPERTY_BY_DIRECTION;
+- protected static final VoxelShape AABB = Block.box(0.0, 1.0, 0.0, 16.0, 2.5, 16.0);
+- protected static final VoxelShape NOT_ATTACHED_AABB = Block.box(0.0, 0.0, 0.0, 16.0, 8.0, 16.0);
++ protected static final VoxelShape AABB = Block.box(0.0D, 1.0D, 0.0D, 16.0D, 2.5D, 16.0D);
++ protected static final VoxelShape NOT_ATTACHED_AABB = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D);
+ private static final int RECHECK_PERIOD = 10;
+ private final Block hook;
+
+ @Override
+ public MapCodec<TripWireBlock> codec() {
+- return CODEC;
++ return TripWireBlock.CODEC;
+ }
+
+- public TripWireBlock(Block block, BlockBehaviour.Properties properties) {
+- super(properties);
+- this.registerDefaultState(
+- this.stateDefinition
+- .any()
+- .setValue(POWERED, Boolean.valueOf(false))
+- .setValue(ATTACHED, Boolean.valueOf(false))
+- .setValue(DISARMED, Boolean.valueOf(false))
+- .setValue(NORTH, Boolean.valueOf(false))
+- .setValue(EAST, Boolean.valueOf(false))
+- .setValue(SOUTH, Boolean.valueOf(false))
+- .setValue(WEST, Boolean.valueOf(false))
+- );
++ public TripWireBlock(Block block, BlockBehaviour.Properties blockbase_info) {
++ super(blockbase_info);
++ this.registerDefaultState((IBlockData) ((IBlockData) ((IBlockData) ((IBlockData) ((IBlockData) ((IBlockData) ((IBlockData) ((IBlockData) this.stateDefinition.any()).setValue(TripWireBlock.POWERED, false)).setValue(TripWireBlock.ATTACHED, false)).setValue(TripWireBlock.DISARMED, false)).setValue(TripWireBlock.NORTH, false)).setValue(TripWireBlock.EAST, false)).setValue(TripWireBlock.SOUTH, false)).setValue(TripWireBlock.WEST, false));
+ this.hook = block;
+ }
+
+ @Override
+- public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
+- return state.getValue(ATTACHED) ? AABB : NOT_ATTACHED_AABB;
++ public VoxelShape getShape(IBlockData state, BlockGetter level, BlockPos pos, CollisionContext context) {
++ return (Boolean) state.getValue(TripWireBlock.ATTACHED) ? TripWireBlock.AABB : TripWireBlock.NOT_ATTACHED_AABB;
+ }
+
+ @Override
+- public BlockState getStateForPlacement(BlockPlaceContext context) {
+- BlockGetter level = context.getLevel();
+- BlockPos clickedPos = context.getClickedPos();
+- return this.defaultBlockState()
+- .setValue(NORTH, Boolean.valueOf(this.shouldConnectTo(level.getBlockState(clickedPos.north()), Direction.NORTH)))
+- .setValue(EAST, Boolean.valueOf(this.shouldConnectTo(level.getBlockState(clickedPos.east()), Direction.EAST)))
+- .setValue(SOUTH, Boolean.valueOf(this.shouldConnectTo(level.getBlockState(clickedPos.south()), Direction.SOUTH)))
+- .setValue(WEST, Boolean.valueOf(this.shouldConnectTo(level.getBlockState(clickedPos.west()), Direction.WEST)));
++ public IBlockData getStateForPlacement(BlockPlaceContext context) {
++ Level world = context.getLevel();
++ BlockPos blockposition = context.getClickedPos();
++
++ return (IBlockData) ((IBlockData) ((IBlockData) ((IBlockData) this.defaultBlockState().setValue(TripWireBlock.NORTH, this.shouldConnectTo(world.getBlockState(blockposition.north()), Direction.NORTH))).setValue(TripWireBlock.EAST, this.shouldConnectTo(world.getBlockState(blockposition.east()), Direction.EAST))).setValue(TripWireBlock.SOUTH, this.shouldConnectTo(world.getBlockState(blockposition.south()), Direction.SOUTH))).setValue(TripWireBlock.WEST, this.shouldConnectTo(world.getBlockState(blockposition.west()), Direction.WEST));
+ }
+
+ @Override
+- public BlockState updateShape(BlockState state, Direction facing, BlockState facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) {
+- return facing.getAxis().isHorizontal()
+- ? state.setValue(PROPERTY_BY_DIRECTION.get(facing), Boolean.valueOf(this.shouldConnectTo(facingState, facing)))
+- : super.updateShape(state, facing, facingState, level, currentPos, facingPos);
++ public IBlockData updateShape(IBlockData state, Direction facing, IBlockData facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) {
++ return facing.getAxis().isHorizontal() ? (IBlockData) state.setValue((Property) TripWireBlock.PROPERTY_BY_DIRECTION.get(facing), this.shouldConnectTo(facingState, facing)) : super.updateShape(state, facing, facingState, level, currentPos, facingPos);
+ }
+
+ @Override
+- public void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean isMoving) {
++ public void onPlace(IBlockData state, Level level, BlockPos pos, IBlockData oldState, boolean isMoving) {
+ if (!oldState.is(state.getBlock())) {
+ this.updateSource(level, pos, state);
+ }
+ }
+
+ @Override
+- public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
++ public void onRemove(IBlockData state, Level level, BlockPos pos, IBlockData newState, boolean isMoving) {
+ if (!isMoving && !state.is(newState.getBlock())) {
+- this.updateSource(level, pos, state.setValue(POWERED, Boolean.valueOf(true)));
++ this.updateSource(level, pos, (IBlockData) state.setValue(TripWireBlock.POWERED, true));
+ }
+ }
+
+ @Override
+- public BlockState playerWillDestroy(Level level, BlockPos blockPos, BlockState blockState, Player player) {
+- if (!level.isClientSide && !player.getMainHandItem().isEmpty() && player.getMainHandItem().is(Items.SHEARS)) {
+- level.setBlock(blockPos, blockState.setValue(DISARMED, Boolean.valueOf(true)), 4);
+- level.gameEvent(player, GameEvent.SHEAR, blockPos);
++ public IBlockData playerWillDestroy(Level world, BlockPos blockposition, IBlockData iblockdata, Player entityhuman) {
++ if (!world.isClientSide && !entityhuman.getMainHandItem().isEmpty() && entityhuman.getMainHandItem().is(Items.SHEARS)) {
++ world.setBlock(blockposition, (IBlockData) iblockdata.setValue(TripWireBlock.DISARMED, true), 4);
++ world.gameEvent((Entity) entityhuman, GameEvent.SHEAR, blockposition);
+ }
+
+- return super.playerWillDestroy(level, blockPos, blockState, player);
++ return super.playerWillDestroy(world, blockposition, iblockdata, entityhuman);
+ }
+
+- private void updateSource(Level level, BlockPos pos, BlockState state) {
+- for (Direction direction : new Direction[]{Direction.SOUTH, Direction.WEST}) {
+- for (int i = 1; i < 42; i++) {
+- BlockPos blockPos = pos.relative(direction, i);
+- BlockState blockState = level.getBlockState(blockPos);
+- if (blockState.is(this.hook)) {
+- if (blockState.getValue(TripWireHookBlock.FACING) == direction.getOpposite()) {
+- TripWireHookBlock.calculateState(level, blockPos, blockState, false, true, i, state);
++ private void updateSource(Level level, BlockPos pos, IBlockData state) {
++ Direction[] aenumdirection = new Direction[]{Direction.SOUTH, Direction.WEST};
++ int i = aenumdirection.length;
++ int j = 0;
++
++ while (j < i) {
++ Direction enumdirection = aenumdirection[j];
++ int k = 1;
++
++ while (true) {
++ if (k < 42) {
++ BlockPos blockposition1 = pos.relative(enumdirection, k);
++ IBlockData iblockdata1 = level.getBlockState(blockposition1);
++
++ if (iblockdata1.is(this.hook)) {
++ if (iblockdata1.getValue(TripWireHookBlock.FACING) == enumdirection.getOpposite()) {
++ TripWireHookBlock.calculateState(level, blockposition1, iblockdata1, false, true, k, state);
++ }
++ } else if (iblockdata1.is((Block) this)) {
++ ++k;
++ continue;
+ }
+- break;
+ }
+
+- if (!blockState.is(this)) {
+- break;
+- }
++ ++j;
++ break;
+ }
+ }
++
+ }
+
+ @Override
+- public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) {
++ public void entityInside(IBlockData state, Level level, BlockPos pos, Entity entity) {
+ if (!level.isClientSide) {
+- if (!state.getValue(POWERED)) {
++ if (!(Boolean) state.getValue(TripWireBlock.POWERED)) {
+ this.checkPressed(level, pos);
+ }
+ }
+ }
+
+ @Override
+- public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
+- if (level.getBlockState(pos).getValue(POWERED)) {
++ public void tick(IBlockData state, ServerLevel level, BlockPos pos, RandomSource random) {
++ if ((Boolean) level.getBlockState(pos).getValue(TripWireBlock.POWERED)) {
+ this.checkPressed(level, pos);
+ }
+ }
+
+ private void checkPressed(Level level, BlockPos pos) {
+- BlockState blockState = level.getBlockState(pos);
+- boolean flag = blockState.getValue(POWERED);
++ IBlockData iblockdata = level.getBlockState(pos);
++ boolean flag = (Boolean) iblockdata.getValue(TripWireBlock.POWERED);
+ boolean flag1 = false;
+- List<? extends Entity> entities = level.getEntities(null, blockState.getShape(level, pos).bounds().move(pos));
+- if (!entities.isEmpty()) {
+- for (Entity entity : entities) {
++ List<? extends Entity> list = level.getEntities((Entity) null, iblockdata.getShape(level, pos).bounds().move(pos));
++
++ if (!list.isEmpty()) {
++ Iterator iterator = list.iterator();
++
++ while (iterator.hasNext()) {
++ Entity entity = (Entity) iterator.next();
++
+ if (!entity.isIgnoringBlockTriggers()) {
+ flag1 = true;
+ break;
+@@ -161,58 +167,84 @@
+ }
+ }
+
++ // CraftBukkit start - Call interact even when triggering connected tripwire
++ if (flag != flag1 && flag1 && (Boolean)iblockdata.getValue(ATTACHED)) {
++ org.bukkit.World bworld = level.getWorld();
++ org.bukkit.plugin.PluginManager manager = level.getCraftServer().getPluginManager();
++ org.bukkit.block.Block block = bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ boolean allowed = false;
++
++ // If all of the events are cancelled block the tripwire trigger, else allow
++ for (Object object : list) {
++ if (object != null) {
++ org.bukkit.event.Cancellable cancellable;
++
++ if (object instanceof Player) {
++ cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((Player) object, org.bukkit.event.block.Action.PHYSICAL, pos, null, null, null);
++ } else if (object instanceof Entity) {
++ cancellable = new EntityInteractEvent(((Entity) object).getBukkitEntity(), block);
++ manager.callEvent((EntityInteractEvent) cancellable);
++ } else {
++ continue;
++ }
++
++ if (!cancellable.isCancelled()) {
++ allowed = true;
++ break;
++ }
++ }
++ }
++
++ if (!allowed) {
++ return;
++ }
++ }
++ // CraftBukkit end
++
+ if (flag1 != flag) {
+- blockState = blockState.setValue(POWERED, Boolean.valueOf(flag1));
+- level.setBlock(pos, blockState, 3);
+- this.updateSource(level, pos, blockState);
++ iblockdata = (IBlockData) iblockdata.setValue(TripWireBlock.POWERED, flag1);
++ level.setBlock(pos, iblockdata, 3);
++ this.updateSource(level, pos, iblockdata);
+ }
+
+ if (flag1) {
+- level.scheduleTick(new BlockPos(pos), this, 10);
++ level.scheduleTick(new BlockPos(pos), (Block) this, 10);
+ }
++
+ }
+
+- public boolean shouldConnectTo(BlockState state, Direction direction) {
+- return state.is(this.hook) ? state.getValue(TripWireHookBlock.FACING) == direction.getOpposite() : state.is(this);
++ public boolean shouldConnectTo(IBlockData state, Direction direction) {
++ return state.is(this.hook) ? state.getValue(TripWireHookBlock.FACING) == direction.getOpposite() : state.is((Block) this);
+ }
+
+ @Override
+- public BlockState rotate(BlockState state, Rotation rot) {
++ public IBlockData rotate(IBlockData state, Rotation rot) {
+ switch (rot) {
+ case CLOCKWISE_180:
+- return state.setValue(NORTH, state.getValue(SOUTH))
+- .setValue(EAST, state.getValue(WEST))
+- .setValue(SOUTH, state.getValue(NORTH))
+- .setValue(WEST, state.getValue(EAST));
++ return (IBlockData) ((IBlockData) ((IBlockData) ((IBlockData) state.setValue(TripWireBlock.NORTH, (Boolean) state.getValue(TripWireBlock.SOUTH))).setValue(TripWireBlock.EAST, (Boolean) state.getValue(TripWireBlock.WEST))).setValue(TripWireBlock.SOUTH, (Boolean) state.getValue(TripWireBlock.NORTH))).setValue(TripWireBlock.WEST, (Boolean) state.getValue(TripWireBlock.EAST));
+ case COUNTERCLOCKWISE_90:
+- return state.setValue(NORTH, state.getValue(EAST))
+- .setValue(EAST, state.getValue(SOUTH))
+- .setValue(SOUTH, state.getValue(WEST))
+- .setValue(WEST, state.getValue(NORTH));
++ return (IBlockData) ((IBlockData) ((IBlockData) ((IBlockData) state.setValue(TripWireBlock.NORTH, (Boolean) state.getValue(TripWireBlock.EAST))).setValue(TripWireBlock.EAST, (Boolean) state.getValue(TripWireBlock.SOUTH))).setValue(TripWireBlock.SOUTH, (Boolean) state.getValue(TripWireBlock.WEST))).setValue(TripWireBlock.WEST, (Boolean) state.getValue(TripWireBlock.NORTH));
+ case CLOCKWISE_90:
+- return state.setValue(NORTH, state.getValue(WEST))
+- .setValue(EAST, state.getValue(NORTH))
+- .setValue(SOUTH, state.getValue(EAST))
+- .setValue(WEST, state.getValue(SOUTH));
++ return (IBlockData) ((IBlockData) ((IBlockData) ((IBlockData) state.setValue(TripWireBlock.NORTH, (Boolean) state.getValue(TripWireBlock.WEST))).setValue(TripWireBlock.EAST, (Boolean) state.getValue(TripWireBlock.NORTH))).setValue(TripWireBlock.SOUTH, (Boolean) state.getValue(TripWireBlock.EAST))).setValue(TripWireBlock.WEST, (Boolean) state.getValue(TripWireBlock.SOUTH));
+ default:
+ return state;
+ }
+ }
+
+ @Override
+- public BlockState mirror(BlockState state, Mirror mirror) {
++ public IBlockData mirror(IBlockData state, Mirror mirror) {
+ switch (mirror) {
+ case LEFT_RIGHT:
+- return state.setValue(NORTH, state.getValue(SOUTH)).setValue(SOUTH, state.getValue(NORTH));
++ return (IBlockData) ((IBlockData) state.setValue(TripWireBlock.NORTH, (Boolean) state.getValue(TripWireBlock.SOUTH))).setValue(TripWireBlock.SOUTH, (Boolean) state.getValue(TripWireBlock.NORTH));
+ case FRONT_BACK:
+- return state.setValue(EAST, state.getValue(WEST)).setValue(WEST, state.getValue(EAST));
++ return (IBlockData) ((IBlockData) state.setValue(TripWireBlock.EAST, (Boolean) state.getValue(TripWireBlock.WEST))).setValue(TripWireBlock.WEST, (Boolean) state.getValue(TripWireBlock.EAST));
+ default:
+ return super.mirror(state, mirror);
+ }
+ }
+
+ @Override
+- protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
+- builder.add(POWERED, ATTACHED, DISARMED, NORTH, EAST, WEST, SOUTH);
++ protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) {
++ builder.add(TripWireBlock.POWERED, TripWireBlock.ATTACHED, TripWireBlock.DISARMED, TripWireBlock.NORTH, TripWireBlock.EAST, TripWireBlock.WEST, TripWireBlock.SOUTH);
+ }
+ }