11package gregtech .mixins .minecraft ;
22
3- import gregtech .api .GregTechAPI ;
4- import gregtech .api .metatileentity .MetaTileEntity ;
5- import gregtech .api .metatileentity .registry .MTERegistry ;
3+ import gregtech .client .utils .ClientHandlerHooks ;
64
75import net .minecraft .client .multiplayer .WorldClient ;
86import net .minecraft .client .network .NetHandlerPlayClient ;
9- import net .minecraft .nbt .NBTTagCompound ;
107import net .minecraft .network .PacketBuffer ;
118import net .minecraft .network .play .server .SPacketChunkData ;
129import net .minecraft .network .play .server .SPacketUpdateTileEntity ;
13- import net .minecraft .util .ResourceLocation ;
14- import net .minecraft .util .math .BlockPos ;
15- import net .minecraft .world .World ;
1610import net .minecraft .world .chunk .Chunk ;
1711
1812import org .spongepowered .asm .mixin .Mixin ;
1913import org .spongepowered .asm .mixin .Shadow ;
20- import org .spongepowered .asm .mixin .Unique ;
2114import org .spongepowered .asm .mixin .injection .At ;
2215import org .spongepowered .asm .mixin .injection .Inject ;
2316import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
@@ -40,9 +33,7 @@ public abstract class ClientHandlerMixin {
4033 target = "Lnet/minecraft/world/chunk/Chunk;read(Lnet/minecraft/network/PacketBuffer;IZ)V" ))
4134 public void initClientTiles (SPacketChunkData packetIn , CallbackInfo ci ) {
4235 // todo this might not be necessary anymore, though the TE does need to be initialized for initial sync data
43- for (NBTTagCompound tag : packetIn .getTileEntityTags ()) {
44- gregTech$initMetaTile (this .world , tag );
45- }
36+ ClientHandlerHooks .handleTags (this .world , packetIn .getTileEntityTags ());
4637 }
4738
4839 /**
@@ -54,33 +45,6 @@ public void initClientTiles(SPacketChunkData packetIn, CallbackInfo ci) {
5445 at = @ At (value = "INVOKE" ,
5546 target = "Lnet/minecraft/client/multiplayer/WorldClient;getTileEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/tileentity/TileEntity;" ))
5647 public void initClientTile (SPacketUpdateTileEntity packetIn , CallbackInfo ci ) {
57- gregTech$initMetaTile (this .world , packetIn .getNbtCompound ());
58- }
59-
60- // todo move this into a hook class or something
61- /**
62- * Creates the correct MetaTileEntity from the given tag and sets the tile entity to the world
63- * IF a TileEntity doesn't already exist at the position
64- *
65- * @param tag TileEntity tag data
66- */
67- @ Unique
68- public void gregTech$initMetaTile (World world , NBTTagCompound tag ) {
69- if (!tag .hasKey ("MetaId" )) return ;
70-
71- ResourceLocation metaId = new ResourceLocation (tag .getString ("MetaId" ));
72- MTERegistry registry = GregTechAPI .mteManager .getRegistry (metaId .getNamespace ());
73- MetaTileEntity mte = registry .getObject (metaId );
74- BlockPos pos = new BlockPos (tag .getInteger ("x" ), tag .getInteger ("y" ), tag .getInteger ("z" ));
75- if (mte == null ) return ;
76-
77- // set te in world directly
78- // check if world contains a TE at this pos?
79- // is null checking good enough?
80- if (world .getChunk (pos ).getTileEntity (pos , Chunk .EnumCreateEntityType .CHECK ) == null ) {
81- if (world .getBlockState (pos ).getBlock () != registry .getBlock ())
82- world .setBlockState (pos , registry .getBlock ().getDefaultState ());
83- world .setTileEntity (pos , mte .copy ());
84- }
48+ ClientHandlerHooks .handleTag (this .world , packetIn .getNbtCompound ());
8549 }
8650}
0 commit comments