aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/level/block/LeavesBlock.java.patch
blob: 9772e8b6353fded7b731edde57cee137381a6bff (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
--- a/net/minecraft/world/level/block/LeavesBlock.java
+++ b/net/minecraft/world/level/block/LeavesBlock.java
@@ -14,17 +14,20 @@
 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.BlockStateProperties;
 import net.minecraft.world.level.block.state.properties.BooleanProperty;
 import net.minecraft.world.level.block.state.properties.IntegerProperty;
+import net.minecraft.world.level.material.Fluid;
 import net.minecraft.world.level.material.FluidState;
 import net.minecraft.world.level.material.Fluids;
 import net.minecraft.world.phys.shapes.Shapes;
 import net.minecraft.world.phys.shapes.VoxelShape;
+import org.bukkit.event.block.LeavesDecayEvent; // CraftBukkit
 
 public class LeavesBlock extends Block implements SimpleWaterloggedBlock {
+
     public static final MapCodec<LeavesBlock> CODEC = simpleCodec(LeavesBlock::new);
     public static final int DECAY_DISTANCE = 7;
     public static final IntegerProperty DISTANCE = BlockStateProperties.DISTANCE;
@@ -34,105 +37,110 @@
 
     @Override
     public MapCodec<? extends LeavesBlock> codec() {
-        return CODEC;
+        return LeavesBlock.CODEC;
     }
 
     public LeavesBlock(BlockBehaviour.Properties properties) {
         super(properties);
-        this.registerDefaultState(
-            this.stateDefinition
-                .any()
-                .setValue(DISTANCE, Integer.valueOf(7))
-                .setValue(PERSISTENT, Boolean.valueOf(false))
-                .setValue(WATERLOGGED, Boolean.valueOf(false))
-        );
+        this.registerDefaultState((IBlockData) ((IBlockData) ((IBlockData) ((IBlockData) this.stateDefinition.any()).setValue(LeavesBlock.DISTANCE, 7)).setValue(LeavesBlock.PERSISTENT, false)).setValue(LeavesBlock.WATERLOGGED, false));
     }
 
     @Override
-    public VoxelShape getBlockSupportShape(BlockState state, BlockGetter reader, BlockPos pos) {
+    public VoxelShape getBlockSupportShape(IBlockData state, BlockGetter reader, BlockPos pos) {
         return Shapes.empty();
     }
 
     @Override
-    public boolean isRandomlyTicking(BlockState state) {
-        return state.getValue(DISTANCE) == 7 && !state.getValue(PERSISTENT);
+    public boolean isRandomlyTicking(IBlockData state) {
+        return (Integer) state.getValue(LeavesBlock.DISTANCE) == 7 && !(Boolean) state.getValue(LeavesBlock.PERSISTENT);
     }
 
     @Override
-    public void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
+    public void randomTick(IBlockData state, ServerLevel level, BlockPos pos, RandomSource random) {
         if (this.decaying(state)) {
+            // CraftBukkit start
+            LeavesDecayEvent event = new LeavesDecayEvent(level.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+            level.getCraftServer().getPluginManager().callEvent(event);
+
+            if (event.isCancelled() || level.getBlockState(pos).getBlock() != this) {
+                return;
+            }
+            // CraftBukkit end
             dropResources(state, level, pos);
             level.removeBlock(pos, false);
         }
+
     }
 
-    protected boolean decaying(BlockState state) {
-        return !state.getValue(PERSISTENT) && state.getValue(DISTANCE) == 7;
+    protected boolean decaying(IBlockData state) {
+        return !(Boolean) state.getValue(LeavesBlock.PERSISTENT) && (Integer) state.getValue(LeavesBlock.DISTANCE) == 7;
     }
 
     @Override
-    public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
+    public void tick(IBlockData state, ServerLevel level, BlockPos pos, RandomSource random) {
         level.setBlock(pos, updateDistance(state, level, pos), 3);
     }
 
     @Override
-    public int getLightBlock(BlockState state, BlockGetter level, BlockPos pos) {
+    public int getLightBlock(IBlockData state, BlockGetter level, BlockPos pos) {
         return 1;
     }
 
     @Override
-    public BlockState updateShape(BlockState state, Direction facing, BlockState facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) {
-        if (state.getValue(WATERLOGGED)) {
-            level.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
+    public IBlockData updateShape(IBlockData state, Direction facing, IBlockData facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) {
+        if ((Boolean) state.getValue(LeavesBlock.WATERLOGGED)) {
+            level.scheduleTick(currentPos, (Fluid) Fluids.WATER, Fluids.WATER.getTickDelay(level));
         }
 
         int i = getDistanceAt(facingState) + 1;
-        if (i != 1 || state.getValue(DISTANCE) != i) {
-            level.scheduleTick(currentPos, this, 1);
+
+        if (i != 1 || (Integer) state.getValue(LeavesBlock.DISTANCE) != i) {
+            level.scheduleTick(currentPos, (Block) this, 1);
         }
 
         return state;
     }
 
-    private static BlockState updateDistance(BlockState state, LevelAccessor level, BlockPos pos) {
+    private static IBlockData updateDistance(IBlockData state, LevelAccessor level, BlockPos pos) {
         int i = 7;
-        BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
+        BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
+        Direction[] aenumdirection = Direction.values();
+        int j = aenumdirection.length;
 
-        for (Direction direction : Direction.values()) {
-            mutableBlockPos.setWithOffset(pos, direction);
-            i = Math.min(i, getDistanceAt(level.getBlockState(mutableBlockPos)) + 1);
+        for (int k = 0; k < j; ++k) {
+            Direction enumdirection = aenumdirection[k];
+
+            blockposition_mutableblockposition.setWithOffset(pos, enumdirection);
+            i = Math.min(i, getDistanceAt(level.getBlockState(blockposition_mutableblockposition)) + 1);
             if (i == 1) {
                 break;
             }
         }
 
-        return state.setValue(DISTANCE, Integer.valueOf(i));
+        return (IBlockData) state.setValue(LeavesBlock.DISTANCE, i);
     }
 
-    private static int getDistanceAt(BlockState neighbor) {
+    private static int getDistanceAt(IBlockData neighbor) {
         return getOptionalDistanceAt(neighbor).orElse(7);
     }
 
-    public static OptionalInt getOptionalDistanceAt(BlockState state) {
-        if (state.is(BlockTags.LOGS)) {
-            return OptionalInt.of(0);
-        } else {
-            return state.hasProperty(DISTANCE) ? OptionalInt.of(state.getValue(DISTANCE)) : OptionalInt.empty();
-        }
+    public static OptionalInt getOptionalDistanceAt(IBlockData state) {
+        return state.is(BlockTags.LOGS) ? OptionalInt.of(0) : (state.hasProperty(LeavesBlock.DISTANCE) ? OptionalInt.of((Integer) state.getValue(LeavesBlock.DISTANCE)) : OptionalInt.empty());
     }
 
     @Override
-    public FluidState getFluidState(BlockState state) {
-        return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
+    public FluidState getFluidState(IBlockData state) {
+        return (Boolean) state.getValue(LeavesBlock.WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
     }
 
     @Override
-    public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) {
+    public void animateTick(IBlockData state, Level level, BlockPos pos, RandomSource random) {
         if (level.isRainingAt(pos.above())) {
             if (random.nextInt(15) == 1) {
-                BlockPos blockPos = pos.below();
-                BlockState blockState = level.getBlockState(blockPos);
-                if (!blockState.canOcclude() || !blockState.isFaceSturdy(level, blockPos, Direction.UP)) {
+                BlockPos blockposition1 = pos.below();
+                IBlockData iblockdata1 = level.getBlockState(blockposition1);
+
+                if (!iblockdata1.canOcclude() || !iblockdata1.isFaceSturdy(level, blockposition1, Direction.UP)) {
                     ParticleUtils.spawnParticleBelow(level, pos, random, ParticleTypes.DRIPPING_WATER);
                 }
             }
@@ -140,16 +148,15 @@
     }
 
     @Override
-    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
-        builder.add(DISTANCE, PERSISTENT, WATERLOGGED);
+    protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) {
+        builder.add(LeavesBlock.DISTANCE, LeavesBlock.PERSISTENT, LeavesBlock.WATERLOGGED);
     }
 
     @Override
-    public BlockState getStateForPlacement(BlockPlaceContext context) {
-        FluidState fluidState = context.getLevel().getFluidState(context.getClickedPos());
-        BlockState blockState = this.defaultBlockState()
-            .setValue(PERSISTENT, Boolean.valueOf(true))
-            .setValue(WATERLOGGED, Boolean.valueOf(fluidState.getType() == Fluids.WATER));
-        return updateDistance(blockState, context.getLevel(), context.getClickedPos());
+    public IBlockData getStateForPlacement(BlockPlaceContext context) {
+        FluidState fluid = context.getLevel().getFluidState(context.getClickedPos());
+        IBlockData iblockdata = (IBlockData) ((IBlockData) this.defaultBlockState().setValue(LeavesBlock.PERSISTENT, true)).setValue(LeavesBlock.WATERLOGGED, fluid.getType() == Fluids.WATER);
+
+        return updateDistance(iblockdata, context.getLevel(), context.getClickedPos());
     }
 }