mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 01:27:27 +00:00
Implemented storeddata and tempdata
This commit is contained in:
1 parent
b42ab94251
commit
d6875c4ecc
2 files changed
+128
-5
No files matched your search
@@ -21,21 +21,21 @@ import noppes.npcs.api.block.ITextPlane;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.INpcScriptHandler;
|
||||
import noppes.npcs.controllers.data.IScriptBlockHandler;
|
||||
import noppes.npcs.entity.data.DataTimers;
|
||||
import noppes.npcs.scripted.BlockScriptedWrapper;
|
||||
import noppes.npcs.util.ValueUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class TileScripted extends TileEntity implements IScriptBlockHandler {
|
||||
public List<ScriptContainer> scripts = new ArrayList<>();
|
||||
|
||||
public Map<String,Object> tempData = new HashMap<>();
|
||||
|
||||
private NBTTagCompound customTileData;
|
||||
|
||||
public String scriptLanguage = "ECMAScript";
|
||||
public boolean enabled = false;
|
||||
|
||||
@@ -89,6 +89,10 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler {
|
||||
setNBT(compound);
|
||||
setDisplayNBT(compound);
|
||||
timers.readFromNBT(compound);
|
||||
NBTTagCompound extraData = compound.getCompoundTag("ExtraData");
|
||||
if(!extraData.hasNoTags()){
|
||||
getTileData().setTag("CustomNPCsData", extraData);
|
||||
}
|
||||
}
|
||||
|
||||
public void setNBT(NBTTagCompound compound){
|
||||
@@ -149,6 +153,7 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler {
|
||||
getNBT(compound);
|
||||
getDisplayNBT(compound);
|
||||
timers.writeToNBT(compound);
|
||||
compound.setTag("ExtraData",getTileData().getTag("CustomNPCsData"));
|
||||
}
|
||||
|
||||
public NBTTagCompound getNBT(NBTTagCompound compound){
|
||||
@@ -395,6 +400,15 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler {
|
||||
.offset(xCoord,yCoord,zCoord);
|
||||
}
|
||||
|
||||
public NBTTagCompound getTileData()
|
||||
{
|
||||
if (this.customTileData == null)
|
||||
{
|
||||
this.customTileData = new NBTTagCompound();
|
||||
}
|
||||
return this.customTileData;
|
||||
}
|
||||
|
||||
public class TextPlane implements ITextPlane {
|
||||
public boolean textHasChanged = true;
|
||||
public TextBlock textBlock;
|
||||
|
||||
@@ -3,6 +3,9 @@ package noppes.npcs.scripted;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -14,6 +17,8 @@ import noppes.npcs.api.block.ITextPlane;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.blocks.tiles.TileScripted;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class BlockScriptedWrapper extends ScriptBlock implements IBlockScripted{
|
||||
private TileScripted tile;
|
||||
|
||||
@@ -202,5 +207,109 @@ public class BlockScriptedWrapper extends ScriptBlock implements IBlockScripted{
|
||||
this.tile = (TileScripted) tile;
|
||||
super.setTileEntity(tile);
|
||||
}
|
||||
|
||||
private NBTTagCompound getNBT(){
|
||||
if(tile == null)
|
||||
return null;
|
||||
NBTTagCompound compound = tile.getTileData().getCompoundTag("CustomNPCsData");
|
||||
if(compound.hasNoTags() && !tile.getTileData().hasKey("CustomNPCsData")){
|
||||
tile.getTileData().setTag("CustomNPCsData", compound);
|
||||
}
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStoredData(String key, Object value) {
|
||||
NBTTagCompound compound = getNBT();
|
||||
if(compound == null)
|
||||
return;
|
||||
if(value instanceof Number)
|
||||
compound.setDouble(key, ((Number) value).doubleValue());
|
||||
else if(value instanceof String)
|
||||
compound.setString(key, (String)value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getStoredData(String key) {
|
||||
NBTTagCompound compound = getNBT();
|
||||
if(compound == null)
|
||||
return null;
|
||||
if(!compound.hasKey(key))
|
||||
return null;
|
||||
NBTBase base = compound.getTag(key);
|
||||
if(base instanceof NBTBase.NBTPrimitive)
|
||||
return ((NBTBase.NBTPrimitive)base).func_150286_g();
|
||||
return ((NBTTagString)base).func_150285_a_();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStoredData(String key) {
|
||||
NBTTagCompound compound = getNBT();
|
||||
if(compound == null)
|
||||
return;
|
||||
compound.removeTag(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStoredData(String key) {
|
||||
NBTTagCompound compound = getNBT();
|
||||
if(compound == null)
|
||||
return false;
|
||||
return compound.hasKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearStoredData() {
|
||||
if(tile == null)
|
||||
return;
|
||||
tile.getTileData().setTag("CustomNPCsData", new NBTTagCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getStoredDataKeys() {
|
||||
NBTTagCompound compound = getNBT();
|
||||
if(compound == null)
|
||||
return new String[0];
|
||||
return ((Set<String>)compound.func_150296_c()).toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTempData(String key) {
|
||||
if(tile == null)
|
||||
return;
|
||||
tile.tempData.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTempData(String key, Object value) {
|
||||
if(tile == null)
|
||||
return;
|
||||
tile.tempData.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTempData(String key) {
|
||||
if(tile == null)
|
||||
return false;
|
||||
return tile.tempData.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTempData(String key) {
|
||||
if(tile == null)
|
||||
return null;
|
||||
return tile.tempData.get(key);
|
||||
}
|
||||
@Override
|
||||
public void clearTempData() {
|
||||
if(tile == null)
|
||||
return;
|
||||
tile.tempData.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTempDataKeys() {
|
||||
return tile.tempData.keySet().toArray(new String[tile.tempData.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user