aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/level/block/DispenserBlock.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/level/block/DispenserBlock.java.patch')
-rw-r--r--patch-remap/mache-vineflower/net/minecraft/world/level/block/DispenserBlock.java.patch254
1 files changed, 254 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/level/block/DispenserBlock.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/level/block/DispenserBlock.java.patch
new file mode 100644
index 0000000000..62de3efd20
--- /dev/null
+++ b/patch-remap/mache-vineflower/net/minecraft/world/level/block/DispenserBlock.java.patch
@@ -0,0 +1,254 @@
+--- a/net/minecraft/world/level/block/DispenserBlock.java
++++ b/net/minecraft/world/level/block/DispenserBlock.java
+@@ -7,15 +7,15 @@
+ import net.minecraft.Util;
+ import net.minecraft.core.BlockPos;
+ import net.minecraft.core.Direction;
+-import net.minecraft.core.Position;
+-import net.minecraft.core.dispenser.BlockSource;
++import net.minecraft.core.IPosition;
+ import net.minecraft.core.dispenser.DefaultDispenseItemBehavior;
+ import net.minecraft.core.dispenser.DispenseItemBehavior;
++import net.minecraft.core.dispenser.SourceBlock;
+ import net.minecraft.server.level.ServerLevel;
+ import net.minecraft.stats.Stats;
+ import net.minecraft.util.RandomSource;
+ import net.minecraft.world.Containers;
+-import net.minecraft.world.InteractionHand;
++import net.minecraft.world.EnumHand;
+ import net.minecraft.world.InteractionResult;
+ import net.minecraft.world.entity.LivingEntity;
+ import net.minecraft.world.entity.player.Player;
+@@ -23,14 +23,14 @@
+ import net.minecraft.world.item.Item;
+ import net.minecraft.world.item.ItemStack;
+ import net.minecraft.world.item.context.BlockPlaceContext;
+-import net.minecraft.world.level.ItemLike;
++import net.minecraft.world.level.IMaterial;
+ import net.minecraft.world.level.Level;
+ import net.minecraft.world.level.block.entity.BlockEntity;
+ import net.minecraft.world.level.block.entity.BlockEntityType;
+ import net.minecraft.world.level.block.entity.DispenserBlockEntity;
+-import net.minecraft.world.level.block.entity.DropperBlockEntity;
++import net.minecraft.world.level.block.entity.TileEntityDropper;
+ 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;
+@@ -40,38 +40,41 @@
+ import org.slf4j.Logger;
+
+ public class DispenserBlock extends BaseEntityBlock {
++
+ private static final Logger LOGGER = LogUtils.getLogger();
+ public static final MapCodec<DispenserBlock> CODEC = simpleCodec(DispenserBlock::new);
+- public static final DirectionProperty FACING = DirectionalBlock.FACING;
++ public static final DirectionProperty FACING = BlockDirectional.FACING;
+ public static final BooleanProperty TRIGGERED = BlockStateProperties.TRIGGERED;
+- private static final Map<Item, DispenseItemBehavior> DISPENSER_REGISTRY = Util.make(
+- new Object2ObjectOpenHashMap<>(), map -> map.defaultReturnValue(new DefaultDispenseItemBehavior())
+- );
++ public static final Map<Item, DispenseItemBehavior> DISPENSER_REGISTRY = (Map) Util.make(new Object2ObjectOpenHashMap(), (object2objectopenhashmap) -> {
++ object2objectopenhashmap.defaultReturnValue(new DefaultDispenseItemBehavior());
++ });
+ private static final int TRIGGER_DURATION = 4;
++ public static boolean eventFired = false; // CraftBukkit
+
+ @Override
+ public MapCodec<? extends DispenserBlock> codec() {
+- return CODEC;
++ return DispenserBlock.CODEC;
+ }
+
+- public static void registerBehavior(ItemLike item, DispenseItemBehavior behavior) {
+- DISPENSER_REGISTRY.put(item.asItem(), behavior);
++ public static void registerBehavior(IMaterial item, DispenseItemBehavior behavior) {
++ DispenserBlock.DISPENSER_REGISTRY.put(item.asItem(), behavior);
+ }
+
+ protected DispenserBlock(BlockBehaviour.Properties properties) {
+ super(properties);
+- this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(TRIGGERED, Boolean.valueOf(false)));
++ this.registerDefaultState((IBlockData) ((IBlockData) ((IBlockData) this.stateDefinition.any()).setValue(DispenserBlock.FACING, Direction.NORTH)).setValue(DispenserBlock.TRIGGERED, false));
+ }
+
+ @Override
+- public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
++ public InteractionResult use(IBlockData state, Level level, BlockPos pos, Player player, EnumHand hand, BlockHitResult hit) {
+ if (level.isClientSide) {
+ return InteractionResult.SUCCESS;
+ } else {
+- BlockEntity blockEntity = level.getBlockEntity(pos);
+- if (blockEntity instanceof DispenserBlockEntity) {
+- player.openMenu((DispenserBlockEntity)blockEntity);
+- if (blockEntity instanceof DropperBlockEntity) {
++ BlockEntity tileentity = level.getBlockEntity(pos);
++
++ if (tileentity instanceof DispenserBlockEntity) {
++ player.openMenu((DispenserBlockEntity) tileentity);
++ if (tileentity instanceof TileEntityDropper) {
+ player.awardStat(Stats.INSPECT_DROPPER);
+ } else {
+ player.awardStat(Stats.INSPECT_DISPENSER);
+@@ -82,105 +85,115 @@
+ }
+ }
+
+- protected void dispenseFrom(ServerLevel serverLevel, BlockState blockState, BlockPos blockPos) {
+- DispenserBlockEntity dispenserBlockEntity = serverLevel.getBlockEntity(blockPos, BlockEntityType.DISPENSER).orElse(null);
+- if (dispenserBlockEntity == null) {
+- LOGGER.warn("Ignoring dispensing attempt for Dispenser without matching block entity at {}", blockPos);
++ public void dispenseFrom(ServerLevel worldserver, IBlockData iblockdata, BlockPos blockposition) {
++ DispenserBlockEntity tileentitydispenser = (DispenserBlockEntity) worldserver.getBlockEntity(blockposition, BlockEntityType.DISPENSER).orElse(null); // CraftBukkit - decompile error
++
++ if (tileentitydispenser == null) {
++ DispenserBlock.LOGGER.warn("Ignoring dispensing attempt for Dispenser without matching block entity at {}", blockposition);
+ } else {
+- BlockSource blockSource = new BlockSource(serverLevel, blockPos, blockState, dispenserBlockEntity);
+- int randomSlot = dispenserBlockEntity.getRandomSlot(serverLevel.random);
+- if (randomSlot < 0) {
+- serverLevel.levelEvent(1001, blockPos, 0);
+- serverLevel.gameEvent(GameEvent.BLOCK_ACTIVATE, blockPos, GameEvent.Context.of(dispenserBlockEntity.getBlockState()));
++ SourceBlock sourceblock = new SourceBlock(worldserver, blockposition, iblockdata, tileentitydispenser);
++ int i = tileentitydispenser.getRandomSlot(worldserver.random);
++
++ if (i < 0) {
++ worldserver.levelEvent(1001, blockposition, 0);
++ worldserver.gameEvent(GameEvent.BLOCK_ACTIVATE, blockposition, GameEvent.Context.of(tileentitydispenser.getBlockState()));
+ } else {
+- ItemStack item = dispenserBlockEntity.getItem(randomSlot);
+- DispenseItemBehavior dispenseMethod = this.getDispenseMethod(item);
+- if (dispenseMethod != DispenseItemBehavior.NOOP) {
+- dispenserBlockEntity.setItem(randomSlot, dispenseMethod.dispense(blockSource, item));
++ ItemStack itemstack = tileentitydispenser.getItem(i);
++ DispenseItemBehavior idispensebehavior = this.getDispenseMethod(itemstack);
++
++ if (idispensebehavior != DispenseItemBehavior.NOOP) {
++ eventFired = false; // CraftBukkit - reset event status
++ tileentitydispenser.setItem(i, idispensebehavior.dispense(sourceblock, itemstack));
+ }
++
+ }
+ }
+ }
+
+ protected DispenseItemBehavior getDispenseMethod(ItemStack stack) {
+- return DISPENSER_REGISTRY.get(stack.getItem());
++ return (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(stack.getItem());
+ }
+
+ @Override
+- public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) {
+- boolean flag = level.hasNeighborSignal(pos) || level.hasNeighborSignal(pos.above());
+- boolean flag1 = state.getValue(TRIGGERED);
+- if (flag && !flag1) {
+- level.scheduleTick(pos, this, 4);
+- level.setBlock(pos, state.setValue(TRIGGERED, Boolean.valueOf(true)), 2);
+- } else if (!flag && flag1) {
+- level.setBlock(pos, state.setValue(TRIGGERED, Boolean.valueOf(false)), 2);
++ public void neighborChanged(IBlockData state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) {
++ boolean flag1 = level.hasNeighborSignal(pos) || level.hasNeighborSignal(pos.above());
++ boolean flag2 = (Boolean) state.getValue(DispenserBlock.TRIGGERED);
++
++ if (flag1 && !flag2) {
++ level.scheduleTick(pos, (Block) this, 4);
++ level.setBlock(pos, (IBlockData) state.setValue(DispenserBlock.TRIGGERED, true), 2);
++ } else if (!flag1 && flag2) {
++ level.setBlock(pos, (IBlockData) state.setValue(DispenserBlock.TRIGGERED, false), 2);
+ }
++
+ }
+
+ @Override
+- public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
++ public void tick(IBlockData state, ServerLevel level, BlockPos pos, RandomSource random) {
+ this.dispenseFrom(level, state, pos);
+ }
+
+ @Override
+- public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
++ public BlockEntity newBlockEntity(BlockPos pos, IBlockData state) {
+ return new DispenserBlockEntity(pos, state);
+ }
+
+ @Override
+- public BlockState getStateForPlacement(BlockPlaceContext context) {
+- return this.defaultBlockState().setValue(FACING, context.getNearestLookingDirection().getOpposite());
++ public IBlockData getStateForPlacement(BlockPlaceContext context) {
++ return (IBlockData) this.defaultBlockState().setValue(DispenserBlock.FACING, context.getNearestLookingDirection().getOpposite());
+ }
+
+ @Override
+- public void setPlacedBy(Level level, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
++ public void setPlacedBy(Level level, BlockPos pos, IBlockData state, LivingEntity placer, ItemStack stack) {
+ if (stack.hasCustomHoverName()) {
+- BlockEntity blockEntity = level.getBlockEntity(pos);
+- if (blockEntity instanceof DispenserBlockEntity) {
+- ((DispenserBlockEntity)blockEntity).setCustomName(stack.getHoverName());
++ BlockEntity tileentity = level.getBlockEntity(pos);
++
++ if (tileentity instanceof DispenserBlockEntity) {
++ ((DispenserBlockEntity) tileentity).setCustomName(stack.getHoverName());
+ }
+ }
++
+ }
+
+ @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) {
+ Containers.dropContentsOnDestroy(state, newState, level, pos);
+ super.onRemove(state, level, pos, newState, isMoving);
+ }
+
+- public static Position getDispensePosition(BlockSource blockSource) {
+- Direction direction = blockSource.state().getValue(FACING);
+- return blockSource.center().add(0.7 * (double)direction.getStepX(), 0.7 * (double)direction.getStepY(), 0.7 * (double)direction.getStepZ());
++ public static IPosition getDispensePosition(SourceBlock sourceblock) {
++ Direction enumdirection = (Direction) sourceblock.state().getValue(DispenserBlock.FACING);
++
++ return sourceblock.center().add(0.7D * (double) enumdirection.getStepX(), 0.7D * (double) enumdirection.getStepY(), 0.7D * (double) enumdirection.getStepZ());
+ }
+
+ @Override
+- public boolean hasAnalogOutputSignal(BlockState state) {
++ public boolean hasAnalogOutputSignal(IBlockData state) {
+ return true;
+ }
+
+ @Override
+- public int getAnalogOutputSignal(BlockState blockState, Level level, BlockPos pos) {
++ public int getAnalogOutputSignal(IBlockData blockState, Level level, BlockPos pos) {
+ return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(level.getBlockEntity(pos));
+ }
+
+ @Override
+- public RenderShape getRenderShape(BlockState state) {
+- return RenderShape.MODEL;
++ public EnumRenderType getRenderShape(IBlockData state) {
++ return EnumRenderType.MODEL;
+ }
+
+ @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(DispenserBlock.FACING, rotation.rotate((Direction) state.getValue(DispenserBlock.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(DispenserBlock.FACING)));
+ }
+
+ @Override
+- protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
+- builder.add(FACING, TRIGGERED);
++ protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) {
++ builder.add(DispenserBlock.FACING, DispenserBlock.TRIGGERED);
+ }
+ }