-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from BentoBoxWorld/on_demand_structures
- Loading branch information
Showing
10 changed files
with
145 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/world/bentobox/boxed/nms/AbstractMetaData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,43 @@ | ||
package world.bentobox.boxed.nms; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
|
||
import org.bukkit.block.Block; | ||
|
||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.network.protocol.game.PacketPlayOutTileEntityData; | ||
import net.minecraft.world.level.block.entity.TileEntity; | ||
|
||
/** | ||
* | ||
*/ | ||
public abstract class AbstractMetaData { | ||
|
||
public abstract String nmsData(Block block); | ||
|
||
protected String getData(TileEntity te, String method, String field) { | ||
try { | ||
// Check if the method 'j' exists | ||
Method updatePacketMethod = te.getClass().getDeclaredMethod(method); | ||
if (updatePacketMethod != null) { | ||
// Invoke the method to get the PacketPlayOutTileEntityData object | ||
updatePacketMethod.setAccessible(true); | ||
PacketPlayOutTileEntityData packet = (PacketPlayOutTileEntityData) updatePacketMethod.invoke(te); | ||
|
||
// Access the private field for the NBTTagCompound getter in PacketPlayOutTileEntityData | ||
Field fieldC = packet.getClass().getDeclaredField(field); | ||
fieldC.setAccessible(true); | ||
NBTTagCompound nbtTag = (NBTTagCompound) fieldC.get(packet); | ||
|
||
return nbtTag.toString(); // This will show what you want | ||
} | ||
} catch (NoSuchMethodException e) { | ||
System.out.println("The method '" + method + "' does not exist in the TileEntity class."); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return ""; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.