diff options
Diffstat (limited to 'patch-remap/mache-spigotflower/net/minecraft/world/level/block/ButtonBlock.java.patch')
-rw-r--r-- | patch-remap/mache-spigotflower/net/minecraft/world/level/block/ButtonBlock.java.patch | 294 |
1 files changed, 294 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower/net/minecraft/world/level/block/ButtonBlock.java.patch b/patch-remap/mache-spigotflower/net/minecraft/world/level/block/ButtonBlock.java.patch new file mode 100644 index 0000000000..601cd179d8 --- /dev/null +++ b/patch-remap/mache-spigotflower/net/minecraft/world/level/block/ButtonBlock.java.patch @@ -0,0 +1,294 @@ +--- a/net/minecraft/world/level/block/ButtonBlock.java ++++ b/net/minecraft/world/level/block/ButtonBlock.java +@@ -11,7 +11,7 @@ + import net.minecraft.sounds.SoundEvent; + import net.minecraft.sounds.SoundSource; + import net.minecraft.util.RandomSource; +-import net.minecraft.world.InteractionHand; ++import net.minecraft.world.EnumHand; + import net.minecraft.world.InteractionResult; + import net.minecraft.world.entity.Entity; + import net.minecraft.world.entity.player.Player; +@@ -22,7 +22,7 @@ + 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.AttachFace; + import net.minecraft.world.level.block.state.properties.BlockSetType; +@@ -32,14 +32,18 @@ + import net.minecraft.world.phys.BlockHitResult; + import net.minecraft.world.phys.shapes.CollisionContext; + import net.minecraft.world.phys.shapes.VoxelShape; ++// CraftBukkit start ++import org.bukkit.event.block.BlockRedstoneEvent; ++import org.bukkit.event.entity.EntityInteractEvent; ++// CraftBukkit end + + public class ButtonBlock extends FaceAttachedHorizontalDirectionalBlock { + + public static final MapCodec<ButtonBlock> CODEC = RecordCodecBuilder.mapCodec((instance) -> { +- return instance.group(BlockSetType.CODEC.fieldOf("block_set_type").forGetter((buttonblock) -> { +- return buttonblock.type; +- }), Codec.intRange(1, 1024).fieldOf("ticks_to_stay_pressed").forGetter((buttonblock) -> { +- return buttonblock.ticksToStayPressed; ++ return instance.group(BlockSetType.CODEC.fieldOf("block_set_type").forGetter((blockbuttonabstract) -> { ++ return blockbuttonabstract.type; ++ }), Codec.intRange(1, 1024).fieldOf("ticks_to_stay_pressed").forGetter((blockbuttonabstract) -> { ++ return blockbuttonabstract.ticksToStayPressed; + }), propertiesCodec()).apply(instance, ButtonBlock::new); + }); + public static final BooleanProperty POWERED = BlockStateProperties.POWERED; +@@ -67,27 +71,25 @@ + private final int ticksToStayPressed; + + @Override +- @Override + public MapCodec<ButtonBlock> codec() { + return ButtonBlock.CODEC; + } + +- protected ButtonBlock(BlockSetType blocksettype, int i, BlockBehaviour.Properties blockbehaviour_properties) { +- super(blockbehaviour_properties.sound(blocksettype.soundType())); ++ protected ButtonBlock(BlockSetType blocksettype, int i, BlockBehaviour.Properties blockbase_info) { ++ super(blockbase_info.sound(blocksettype.soundType())); + this.type = blocksettype; +- this.registerDefaultState((BlockState) ((BlockState) ((BlockState) ((BlockState) this.stateDefinition.any()).setValue(ButtonBlock.FACING, Direction.NORTH)).setValue(ButtonBlock.POWERED, false)).setValue(ButtonBlock.FACE, AttachFace.WALL)); ++ this.registerDefaultState((IBlockData) ((IBlockData) ((IBlockData) ((IBlockData) this.stateDefinition.any()).setValue(ButtonBlock.FACING, Direction.NORTH)).setValue(ButtonBlock.POWERED, false)).setValue(ButtonBlock.FACE, AttachFace.WALL)); + this.ticksToStayPressed = i; + } + + @Override +- @Override +- public VoxelShape getShape(BlockState blockstate, BlockGetter blockgetter, BlockPos blockpos, CollisionContext collisioncontext) { +- Direction direction = (Direction) blockstate.getValue(ButtonBlock.FACING); +- boolean flag = (Boolean) blockstate.getValue(ButtonBlock.POWERED); ++ public VoxelShape getShape(IBlockData state, BlockGetter level, BlockPos pos, CollisionContext context) { ++ Direction enumdirection = (Direction) state.getValue(ButtonBlock.FACING); ++ boolean flag = (Boolean) state.getValue(ButtonBlock.POWERED); + +- switch ((AttachFace) blockstate.getValue(ButtonBlock.FACE)) { ++ switch ((AttachFace) state.getValue(ButtonBlock.FACE)) { + case FLOOR: +- if (direction.getAxis() == Direction.Axis.X) { ++ if (enumdirection.getAxis() == Direction.Axis.X) { + return flag ? ButtonBlock.PRESSED_FLOOR_AABB_X : ButtonBlock.FLOOR_AABB_X; + } + +@@ -95,7 +97,7 @@ + case WALL: + VoxelShape voxelshape; + +- switch (direction) { ++ switch (enumdirection) { + case EAST: + voxelshape = flag ? ButtonBlock.PRESSED_EAST_AABB : ButtonBlock.EAST_AABB; + break; +@@ -117,119 +119,148 @@ + return voxelshape; + case CEILING: + default: +- return direction.getAxis() == Direction.Axis.X ? (flag ? ButtonBlock.PRESSED_CEILING_AABB_X : ButtonBlock.CEILING_AABB_X) : (flag ? ButtonBlock.PRESSED_CEILING_AABB_Z : ButtonBlock.CEILING_AABB_Z); ++ return enumdirection.getAxis() == Direction.Axis.X ? (flag ? ButtonBlock.PRESSED_CEILING_AABB_X : ButtonBlock.CEILING_AABB_X) : (flag ? ButtonBlock.PRESSED_CEILING_AABB_Z : ButtonBlock.CEILING_AABB_Z); + } + } + + @Override +- @Override +- public InteractionResult use(BlockState blockstate, Level level, BlockPos blockpos, Player player, InteractionHand interactionhand, BlockHitResult blockhitresult) { +- if ((Boolean) blockstate.getValue(ButtonBlock.POWERED)) { ++ public InteractionResult use(IBlockData state, Level level, BlockPos pos, Player player, EnumHand hand, BlockHitResult hit) { ++ if ((Boolean) state.getValue(ButtonBlock.POWERED)) { + return InteractionResult.CONSUME; + } else { +- this.press(blockstate, level, blockpos); +- this.playSound(player, level, blockpos, true); +- level.gameEvent((Entity) player, GameEvent.BLOCK_ACTIVATE, blockpos); ++ // CraftBukkit start ++ boolean powered = ((Boolean) state.getValue(POWERED)); ++ org.bukkit.block.Block block = level.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()); ++ int old = (powered) ? 15 : 0; ++ int current = (!powered) ? 15 : 0; ++ ++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, old, current); ++ level.getCraftServer().getPluginManager().callEvent(eventRedstone); ++ ++ if ((eventRedstone.getNewCurrent() > 0) != (!powered)) { ++ return InteractionResult.SUCCESS; ++ } ++ // CraftBukkit end ++ this.press(state, level, pos); ++ this.playSound(player, level, pos, true); ++ level.gameEvent((Entity) player, GameEvent.BLOCK_ACTIVATE, pos); + return InteractionResult.sidedSuccess(level.isClientSide); + } + } + + @Override +- @Override +- public void onExplosionHit(BlockState blockstate, Level level, BlockPos blockpos, Explosion explosion, BiConsumer<ItemStack, BlockPos> biconsumer) { +- if (explosion.getBlockInteraction() == Explosion.BlockInteraction.TRIGGER_BLOCK && !level.isClientSide() && !(Boolean) blockstate.getValue(ButtonBlock.POWERED)) { +- this.press(blockstate, level, blockpos); ++ public void onExplosionHit(IBlockData iblockdata, Level world, BlockPos blockposition, Explosion explosion, BiConsumer<ItemStack, BlockPos> biconsumer) { ++ if (explosion.getBlockInteraction() == Explosion.Effect.TRIGGER_BLOCK && !world.isClientSide() && !(Boolean) iblockdata.getValue(ButtonBlock.POWERED)) { ++ this.press(iblockdata, world, blockposition); + } + +- super.onExplosionHit(blockstate, level, blockpos, explosion, biconsumer); ++ super.onExplosionHit(iblockdata, world, blockposition, explosion, biconsumer); + } + +- public void press(BlockState blockstate, Level level, BlockPos blockpos) { +- level.setBlock(blockpos, (BlockState) blockstate.setValue(ButtonBlock.POWERED, true), 3); +- this.updateNeighbours(blockstate, level, blockpos); +- level.scheduleTick(blockpos, (Block) this, this.ticksToStayPressed); ++ public void press(IBlockData state, Level level, BlockPos pos) { ++ level.setBlock(pos, (IBlockData) state.setValue(ButtonBlock.POWERED, true), 3); ++ this.updateNeighbours(state, level, pos); ++ level.scheduleTick(pos, (Block) this, this.ticksToStayPressed); + } + +- protected void playSound(@Nullable Player player, LevelAccessor levelaccessor, BlockPos blockpos, boolean flag) { +- levelaccessor.playSound(flag ? player : null, blockpos, this.getSound(flag), SoundSource.BLOCKS); ++ protected void playSound(@Nullable Player player, LevelAccessor level, BlockPos pos, boolean hitByArrow) { ++ level.playSound(hitByArrow ? player : null, pos, this.getSound(hitByArrow), SoundSource.BLOCKS); + } + +- protected SoundEvent getSound(boolean flag) { +- return flag ? this.type.buttonClickOn() : this.type.buttonClickOff(); ++ protected SoundEvent getSound(boolean isOn) { ++ return isOn ? this.type.buttonClickOn() : this.type.buttonClickOff(); + } + + @Override +- @Override +- public void onRemove(BlockState blockstate, Level level, BlockPos blockpos, BlockState blockstate1, boolean flag) { +- if (!flag && !blockstate.is(blockstate1.getBlock())) { +- if ((Boolean) blockstate.getValue(ButtonBlock.POWERED)) { +- this.updateNeighbours(blockstate, level, blockpos); ++ public void onRemove(IBlockData state, Level level, BlockPos pos, IBlockData newState, boolean isMoving) { ++ if (!isMoving && !state.is(newState.getBlock())) { ++ if ((Boolean) state.getValue(ButtonBlock.POWERED)) { ++ this.updateNeighbours(state, level, pos); + } + +- super.onRemove(blockstate, level, blockpos, blockstate1, flag); ++ super.onRemove(state, level, pos, newState, isMoving); + } + } + + @Override +- @Override +- public int getSignal(BlockState blockstate, BlockGetter blockgetter, BlockPos blockpos, Direction direction) { +- return (Boolean) blockstate.getValue(ButtonBlock.POWERED) ? 15 : 0; ++ public int getSignal(IBlockData blockState, BlockGetter blockAccess, BlockPos pos, Direction side) { ++ return (Boolean) blockState.getValue(ButtonBlock.POWERED) ? 15 : 0; + } + + @Override +- @Override +- public int getDirectSignal(BlockState blockstate, BlockGetter blockgetter, BlockPos blockpos, Direction direction) { +- return (Boolean) blockstate.getValue(ButtonBlock.POWERED) && getConnectedDirection(blockstate) == direction ? 15 : 0; ++ public int getDirectSignal(IBlockData blockState, BlockGetter blockAccess, BlockPos pos, Direction side) { ++ return (Boolean) blockState.getValue(ButtonBlock.POWERED) && getConnectedDirection(blockState) == side ? 15 : 0; + } + + @Override +- @Override +- public boolean isSignalSource(BlockState blockstate) { ++ public boolean isSignalSource(IBlockData state) { + return true; + } + + @Override +- @Override +- public void tick(BlockState blockstate, ServerLevel serverlevel, BlockPos blockpos, RandomSource randomsource) { +- if ((Boolean) blockstate.getValue(ButtonBlock.POWERED)) { +- this.checkPressed(blockstate, serverlevel, blockpos); ++ public void tick(IBlockData state, ServerLevel level, BlockPos pos, RandomSource random) { ++ if ((Boolean) state.getValue(ButtonBlock.POWERED)) { ++ this.checkPressed(state, level, pos); + } + } + + @Override +- @Override +- public void entityInside(BlockState blockstate, Level level, BlockPos blockpos, Entity entity) { +- if (!level.isClientSide && this.type.canButtonBeActivatedByArrows() && !(Boolean) blockstate.getValue(ButtonBlock.POWERED)) { +- this.checkPressed(blockstate, level, blockpos); ++ public void entityInside(IBlockData state, Level level, BlockPos pos, Entity entity) { ++ if (!level.isClientSide && this.type.canButtonBeActivatedByArrows() && !(Boolean) state.getValue(ButtonBlock.POWERED)) { ++ this.checkPressed(state, level, pos); + } + } + +- protected void checkPressed(BlockState blockstate, Level level, BlockPos blockpos) { +- AbstractArrow abstractarrow = this.type.canButtonBeActivatedByArrows() ? (AbstractArrow) level.getEntitiesOfClass(AbstractArrow.class, blockstate.getShape(level, blockpos).bounds().move(blockpos)).stream().findFirst().orElse((Object) null) : null; +- boolean flag = abstractarrow != null; +- boolean flag1 = (Boolean) blockstate.getValue(ButtonBlock.POWERED); ++ protected void checkPressed(IBlockData state, Level level, BlockPos pos) { ++ AbstractArrow entityarrow = this.type.canButtonBeActivatedByArrows() ? (AbstractArrow) level.getEntitiesOfClass(AbstractArrow.class, state.getShape(level, pos).bounds().move(pos)).stream().findFirst().orElse(null) : null; // CraftBukkit - decompile error ++ boolean flag = entityarrow != null; ++ boolean flag1 = (Boolean) state.getValue(ButtonBlock.POWERED); + ++ // CraftBukkit start - Call interact event when arrows turn on wooden buttons ++ if (flag1 != flag && flag) { ++ org.bukkit.block.Block block = level.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()); ++ EntityInteractEvent event = new EntityInteractEvent(entityarrow.getBukkitEntity(), block); ++ level.getCraftServer().getPluginManager().callEvent(event); ++ ++ if (event.isCancelled()) { ++ return; ++ } ++ } ++ // CraftBukkit end ++ + if (flag != flag1) { +- level.setBlock(blockpos, (BlockState) blockstate.setValue(ButtonBlock.POWERED, flag), 3); +- this.updateNeighbours(blockstate, level, blockpos); +- this.playSound((Player) null, level, blockpos, flag); +- level.gameEvent((Entity) abstractarrow, flag ? GameEvent.BLOCK_ACTIVATE : GameEvent.BLOCK_DEACTIVATE, blockpos); ++ // CraftBukkit start ++ boolean powered = flag1; ++ org.bukkit.block.Block block = level.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()); ++ int old = (powered) ? 15 : 0; ++ int current = (!powered) ? 15 : 0; ++ ++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, old, current); ++ level.getCraftServer().getPluginManager().callEvent(eventRedstone); ++ ++ if ((flag && eventRedstone.getNewCurrent() <= 0) || (!flag && eventRedstone.getNewCurrent() > 0)) { ++ return; ++ } ++ // CraftBukkit end ++ level.setBlock(pos, (IBlockData) state.setValue(ButtonBlock.POWERED, flag), 3); ++ this.updateNeighbours(state, level, pos); ++ this.playSound((Player) null, level, pos, flag); ++ level.gameEvent((Entity) entityarrow, flag ? GameEvent.BLOCK_ACTIVATE : GameEvent.BLOCK_DEACTIVATE, pos); + } + + if (flag) { +- level.scheduleTick(new BlockPos(blockpos), (Block) this, this.ticksToStayPressed); ++ level.scheduleTick(new BlockPos(pos), (Block) this, this.ticksToStayPressed); + } + + } + +- private void updateNeighbours(BlockState blockstate, Level level, BlockPos blockpos) { +- level.updateNeighborsAt(blockpos, this); +- level.updateNeighborsAt(blockpos.relative(getConnectedDirection(blockstate).getOpposite()), this); ++ private void updateNeighbours(IBlockData state, Level level, BlockPos pos) { ++ level.updateNeighborsAt(pos, this); ++ level.updateNeighborsAt(pos.relative(getConnectedDirection(state).getOpposite()), this); + } + + @Override +- @Override +- protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> statedefinition_builder) { +- statedefinition_builder.add(ButtonBlock.FACING, ButtonBlock.POWERED, ButtonBlock.FACE); ++ protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) { ++ builder.add(ButtonBlock.FACING, ButtonBlock.POWERED, ButtonBlock.FACE); + } + } |