diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/level/block/TripWireHookBlock.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/world/level/block/TripWireHookBlock.java.patch | 403 |
1 files changed, 403 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/level/block/TripWireHookBlock.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/level/block/TripWireHookBlock.java.patch new file mode 100644 index 0000000000..ca96239d64 --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/world/level/block/TripWireHookBlock.java.patch @@ -0,0 +1,403 @@ +--- a/net/minecraft/world/level/block/TripWireHookBlock.java ++++ b/net/minecraft/world/level/block/TripWireHookBlock.java +@@ -10,7 +10,9 @@ + import net.minecraft.sounds.SoundEvents; + import net.minecraft.sounds.SoundSource; + import net.minecraft.util.RandomSource; ++import net.minecraft.world.entity.Entity; + import net.minecraft.world.entity.LivingEntity; ++import net.minecraft.world.entity.player.Player; + import net.minecraft.world.item.ItemStack; + import net.minecraft.world.item.context.BlockPlaceContext; + import net.minecraft.world.level.BlockGetter; +@@ -18,7 +20,7 @@ + import net.minecraft.world.level.LevelAccessor; + import net.minecraft.world.level.LevelReader; + 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; +@@ -26,8 +28,13 @@ + import net.minecraft.world.level.gameevent.GameEvent; + import net.minecraft.world.phys.shapes.CollisionContext; + import net.minecraft.world.phys.shapes.VoxelShape; ++// CraftBukkit start ++import org.bukkit.craftbukkit.block.CraftBlock; ++import org.bukkit.event.block.BlockRedstoneEvent; ++// CraftBukkit end + + public class TripWireHookBlock extends Block { ++ + public static final MapCodec<TripWireHookBlock> CODEC = simpleCodec(TripWireHookBlock::new); + public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; + public static final BooleanProperty POWERED = BlockStateProperties.POWERED; +@@ -36,67 +43,69 @@ + protected static final int WIRE_DIST_MAX = 42; + private static final int RECHECK_PERIOD = 10; + protected static final int AABB_OFFSET = 3; +- protected static final VoxelShape NORTH_AABB = Block.box(5.0, 0.0, 10.0, 11.0, 10.0, 16.0); +- protected static final VoxelShape SOUTH_AABB = Block.box(5.0, 0.0, 0.0, 11.0, 10.0, 6.0); +- protected static final VoxelShape WEST_AABB = Block.box(10.0, 0.0, 5.0, 16.0, 10.0, 11.0); +- protected static final VoxelShape EAST_AABB = Block.box(0.0, 0.0, 5.0, 6.0, 10.0, 11.0); ++ protected static final VoxelShape NORTH_AABB = Block.box(5.0D, 0.0D, 10.0D, 11.0D, 10.0D, 16.0D); ++ protected static final VoxelShape SOUTH_AABB = Block.box(5.0D, 0.0D, 0.0D, 11.0D, 10.0D, 6.0D); ++ protected static final VoxelShape WEST_AABB = Block.box(10.0D, 0.0D, 5.0D, 16.0D, 10.0D, 11.0D); ++ protected static final VoxelShape EAST_AABB = Block.box(0.0D, 0.0D, 5.0D, 6.0D, 10.0D, 11.0D); + + @Override + public MapCodec<TripWireHookBlock> codec() { +- return CODEC; ++ return TripWireHookBlock.CODEC; + } + + public TripWireHookBlock(BlockBehaviour.Properties properties) { + super(properties); +- this.registerDefaultState( +- this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(POWERED, Boolean.valueOf(false)).setValue(ATTACHED, Boolean.valueOf(false)) +- ); ++ this.registerDefaultState((IBlockData) ((IBlockData) ((IBlockData) ((IBlockData) this.stateDefinition.any()).setValue(TripWireHookBlock.FACING, Direction.NORTH)).setValue(TripWireHookBlock.POWERED, false)).setValue(TripWireHookBlock.ATTACHED, false)); + } + + @Override +- public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { +- switch ((Direction)state.getValue(FACING)) { ++ public VoxelShape getShape(IBlockData state, BlockGetter level, BlockPos pos, CollisionContext context) { ++ switch ((Direction) state.getValue(TripWireHookBlock.FACING)) { + case EAST: + default: +- return EAST_AABB; ++ return TripWireHookBlock.EAST_AABB; + case WEST: +- return WEST_AABB; ++ return TripWireHookBlock.WEST_AABB; + case SOUTH: +- return SOUTH_AABB; ++ return TripWireHookBlock.SOUTH_AABB; + case NORTH: +- return NORTH_AABB; ++ return TripWireHookBlock.NORTH_AABB; + } + } + + @Override +- public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) { +- Direction direction = state.getValue(FACING); +- BlockPos blockPos = pos.relative(direction.getOpposite()); +- BlockState blockState = level.getBlockState(blockPos); +- return direction.getAxis().isHorizontal() && blockState.isFaceSturdy(level, blockPos, direction); ++ public boolean canSurvive(IBlockData state, LevelReader level, BlockPos pos) { ++ Direction enumdirection = (Direction) state.getValue(TripWireHookBlock.FACING); ++ BlockPos blockposition1 = pos.relative(enumdirection.getOpposite()); ++ IBlockData iblockdata1 = level.getBlockState(blockposition1); ++ ++ return enumdirection.getAxis().isHorizontal() && iblockdata1.isFaceSturdy(level, blockposition1, enumdirection); + } + + @Override +- public BlockState updateShape(BlockState state, Direction facing, BlockState facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) { +- return facing.getOpposite() == state.getValue(FACING) && !state.canSurvive(level, currentPos) +- ? Blocks.AIR.defaultBlockState() +- : 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.getOpposite() == state.getValue(TripWireHookBlock.FACING) && !state.canSurvive(level, currentPos) ? Blocks.AIR.defaultBlockState() : super.updateShape(state, facing, facingState, level, currentPos, facingPos); + } + + @Nullable + @Override +- public BlockState getStateForPlacement(BlockPlaceContext context) { +- BlockState blockState = this.defaultBlockState().setValue(POWERED, Boolean.valueOf(false)).setValue(ATTACHED, Boolean.valueOf(false)); +- LevelReader level = context.getLevel(); +- BlockPos clickedPos = context.getClickedPos(); +- Direction[] nearestLookingDirections = context.getNearestLookingDirections(); ++ public IBlockData getStateForPlacement(BlockPlaceContext context) { ++ IBlockData iblockdata = (IBlockData) ((IBlockData) this.defaultBlockState().setValue(TripWireHookBlock.POWERED, false)).setValue(TripWireHookBlock.ATTACHED, false); ++ Level world = context.getLevel(); ++ BlockPos blockposition = context.getClickedPos(); ++ Direction[] aenumdirection = context.getNearestLookingDirections(); ++ Direction[] aenumdirection1 = aenumdirection; ++ int i = aenumdirection.length; + +- for (Direction direction : nearestLookingDirections) { +- if (direction.getAxis().isHorizontal()) { +- Direction opposite = direction.getOpposite(); +- blockState = blockState.setValue(FACING, opposite); +- if (blockState.canSurvive(level, clickedPos)) { +- return blockState; ++ for (int j = 0; j < i; ++j) { ++ Direction enumdirection = aenumdirection1[j]; ++ ++ if (enumdirection.getAxis().isHorizontal()) { ++ Direction enumdirection1 = enumdirection.getOpposite(); ++ ++ iblockdata = (IBlockData) iblockdata.setValue(TripWireHookBlock.FACING, enumdirection1); ++ if (iblockdata.canSurvive(world, blockposition)) { ++ return iblockdata; + } + } + } +@@ -105,124 +114,143 @@ + } + + @Override +- public void setPlacedBy(Level level, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { +- calculateState(level, pos, state, false, false, -1, null); ++ public void setPlacedBy(Level level, BlockPos pos, IBlockData state, LivingEntity placer, ItemStack stack) { ++ calculateState(level, pos, state, false, false, -1, (IBlockData) null); + } + +- public static void calculateState( +- Level level, BlockPos level1, BlockState pos, boolean hookState, boolean attaching, int shouldNotifyNeighbours, @Nullable BlockState searchRange +- ) { +- Optional<Direction> state = pos.getOptionalValue(FACING); +- if (state.isPresent()) { +- Direction direction = state.get(); +- boolean flag = pos.getOptionalValue(ATTACHED).orElse(false); +- boolean flag1 = pos.getOptionalValue(POWERED).orElse(false); ++ public static void calculateState(Level world, BlockPos level, IBlockData pos, boolean hookState, boolean attaching, int shouldNotifyNeighbours, @Nullable IBlockData searchRange) { ++ Optional<Direction> optional = pos.getOptionalValue(TripWireHookBlock.FACING); ++ ++ if (optional.isPresent()) { ++ Direction enumdirection = (Direction) optional.get(); ++ boolean flag2 = (Boolean) pos.getOptionalValue(TripWireHookBlock.ATTACHED).orElse(false); ++ boolean flag3 = (Boolean) pos.getOptionalValue(TripWireHookBlock.POWERED).orElse(false); + Block block = pos.getBlock(); +- boolean flag2 = !hookState; +- boolean flag3 = false; +- int i = 0; +- BlockState[] blockStates = new BlockState[42]; ++ boolean flag4 = !hookState; ++ boolean flag5 = false; ++ int j = 0; ++ IBlockData[] aiblockdata = new IBlockData[42]; + +- for (int i1 = 1; i1 < 42; i1++) { +- BlockPos blockPos = level1.relative(direction, i1); +- BlockState blockState = level.getBlockState(blockPos); +- if (blockState.is(Blocks.TRIPWIRE_HOOK)) { +- if (blockState.getValue(FACING) == direction.getOpposite()) { +- i = i1; ++ BlockPos blockposition1; ++ ++ for (int k = 1; k < 42; ++k) { ++ blockposition1 = level.relative(enumdirection, k); ++ IBlockData iblockdata2 = world.getBlockState(blockposition1); ++ ++ if (iblockdata2.is(Blocks.TRIPWIRE_HOOK)) { ++ if (iblockdata2.getValue(TripWireHookBlock.FACING) == enumdirection.getOpposite()) { ++ j = k; + } + break; + } + +- if (!blockState.is(Blocks.TRIPWIRE) && i1 != shouldNotifyNeighbours) { +- blockStates[i1] = null; +- flag2 = false; ++ if (!iblockdata2.is(Blocks.TRIPWIRE) && k != shouldNotifyNeighbours) { ++ aiblockdata[k] = null; ++ flag4 = false; + } else { +- if (i1 == shouldNotifyNeighbours) { +- blockState = MoreObjects.firstNonNull(searchRange, blockState); ++ if (k == shouldNotifyNeighbours) { ++ iblockdata2 = (IBlockData) MoreObjects.firstNonNull(searchRange, iblockdata2); + } + +- boolean flag4 = !blockState.getValue(TripWireBlock.DISARMED); +- boolean flag5 = blockState.getValue(TripWireBlock.POWERED); +- flag3 |= flag4 && flag5; +- blockStates[i1] = blockState; +- if (i1 == shouldNotifyNeighbours) { +- level.scheduleTick(level1, block, 10); +- flag2 &= flag4; ++ boolean flag6 = !(Boolean) iblockdata2.getValue(TripWireBlock.DISARMED); ++ boolean flag7 = (Boolean) iblockdata2.getValue(TripWireBlock.POWERED); ++ ++ flag5 |= flag6 && flag7; ++ aiblockdata[k] = iblockdata2; ++ if (k == shouldNotifyNeighbours) { ++ world.scheduleTick(level, block, 10); ++ flag4 &= flag6; + } + } + } + +- boolean var21 = flag2 & i > 1; +- boolean var22 = flag3 & var21; +- BlockState blockState1 = block.defaultBlockState().trySetValue(ATTACHED, Boolean.valueOf(var21)).trySetValue(POWERED, Boolean.valueOf(var22)); +- if (i > 0) { +- BlockPos blockPosx = level1.relative(direction, i); +- Direction opposite = direction.getOpposite(); +- level.setBlock(blockPosx, blockState1.setValue(FACING, opposite), 3); +- notifyNeighbors(block, level, blockPosx, opposite); +- emitState(level, blockPosx, var21, var22, flag, flag1); ++ flag4 &= j > 1; ++ flag5 &= flag4; ++ IBlockData iblockdata3 = (IBlockData) ((IBlockData) block.defaultBlockState().trySetValue(TripWireHookBlock.ATTACHED, flag4)).trySetValue(TripWireHookBlock.POWERED, flag5); ++ ++ if (j > 0) { ++ blockposition1 = level.relative(enumdirection, j); ++ Direction enumdirection1 = enumdirection.getOpposite(); ++ ++ world.setBlock(blockposition1, (IBlockData) iblockdata3.setValue(TripWireHookBlock.FACING, enumdirection1), 3); ++ notifyNeighbors(block, world, blockposition1, enumdirection1); ++ emitState(world, blockposition1, flag4, flag5, flag2, flag3); + } + +- emitState(level, level1, var21, var22, flag, flag1); ++ // CraftBukkit start ++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(CraftBlock.at(world, level), 15, 0); ++ world.getCraftServer().getPluginManager().callEvent(eventRedstone); ++ ++ if (eventRedstone.getNewCurrent() > 0) { ++ return; ++ } ++ // CraftBukkit end ++ ++ emitState(world, level, flag4, flag5, flag2, flag3); + if (!hookState) { +- level.setBlock(level1, blockState1.setValue(FACING, direction), 3); ++ world.setBlock(level, (IBlockData) iblockdata3.setValue(TripWireHookBlock.FACING, enumdirection), 3); + if (attaching) { +- notifyNeighbors(block, level, level1, direction); ++ notifyNeighbors(block, world, level, enumdirection); + } + } + +- if (flag != var21) { +- for (int i2 = 1; i2 < i; i2++) { +- BlockPos blockPos1 = level1.relative(direction, i2); +- BlockState blockState2 = blockStates[i2]; +- if (blockState2 != null) { +- level.setBlock(blockPos1, blockState2.trySetValue(ATTACHED, Boolean.valueOf(var21)), 3); +- if (!level.getBlockState(blockPos1).isAir()) { ++ if (flag2 != flag4) { ++ for (int l = 1; l < j; ++l) { ++ BlockPos blockposition2 = level.relative(enumdirection, l); ++ IBlockData iblockdata4 = aiblockdata[l]; ++ ++ if (iblockdata4 != null) { ++ world.setBlock(blockposition2, (IBlockData) iblockdata4.trySetValue(TripWireHookBlock.ATTACHED, flag4), 3); ++ if (!world.getBlockState(blockposition2).isAir()) { ++ ; + } + } + } + } ++ + } + } + + @Override +- public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { +- calculateState(level, pos, state, false, true, -1, null); ++ public void tick(IBlockData state, ServerLevel level, BlockPos pos, RandomSource random) { ++ calculateState(level, pos, state, false, true, -1, (IBlockData) null); + } + +- private static void emitState(Level level, BlockPos level1, boolean pos, boolean attached, boolean powered, boolean wasAttached) { ++ private static void emitState(Level world, BlockPos level, boolean pos, boolean attached, boolean powered, boolean wasAttached) { + if (attached && !wasAttached) { +- level.playSound(null, level1, SoundEvents.TRIPWIRE_CLICK_ON, SoundSource.BLOCKS, 0.4F, 0.6F); +- level.gameEvent(null, GameEvent.BLOCK_ACTIVATE, level1); ++ world.playSound((Player) null, level, SoundEvents.TRIPWIRE_CLICK_ON, SoundSource.BLOCKS, 0.4F, 0.6F); ++ world.gameEvent((Entity) null, GameEvent.BLOCK_ACTIVATE, level); + } else if (!attached && wasAttached) { +- level.playSound(null, level1, SoundEvents.TRIPWIRE_CLICK_OFF, SoundSource.BLOCKS, 0.4F, 0.5F); +- level.gameEvent(null, GameEvent.BLOCK_DEACTIVATE, level1); ++ world.playSound((Player) null, level, SoundEvents.TRIPWIRE_CLICK_OFF, SoundSource.BLOCKS, 0.4F, 0.5F); ++ world.gameEvent((Entity) null, GameEvent.BLOCK_DEACTIVATE, level); + } else if (pos && !powered) { +- level.playSound(null, level1, SoundEvents.TRIPWIRE_ATTACH, SoundSource.BLOCKS, 0.4F, 0.7F); +- level.gameEvent(null, GameEvent.BLOCK_ATTACH, level1); ++ world.playSound((Player) null, level, SoundEvents.TRIPWIRE_ATTACH, SoundSource.BLOCKS, 0.4F, 0.7F); ++ world.gameEvent((Entity) null, GameEvent.BLOCK_ATTACH, level); + } else if (!pos && powered) { +- level.playSound(null, level1, SoundEvents.TRIPWIRE_DETACH, SoundSource.BLOCKS, 0.4F, 1.2F / (level.random.nextFloat() * 0.2F + 0.9F)); +- level.gameEvent(null, GameEvent.BLOCK_DETACH, level1); ++ world.playSound((Player) null, level, SoundEvents.TRIPWIRE_DETACH, SoundSource.BLOCKS, 0.4F, 1.2F / (world.random.nextFloat() * 0.2F + 0.9F)); ++ world.gameEvent((Entity) null, GameEvent.BLOCK_DETACH, level); + } ++ + } + +- private static void notifyNeighbors(Block block, Level level, BlockPos blockPos, Direction direction) { +- level.updateNeighborsAt(blockPos, block); +- level.updateNeighborsAt(blockPos.relative(direction.getOpposite()), block); ++ private static void notifyNeighbors(Block block, Level world, BlockPos blockposition, Direction enumdirection) { ++ world.updateNeighborsAt(blockposition, block); ++ world.updateNeighborsAt(blockposition.relative(enumdirection.getOpposite()), block); + } + + @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())) { +- boolean flag = state.getValue(ATTACHED); +- boolean flag1 = state.getValue(POWERED); +- if (flag || flag1) { +- calculateState(level, pos, state, true, false, -1, null); ++ boolean flag1 = (Boolean) state.getValue(TripWireHookBlock.ATTACHED); ++ boolean flag2 = (Boolean) state.getValue(TripWireHookBlock.POWERED); ++ ++ if (flag1 || flag2) { ++ calculateState(level, pos, state, true, false, -1, (IBlockData) null); + } + +- if (flag1) { ++ if (flag2) { + level.updateNeighborsAt(pos, this); +- level.updateNeighborsAt(pos.relative(state.getValue(FACING).getOpposite()), this); ++ level.updateNeighborsAt(pos.relative(((Direction) state.getValue(TripWireHookBlock.FACING)).getOpposite()), this); + } + + super.onRemove(state, level, pos, newState, isMoving); +@@ -230,36 +258,32 @@ + } + + @Override +- public int getSignal(BlockState blockState, BlockGetter blockAccess, BlockPos pos, Direction side) { +- return blockState.getValue(POWERED) ? 15 : 0; ++ public int getSignal(IBlockData blockState, BlockGetter blockAccess, BlockPos pos, Direction side) { ++ return (Boolean) blockState.getValue(TripWireHookBlock.POWERED) ? 15 : 0; + } + + @Override +- public int getDirectSignal(BlockState blockState, BlockGetter blockAccess, BlockPos pos, Direction side) { +- if (!blockState.getValue(POWERED)) { +- return 0; +- } else { +- return blockState.getValue(FACING) == side ? 15 : 0; +- } ++ public int getDirectSignal(IBlockData blockState, BlockGetter blockAccess, BlockPos pos, Direction side) { ++ return !(Boolean) blockState.getValue(TripWireHookBlock.POWERED) ? 0 : (blockState.getValue(TripWireHookBlock.FACING) == side ? 15 : 0); + } + + @Override +- public boolean isSignalSource(BlockState state) { ++ public boolean isSignalSource(IBlockData state) { + return true; + } + + @Override +- public BlockState rotate(BlockState state, Rotation rotation) { +- return state.setValue(FACING, rotation.rotate(state.getValue(FACING))); ++ public IBlockData rotate(IBlockData state, Rotation rotation) { ++ return (IBlockData) state.setValue(TripWireHookBlock.FACING, rotation.rotate((Direction) state.getValue(TripWireHookBlock.FACING))); + } + + @Override +- public BlockState mirror(BlockState state, Mirror mirror) { +- return state.rotate(mirror.getRotation(state.getValue(FACING))); ++ public IBlockData mirror(IBlockData state, Mirror mirror) { ++ return state.rotate(mirror.getRotation((Direction) state.getValue(TripWireHookBlock.FACING))); + } + + @Override +- protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { +- builder.add(FACING, POWERED, ATTACHED); ++ protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) { ++ builder.add(TripWireHookBlock.FACING, TripWireHookBlock.POWERED, TripWireHookBlock.ATTACHED); + } + } |