aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower/net/minecraft/world/level/block/DispenserBlock.java.patch
blob: 5deb28528db4a1f6310f8032b01fe3475152a35b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
--- 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;
@@ -43,39 +43,38 @@
 
     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 = (Map) Util.make(new Object2ObjectOpenHashMap(), (object2objectopenhashmap) -> {
+    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
-    @Override
     public MapCodec<? extends DispenserBlock> codec() {
         return DispenserBlock.CODEC;
     }
 
-    public static void registerBehavior(ItemLike itemlike, DispenseItemBehavior dispenseitembehavior) {
-        DispenserBlock.DISPENSER_REGISTRY.put(itemlike.asItem(), dispenseitembehavior);
+    public static void registerBehavior(IMaterial item, DispenseItemBehavior behavior) {
+        DispenserBlock.DISPENSER_REGISTRY.put(item.asItem(), behavior);
     }
 
-    protected DispenserBlock(BlockBehaviour.Properties blockbehaviour_properties) {
-        super(blockbehaviour_properties);
-        this.registerDefaultState((BlockState) ((BlockState) ((BlockState) this.stateDefinition.any()).setValue(DispenserBlock.FACING, Direction.NORTH)).setValue(DispenserBlock.TRIGGERED, false));
+    protected DispenserBlock(BlockBehaviour.Properties properties) {
+        super(properties);
+        this.registerDefaultState((IBlockData) ((IBlockData) ((IBlockData) this.stateDefinition.any()).setValue(DispenserBlock.FACING, Direction.NORTH)).setValue(DispenserBlock.TRIGGERED, false));
     }
 
     @Override
-    @Override
-    public InteractionResult use(BlockState blockstate, Level level, BlockPos blockpos, Player player, InteractionHand interactionhand, BlockHitResult blockhitresult) {
+    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(blockpos);
+            BlockEntity tileentity = level.getBlockEntity(pos);
 
-            if (blockentity instanceof DispenserBlockEntity) {
-                player.openMenu((DispenserBlockEntity) blockentity);
-                if (blockentity instanceof DropperBlockEntity) {
+            if (tileentity instanceof DispenserBlockEntity) {
+                player.openMenu((DispenserBlockEntity) tileentity);
+                if (tileentity instanceof TileEntityDropper) {
                     player.awardStat(Stats.INSPECT_DROPPER);
                 } else {
                     player.awardStat(Stats.INSPECT_DISPENSER);
@@ -86,126 +85,115 @@
         }
     }
 
-    protected void dispenseFrom(ServerLevel serverlevel, BlockState blockstate, BlockPos blockpos) {
-        DispenserBlockEntity dispenserblockentity = (DispenserBlockEntity) serverlevel.getBlockEntity(blockpos, BlockEntityType.DISPENSER).orElse((Object) null);
+    public void dispenseFrom(ServerLevel worldserver, IBlockData iblockdata, BlockPos blockposition) {
+        DispenserBlockEntity tileentitydispenser = (DispenserBlockEntity) worldserver.getBlockEntity(blockposition, BlockEntityType.DISPENSER).orElse(null); // CraftBukkit - decompile error
 
-        if (dispenserblockentity == null) {
-            DispenserBlock.LOGGER.warn("Ignoring dispensing attempt for Dispenser without matching block entity at {}", blockpos);
+        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 i = dispenserblockentity.getRandomSlot(serverlevel.random);
+            SourceBlock sourceblock = new SourceBlock(worldserver, blockposition, iblockdata, tileentitydispenser);
+            int i = tileentitydispenser.getRandomSlot(worldserver.random);
 
             if (i < 0) {
-                serverlevel.levelEvent(1001, blockpos, 0);
-                serverlevel.gameEvent(GameEvent.BLOCK_ACTIVATE, blockpos, GameEvent.Context.of(dispenserblockentity.getBlockState()));
+                worldserver.levelEvent(1001, blockposition, 0);
+                worldserver.gameEvent(GameEvent.BLOCK_ACTIVATE, blockposition, GameEvent.Context.of(tileentitydispenser.getBlockState()));
             } else {
-                ItemStack itemstack = dispenserblockentity.getItem(i);
-                DispenseItemBehavior dispenseitembehavior = this.getDispenseMethod(itemstack);
+                ItemStack itemstack = tileentitydispenser.getItem(i);
+                DispenseItemBehavior idispensebehavior = this.getDispenseMethod(itemstack);
 
-                if (dispenseitembehavior != DispenseItemBehavior.NOOP) {
-                    dispenserblockentity.setItem(i, dispenseitembehavior.dispense(blocksource, itemstack));
+                if (idispensebehavior != DispenseItemBehavior.NOOP) {
+                    eventFired = false; // CraftBukkit - reset event status
+                    tileentitydispenser.setItem(i, idispensebehavior.dispense(sourceblock, itemstack));
                 }
 
             }
         }
     }
 
-    protected DispenseItemBehavior getDispenseMethod(ItemStack itemstack) {
-        return (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(itemstack.getItem());
+    protected DispenseItemBehavior getDispenseMethod(ItemStack stack) {
+        return (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(stack.getItem());
     }
 
     @Override
-    @Override
-    public void neighborChanged(BlockState blockstate, Level level, BlockPos blockpos, Block block, BlockPos blockpos1, boolean flag) {
-        boolean flag1 = level.hasNeighborSignal(blockpos) || level.hasNeighborSignal(blockpos.above());
-        boolean flag2 = (Boolean) blockstate.getValue(DispenserBlock.TRIGGERED);
+    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(blockpos, (Block) this, 4);
-            level.setBlock(blockpos, (BlockState) blockstate.setValue(DispenserBlock.TRIGGERED, true), 2);
+            level.scheduleTick(pos, (Block) this, 4);
+            level.setBlock(pos, (IBlockData) state.setValue(DispenserBlock.TRIGGERED, true), 2);
         } else if (!flag1 && flag2) {
-            level.setBlock(blockpos, (BlockState) blockstate.setValue(DispenserBlock.TRIGGERED, false), 2);
+            level.setBlock(pos, (IBlockData) state.setValue(DispenserBlock.TRIGGERED, false), 2);
         }
 
     }
 
     @Override
-    @Override
-    public void tick(BlockState blockstate, ServerLevel serverlevel, BlockPos blockpos, RandomSource randomsource) {
-        this.dispenseFrom(serverlevel, blockstate, blockpos);
+    public void tick(IBlockData state, ServerLevel level, BlockPos pos, RandomSource random) {
+        this.dispenseFrom(level, state, pos);
     }
 
     @Override
-    @Override
-    public BlockEntity newBlockEntity(BlockPos blockpos, BlockState blockstate) {
-        return new DispenserBlockEntity(blockpos, blockstate);
+    public BlockEntity newBlockEntity(BlockPos pos, IBlockData state) {
+        return new DispenserBlockEntity(pos, state);
     }
 
     @Override
-    @Override
-    public BlockState getStateForPlacement(BlockPlaceContext blockplacecontext) {
-        return (BlockState) this.defaultBlockState().setValue(DispenserBlock.FACING, blockplacecontext.getNearestLookingDirection().getOpposite());
+    public IBlockData getStateForPlacement(BlockPlaceContext context) {
+        return (IBlockData) this.defaultBlockState().setValue(DispenserBlock.FACING, context.getNearestLookingDirection().getOpposite());
     }
 
     @Override
-    @Override
-    public void setPlacedBy(Level level, BlockPos blockpos, BlockState blockstate, LivingEntity livingentity, ItemStack itemstack) {
-        if (itemstack.hasCustomHoverName()) {
-            BlockEntity blockentity = level.getBlockEntity(blockpos);
+    public void setPlacedBy(Level level, BlockPos pos, IBlockData state, LivingEntity placer, ItemStack stack) {
+        if (stack.hasCustomHoverName()) {
+            BlockEntity tileentity = level.getBlockEntity(pos);
 
-            if (blockentity instanceof DispenserBlockEntity) {
-                ((DispenserBlockEntity) blockentity).setCustomName(itemstack.getHoverName());
+            if (tileentity instanceof DispenserBlockEntity) {
+                ((DispenserBlockEntity) tileentity).setCustomName(stack.getHoverName());
             }
         }
 
     }
 
     @Override
-    @Override
-    public void onRemove(BlockState blockstate, Level level, BlockPos blockpos, BlockState blockstate1, boolean flag) {
-        Containers.dropContentsOnDestroy(blockstate, blockstate1, level, blockpos);
-        super.onRemove(blockstate, level, blockpos, blockstate1, flag);
+    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 = (Direction) blocksource.state().getValue(DispenserBlock.FACING);
+    public static IPosition getDispensePosition(SourceBlock sourceblock) {
+        Direction enumdirection = (Direction) sourceblock.state().getValue(DispenserBlock.FACING);
 
-        return blocksource.center().add(0.7D * (double) direction.getStepX(), 0.7D * (double) direction.getStepY(), 0.7D * (double) direction.getStepZ());
+        return sourceblock.center().add(0.7D * (double) enumdirection.getStepX(), 0.7D * (double) enumdirection.getStepY(), 0.7D * (double) enumdirection.getStepZ());
     }
 
     @Override
-    @Override
-    public boolean hasAnalogOutputSignal(BlockState blockstate) {
+    public boolean hasAnalogOutputSignal(IBlockData state) {
         return true;
     }
 
     @Override
-    @Override
-    public int getAnalogOutputSignal(BlockState blockstate, Level level, BlockPos blockpos) {
-        return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(level.getBlockEntity(blockpos));
+    public int getAnalogOutputSignal(IBlockData blockState, Level level, BlockPos pos) {
+        return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(level.getBlockEntity(pos));
     }
 
     @Override
-    @Override
-    public RenderShape getRenderShape(BlockState blockstate) {
-        return RenderShape.MODEL;
+    public EnumRenderType getRenderShape(IBlockData state) {
+        return EnumRenderType.MODEL;
     }
 
     @Override
-    @Override
-    public BlockState rotate(BlockState blockstate, Rotation rotation) {
-        return (BlockState) blockstate.setValue(DispenserBlock.FACING, rotation.rotate((Direction) blockstate.getValue(DispenserBlock.FACING)));
+    public IBlockData rotate(IBlockData state, Rotation rotation) {
+        return (IBlockData) state.setValue(DispenserBlock.FACING, rotation.rotate((Direction) state.getValue(DispenserBlock.FACING)));
     }
 
     @Override
-    @Override
-    public BlockState mirror(BlockState blockstate, Mirror mirror) {
-        return blockstate.rotate(mirror.getRotation((Direction) blockstate.getValue(DispenserBlock.FACING)));
+    public IBlockData mirror(IBlockData state, Mirror mirror) {
+        return state.rotate(mirror.getRotation((Direction) state.getValue(DispenserBlock.FACING)));
     }
 
     @Override
-    @Override
-    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> statedefinition_builder) {
-        statedefinition_builder.add(DispenserBlock.FACING, DispenserBlock.TRIGGERED);
+    protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) {
+        builder.add(DispenserBlock.FACING, DispenserBlock.TRIGGERED);
     }
 }