diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/level/block/ButtonBlock.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/world/level/block/ButtonBlock.java.patch | 342 |
1 files changed, 342 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/level/block/ButtonBlock.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/level/block/ButtonBlock.java.patch new file mode 100644 index 0000000000..e677005474 --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/world/level/block/ButtonBlock.java.patch @@ -0,0 +1,342 @@ +--- a/net/minecraft/world/level/block/ButtonBlock.java ++++ b/net/minecraft/world/level/block/ButtonBlock.java +@@ -3,7 +3,6 @@ + import com.mojang.serialization.Codec; + import com.mojang.serialization.MapCodec; + import com.mojang.serialization.codecs.RecordCodecBuilder; +-import com.mojang.serialization.codecs.RecordCodecBuilder.Instance; + import java.util.function.BiConsumer; + import javax.annotation.Nullable; + import net.minecraft.core.BlockPos; +@@ -12,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; +@@ -23,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; +@@ -33,107 +32,135 @@ + 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 -> instance.group( +- BlockSetType.CODEC.fieldOf("block_set_type").forGetter(buttonBlock -> buttonBlock.type), +- Codec.intRange(1, 1024).fieldOf("ticks_to_stay_pressed").forGetter(buttonBlock -> buttonBlock.ticksToStayPressed), +- propertiesCodec() +- ) +- .apply(instance, ButtonBlock::new) +- ); ++ ++ public static final MapCodec<ButtonBlock> CODEC = RecordCodecBuilder.mapCodec((instance) -> { ++ 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; + private static final int PRESSED_DEPTH = 1; + private static final int UNPRESSED_DEPTH = 2; + protected static final int HALF_AABB_HEIGHT = 2; + protected static final int HALF_AABB_WIDTH = 3; +- protected static final VoxelShape CEILING_AABB_X = Block.box(6.0, 14.0, 5.0, 10.0, 16.0, 11.0); +- protected static final VoxelShape CEILING_AABB_Z = Block.box(5.0, 14.0, 6.0, 11.0, 16.0, 10.0); +- protected static final VoxelShape FLOOR_AABB_X = Block.box(6.0, 0.0, 5.0, 10.0, 2.0, 11.0); +- protected static final VoxelShape FLOOR_AABB_Z = Block.box(5.0, 0.0, 6.0, 11.0, 2.0, 10.0); +- protected static final VoxelShape NORTH_AABB = Block.box(5.0, 6.0, 14.0, 11.0, 10.0, 16.0); +- protected static final VoxelShape SOUTH_AABB = Block.box(5.0, 6.0, 0.0, 11.0, 10.0, 2.0); +- protected static final VoxelShape WEST_AABB = Block.box(14.0, 6.0, 5.0, 16.0, 10.0, 11.0); +- protected static final VoxelShape EAST_AABB = Block.box(0.0, 6.0, 5.0, 2.0, 10.0, 11.0); +- protected static final VoxelShape PRESSED_CEILING_AABB_X = Block.box(6.0, 15.0, 5.0, 10.0, 16.0, 11.0); +- protected static final VoxelShape PRESSED_CEILING_AABB_Z = Block.box(5.0, 15.0, 6.0, 11.0, 16.0, 10.0); +- protected static final VoxelShape PRESSED_FLOOR_AABB_X = Block.box(6.0, 0.0, 5.0, 10.0, 1.0, 11.0); +- protected static final VoxelShape PRESSED_FLOOR_AABB_Z = Block.box(5.0, 0.0, 6.0, 11.0, 1.0, 10.0); +- protected static final VoxelShape PRESSED_NORTH_AABB = Block.box(5.0, 6.0, 15.0, 11.0, 10.0, 16.0); +- protected static final VoxelShape PRESSED_SOUTH_AABB = Block.box(5.0, 6.0, 0.0, 11.0, 10.0, 1.0); +- protected static final VoxelShape PRESSED_WEST_AABB = Block.box(15.0, 6.0, 5.0, 16.0, 10.0, 11.0); +- protected static final VoxelShape PRESSED_EAST_AABB = Block.box(0.0, 6.0, 5.0, 1.0, 10.0, 11.0); ++ protected static final VoxelShape CEILING_AABB_X = Block.box(6.0D, 14.0D, 5.0D, 10.0D, 16.0D, 11.0D); ++ protected static final VoxelShape CEILING_AABB_Z = Block.box(5.0D, 14.0D, 6.0D, 11.0D, 16.0D, 10.0D); ++ protected static final VoxelShape FLOOR_AABB_X = Block.box(6.0D, 0.0D, 5.0D, 10.0D, 2.0D, 11.0D); ++ protected static final VoxelShape FLOOR_AABB_Z = Block.box(5.0D, 0.0D, 6.0D, 11.0D, 2.0D, 10.0D); ++ protected static final VoxelShape NORTH_AABB = Block.box(5.0D, 6.0D, 14.0D, 11.0D, 10.0D, 16.0D); ++ protected static final VoxelShape SOUTH_AABB = Block.box(5.0D, 6.0D, 0.0D, 11.0D, 10.0D, 2.0D); ++ protected static final VoxelShape WEST_AABB = Block.box(14.0D, 6.0D, 5.0D, 16.0D, 10.0D, 11.0D); ++ protected static final VoxelShape EAST_AABB = Block.box(0.0D, 6.0D, 5.0D, 2.0D, 10.0D, 11.0D); ++ protected static final VoxelShape PRESSED_CEILING_AABB_X = Block.box(6.0D, 15.0D, 5.0D, 10.0D, 16.0D, 11.0D); ++ protected static final VoxelShape PRESSED_CEILING_AABB_Z = Block.box(5.0D, 15.0D, 6.0D, 11.0D, 16.0D, 10.0D); ++ protected static final VoxelShape PRESSED_FLOOR_AABB_X = Block.box(6.0D, 0.0D, 5.0D, 10.0D, 1.0D, 11.0D); ++ protected static final VoxelShape PRESSED_FLOOR_AABB_Z = Block.box(5.0D, 0.0D, 6.0D, 11.0D, 1.0D, 10.0D); ++ protected static final VoxelShape PRESSED_NORTH_AABB = Block.box(5.0D, 6.0D, 15.0D, 11.0D, 10.0D, 16.0D); ++ protected static final VoxelShape PRESSED_SOUTH_AABB = Block.box(5.0D, 6.0D, 0.0D, 11.0D, 10.0D, 1.0D); ++ protected static final VoxelShape PRESSED_WEST_AABB = Block.box(15.0D, 6.0D, 5.0D, 16.0D, 10.0D, 11.0D); ++ protected static final VoxelShape PRESSED_EAST_AABB = Block.box(0.0D, 6.0D, 5.0D, 1.0D, 10.0D, 11.0D); + private final BlockSetType type; + private final int ticksToStayPressed; + + @Override + public MapCodec<ButtonBlock> codec() { +- return CODEC; ++ return ButtonBlock.CODEC; + } + +- protected ButtonBlock(BlockSetType blockSetType, int i, BlockBehaviour.Properties properties) { +- super(properties.sound(blockSetType.soundType())); +- this.type = blockSetType; +- this.registerDefaultState( +- this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(POWERED, Boolean.valueOf(false)).setValue(FACE, AttachFace.WALL) +- ); ++ protected ButtonBlock(BlockSetType blocksettype, int i, BlockBehaviour.Properties blockbase_info) { ++ super(blockbase_info.sound(blocksettype.soundType())); ++ this.type = blocksettype; ++ 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 +- public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { +- Direction direction = state.getValue(FACING); +- boolean flag = state.getValue(POWERED); +- switch ((AttachFace)state.getValue(FACE)) { ++ 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) state.getValue(ButtonBlock.FACE)) { + case FLOOR: +- if (direction.getAxis() == Direction.Axis.X) { +- return flag ? PRESSED_FLOOR_AABB_X : FLOOR_AABB_X; ++ if (enumdirection.getAxis() == Direction.Axis.X) { ++ return flag ? ButtonBlock.PRESSED_FLOOR_AABB_X : ButtonBlock.FLOOR_AABB_X; + } + +- return flag ? PRESSED_FLOOR_AABB_Z : FLOOR_AABB_Z; ++ return flag ? ButtonBlock.PRESSED_FLOOR_AABB_Z : ButtonBlock.FLOOR_AABB_Z; + case WALL: +- return switch (direction) { +- case EAST -> flag ? PRESSED_EAST_AABB : EAST_AABB; +- case WEST -> flag ? PRESSED_WEST_AABB : WEST_AABB; +- case SOUTH -> flag ? PRESSED_SOUTH_AABB : SOUTH_AABB; +- case NORTH, UP, DOWN -> flag ? PRESSED_NORTH_AABB : NORTH_AABB; +- }; ++ VoxelShape voxelshape; ++ ++ switch (enumdirection) { ++ case EAST: ++ voxelshape = flag ? ButtonBlock.PRESSED_EAST_AABB : ButtonBlock.EAST_AABB; ++ break; ++ case WEST: ++ voxelshape = flag ? ButtonBlock.PRESSED_WEST_AABB : ButtonBlock.WEST_AABB; ++ break; ++ case SOUTH: ++ voxelshape = flag ? ButtonBlock.PRESSED_SOUTH_AABB : ButtonBlock.SOUTH_AABB; ++ break; ++ case NORTH: ++ case UP: ++ case DOWN: ++ voxelshape = flag ? ButtonBlock.PRESSED_NORTH_AABB : ButtonBlock.NORTH_AABB; ++ break; ++ default: ++ throw new IncompatibleClassChangeError(); ++ } ++ ++ return voxelshape; + case CEILING: + default: +- if (direction.getAxis() == Direction.Axis.X) { +- return flag ? PRESSED_CEILING_AABB_X : CEILING_AABB_X; +- } else { +- return flag ? PRESSED_CEILING_AABB_Z : 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 +- public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { +- if (state.getValue(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 { ++ // 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(player, GameEvent.BLOCK_ACTIVATE, pos); ++ level.gameEvent((Entity) player, GameEvent.BLOCK_ACTIVATE, pos); + return InteractionResult.sidedSuccess(level.isClientSide); + } + } + + @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() && !blockState.getValue(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 state, Level level, BlockPos pos) { +- level.setBlock(pos, state.setValue(POWERED, Boolean.valueOf(true)), 3); ++ 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, this, this.ticksToStayPressed); ++ level.scheduleTick(pos, (Block) this, this.ticksToStayPressed); + } + + protected void playSound(@Nullable Player player, LevelAccessor level, BlockPos pos, boolean hitByArrow) { +@@ -145,9 +172,9 @@ + } + + @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())) { +- if (state.getValue(POWERED)) { ++ if ((Boolean) state.getValue(ButtonBlock.POWERED)) { + this.updateNeighbours(state, level, pos); + } + +@@ -156,59 +183,84 @@ + } + + @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(ButtonBlock.POWERED) ? 15 : 0; + } + + @Override +- public int getDirectSignal(BlockState blockState, BlockGetter blockAccess, BlockPos pos, Direction side) { +- return blockState.getValue(POWERED) && getConnectedDirection(blockState) == side ? 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 +- public boolean isSignalSource(BlockState state) { ++ public boolean isSignalSource(IBlockData state) { + return true; + } + + @Override +- public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { +- if (state.getValue(POWERED)) { ++ public void tick(IBlockData state, ServerLevel level, BlockPos pos, RandomSource random) { ++ if ((Boolean) state.getValue(ButtonBlock.POWERED)) { + this.checkPressed(state, level, pos); + } + } + + @Override +- public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) { +- if (!level.isClientSide && this.type.canButtonBeActivatedByArrows() && !state.getValue(POWERED)) { ++ 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 state, Level level, BlockPos pos) { +- AbstractArrow abstractArrow = this.type.canButtonBeActivatedByArrows() +- ? level.getEntitiesOfClass(AbstractArrow.class, state.getShape(level, pos).bounds().move(pos)).stream().findFirst().orElse(null) +- : null; +- boolean flag = abstractArrow != null; +- boolean flag1 = state.getValue(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(pos, state.setValue(POWERED, Boolean.valueOf(flag)), 3); ++ // 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(null, level, pos, flag); +- level.gameEvent(abstractArrow, flag ? GameEvent.BLOCK_ACTIVATE : GameEvent.BLOCK_DEACTIVATE, 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(pos), this, this.ticksToStayPressed); ++ level.scheduleTick(new BlockPos(pos), (Block) this, this.ticksToStayPressed); + } ++ + } + +- private void updateNeighbours(BlockState state, Level level, BlockPos pos) { ++ private void updateNeighbours(IBlockData state, Level level, BlockPos pos) { + level.updateNeighborsAt(pos, this); + level.updateNeighborsAt(pos.relative(getConnectedDirection(state).getOpposite()), this); + } + + @Override +- protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { +- builder.add(FACING, POWERED, FACE); ++ protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) { ++ builder.add(ButtonBlock.FACING, ButtonBlock.POWERED, ButtonBlock.FACE); + } + } |