reworked container access (never throw, multi-field access, return values, operator), added package storage

This commit is contained in:
gnembon committed 2019-10-13 02:54:18 -03:00
1 parent 8b531834d0
commit 701a717135
12 files changed
+369 -114

No files matched your search

@@ -50,6 +50,7 @@ import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.server.MinecraftServer;
@@ -2873,6 +2874,34 @@ public class CarpetExpression
CarpetServer.scriptServer.events.scheduleCall(cc, funname, args, delay);
return (c_, t_) -> Value.TRUE;
});
this.expr.addLazyFunction("get_global_state", -1, (c, t, lv) ->
{
String file = null;
if (lv.size()>0)
file = lv.get(0).evalValue(c).getString();
Tag state = ((CarpetContext)c).host.getGlobalState(file);
if (state == null)
return (cc, tt) -> Value.NULL;
Value retVal = new NBTSerializableValue(state);
return (cc, tt) -> retVal;
});
this.expr.addLazyFunction("set_global_state", -1, (c, t, lv) ->
{
if (lv.size() == 0)
throw new InternalExpressionException("save_state needs nbt tag and optional file");
Value val = lv.get(0).evalValue(c);
String file = null;
if (lv.size()>1)
file = lv.get(1).evalValue(c).getString();
NBTSerializableValue tagValue = (val instanceof NBTSerializableValue)
? (NBTSerializableValue) val
: new NBTSerializableValue(val.getString());
Tag tag = tagValue.getTag();
((CarpetContext)c).host.setGlobalState(tag, file);
return (cc, tt) -> Value.NULL;
});
}
/**