|
6 | 6 | import net.iso2013.peapi.api.packet.*; |
7 | 7 | import net.iso2013.peapi.entity.EntityIdentifierImpl; |
8 | 8 | import net.iso2013.peapi.util.EntityTypeUtil; |
| 9 | +import net.iso2013.peapi.util.ReflectUtil; |
9 | 10 | import org.bukkit.Art; |
10 | 11 | import org.bukkit.block.BlockFace; |
11 | 12 | import org.bukkit.block.data.BlockData; |
|
18 | 19 | import org.bukkit.projectiles.ProjectileSource; |
19 | 20 | import org.bukkit.util.Vector; |
20 | 21 |
|
| 22 | +import java.lang.reflect.InvocationTargetException; |
| 23 | +import java.lang.reflect.Method; |
| 24 | + |
21 | 25 | /** |
22 | 26 | * Created by iso2013 on 4/23/2018. |
23 | 27 | */ |
24 | 28 | public class EntityPacketFactoryImpl implements EntityPacketFactory { |
| 29 | + private static final Class<?> cbBlockData; |
| 30 | + private static final Method getCombinedID; |
| 31 | + private static final Method getState; |
| 32 | + |
| 33 | + static { |
| 34 | + cbBlockData = ReflectUtil.getCBClass("CraftBlockData"); |
| 35 | + Class<?> nmsBD = ReflectUtil.getNMSClass("Block"); |
| 36 | + getCombinedID = ReflectUtil.getMethod(nmsBD, "getCombinedId"); |
| 37 | + getState = ReflectUtil.getMethod(cbBlockData, "getState"); |
| 38 | + } |
| 39 | + |
| 40 | + |
25 | 41 | @Override |
26 | 42 | public EntityAnimationPacket createAnimationPacket(EntityIdentifier entity, EntityAnimationPacket |
27 | 43 | .AnimationType type) { |
@@ -195,12 +211,15 @@ private int getData(boolean fake, FakeEntity f, Entity e, EntityType t) { |
195 | 211 | return ((Entity) s).getEntityId(); |
196 | 212 | } |
197 | 213 | case FALLING_BLOCK: |
198 | | - BlockData bd = ((FallingBlock) e).getBlockData(); |
199 | | - int type = fake ? (int) f.getField("id") : bd.getMaterial().getId(); |
200 | | - //FIXME: How is this done in 1.14? |
201 | | - int data = 0; |
202 | | - //int data = fake ? (int) f.getField("data") : bd.; |
203 | | - return type | (data << 12); |
| 214 | + BlockData bd = fake ? (BlockData) f.getField("blockdata") : ((FallingBlock) e).getBlockData(); |
| 215 | + if (getState != null) { |
| 216 | + try { |
| 217 | + return (int) getCombinedID.invoke(null, getState.invoke(cbBlockData.cast(bd))); |
| 218 | + } catch (IllegalAccessException | InvocationTargetException ignored) { |
| 219 | + } |
| 220 | + } |
| 221 | + |
| 222 | + return bd.getMaterial().getId(); |
204 | 223 | case DROPPED_ITEM: |
205 | 224 | case MINECART_CHEST: |
206 | 225 | return 1; |
|
0 commit comments