|
1 | 1 | package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2; |
2 | 2 |
|
| 3 | +import com.fastasyncworldedit.bukkit.adapter.BukkitBlockMaterial; |
3 | 4 | import com.fastasyncworldedit.core.nbt.FaweCompoundTag; |
4 | | -import com.sk89q.util.ReflectionUtil; |
5 | | -import com.sk89q.worldedit.bukkit.adapter.Refraction; |
6 | | -import com.sk89q.worldedit.world.registry.BlockMaterial; |
7 | 5 | import net.minecraft.core.BlockPos; |
8 | 6 | import net.minecraft.world.level.EmptyBlockGetter; |
9 | 7 | import net.minecraft.world.level.block.Block; |
10 | 8 | import net.minecraft.world.level.block.EntityBlock; |
11 | | -import net.minecraft.world.level.block.LiquidBlock; |
12 | 9 | import net.minecraft.world.level.block.entity.BlockEntity; |
13 | | -import net.minecraft.world.level.block.state.BlockBehaviour; |
14 | 10 | import net.minecraft.world.level.block.state.BlockState; |
| 11 | +import net.minecraft.world.level.material.Fluids; |
15 | 12 | import net.minecraft.world.level.material.PushReaction; |
16 | 13 | import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData; |
17 | 14 |
|
18 | | -import javax.annotation.Nullable; |
| 15 | +public class PaperweightBlockMaterial extends BukkitBlockMaterial<Block, BlockState> { |
19 | 16 |
|
20 | | -public class PaperweightBlockMaterial implements BlockMaterial { |
21 | | - |
22 | | - private final Block block; |
23 | | - private final BlockState blockState; |
24 | | - private final boolean isTranslucent; |
25 | | - private final CraftBlockData craftBlockData; |
26 | | - private final org.bukkit.Material craftMaterial; |
27 | 17 | private final int opacity; |
28 | | - private final FaweCompoundTag tile; |
29 | 18 |
|
30 | 19 | public PaperweightBlockMaterial(Block block) { |
31 | 20 | this(block, block.defaultBlockState()); |
32 | 21 | } |
33 | 22 |
|
34 | 23 | public PaperweightBlockMaterial(Block block, BlockState blockState) { |
35 | | - this.block = block; |
36 | | - this.blockState = blockState; |
37 | | - this.craftBlockData = CraftBlockData.fromData(blockState); |
38 | | - this.craftMaterial = craftBlockData.getMaterial(); |
39 | | - BlockBehaviour.Properties blockInfo = ReflectionUtil.getField(BlockBehaviour.class, block, |
40 | | - Refraction.pickName("properties", "aN")); |
41 | | - this.isTranslucent = !(boolean) ReflectionUtil.getField(BlockBehaviour.Properties.class, blockInfo, |
42 | | - Refraction.pickName("canOcclude", "m") |
43 | | - ); |
44 | | - opacity = blockState.getLightBlock(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); |
45 | | - BlockEntity tileEntity = !(block instanceof EntityBlock) ? null : ((EntityBlock) block).newBlockEntity( |
46 | | - BlockPos.ZERO, |
47 | | - blockState |
48 | | - ); |
49 | | - tile = tileEntity == null |
50 | | - ? null |
51 | | - : PaperweightGetBlocks.NMS_TO_TILE.apply(tileEntity); |
52 | | - } |
53 | | - |
54 | | - public Block getBlock() { |
55 | | - return block; |
| 24 | + super(block, blockState, CraftBlockData.fromData(blockState)); |
| 25 | + this.opacity = blockState.getLightBlock(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); |
56 | 26 | } |
57 | 27 |
|
58 | | - public BlockState getState() { |
59 | | - return blockState; |
60 | | - } |
61 | | - |
62 | | - public CraftBlockData getCraftBlockData() { |
63 | | - return craftBlockData; |
| 28 | + @Override |
| 29 | + protected FaweCompoundTag tileForBlock(final Block block) { |
| 30 | + BlockEntity tileEntity = !(block instanceof EntityBlock eb) ? null : eb.newBlockEntity(BlockPos.ZERO, this.blockState); |
| 31 | + return tileEntity == null ? null : PaperweightGetBlocks.NMS_TO_TILE.apply(tileEntity); |
64 | 32 | } |
65 | 33 |
|
66 | 34 | @Override |
67 | 35 | public boolean isAir() { |
68 | | - return blockState.isAir(); |
| 36 | + return this.blockState.isAir(); |
69 | 37 | } |
70 | 38 |
|
71 | 39 | @Override |
72 | 40 | public boolean isFullCube() { |
73 | | - return Block.isShapeFullBlock(blockState.getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); |
| 41 | + return Block.isShapeFullBlock(this.blockState.getShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); |
74 | 42 | } |
75 | 43 |
|
76 | 44 | @Override |
77 | 45 | public boolean isOpaque() { |
78 | | - return blockState.isOpaque(); |
| 46 | + return this.blockState.canOcclude(); |
79 | 47 | } |
80 | 48 |
|
81 | 49 | @Override |
82 | 50 | public boolean isPowerSource() { |
83 | | - return blockState.isSignalSource(); |
| 51 | + return this.blockState.isSignalSource(); |
84 | 52 | } |
85 | 53 |
|
86 | 54 | @Override |
87 | 55 | public boolean isLiquid() { |
88 | | - // TODO: Better check ? |
89 | | - return block instanceof LiquidBlock; |
| 56 | + return !this.blockState.getFluidState().is(Fluids.EMPTY); |
90 | 57 | } |
91 | 58 |
|
92 | 59 | @Override |
93 | 60 | public boolean isSolid() { |
94 | | - // TODO: Replace |
95 | | - return blockState.isSolid(); |
| 61 | + return this.blockState.isSolidRender(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); |
96 | 62 | } |
97 | 63 |
|
98 | 64 | @Override |
99 | 65 | public float getHardness() { |
100 | | - return craftBlockData.getState().destroySpeed; |
| 66 | + return this.blockState.destroySpeed; |
101 | 67 | } |
102 | 68 |
|
103 | 69 | @Override |
104 | 70 | public float getResistance() { |
105 | | - return block.getExplosionResistance(); |
| 71 | + return this.block.getExplosionResistance(); |
106 | 72 | } |
107 | 73 |
|
108 | 74 | @Override |
109 | 75 | public float getSlipperiness() { |
110 | | - return block.getFriction(); |
| 76 | + return this.block.getFriction(); |
111 | 77 | } |
112 | 78 |
|
113 | 79 | @Override |
114 | 80 | public int getLightValue() { |
115 | | - return blockState.getLightEmission(); |
| 81 | + return this.blockState.getLightEmission(); |
116 | 82 | } |
117 | 83 |
|
118 | 84 | @Override |
119 | 85 | public int getLightOpacity() { |
120 | | - return opacity; |
| 86 | + return this.opacity; |
121 | 87 | } |
122 | 88 |
|
123 | 89 | @Override |
124 | 90 | public boolean isFragileWhenPushed() { |
125 | | - return blockState.getPistonPushReaction() == PushReaction.DESTROY; |
| 91 | + return this.blockState.getPistonPushReaction() == PushReaction.DESTROY; |
126 | 92 | } |
127 | 93 |
|
128 | 94 | @Override |
129 | 95 | public boolean isUnpushable() { |
130 | | - return blockState.getPistonPushReaction() == PushReaction.BLOCK; |
| 96 | + return this.blockState.getPistonPushReaction() == PushReaction.BLOCK; |
131 | 97 | } |
132 | 98 |
|
133 | 99 | @Override |
134 | 100 | public boolean isTicksRandomly() { |
135 | | - return block.isRandomlyTicking(blockState); |
| 101 | + return this.blockState.isRandomlyTicking(); |
136 | 102 | } |
137 | 103 |
|
138 | 104 | @SuppressWarnings("deprecation") |
139 | 105 | @Override |
140 | 106 | public boolean isMovementBlocker() { |
141 | | - return blockState.blocksMotion(); |
142 | | - } |
143 | | - |
144 | | - @Override |
145 | | - public boolean isBurnable() { |
146 | | - return craftMaterial.isBurnable(); |
147 | | - } |
148 | | - |
149 | | - @Override |
150 | | - public boolean isToolRequired() { |
151 | | - // Removed in 1.16.1, this is not present in higher versions |
152 | | - return false; |
| 107 | + return this.blockState.blocksMotion(); |
153 | 108 | } |
154 | 109 |
|
155 | 110 | @Override |
156 | 111 | public boolean isReplacedDuringPlacement() { |
157 | | - return blockState.canBeReplaced(); |
| 112 | + return this.blockState.canBeReplaced(); |
158 | 113 | } |
159 | 114 |
|
160 | 115 | @Override |
161 | 116 | public boolean isTranslucent() { |
162 | | - return isTranslucent; |
163 | | - } |
164 | | - |
165 | | - @Override |
166 | | - public boolean hasContainer() { |
167 | | - return block instanceof EntityBlock; |
168 | | - } |
169 | | - |
170 | | - @Override |
171 | | - public boolean isTile() { |
172 | | - return block instanceof EntityBlock; |
173 | | - } |
174 | | - |
175 | | - @Override |
176 | | - public @Nullable FaweCompoundTag defaultTile() { |
177 | | - return tile; |
| 117 | + return !this.blockState.canOcclude(); |
178 | 118 | } |
179 | 119 |
|
180 | 120 | @Override |
181 | 121 | public int getMapColor() { |
182 | 122 | // rgb field |
183 | | - return block.defaultMapColor().col; |
| 123 | + return this.block.defaultMapColor().col; |
184 | 124 | } |
185 | 125 |
|
186 | 126 | } |
0 commit comments