mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 08:49:41 +00:00
Added ScriptBlock and ScriptNbt support to scripting API
This commit is contained in:
1 parent
6752f8baec
commit
699182f4c0
9 files changed
+339
-4
No files matched your search
@@ -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();
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<T extends Entity> 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());
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user