aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/level/block/ConcretePowderBlock.java.patch
blob: 2817e3b0968baab57b491b339473dbd9be76c24a (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
--- a/net/minecraft/world/level/block/ConcretePowderBlock.java
+++ b/net/minecraft/world/level/block/ConcretePowderBlock.java
@@ -2,7 +2,6 @@
 
 import com.mojang.serialization.MapCodec;
 import com.mojang.serialization.codecs.RecordCodecBuilder;
-import com.mojang.serialization.codecs.RecordCodecBuilder.Instance;
 import net.minecraft.core.BlockPos;
 import net.minecraft.core.Direction;
 import net.minecraft.core.registries.BuiltInRegistries;
@@ -13,20 +12,26 @@
 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;
 
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.craftbukkit.block.CraftBlockStates;
+import org.bukkit.event.block.BlockFormEvent;
+// CraftBukkit end
+
 public class ConcretePowderBlock extends FallingBlock {
-    public static final MapCodec<ConcretePowderBlock> CODEC = RecordCodecBuilder.mapCodec(
-        instance -> instance.group(
-                    BuiltInRegistries.BLOCK.byNameCodec().fieldOf("concrete").forGetter(concretePowderBlock -> concretePowderBlock.concrete), propertiesCodec()
-                )
-                .apply(instance, ConcretePowderBlock::new)
-    );
+
+    public static final MapCodec<ConcretePowderBlock> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
+        return instance.group(BuiltInRegistries.BLOCK.byNameCodec().fieldOf("concrete").forGetter((blockconcretepowder) -> {
+            return blockconcretepowder.concrete;
+        }), propertiesCodec()).apply(instance, ConcretePowderBlock::new);
+    });
     private final Block concrete;
 
     @Override
     public MapCodec<ConcretePowderBlock> codec() {
-        return CODEC;
+        return ConcretePowderBlock.CODEC;
     }
 
     public ConcretePowderBlock(Block concrete, BlockBehaviour.Properties properties) {
@@ -35,34 +40,57 @@
     }
 
     @Override
-    public void onLand(Level level, BlockPos pos, BlockState state, BlockState replaceableState, FallingBlockEntity fallingBlock) {
+    public void onLand(Level level, BlockPos pos, IBlockData state, IBlockData replaceableState, FallingBlockEntity fallingBlock) {
         if (shouldSolidify(level, pos, replaceableState)) {
-            level.setBlock(pos, this.concrete.defaultBlockState(), 3);
+            org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(level, pos, this.concrete.defaultBlockState(), 3); // CraftBukkit
         }
+
     }
 
     @Override
-    public BlockState getStateForPlacement(BlockPlaceContext context) {
-        BlockGetter level = context.getLevel();
-        BlockPos clickedPos = context.getClickedPos();
-        BlockState blockState = level.getBlockState(clickedPos);
-        return shouldSolidify(level, clickedPos, blockState) ? this.concrete.defaultBlockState() : super.getStateForPlacement(context);
+    public IBlockData getStateForPlacement(BlockPlaceContext context) {
+        Level world = context.getLevel();
+        BlockPos blockposition = context.getClickedPos();
+        IBlockData iblockdata = world.getBlockState(blockposition);
+
+        // CraftBukkit start
+        if (!shouldSolidify(world, blockposition, iblockdata)) {
+            return super.getStateForPlacement(context);
+        }
+
+        // TODO: An event factory call for methods like this
+        CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockposition);
+        blockState.setData(this.concrete.defaultBlockState());
+
+        BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState);
+        world.getServer().server.getPluginManager().callEvent(event);
+
+        if (!event.isCancelled()) {
+            return blockState.getHandle();
+        }
+
+        return super.getStateForPlacement(context);
+        // CraftBukkit end
     }
 
-    private static boolean shouldSolidify(BlockGetter level, BlockPos pos, BlockState state) {
+    private static boolean shouldSolidify(BlockGetter level, BlockPos pos, IBlockData state) {
         return canSolidify(state) || touchesLiquid(level, pos);
     }
 
     private static boolean touchesLiquid(BlockGetter level, BlockPos pos) {
         boolean flag = false;
-        BlockPos.MutableBlockPos mutableBlockPos = pos.mutable();
+        BlockPos.MutableBlockPos blockposition_mutableblockposition = pos.mutable();
+        Direction[] aenumdirection = Direction.values();
+        int i = aenumdirection.length;
 
-        for (Direction direction : Direction.values()) {
-            BlockState blockState = level.getBlockState(mutableBlockPos);
-            if (direction != Direction.DOWN || canSolidify(blockState)) {
-                mutableBlockPos.setWithOffset(pos, direction);
-                blockState = level.getBlockState(mutableBlockPos);
-                if (canSolidify(blockState) && !blockState.isFaceSturdy(level, pos, direction.getOpposite())) {
+        for (int j = 0; j < i; ++j) {
+            Direction enumdirection = aenumdirection[j];
+            IBlockData iblockdata = level.getBlockState(blockposition_mutableblockposition);
+
+            if (enumdirection != Direction.DOWN || canSolidify(iblockdata)) {
+                blockposition_mutableblockposition.setWithOffset(pos, enumdirection);
+                iblockdata = level.getBlockState(blockposition_mutableblockposition);
+                if (canSolidify(iblockdata) && !iblockdata.isFaceSturdy(level, pos, enumdirection.getOpposite())) {
                     flag = true;
                     break;
                 }
@@ -72,19 +100,35 @@
         return flag;
     }
 
-    private static boolean canSolidify(BlockState state) {
+    private static boolean canSolidify(IBlockData state) {
         return state.getFluidState().is(FluidTags.WATER);
     }
 
     @Override
-    public BlockState updateShape(BlockState state, Direction facing, BlockState facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) {
-        return touchesLiquid(level, currentPos)
-            ? this.concrete.defaultBlockState()
-            : super.updateShape(state, facing, facingState, level, currentPos, facingPos);
+    public IBlockData updateShape(IBlockData state, Direction facing, IBlockData facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) {
+        // CraftBukkit start
+        if (touchesLiquid(level, currentPos)) {
+            // Suppress during worldgen
+            if (!(level instanceof Level)) {
+                return this.concrete.defaultBlockState();
+            }
+            CraftBlockState blockState = CraftBlockStates.getBlockState(level, currentPos);
+            blockState.setData(this.concrete.defaultBlockState());
+
+            BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState);
+            ((Level) level).getCraftServer().getPluginManager().callEvent(event);
+
+            if (!event.isCancelled()) {
+                return blockState.getHandle();
+            }
+        }
+
+        return super.updateShape(state, facing, facingState, level, currentPos, facingPos);
+        // CraftBukkit end
     }
 
     @Override
-    public int getDustColor(BlockState state, BlockGetter reader, BlockPos pos) {
+    public int getDustColor(IBlockData state, BlockGetter reader, BlockPos pos) {
         return state.getMapColor(reader, pos).col;
     }
 }