diff --git a/src/main/java/noppes/npcs/scripted/INbt.java b/src/main/java/noppes/npcs/scripted/INbt.java new file mode 100644 index 000000000..5ac4ddc95 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/INbt.java @@ -0,0 +1,76 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.nbt.NBTTagCompound; + +public interface INbt { + void remove(String var1); + + boolean has(String var1); + + boolean getBoolean(String var1); + + void setBoolean(String var1, boolean var2); + + short getShort(String var1); + + void setShort(String var1, short var2); + + int getInteger(String var1); + + void setInteger(String var1, int var2); + + byte getByte(String var1); + + void setByte(String var1, byte var2); + + long getLong(String var1); + + void setLong(String var1, long var2); + + double getDouble(String var1); + + void setDouble(String var1, double var2); + + float getFloat(String var1); + + void setFloat(String var1, float var2); + + String getString(String var1); + + void setString(String var1, String var2); + + byte[] getByteArray(String var1); + + void setByteArray(String var1, byte[] var2); + + int[] getIntegerArray(String var1); + + void setIntegerArray(String var1, int[] var2); + + Object[] getList(String var1, int var2); + + int getListType(String var1); + + void setList(String var1, Object[] var2); + + INbt getCompound(String var1); + + void setCompound(String var1, INbt var2); + + String[] getKeys(); + + int getType(String var1); + + NBTTagCompound getMCNBT(); + + String toJsonString(); + + boolean isEqual(INbt var1); + + void clear(); +} diff --git a/src/main/java/noppes/npcs/scripted/IWorld.java b/src/main/java/noppes/npcs/scripted/IWorld.java index 291624518..1be45c61e 100644 --- a/src/main/java/noppes/npcs/scripted/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/IWorld.java @@ -13,6 +13,7 @@ import net.minecraft.nbt.NBTTagString; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import noppes.npcs.NoppesUtilServer; @@ -41,7 +42,7 @@ public interface IWorld { * @param z World position z * @return The block at the given position. Returns null if there isn't a block */ - public ScriptItemStack getBlock(int x, int y, int z); + public IBlock getBlock(int x, int y, int z); /** * @param x World position x @@ -219,6 +220,8 @@ public interface IWorld { public ScriptScoreboard getScoreboard(); + BlockPos getMCBlockPos(int x, int y, int z); + /** * @since 1.7.10c * Expert use only diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 327e155ba..e43f1bed9 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -77,4 +77,6 @@ public abstract class NpcAPI { public abstract String executeCommand(IWorld var1, String var2); public abstract String getRandomName(int var1, int var2); + + public abstract INbt getINbt(NBTTagCompound entityData); } diff --git a/src/main/java/noppes/npcs/scripted/ScriptBlock.java b/src/main/java/noppes/npcs/scripted/ScriptBlock.java index e74850582..86893eb5d 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptBlock.java +++ b/src/main/java/noppes/npcs/scripted/ScriptBlock.java @@ -9,6 +9,7 @@ import java.util.Map; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.inventory.IInventory; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; @@ -109,4 +110,10 @@ public class ScriptBlock implements IBlock { public TileEntity getMCTileEntity() { return this.tile; } + + public INbt getTileEntityNBT() { + NBTTagCompound compound = new NBTTagCompound(); + this.tile.writeToNBT(compound); + return NpcAPI.Instance().getINbt(compound); + } } diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/ScriptEntity.java index c95abd0e8..bba2fa4af 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntity.java @@ -19,6 +19,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagString; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import noppes.npcs.NoppesUtilServer; import noppes.npcs.Server; @@ -486,4 +487,12 @@ public class ScriptEntity implements IEntity{ public T getMCEntity(){ return entity; } + + public INbt getNbt() { + return NpcAPI.Instance().getINbt(this.entity.getEntityData()); + } + + public void setNbt(INbt nbt) { + this.entity.readFromNBT(nbt.getMCNBT()); + } } diff --git a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java index 477346d08..ba0d1030e 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java +++ b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java @@ -199,6 +199,21 @@ public class ScriptItemStack implements IItemStack { return true; } + public INbt getNbt() { + NBTTagCompound compound = this.item.getTagCompound(); + if(compound == null) { + this.item.setTagCompound(compound = new NBTTagCompound()); + } + + return NpcAPI.Instance().getINbt(compound); + } + + public INbt getItemNbt() { + NBTTagCompound compound = new NBTTagCompound(); + this.item.writeToNBT(compound); + return NpcAPI.Instance().getINbt(compound); + } + /** * No support is given for this method. Dont use if you dont know what you are doing. * @return Minecraft ItemStack diff --git a/src/main/java/noppes/npcs/scripted/ScriptNbt.java b/src/main/java/noppes/npcs/scripted/ScriptNbt.java new file mode 100644 index 000000000..25816f90f --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/ScriptNbt.java @@ -0,0 +1,214 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import java.util.Iterator; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagDouble; +import net.minecraft.nbt.NBTTagFloat; +import net.minecraft.nbt.NBTTagInt; +import net.minecraft.nbt.NBTTagIntArray; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import noppes.npcs.util.NBTJsonUtil; + +public class ScriptNbt implements INbt { + private NBTTagCompound compound; + + public ScriptNbt(NBTTagCompound compound) { + this.compound = compound; + } + + public void remove(String key) { + this.compound.removeTag(key); + } + + public boolean has(String key) { + return this.compound.hasKey(key); + } + + public boolean getBoolean(String key) { + return this.compound.getBoolean(key); + } + + public void setBoolean(String key, boolean value) { + this.compound.setBoolean(key, value); + } + + public short getShort(String key) { + return this.compound.getShort(key); + } + + public void setShort(String key, short value) { + this.compound.setShort(key, value); + } + + public int getInteger(String key) { + return this.compound.getInteger(key); + } + + public void setInteger(String key, int value) { + this.compound.setInteger(key, value); + } + + public byte getByte(String key) { + return this.compound.getByte(key); + } + + public void setByte(String key, byte value) { + this.compound.setByte(key, value); + } + + public long getLong(String key) { + return this.compound.getLong(key); + } + + public void setLong(String key, long value) { + this.compound.setLong(key, value); + } + + public double getDouble(String key) { + return this.compound.getDouble(key); + } + + public void setDouble(String key, double value) { + this.compound.setDouble(key, value); + } + + public float getFloat(String key) { + return this.compound.getFloat(key); + } + + public void setFloat(String key, float value) { + this.compound.setFloat(key, value); + } + + public String getString(String key) { + return this.compound.getString(key); + } + + public void setString(String key, String value) { + this.compound.setString(key, value); + } + + public byte[] getByteArray(String key) { + return this.compound.getByteArray(key); + } + + public void setByteArray(String key, byte[] value) { + this.compound.setByteArray(key, value); + } + + public int[] getIntegerArray(String key) { + return this.compound.getIntArray(key); + } + + public void setIntegerArray(String key, int[] value) { + this.compound.setIntArray(key, value); + } + + public Object[] getList(String key, int type) { + NBTTagList list = this.compound.getTagList(key, type); + Object[] nbts = new Object[list.tagCount()]; + + for(int i = 0; i < list.tagCount(); ++i) { + if(list.func_150303_d() == 10) { + nbts[i] = new ScriptNbt(list.getCompoundTagAt(i)); + } else if(list.func_150303_d() == 8) { + nbts[i] = list.getStringTagAt(i); + } else if(list.func_150303_d() == 6) { + nbts[i] = Double.valueOf(list.func_150309_d(i)); + } else if(list.func_150303_d() == 5) { + nbts[i] = Float.valueOf(list.func_150308_e(i)); + } else if(list.func_150303_d() == 3) { + nbts[i] = Integer.valueOf(list.getStringTagAt(i)); + } else if(list.func_150303_d() == 11) { + nbts[i] = list.func_150306_c(i); + } + } + + return nbts; + } + + public int getListType(String key) { + NBTBase b = this.compound.getTag(key); + if(b == null) { + return 0; + } else if(b.getId() != 9) { + throw new CustomNPCsException("NBT tag " + key + " isn\'t a list", new Object[0]); + } else { + return ((NBTTagList)b).func_150303_d(); + } + } + + public void setList(String key, Object[] value) { + NBTTagList list = new NBTTagList(); + Object[] var4 = value; + int var5 = value.length; + + for(int var6 = 0; var6 < var5; ++var6) { + Object nbt = var4[var6]; + if(nbt instanceof INbt) { + list.appendTag(((INbt) nbt).getMCNBT()); + } else if(nbt instanceof String) { + list.appendTag(new NBTTagString((String) nbt)); + } else if(nbt instanceof Double) { + list.appendTag(new NBTTagDouble(((Double) nbt).doubleValue())); + } else if(nbt instanceof Float) { + list.appendTag(new NBTTagFloat(((Float) nbt).floatValue())); + } else if(nbt instanceof Integer) { + list.appendTag(new NBTTagInt(((Integer) nbt).intValue())); + } else if(nbt instanceof int[]) { + list.appendTag(new NBTTagIntArray((int[]) ((int[]) nbt))); + } + } + + this.compound.setTag(key, list); + } + + public INbt getCompound(String key) { + return new ScriptNbt(this.compound.getCompoundTag(key)); + } + + public void setCompound(String key, INbt value) { + if(value == null) { + throw new CustomNPCsException("Value cant be null", new Object[0]); + } else { + this.compound.setTag(key, value.getMCNBT()); + } + } + + public String[] getKeys() { + return (String[])this.compound.func_150296_c().toArray(new String[this.compound.func_150296_c().size()]); + } + + public int getType(String key) { + return this.compound.func_150299_b(key); + } + + public NBTTagCompound getMCNBT() { + return this.compound; + } + + public String toJsonString() { + return NBTJsonUtil.Convert(this.compound); + } + + public boolean isEqual(INbt nbt) { + return nbt == null?false:this.compound.equals(nbt.getMCNBT()); + } + + public void clear() { + Iterator var1 = this.compound.func_150296_c().iterator(); + + while(var1.hasNext()) { + String name = (String)var1.next(); + this.compound.removeTag(name); + } + + } +} diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index b47dc19b4..82f354fce 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -18,6 +18,7 @@ import net.minecraft.nbt.NBTTagString; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import noppes.npcs.NoppesUtilServer; @@ -57,11 +58,11 @@ public class ScriptWorld implements IWorld{ * @param z World position z * @return The block at the given position. Returns null if there isn't a block */ - public ScriptItemStack getBlock(int x, int y, int z){ + public IBlock getBlock(int x, int y, int z){ Block block = world.getBlock(x, y, z); if(block == null || block.isAir(world, x, y, z)) return null; - return new ScriptItemStack(new ItemStack(block, 1, world.getBlockMetadata(x, y, z))); + return new ScriptBlock(world, block, new BlockPos(x,y,z)); } /** @@ -345,7 +346,11 @@ public class ScriptWorld implements IWorld{ public ScriptScoreboard getScoreboard(){ return new ScriptScoreboard(); } - + + public BlockPos getMCBlockPos(int x, int y, int z){ + return new BlockPos(x,y,z); + } + /** * @since 1.7.10c * Expert use only diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index 455e53a87..7af89455a 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -63,6 +63,10 @@ public class WrapperNpcAPI extends NpcAPI { return new ScriptBlock(world, world.getBlock(pos.getX(),pos.getY(),pos.getZ()), pos); } + public INbt getINbt(NBTTagCompound compound) { + return compound == null?new ScriptNbt(new NBTTagCompound()):new ScriptNbt(compound); + } + public ICustomNpc createNPC(World world) { if (world.isRemote) { return null;