compressed data tree cleanup, streamlining

This commit is contained in:
Sen 2025-05-28 13:51:07 +02:00
parent f76d3c8b89
commit b52053f5ea
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
50 changed files with 560 additions and 598 deletions

View file

@ -7,7 +7,7 @@ import common.entity.Entity;
import common.init.SoundEvent; import common.init.SoundEvent;
import common.item.ItemDye; import common.item.ItemDye;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList; import java.util.List;
import common.util.BoundingBox; import common.util.BoundingBox;
import common.util.ExtMath; import common.util.ExtMath;
import common.world.World; import common.world.World;
@ -192,7 +192,7 @@ public class EntityFirework
{ {
private int fireworkAge; private int fireworkAge;
private final EffectRenderer theEffectRenderer; private final EffectRenderer theEffectRenderer;
private TagObjectList fireworkExplosions; private List<TagObject> fireworkExplosions;
boolean twinkle; boolean twinkle;
public StarterFX(World p_i46464_1_, double p_i46464_2_, double p_i46464_4_, double p_i46464_6_, double p_i46464_8_, double p_i46464_10_, double p_i46464_12_, EffectRenderer p_i46464_14_, TagObject p_i46464_15_) public StarterFX(World p_i46464_1_, double p_i46464_2_, double p_i46464_4_, double p_i46464_6_, double p_i46464_8_, double p_i46464_10_, double p_i46464_12_, EffectRenderer p_i46464_14_, TagObject p_i46464_15_)
@ -206,7 +206,7 @@ public class EntityFirework
if (p_i46464_15_ != null) if (p_i46464_15_ != null)
{ {
this.fireworkExplosions = p_i46464_15_.getObjectList("Explosions"); this.fireworkExplosions = p_i46464_15_.getList("Explosions");
if (this.fireworkExplosions.size() == 0) if (this.fireworkExplosions.size() == 0)
{ {

View file

@ -2,9 +2,10 @@ package common.attributes;
import java.util.Collection; import java.util.Collection;
import common.collect.Lists;
import common.log.Log; import common.log.Log;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList; import java.util.List;
public class Attributes public class Attributes
{ {
@ -40,9 +41,9 @@ public class Attributes
/** /**
* Creates an NBTTagList from a BaseAttributeMap, including all its AttributeInstances * Creates an NBTTagList from a BaseAttributeMap, including all its AttributeInstances
*/ */
public static TagObjectList writeBaseAttributeMapToNBT(AttributeMap map) public static List<TagObject> writeBaseAttributeMapToNBT(AttributeMap map)
{ {
TagObjectList nbttaglist = new TagObjectList(); List<TagObject> nbttaglist = Lists.newArrayList();
for (AttributeInstance iattributeinstance : map.getAllAttributes()) for (AttributeInstance iattributeinstance : map.getAllAttributes())
{ {
@ -65,7 +66,7 @@ public class Attributes
if (collection != null && !collection.isEmpty()) if (collection != null && !collection.isEmpty())
{ {
TagObjectList nbttaglist = new TagObjectList(); List<TagObject> nbttaglist = Lists.newArrayList();
for (AttributeModifier attributemodifier : collection) for (AttributeModifier attributemodifier : collection)
{ {
@ -75,7 +76,7 @@ public class Attributes
} }
} }
nbttagcompound.setObjectList("Modifiers", nbttaglist); nbttagcompound.setList("Modifiers", nbttaglist);
} }
return nbttagcompound; return nbttagcompound;
@ -94,7 +95,7 @@ public class Attributes
return nbttagcompound; return nbttagcompound;
} }
public static void setAttributeModifiers(AttributeMap map, TagObjectList list) public static void setAttributeModifiers(AttributeMap map, List<TagObject> list)
{ {
for (int i = 0; i < list.size(); ++i) for (int i = 0; i < list.size(); ++i)
{ {
@ -116,9 +117,9 @@ public class Attributes
{ {
instance.setBaseValue(compound.getDouble("Base")); instance.setBaseValue(compound.getDouble("Base"));
if (compound.hasObjectList("Modifiers")) if (compound.hasList("Modifiers"))
{ {
TagObjectList nbttaglist = compound.getObjectList("Modifiers"); List<TagObject> nbttaglist = compound.getList("Modifiers");
for (int i = 0; i < nbttaglist.size(); ++i) for (int i = 0; i < nbttaglist.size(); ++i)
{ {

View file

@ -12,8 +12,6 @@ import common.init.Blocks;
import common.init.MetalType; import common.init.MetalType;
import common.init.UniverseRegistry; import common.init.UniverseRegistry;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.tags.TagStringList;
import common.util.ExtMath; import common.util.ExtMath;
import common.util.Vec3; import common.util.Vec3;
import common.world.State; import common.world.State;
@ -920,85 +918,85 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
this.alt1 = BlockRegistry.getFromIdName(tag.getString("AltBlock1"), Blocks.gravel.getState()); this.alt1 = BlockRegistry.getFromIdName(tag.getString("AltBlock1"), Blocks.gravel.getState());
this.alt2 = BlockRegistry.getFromIdName(tag.getString("AltBlock2"), Blocks.sand.getState()); this.alt2 = BlockRegistry.getFromIdName(tag.getString("AltBlock2"), Blocks.sand.getState());
this.caveFiller = BlockRegistry.getFromIdName(tag.getString("CaveFillBlock"), Blocks.lava.getState()); this.caveFiller = BlockRegistry.getFromIdName(tag.getString("CaveFillBlock"), Blocks.lava.getState());
if(tag.hasStringList("Layers")) { if(tag.hasStringArray("Layers")) {
TagStringList list = tag.getStringList("Layers"); String[] list = tag.getStringArray("Layers");
this.layers = new State[list.size()]; this.layers = new State[list.length];
for(int z = 0; z < this.layers.length; z++) { for(int z = 0; z < this.layers.length; z++) {
this.layers[z] = BlockRegistry.getFromIdName(list.get(z), Blocks.stone.getState()); this.layers[z] = BlockRegistry.getFromIdName(list[z], Blocks.stone.getState());
} }
} }
else { else {
this.layers = null; this.layers = null;
} }
if(tag.hasStringList("AddBiomes")) { if(tag.hasStringArray("AddBiomes")) {
TagStringList list = tag.getStringList("AddBiomes"); String[] list = tag.getStringArray("AddBiomes");
if(list.isEmpty()) { if(list.length == 0) {
this.addBiomes = null; this.addBiomes = null;
} }
else { else {
this.addBiomes = new Biome[list.size()]; this.addBiomes = new Biome[list.length];
for(int z = 0; z < this.addBiomes.length; z++) { for(int z = 0; z < this.addBiomes.length; z++) {
this.addBiomes[z] = Biome.findByName(list.get(z)); this.addBiomes[z] = Biome.findByName(list[z]);
} }
} }
} }
else { else {
this.addBiomes = null; this.addBiomes = null;
} }
if(tag.hasStringList("FrostBiomes")) { if(tag.hasStringArray("FrostBiomes")) {
TagStringList list = tag.getStringList("FrostBiomes"); String[] list = tag.getStringArray("FrostBiomes");
if(list.isEmpty()) { if(list.length == 0) {
this.frostBiomes = null; this.frostBiomes = null;
} }
else { else {
this.frostBiomes = new Biome[list.size()]; this.frostBiomes = new Biome[list.length];
for(int z = 0; z < this.frostBiomes.length; z++) { for(int z = 0; z < this.frostBiomes.length; z++) {
this.frostBiomes[z] = Biome.findByName(list.get(z)); this.frostBiomes[z] = Biome.findByName(list[z]);
} }
} }
} }
else { else {
this.frostBiomes = null; this.frostBiomes = null;
} }
if(tag.hasStringList("ColdBiomes")) { if(tag.hasStringArray("ColdBiomes")) {
TagStringList list = tag.getStringList("ColdBiomes"); String[] list = tag.getStringArray("ColdBiomes");
if(list.isEmpty()) { if(list.length == 0) {
this.coldBiomes = null; this.coldBiomes = null;
} }
else { else {
this.coldBiomes = new Biome[list.size()]; this.coldBiomes = new Biome[list.length];
for(int z = 0; z < this.coldBiomes.length; z++) { for(int z = 0; z < this.coldBiomes.length; z++) {
this.coldBiomes[z] = Biome.findByName(list.get(z)); this.coldBiomes[z] = Biome.findByName(list[z]);
} }
} }
} }
else { else {
this.coldBiomes = null; this.coldBiomes = null;
} }
if(tag.hasStringList("MediumBiomes")) { if(tag.hasStringArray("MediumBiomes")) {
TagStringList list = tag.getStringList("MediumBiomes"); String[] list = tag.getStringArray("MediumBiomes");
if(list.isEmpty()) { if(list.length == 0) {
this.mediumBiomes = null; this.mediumBiomes = null;
} }
else { else {
this.mediumBiomes = new Biome[list.size()]; this.mediumBiomes = new Biome[list.length];
for(int z = 0; z < this.mediumBiomes.length; z++) { for(int z = 0; z < this.mediumBiomes.length; z++) {
this.mediumBiomes[z] = Biome.findByName(list.get(z)); this.mediumBiomes[z] = Biome.findByName(list[z]);
} }
} }
} }
else { else {
this.mediumBiomes = null; this.mediumBiomes = null;
} }
if(tag.hasStringList("HotBiomes")) { if(tag.hasStringArray("HotBiomes")) {
TagStringList list = tag.getStringList("HotBiomes"); String[] list = tag.getStringArray("HotBiomes");
if(list.isEmpty()) { if(list.length == 0) {
this.hotBiomes = null; this.hotBiomes = null;
} }
else { else {
this.hotBiomes = new Biome[list.size()]; this.hotBiomes = new Biome[list.length];
for(int z = 0; z < this.hotBiomes.length; z++) { for(int z = 0; z < this.hotBiomes.length; z++) {
this.hotBiomes[z] = Biome.findByName(list.get(z)); this.hotBiomes[z] = Biome.findByName(list[z]);
} }
} }
} }
@ -1006,8 +1004,8 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
this.hotBiomes = null; this.hotBiomes = null;
} }
this.ores.clear(); this.ores.clear();
if(tag.hasObjectList("Ores")) { if(tag.hasList("Ores")) {
TagObjectList list = tag.getObjectList("Ores"); List<TagObject> list = tag.getList("Ores");
for(int z = 0; z < list.size(); z++) { for(int z = 0; z < list.size(); z++) {
TagObject gen = list.get(z); TagObject gen = list.get(z);
this.ores.add(new Ore(BlockRegistry.getFromIdName(gen.getString("Block"), Blocks.iron_ore.getState()), this.ores.add(new Ore(BlockRegistry.getFromIdName(gen.getString("Block"), Blocks.iron_ore.getState()),
@ -1016,8 +1014,8 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
} }
} }
this.lakes.clear(); this.lakes.clear();
if(tag.hasObjectList("Lakes")) { if(tag.hasList("Lakes")) {
TagObjectList list = tag.getObjectList("Lakes"); List<TagObject> list = tag.getList("Lakes");
for(int z = 0; z < list.size(); z++) { for(int z = 0; z < list.size(); z++) {
TagObject gen = list.get(z); TagObject gen = list.get(z);
this.lakes.add(new Lake( this.lakes.add(new Lake(
@ -1028,8 +1026,8 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
} }
} }
this.liquids.clear(); this.liquids.clear();
if(tag.hasObjectList("Liquids")) { if(tag.hasList("Liquids")) {
TagObjectList list = tag.getObjectList("Liquids"); List<TagObject> list = tag.getList("Liquids");
for(int z = 0; z < list.size(); z++) { for(int z = 0; z < list.size(); z++) {
TagObject gen = list.get(z); TagObject gen = list.get(z);
this.liquids.add(new Liquid( this.liquids.add(new Liquid(
@ -1157,49 +1155,49 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
tag.setString("AltBlock2", BlockRegistry.toIdName(this.alt2)); tag.setString("AltBlock2", BlockRegistry.toIdName(this.alt2));
tag.setString("CaveFillBlock", BlockRegistry.toIdName(this.caveFiller)); tag.setString("CaveFillBlock", BlockRegistry.toIdName(this.caveFiller));
if(this.layers != null) { if(this.layers != null) {
TagStringList list = new TagStringList(); String[] list = new String[this.layers.length];
for(State gen : this.layers) { for(int z = 0; z < this.layers.length; z++) {
list.add(BlockRegistry.toIdName(gen)); list[z] = BlockRegistry.toIdName(this.layers[z]);
} }
tag.setStringList("Layers", list); tag.setStringArray("Layers", list);
} }
if(this.addBiomes != null) { if(this.addBiomes != null) {
TagStringList list = new TagStringList(); String[] list = new String[this.addBiomes.length];
for(Biome biome : this.addBiomes) { for(int z = 0; z < this.addBiomes.length; z++) {
list.add(biome.name.toLowerCase()); list[z] = this.addBiomes[z].name.toLowerCase();
} }
tag.setStringList("AddBiomes", list); tag.setStringArray("AddBiomes", list);
} }
if(this.frostBiomes != null) { if(this.frostBiomes != null) {
TagStringList list = new TagStringList(); String[] list = new String[this.frostBiomes.length];
for(Biome biome : this.frostBiomes) { for(int z = 0; z < this.frostBiomes.length; z++) {
list.add(biome.name.toLowerCase()); list[z] = this.frostBiomes[z].name.toLowerCase();
} }
tag.setStringList("FrostBiomes", list); tag.setStringArray("FrostBiomes", list);
} }
if(this.coldBiomes != null) { if(this.coldBiomes != null) {
TagStringList list = new TagStringList(); String[] list = new String[this.coldBiomes.length];
for(Biome biome : this.coldBiomes) { for(int z = 0; z < this.coldBiomes.length; z++) {
list.add(biome.name.toLowerCase()); list[z] = this.coldBiomes[z].name.toLowerCase();
} }
tag.setStringList("ColdBiomes", list); tag.setStringArray("ColdBiomes", list);
} }
if(this.mediumBiomes != null) { if(this.mediumBiomes != null) {
TagStringList list = new TagStringList(); String[] list = new String[this.mediumBiomes.length];
for(Biome biome : this.mediumBiomes) { for(int z = 0; z < this.mediumBiomes.length; z++) {
list.add(biome.name.toLowerCase()); list[z] = this.mediumBiomes[z].name.toLowerCase();
} }
tag.setStringList("MediumBiomes", list); tag.setStringArray("MediumBiomes", list);
} }
if(this.hotBiomes != null) { if(this.hotBiomes != null) {
TagStringList list = new TagStringList(); String[] list = new String[this.hotBiomes.length];
for(Biome biome : this.hotBiomes) { for(int z = 0; z < this.hotBiomes.length; z++) {
list.add(biome.name.toLowerCase()); list[z] = this.hotBiomes[z].name.toLowerCase();
} }
tag.setStringList("HotBiomes", list); tag.setStringArray("HotBiomes", list);
} }
if(!this.ores.isEmpty()) { if(!this.ores.isEmpty()) {
TagObjectList list = new TagObjectList(); List<TagObject> list = Lists.newArrayList();
for(Ore gen : this.ores) { for(Ore gen : this.ores) {
TagObject ore = new TagObject(); TagObject ore = new TagObject();
ore.setString("Block", BlockRegistry.toIdName(gen.state)); ore.setString("Block", BlockRegistry.toIdName(gen.state));
@ -1211,10 +1209,10 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
ore.setInt("MaxS", gen.max); ore.setInt("MaxS", gen.max);
list.add(ore); list.add(ore);
} }
tag.setObjectList("Ores", list); tag.setList("Ores", list);
} }
if(!this.lakes.isEmpty()) { if(!this.lakes.isEmpty()) {
TagObjectList list = new TagObjectList(); List<TagObject> list = Lists.newArrayList();
for(Lake gen : this.lakes) { for(Lake gen : this.lakes) {
TagObject lake = new TagObject(); TagObject lake = new TagObject();
lake.setString("Block", BlockRegistry.toIdName(gen.state)); lake.setString("Block", BlockRegistry.toIdName(gen.state));
@ -1228,10 +1226,10 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
lake.setInt("Max", gen.maxHeight); lake.setInt("Max", gen.maxHeight);
list.add(lake); list.add(lake);
} }
tag.setObjectList("Lakes", list); tag.setList("Lakes", list);
} }
if(!this.liquids.isEmpty()) { if(!this.liquids.isEmpty()) {
TagObjectList list = new TagObjectList(); List<TagObject> list = Lists.newArrayList();
for(Liquid gen : this.liquids) { for(Liquid gen : this.liquids) {
TagObject liquid = new TagObject(); TagObject liquid = new TagObject();
liquid.setString("Block", BlockRegistry.toIdName(gen.state)); liquid.setString("Block", BlockRegistry.toIdName(gen.state));
@ -1241,7 +1239,7 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
liquid.setInt("Max", gen.maxHeight); liquid.setInt("Max", gen.maxHeight);
list.add(liquid); list.add(liquid);
} }
tag.setObjectList("Liquids", list); tag.setList("Liquids", list);
} }
if(!this.populated) if(!this.populated)
tag.setBool("NoPopulation", true); tag.setBool("NoPopulation", true);

View file

@ -15,7 +15,6 @@ import common.item.ItemStack;
import common.rng.Random; import common.rng.Random;
import common.rng.WeightedList; import common.rng.WeightedList;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
public class EnchantmentHelper public class EnchantmentHelper
{ {
@ -45,7 +44,7 @@ public class EnchantmentHelper
} }
else else
{ {
TagObjectList list = stack.getEnchantmentTagList(); List<TagObject> list = stack.getEnchantmentTagList();
if (list == null) if (list == null)
{ {
@ -72,7 +71,7 @@ public class EnchantmentHelper
public static Map<Integer, Integer> getEnchantments(ItemStack stack) public static Map<Integer, Integer> getEnchantments(ItemStack stack)
{ {
Map<Integer, Integer> map = Maps.<Integer, Integer>newLinkedHashMap(); Map<Integer, Integer> map = Maps.<Integer, Integer>newLinkedHashMap();
TagObjectList list = stack.getItem() == Items.enchanted_book ? Items.enchanted_book.getEnchantments(stack) : stack.getEnchantmentTagList(); List<TagObject> list = stack.getItem() == Items.enchanted_book ? Items.enchanted_book.getEnchantments(stack) : stack.getEnchantmentTagList();
if (list != null) if (list != null)
{ {
@ -92,7 +91,7 @@ public class EnchantmentHelper
*/ */
public static void setEnchantments(Map<Integer, Integer> enchMap, ItemStack stack) public static void setEnchantments(Map<Integer, Integer> enchMap, ItemStack stack)
{ {
TagObjectList list = new TagObjectList(); List<TagObject> list = Lists.newArrayList();
Iterator iterator = enchMap.keySet().iterator(); Iterator iterator = enchMap.keySet().iterator();
while (iterator.hasNext()) while (iterator.hasNext())
@ -161,7 +160,7 @@ public class EnchantmentHelper
{ {
if (stack != null) if (stack != null)
{ {
TagObjectList list = stack.getEnchantmentTagList(); List<TagObject> list = stack.getEnchantmentTagList();
if (list != null) if (list != null)
{ {

View file

@ -14,6 +14,7 @@ import common.attributes.AttributeInstance;
import common.attributes.Attributes; import common.attributes.Attributes;
import common.block.Block; import common.block.Block;
import common.block.SoundType; import common.block.SoundType;
import common.collect.Lists;
import common.entity.DamageSource; import common.entity.DamageSource;
import common.entity.Entity; import common.entity.Entity;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
@ -34,7 +35,7 @@ import common.model.ParticleType;
import common.pathfinding.PathNavigateGround; import common.pathfinding.PathNavigateGround;
import common.potion.Potion; import common.potion.Potion;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList; import java.util.List;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.ExtMath; import common.util.ExtMath;
import common.world.World; import common.world.World;
@ -1402,7 +1403,7 @@ public class EntityHorse extends EntityAnimal implements IInvBasic
if (this.isChested()) if (this.isChested())
{ {
TagObjectList nbttaglist = new TagObjectList(); List<TagObject> nbttaglist = Lists.newArrayList();
for (int i = 2; i < this.horseChest.getSizeInventory(); ++i) for (int i = 2; i < this.horseChest.getSizeInventory(); ++i)
{ {
@ -1417,7 +1418,7 @@ public class EntityHorse extends EntityAnimal implements IInvBasic
} }
} }
tagCompound.setObjectList("Items", nbttaglist); tagCompound.setList("Items", nbttaglist);
} }
if (this.horseChest.getStackInSlot(1) != null) if (this.horseChest.getStackInSlot(1) != null)
@ -1466,7 +1467,7 @@ public class EntityHorse extends EntityAnimal implements IInvBasic
if (this.isChested()) if (this.isChested())
{ {
TagObjectList nbttaglist = tagCompund.getObjectList("Items"); List<TagObject> nbttaglist = tagCompund.getList("Items");
this.initHorseChest(); this.initHorseChest();
for (int i = 0; i < nbttaglist.size(); ++i) for (int i = 0; i < nbttaglist.size(); ++i)

View file

@ -1,5 +1,6 @@
package common.entity.item; package common.entity.item;
import common.collect.Lists;
import common.entity.DamageSource; import common.entity.DamageSource;
import common.entity.Entity; import common.entity.Entity;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
@ -8,7 +9,7 @@ import common.inventory.Container;
import common.inventory.InventoryHelper; import common.inventory.InventoryHelper;
import common.item.ItemStack; import common.item.ItemStack;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList; import java.util.List;
import common.tileentity.ILockableContainer; import common.tileentity.ILockableContainer;
import common.tileentity.LockCode; import common.tileentity.LockCode;
import common.util.BlockPos; import common.util.BlockPos;
@ -190,7 +191,7 @@ public abstract class EntityCartContainer extends EntityCart implements ILockabl
protected void writeEntity(TagObject tagCompound) protected void writeEntity(TagObject tagCompound)
{ {
super.writeEntity(tagCompound); super.writeEntity(tagCompound);
TagObjectList nbttaglist = new TagObjectList(); List<TagObject> nbttaglist = Lists.newArrayList();
for (int i = 0; i < this.minecartContainerItems.length; ++i) for (int i = 0; i < this.minecartContainerItems.length; ++i)
{ {
@ -203,7 +204,7 @@ public abstract class EntityCartContainer extends EntityCart implements ILockabl
} }
} }
tagCompound.setObjectList("Items", nbttaglist); tagCompound.setList("Items", nbttaglist);
} }
/** /**
@ -212,7 +213,7 @@ public abstract class EntityCartContainer extends EntityCart implements ILockabl
protected void readEntity(TagObject tagCompund) protected void readEntity(TagObject tagCompund)
{ {
super.readEntity(tagCompund); super.readEntity(tagCompund);
TagObjectList nbttaglist = tagCompund.getObjectList("Items"); List<TagObject> nbttaglist = tagCompund.getList("Items");
this.minecartContainerItems = new ItemStack[this.getSizeInventory()]; this.minecartContainerItems = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.size(); ++i) for (int i = 0; i < nbttaglist.size(); ++i)

View file

@ -4,7 +4,6 @@ import java.util.List;
import common.block.Block; import common.block.Block;
import common.block.BlockFalling; import common.block.BlockFalling;
import common.block.ITileEntityProvider;
import common.block.tech.BlockAnvil; import common.block.tech.BlockAnvil;
import common.collect.Lists; import common.collect.Lists;
import common.entity.DamageSource; import common.entity.DamageSource;
@ -15,9 +14,7 @@ import common.init.BlockRegistry;
import common.init.Blocks; import common.init.Blocks;
import common.init.Config; import common.init.Config;
import common.item.ItemStack; import common.item.ItemStack;
import common.tags.Tag;
import common.tags.TagObject; import common.tags.TagObject;
import common.tileentity.TileEntity;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.ExtMath; import common.util.ExtMath;
import common.util.Facing; import common.util.Facing;
@ -33,7 +30,6 @@ public class EntityFalling extends Entity implements IObjectData
private boolean hurtEntities; private boolean hurtEntities;
private int fallHurtMax = 40; private int fallHurtMax = 40;
private float fallHurtAmount = 2.0F; private float fallHurtAmount = 2.0F;
public TagObject tileEntityData;
public EntityFalling(World worldIn) public EntityFalling(World worldIn)
{ {
@ -141,30 +137,6 @@ public class EntityFalling extends Entity implements IObjectData
{ {
((BlockFalling)block).onEndFalling(this.worldObj, blockpos1); ((BlockFalling)block).onEndFalling(this.worldObj, blockpos1);
} }
if (this.tileEntityData != null && block instanceof ITileEntityProvider)
{
TileEntity tileentity = this.worldObj.getTileEntity(blockpos1);
if (tileentity != null)
{
TagObject nbttagcompound = new TagObject();
tileentity.writeTags(nbttagcompound);
for (String s : this.tileEntityData.getKeySet())
{
Tag nbtbase = this.tileEntityData.get(s);
if (!s.equals("x") && !s.equals("y") && !s.equals("z"))
{
nbttagcompound.set(s, nbtbase.copy());
}
}
tileentity.readTags(nbttagcompound);
tileentity.markDirty();
}
}
} }
else if (this.shouldDropItem && Config.objectDrop) else if (this.shouldDropItem && Config.objectDrop)
{ {
@ -239,11 +211,6 @@ public class EntityFalling extends Entity implements IObjectData
tagCompound.setBool("HurtEntities", this.hurtEntities); tagCompound.setBool("HurtEntities", this.hurtEntities);
tagCompound.setFloat("FallHurtAmount", this.fallHurtAmount); tagCompound.setFloat("FallHurtAmount", this.fallHurtAmount);
tagCompound.setInt("FallHurtMax", this.fallHurtMax); tagCompound.setInt("FallHurtMax", this.fallHurtMax);
if (this.tileEntityData != null)
{
tagCompound.setObject("TileEntityData", this.tileEntityData);
}
} }
/** /**
@ -271,11 +238,6 @@ public class EntityFalling extends Entity implements IObjectData
this.shouldDropItem = tagCompund.getBool("DropItem"); this.shouldDropItem = tagCompund.getBool("DropItem");
if (tagCompund.hasObject("TileEntityData"))
{
this.tileEntityData = tagCompund.getObject("TileEntityData");
}
if (block == null || block == Blocks.air) if (block == null || block == Blocks.air)
{ {
this.fallTile = Blocks.sand.getState(); this.fallTile = Blocks.sand.getState();

View file

@ -23,6 +23,7 @@ import common.attributes.AttributeInstance;
import common.attributes.Attributes; import common.attributes.Attributes;
import common.block.Block; import common.block.Block;
import common.block.artificial.BlockBed; import common.block.artificial.BlockBed;
import common.collect.Lists;
import common.dimension.Space; import common.dimension.Space;
import common.enchantment.Enchantment; import common.enchantment.Enchantment;
import common.enchantment.EnchantmentHelper; import common.enchantment.EnchantmentHelper;
@ -84,7 +85,6 @@ import common.potion.PotionEffect;
import common.rng.Random; import common.rng.Random;
import common.sound.MovingSoundMinecartRiding; import common.sound.MovingSoundMinecartRiding;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.tileentity.IInteractionObject; import common.tileentity.IInteractionObject;
import common.tileentity.LockCode; import common.tileentity.LockCode;
import common.tileentity.TileEntitySign; import common.tileentity.TileEntitySign;
@ -3389,8 +3389,8 @@ public abstract class EntityNPC extends EntityLiving
// this.setCanPickUpLoot(tagCompund.getBoolean("CanPickUpLoot")); // this.setCanPickUpLoot(tagCompund.getBoolean("CanPickUpLoot"));
// } // }
if(tagCompund.hasObjectList("Equipment")) { if(tagCompund.hasList("Equipment")) {
TagObjectList nbttaglist = tagCompund.getObjectList("Equipment"); List<TagObject> nbttaglist = tagCompund.getList("Equipment");
for(int i = 0; i < this.equipment.length; ++i) { for(int i = 0; i < this.equipment.length; ++i) {
this.equipment[i] = ItemStack.readFromTag(nbttaglist.get(i)); this.equipment[i] = ItemStack.readFromTag(nbttaglist.get(i));
@ -3423,7 +3423,7 @@ public abstract class EntityNPC extends EntityLiving
this.setNpcClass(type); this.setNpcClass(type);
this.setHeight(tagCompund.hasFloat("Height") ? tagCompund.getFloat("Height") : this.getBaseSize()); this.setHeight(tagCompund.hasFloat("Height") ? tagCompund.getFloat("Height") : this.getBaseSize());
TagObjectList nbttaglist = tagCompund.getObjectList("Items"); List<TagObject> nbttaglist = tagCompund.getList("Items");
for (int i = 0; i < nbttaglist.size(); ++i) for (int i = 0; i < nbttaglist.size(); ++i)
{ {
@ -3435,9 +3435,9 @@ public abstract class EntityNPC extends EntityLiving
} }
} }
if(tagCompund.hasObjectList("Offers")) { if(tagCompund.hasList("Offers")) {
this.trades = new MerchantRecipeList(); this.trades = new MerchantRecipeList();
this.trades.fromTags(tagCompund.getObjectList("Offers")); this.trades.fromTags(tagCompund.getList("Offers"));
} }
this.healTimer = tagCompund.getInt("healTimer"); this.healTimer = tagCompund.getInt("healTimer");
if(tagCompund.hasByteArray("Skin")) if(tagCompund.hasByteArray("Skin"))
@ -3448,7 +3448,7 @@ public abstract class EntityNPC extends EntityLiving
if(this.isPlayer()) { if(this.isPlayer()) {
// this.entityUniqueID = getOfflineUUID(this.user); // this.entityUniqueID = getOfflineUUID(this.user);
TagObjectList nbttaglist0 = tagCompund.getObjectList("Inventory"); List<TagObject> nbttaglist0 = tagCompund.getList("Inventory");
this.inventory.readFromNBT(nbttaglist0); this.inventory.readFromNBT(nbttaglist0);
this.inventory.currentItem = tagCompund.getInt("SelectedItemSlot"); this.inventory.currentItem = tagCompund.getInt("SelectedItemSlot");
// this.sleeping = tagCompund.getBoolean("Sleeping"); // this.sleeping = tagCompund.getBoolean("Sleeping");
@ -3495,9 +3495,9 @@ public abstract class EntityNPC extends EntityLiving
// this.allowFlyingPersist = tagCompund.getBoolean("alwaysFly"); // this.allowFlyingPersist = tagCompund.getBoolean("alwaysFly");
this.noclip = tagCompund.getBool("noClip"); this.noclip = tagCompund.getBool("noClip");
if (tagCompund.hasObjectList("WarpItems")) if (tagCompund.hasList("WarpItems"))
{ {
TagObjectList nbttaglist1 = tagCompund.getObjectList("WarpItems"); List<TagObject> nbttaglist1 = tagCompund.getList("WarpItems");
this.warpChest.readTags(nbttaglist1); this.warpChest.readTags(nbttaglist1);
} }
@ -3534,7 +3534,7 @@ public abstract class EntityNPC extends EntityLiving
super.writeEntity(tagCompound); super.writeEntity(tagCompound);
// tagCompound.setBoolean("CanPickUpLoot", this.canPickUpLoot()); // tagCompound.setBoolean("CanPickUpLoot", this.canPickUpLoot());
TagObjectList nbttaglist0 = new TagObjectList(); List<TagObject> nbttaglist0 = Lists.newArrayList();
for(int i = 0; i < this.equipment.length; ++i) { for(int i = 0; i < this.equipment.length; ++i) {
TagObject nbttagcompound = new TagObject(); TagObject nbttagcompound = new TagObject();
@ -3546,7 +3546,7 @@ public abstract class EntityNPC extends EntityLiving
nbttaglist0.add(nbttagcompound); nbttaglist0.add(nbttagcompound);
} }
tagCompound.setObjectList("Equipment", nbttaglist0); tagCompound.setList("Equipment", nbttaglist0);
// tagCompound.setString("Species", this.getSpecies()); // tagCompound.setString("Species", this.getSpecies());
tagCompound.setString("Char", this.getChar()); tagCompound.setString("Char", this.getChar());
tagCompound.setString("Cape", this.getCape()); tagCompound.setString("Cape", this.getCape());
@ -3559,7 +3559,7 @@ public abstract class EntityNPC extends EntityLiving
if(type != null) if(type != null)
tagCompound.setString("ClassType", this.species.classnames.inverse().get(type)); tagCompound.setString("ClassType", this.species.classnames.inverse().get(type));
TagObjectList nbttaglist = new TagObjectList(); List<TagObject> nbttaglist = Lists.newArrayList();
for (int i = 0; i < this.extraInventory.getSizeInventory(); ++i) for (int i = 0; i < this.extraInventory.getSizeInventory(); ++i)
{ {
@ -3571,9 +3571,9 @@ public abstract class EntityNPC extends EntityLiving
} }
} }
tagCompound.setObjectList("Items", nbttaglist); tagCompound.setList("Items", nbttaglist);
if(this.trades != null) if(this.trades != null)
tagCompound.setObjectList("Offers", this.trades.toTags()); tagCompound.setList("Offers", this.trades.toTags());
tagCompound.setInt("healTimer", this.healTimer); tagCompound.setInt("healTimer", this.healTimer);
if(this.skin != null) if(this.skin != null)
tagCompound.setByteArray("Skin", this.skin); tagCompound.setByteArray("Skin", this.skin);
@ -3587,7 +3587,7 @@ public abstract class EntityNPC extends EntityLiving
this.getAttributeMap().applyAttributeModifiers(itemstack.getAttributeModifiers(2), z, itemstack.size); this.getAttributeMap().applyAttributeModifiers(itemstack.getAttributeModifiers(2), z, itemstack.size);
} }
} }
tagCompound.setObjectList("Inventory", this.inventory.writeToNBT(new TagObjectList())); tagCompound.setList("Inventory", this.inventory.writeToNBT(Lists.newArrayList()));
tagCompound.setInt("SelectedItemSlot", this.inventory.currentItem); tagCompound.setInt("SelectedItemSlot", this.inventory.currentItem);
// tagCompound.setBoolean("Sleeping", this.sleeping); // tagCompound.setBoolean("Sleeping", this.sleeping);
// tagCompound.setShort("SleepTimer", (short)this.sleepTimer); // tagCompound.setShort("SleepTimer", (short)this.sleepTimer);
@ -3624,7 +3624,7 @@ public abstract class EntityNPC extends EntityLiving
// tagCompound.setBoolean("alwaysFly", this.allowFlyingPersist); // tagCompound.setBoolean("alwaysFly", this.allowFlyingPersist);
tagCompound.setBool("noClip", this.noclip); tagCompound.setBool("noClip", this.noclip);
tagCompound.setObjectList("WarpItems", this.warpChest.writeTags()); tagCompound.setList("WarpItems", this.warpChest.writeTags());
ItemStack itemstack = this.inventory.getCurrentItem(); ItemStack itemstack = this.inventory.getCurrentItem();
if (itemstack != null && itemstack.getItem() != null) if (itemstack != null && itemstack.getItem() != null)

View file

@ -58,7 +58,6 @@ import common.potion.PotionEffect;
import common.potion.PotionHelper; import common.potion.PotionHelper;
import common.rng.Random; import common.rng.Random;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.BoundingBox; import common.util.BoundingBox;
import common.util.ExtMath; import common.util.ExtMath;
@ -557,7 +556,7 @@ public abstract class EntityLiving extends Entity
} }
} }
tagCompound.setObjectList("Attributes", Attributes.writeBaseAttributeMapToNBT(this.getAttributeMap())); tagCompound.setList("Attributes", Attributes.writeBaseAttributeMapToNBT(this.getAttributeMap()));
for (ItemStack itemstack1 : this.getInventory()) for (ItemStack itemstack1 : this.getInventory())
{ {
@ -569,14 +568,14 @@ public abstract class EntityLiving extends Entity
if (!this.effects.isEmpty()) if (!this.effects.isEmpty())
{ {
TagObjectList nbttaglist = new TagObjectList(); List<TagObject> nbttaglist = Lists.newArrayList();
for (PotionEffect potioneffect : this.effects.values()) for (PotionEffect potioneffect : this.effects.values())
{ {
nbttaglist.add(potioneffect.toTags()); nbttaglist.add(potioneffect.toTags());
} }
tagCompound.setObjectList("ActiveEffects", nbttaglist); tagCompound.setList("ActiveEffects", nbttaglist);
} }
tagCompound.setBool("Leashed", this.leashed); tagCompound.setBool("Leashed", this.leashed);
@ -613,14 +612,14 @@ public abstract class EntityLiving extends Entity
{ {
this.setAbsorptionAmount(tagCompund.getInt("Absorption")); this.setAbsorptionAmount(tagCompund.getInt("Absorption"));
if (tagCompund.hasObjectList("Attributes") && this.worldObj != null && !this.worldObj.client) if (tagCompund.hasList("Attributes") && this.worldObj != null && !this.worldObj.client)
{ {
Attributes.setAttributeModifiers(this.getAttributeMap(), tagCompund.getObjectList("Attributes")); Attributes.setAttributeModifiers(this.getAttributeMap(), tagCompund.getList("Attributes"));
} }
if (tagCompund.hasObjectList("ActiveEffects")) if (tagCompund.hasList("ActiveEffects"))
{ {
TagObjectList nbttaglist = tagCompund.getObjectList("ActiveEffects"); List<TagObject> nbttaglist = tagCompund.getList("ActiveEffects");
for (int i = 0; i < nbttaglist.size(); ++i) for (int i = 0; i < nbttaglist.size(); ++i)
{ {

View file

@ -26,7 +26,6 @@ import common.item.ItemArmor;
import common.item.ItemDye; import common.item.ItemDye;
import common.item.ItemStack; import common.item.ItemStack;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.tileentity.TileEntityBanner; import common.tileentity.TileEntityBanner;
import common.world.World; import common.world.World;
@ -617,16 +616,16 @@ public abstract class CraftingRegistry
} }
TagObject tag = itemstack.getSubCompound("BlockEntityTag", true); TagObject tag = itemstack.getSubCompound("BlockEntityTag", true);
TagObjectList list = null; List<TagObject> list = null;
if (tag.hasObjectList("Patterns")) if (tag.hasList("Patterns"))
{ {
list = tag.getObjectList("Patterns"); list = tag.getList("Patterns");
} }
else else
{ {
list = new TagObjectList(); list = Lists.newArrayList();
tag.setObjectList("Patterns", list); tag.setList("Patterns", list);
} }
TagObject pattern = new TagObject(); TagObject pattern = new TagObject();
@ -971,7 +970,7 @@ public abstract class CraftingRegistry
{ {
TagObject tag = new TagObject(); TagObject tag = new TagObject();
TagObject data = new TagObject(); TagObject data = new TagObject();
TagObjectList list = new TagObjectList(); List<TagObject> list = Lists.newArrayList();
for (int k2 = 0; k2 < inv.getSizeInventory(); ++k2) for (int k2 = 0; k2 < inv.getSizeInventory(); ++k2)
{ {
@ -983,7 +982,7 @@ public abstract class CraftingRegistry
} }
} }
data.setObjectList("Explosions", list); data.setList("Explosions", list);
data.setByte("Flight", (byte)j); data.setByte("Flight", (byte)j);
tag.setObject("Fireworks", data); tag.setObject("Fireworks", data);
this.field_92102_a.setTagCompound(tag); this.field_92102_a.setTagCompound(tag);
@ -1552,7 +1551,7 @@ public abstract class CraftingRegistry
if (itemstack1 != null && itemstack1.hasTagCompound()) if (itemstack1 != null && itemstack1.hasTagCompound())
{ {
itemstack.setTagCompound((TagObject)itemstack1.getTagCompound().copy()); itemstack.setTagCompound(itemstack1.getTagCompound().copy());
} }
} }
} }

View file

@ -28,10 +28,7 @@ import common.dimension.Dimension.GeneratorType;
import common.dimension.Dimension.ReplacerType; import common.dimension.Dimension.ReplacerType;
import common.log.Log; import common.log.Log;
import common.rng.Random; import common.rng.Random;
import common.tags.TagException;
import common.tags.TagInterpreter;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.util.PortalType; import common.util.PortalType;
import common.world.State; import common.world.State;
import common.world.Weather; import common.world.Weather;
@ -93,14 +90,14 @@ public abstract class UniverseRegistry {
} }
public static void fromTags(TagObject tag) { public static void fromTags(TagObject tag) {
TagObjectList list = tag.getObjectList("Dimensions"); List<TagObject> list = tag.getList("Dimensions");
for(int z = 0; z < list.size(); z++) { for(int z = 0; z < list.size(); z++) {
Dimension dim = Dimension.getByTag(list.get(z)); Dimension dim = Dimension.getByTag(list.get(z));
if(!REGISTRY.containsKey(dim.getDimensionId()) && !ALIASES.containsKey(dim.getDimensionName())) if(!REGISTRY.containsKey(dim.getDimensionId()) && !ALIASES.containsKey(dim.getDimensionName()))
register(dim); register(dim);
} }
list = tag.getObjectList("Names"); list = tag.getList("Names");
for(int z = 0; z < list.size(); z++) { for(int z = 0; z < list.size(); z++) {
TagObject data = list.get(z); TagObject data = list.get(z);
String id = data.getString("ID"); String id = data.getString("ID");
@ -111,7 +108,7 @@ public abstract class UniverseRegistry {
// } // }
} }
list = tag.getObjectList("Sectors"); list = tag.getList("Sectors");
for(int z = 0; z < list.size(); z++) { for(int z = 0; z < list.size(); z++) {
TagObject data = list.get(z); TagObject data = list.get(z);
String id = data.getString("ID"); String id = data.getString("ID");
@ -121,7 +118,7 @@ public abstract class UniverseRegistry {
sector.readTags(data); sector.readTags(data);
} }
list = tag.getObjectList("Galaxies"); list = tag.getList("Galaxies");
for(int z = 0; z < list.size(); z++) { for(int z = 0; z < list.size(); z++) {
TagObject data = list.get(z); TagObject data = list.get(z);
String id = data.getString("ID"); String id = data.getString("ID");
@ -131,7 +128,7 @@ public abstract class UniverseRegistry {
galaxy.readTags(data); galaxy.readTags(data);
} }
list = tag.getObjectList("Domains"); list = tag.getList("Domains");
for(int z = 0; z < list.size(); z++) { for(int z = 0; z < list.size(); z++) {
TagObject data = list.get(z); TagObject data = list.get(z);
String id = data.getString("ID"); String id = data.getString("ID");
@ -141,7 +138,7 @@ public abstract class UniverseRegistry {
domain.readTags(data); domain.readTags(data);
} }
list = tag.getObjectList("Barycenters"); list = tag.getList("Barycenters");
for(int z = 0; z < list.size(); z++) { for(int z = 0; z < list.size(); z++) {
TagObject link = list.get(z); TagObject link = list.get(z);
if(!assign(link.getString("Celestial"), link.getString("Center"))) if(!assign(link.getString("Celestial"), link.getString("Center")))
@ -152,15 +149,15 @@ public abstract class UniverseRegistry {
public static TagObject toTags() { public static TagObject toTags() {
TagObject tag = new TagObject(); TagObject tag = new TagObject();
TagObjectList list = new TagObjectList(); List<TagObject> list = Lists.newArrayList();
for(Dimension dim : DIMENSIONS) { for(Dimension dim : DIMENSIONS) {
if(!BASE_REGISTRY.containsKey(dim.getDimensionId()) && dim != Space.INSTANCE) if(!BASE_REGISTRY.containsKey(dim.getDimensionId()) && dim != Space.INSTANCE)
list.add(dim.toTags()); list.add(dim.toTags());
} }
if(!list.isEmpty()) if(!list.isEmpty())
tag.setObjectList("Dimensions", list); tag.setList("Dimensions", list);
list = new TagObjectList(); list = Lists.newArrayList();
for(Dimension dim : DIMENSIONS) { for(Dimension dim : DIMENSIONS) {
if(/* BASE_REGISTRY.containsKey(dim.getDimensionId()) */ dim != Space.INSTANCE) { if(/* BASE_REGISTRY.containsKey(dim.getDimensionId()) */ dim != Space.INSTANCE) {
TagObject data = new TagObject(); TagObject data = new TagObject();
@ -172,9 +169,9 @@ public abstract class UniverseRegistry {
} }
} }
if(!list.isEmpty()) if(!list.isEmpty())
tag.setObjectList("Names", list); tag.setList("Names", list);
list = new TagObjectList(); list = Lists.newArrayList();
for(Sector sector : SECTORS.values()) { for(Sector sector : SECTORS.values()) {
TagObject data = new TagObject(); TagObject data = new TagObject();
sector.writeTags(data); sector.writeTags(data);
@ -184,9 +181,9 @@ public abstract class UniverseRegistry {
} }
} }
if(!list.isEmpty()) if(!list.isEmpty())
tag.setObjectList("Sectors", list); tag.setList("Sectors", list);
list = new TagObjectList(); list = Lists.newArrayList();
for(Galaxy galaxy : GALAXIES.values()) { for(Galaxy galaxy : GALAXIES.values()) {
TagObject data = new TagObject(); TagObject data = new TagObject();
galaxy.writeTags(data); galaxy.writeTags(data);
@ -196,9 +193,9 @@ public abstract class UniverseRegistry {
} }
} }
if(!list.isEmpty()) if(!list.isEmpty())
tag.setObjectList("Galaxies", list); tag.setList("Galaxies", list);
list = new TagObjectList(); list = Lists.newArrayList();
for(Domain domain : DOMAINS.values()) { for(Domain domain : DOMAINS.values()) {
TagObject data = new TagObject(); TagObject data = new TagObject();
domain.writeTags(data); domain.writeTags(data);
@ -208,9 +205,9 @@ public abstract class UniverseRegistry {
} }
} }
if(!list.isEmpty()) if(!list.isEmpty())
tag.setObjectList("Domains", list); tag.setList("Domains", list);
list = new TagObjectList(); list = Lists.newArrayList();
for(Entry<Moon, Planet> entry : MOON_MAP.entrySet()) { for(Entry<Moon, Planet> entry : MOON_MAP.entrySet()) {
if(BASE_REGISTRY.containsKey(entry.getKey().getDimensionId())) if(BASE_REGISTRY.containsKey(entry.getKey().getDimensionId()))
continue; continue;
@ -252,7 +249,7 @@ public abstract class UniverseRegistry {
list.add(link); list.add(link);
} }
if(!list.isEmpty()) if(!list.isEmpty())
tag.setObjectList("Barycenters", list); tag.setList("Barycenters", list);
return tag; return tag;
} }
@ -703,9 +700,9 @@ public abstract class UniverseRegistry {
Dimension dim = BASE_ALIASES.get(base).copy(UniverseRegistry.MORE_DIM_ID, "preset"); Dimension dim = BASE_ALIASES.get(base).copy(UniverseRegistry.MORE_DIM_ID, "preset");
TagObject ptag; TagObject ptag;
try { try {
ptag = TagInterpreter.parseTag("{" + data + "}"); ptag = TagObject.parse("{" + data + "}");
} }
catch(TagException e) { catch(IllegalArgumentException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
TagObject dtag = dim.toTags(true); TagObject dtag = dim.toTags(true);

View file

@ -4,7 +4,6 @@ import common.entity.Entity;
import common.entity.item.EntityItem; import common.entity.item.EntityItem;
import common.item.ItemStack; import common.item.ItemStack;
import common.rng.Random; import common.rng.Random;
import common.tags.TagObject;
import common.util.BlockPos; import common.util.BlockPos;
import common.world.World; import common.world.World;
@ -55,7 +54,7 @@ public class InventoryHelper
if (stack.hasTagCompound()) if (stack.hasTagCompound())
{ {
entityitem.getEntityItem().setTagCompound((TagObject)stack.getTagCompound().copy()); entityitem.getEntityItem().setTagCompound(stack.getTagCompound().copy());
} }
float f3 = 0.05F; float f3 = 0.05F;

View file

@ -6,7 +6,7 @@ import common.item.Item;
import common.item.ItemArmor; import common.item.ItemArmor;
import common.item.ItemStack; import common.item.ItemStack;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList; import java.util.List;
public class InventoryPlayer implements IInventory public class InventoryPlayer implements IInventory
{ {
@ -216,7 +216,7 @@ public class InventoryPlayer implements IInventory
if (itemStackIn.hasTagCompound()) if (itemStackIn.hasTagCompound())
{ {
this.mainInventory[j].setTagCompound((TagObject)itemStackIn.getTagCompound().copy()); this.mainInventory[j].setTagCompound(itemStackIn.getTagCompound().copy());
} }
} }
@ -450,7 +450,7 @@ public class InventoryPlayer implements IInventory
* *
* @param nbtTagListIn List to append tags to * @param nbtTagListIn List to append tags to
*/ */
public TagObjectList writeToNBT(TagObjectList nbtTagListIn) public List<TagObject> writeToNBT(List<TagObject> nbtTagListIn)
{ {
for (int i = 0; i < this.mainInventory.length; ++i) for (int i = 0; i < this.mainInventory.length; ++i)
{ {
@ -482,7 +482,7 @@ public class InventoryPlayer implements IInventory
* *
* @param nbtTagListIn tagList to read from * @param nbtTagListIn tagList to read from
*/ */
public void readFromNBT(TagObjectList nbtTagListIn) public void readFromNBT(List<TagObject> nbtTagListIn)
{ {
this.mainInventory = new ItemStack[36]; this.mainInventory = new ItemStack[36];
this.armorInventory = new ItemStack[4]; this.armorInventory = new ItemStack[4];

View file

@ -1,10 +1,11 @@
package common.inventory; package common.inventory;
import common.collect.Lists;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
import common.init.Blocks; import common.init.Blocks;
import common.item.ItemStack; import common.item.ItemStack;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList; import java.util.List;
import common.util.BlockPos; import common.util.BlockPos;
public class InventoryWarpChest extends InventoryBasic public class InventoryWarpChest extends InventoryBasic
@ -21,7 +22,7 @@ public class InventoryWarpChest extends InventoryBasic
this.associatedChest = chestTileEntity; this.associatedChest = chestTileEntity;
} }
public void readTags(TagObjectList list) public void readTags(List<TagObject> list)
{ {
for (int i = 0; i < this.getSizeInventory(); ++i) for (int i = 0; i < this.getSizeInventory(); ++i)
{ {
@ -40,9 +41,9 @@ public class InventoryWarpChest extends InventoryBasic
} }
} }
public TagObjectList writeTags() public List<TagObject> writeTags()
{ {
TagObjectList list = new TagObjectList(); List<TagObject> list = Lists.newArrayList();
for (int i = 0; i < this.getSizeInventory(); ++i) for (int i = 0; i < this.getSizeInventory(); ++i)
{ {

View file

@ -11,7 +11,6 @@ import common.model.ItemMeshDefinition;
import common.model.Model; import common.model.Model;
import common.model.ModelProvider; import common.model.ModelProvider;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.tileentity.TileEntity; import common.tileentity.TileEntity;
import common.tileentity.TileEntityBanner; import common.tileentity.TileEntityBanner;
import common.util.BlockPos; import common.util.BlockPos;
@ -98,9 +97,9 @@ public class ItemBanner extends ItemBlock
{ {
TagObject nbttagcompound = stack.getSubCompound("BlockEntityTag", false); TagObject nbttagcompound = stack.getSubCompound("BlockEntityTag", false);
if (nbttagcompound != null && nbttagcompound.hasObjectList("Patterns")) if (nbttagcompound != null && nbttagcompound.hasList("Patterns"))
{ {
TagObjectList nbttaglist = nbttagcompound.getObjectList("Patterns"); List<TagObject> nbttaglist = nbttagcompound.getList("Patterns");
for (int i = 0; i < nbttaglist.size() && i < 6; ++i) for (int i = 0; i < nbttaglist.size() && i < 6; ++i)
{ {

View file

@ -119,9 +119,9 @@ public class ItemBlock extends Item
} }
TagObject nbttagcompound = new TagObject(); TagObject nbttagcompound = new TagObject();
TagObject nbttagcompound1 = (TagObject)nbttagcompound.copy(); TagObject nbttagcompound1 = nbttagcompound.copy();
tileentity.writeTags(nbttagcompound); tileentity.writeTags(nbttagcompound);
TagObject nbttagcompound2 = (TagObject)p_179224_3_.getTagCompound().get("BlockEntityTag"); TagObject nbttagcompound2 = p_179224_3_.getTagCompound().getObject("BlockEntityTag");
nbttagcompound.merge(nbttagcompound2); nbttagcompound.merge(nbttagcompound2);
nbttagcompound.setInt("x", stack.getX()); nbttagcompound.setInt("x", stack.getX());
nbttagcompound.setInt("y", stack.getY()); nbttagcompound.setInt("y", stack.getY());

View file

@ -2,6 +2,7 @@ package common.item;
import java.util.List; import java.util.List;
import common.collect.Lists;
import common.color.TextColor; import common.color.TextColor;
import common.enchantment.Enchantment; import common.enchantment.Enchantment;
import common.enchantment.EnchantmentHelper; import common.enchantment.EnchantmentHelper;
@ -11,7 +12,6 @@ import common.init.Items;
import common.model.ItemMeshDefinition; import common.model.ItemMeshDefinition;
import common.rng.Random; import common.rng.Random;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
public class ItemEnchantedBook extends Item public class ItemEnchantedBook extends Item
{ {
@ -48,10 +48,10 @@ public class ItemEnchantedBook extends Item
// return this.getEnchantments(stack).tagCount() > 0 ? ChatFormat.YELLOW : super.getColor(stack); // return this.getEnchantments(stack).tagCount() > 0 ? ChatFormat.YELLOW : super.getColor(stack);
// } // }
public TagObjectList getEnchantments(ItemStack stack) public List<TagObject> getEnchantments(ItemStack stack)
{ {
TagObject nbttagcompound = stack.getTagCompound(); TagObject nbttagcompound = stack.getTagCompound();
return nbttagcompound != null && nbttagcompound.hasObjectList("StoredEnchantments") ? nbttagcompound.getObjectList("StoredEnchantments") : new TagObjectList(); return nbttagcompound != null && nbttagcompound.hasList("StoredEnchantments") ? nbttagcompound.getList("StoredEnchantments") : Lists.newArrayList();
} }
/** /**
@ -60,7 +60,7 @@ public class ItemEnchantedBook extends Item
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip) public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip)
{ {
super.addInformation(stack, playerIn, tooltip); super.addInformation(stack, playerIn, tooltip);
TagObjectList nbttaglist = this.getEnchantments(stack); List<TagObject> nbttaglist = this.getEnchantments(stack);
if (nbttaglist != null) if (nbttaglist != null)
{ {
@ -82,7 +82,7 @@ public class ItemEnchantedBook extends Item
*/ */
public void addEnchantment(ItemStack stack, RngEnchantment enchantment) public void addEnchantment(ItemStack stack, RngEnchantment enchantment)
{ {
TagObjectList nbttaglist = this.getEnchantments(stack); List<TagObject> nbttaglist = this.getEnchantments(stack);
boolean flag = true; boolean flag = true;
for (int i = 0; i < nbttaglist.size(); ++i) for (int i = 0; i < nbttaglist.size(); ++i)
@ -114,7 +114,7 @@ public class ItemEnchantedBook extends Item
stack.setTagCompound(new TagObject()); stack.setTagCompound(new TagObject());
} }
stack.getTagCompound().setObjectList("StoredEnchantments", nbttaglist); stack.getTagCompound().setList("StoredEnchantments", nbttaglist);
} }
/** /**

View file

@ -6,7 +6,6 @@ import common.collect.Lists;
import common.entity.item.EntityFireworks; import common.entity.item.EntityFireworks;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.Facing; import common.util.Facing;
import common.world.World; import common.world.World;
@ -52,7 +51,7 @@ public class ItemFirework extends Item
tooltip.add("Flugdauer: " + nbttagcompound.getByte("Flight")); tooltip.add("Flugdauer: " + nbttagcompound.getByte("Flight"));
} }
TagObjectList nbttaglist = nbttagcompound.getObjectList("Explosions"); List<TagObject> nbttaglist = nbttagcompound.getList("Explosions");
if (nbttaglist != null && nbttaglist.size() > 0) if (nbttaglist != null && nbttaglist.size() > 0)
{ {

View file

@ -20,9 +20,7 @@ import common.entity.types.EntityLiving;
import common.init.BlockRegistry; import common.init.BlockRegistry;
import common.init.ItemRegistry; import common.init.ItemRegistry;
import common.rng.Random; import common.rng.Random;
import common.tags.Tag;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.Facing; import common.util.Facing;
import common.world.World; import common.world.World;
@ -121,7 +119,7 @@ public final class ItemStack
if (this.tag != null) if (this.tag != null)
{ {
itemstack.tag = (TagObject)this.tag.copy(); itemstack.tag = this.tag.copy();
} }
this.size -= amount; this.size -= amount;
@ -433,7 +431,7 @@ public final class ItemStack
if (this.tag != null) if (this.tag != null)
{ {
itemstack.tag = (TagObject)this.tag.copy(); itemstack.tag = this.tag.copy();
} }
return itemstack; return itemstack;
@ -580,9 +578,9 @@ public final class ItemStack
} }
} }
public TagObjectList getEnchantmentTagList() public List<TagObject> getEnchantmentTagList()
{ {
return this.tag == null ? null : this.tag.getObjectList("ench"); return this.tag == null ? null : this.tag.getList("ench");
} }
/** /**
@ -825,7 +823,7 @@ public final class ItemStack
{ {
// if ((i1 & 1) == 0) // if ((i1 & 1) == 0)
// { // {
TagObjectList nbttaglist = this.getEnchantmentTagList(); List<TagObject> nbttaglist = this.getEnchantmentTagList();
if (nbttaglist != null) if (nbttaglist != null)
{ {
@ -984,7 +982,7 @@ public final class ItemStack
if (this.hasTagCompound()) if (this.hasTagCompound())
{ {
list.add(TextColor.GRAY + String.format("NBT-Tags: %d", this.getTagCompound().getKeySet().size())); list.add(TextColor.GRAY + String.format("NBT-Tags: %d", this.getTagCompound().keySet().size()));
} }
// } // }
@ -1019,12 +1017,12 @@ public final class ItemStack
this.setTagCompound(new TagObject()); this.setTagCompound(new TagObject());
} }
if (!this.tag.hasObjectList("ench")) if (!this.tag.hasList("ench"))
{ {
this.tag.setObjectList("ench", new TagObjectList()); this.tag.setList("ench", Lists.newArrayList());
} }
TagObjectList nbttaglist = this.tag.getObjectList("ench"); List<TagObject> nbttaglist = this.tag.getList("ench");
TagObject nbttagcompound = new TagObject(); TagObject nbttagcompound = new TagObject();
nbttagcompound.setShort("id", (short)ench.effectId); nbttagcompound.setShort("id", (short)ench.effectId);
nbttagcompound.setShort("lvl", (short)(/* (byte) */ level)); nbttagcompound.setShort("lvl", (short)(/* (byte) */ level));
@ -1038,11 +1036,11 @@ public final class ItemStack
if(this.tag == null) { if(this.tag == null) {
return false; return false;
} }
if(!this.tag.hasObjectList("ench")) { if(!this.tag.hasList("ench")) {
return false; return false;
} }
TagObjectList oldEnch = this.tag.getObjectList("ench"); List<TagObject> oldEnch = this.tag.getList("ench");
TagObjectList newEnch = new TagObjectList(); List<TagObject> newEnch = Lists.newArrayList();
boolean changed = false; boolean changed = false;
TagObject tag; TagObject tag;
for(int z = 0; z < oldEnch.size(); z++) { for(int z = 0; z < oldEnch.size(); z++) {
@ -1064,7 +1062,7 @@ public final class ItemStack
} }
} }
else { else {
this.tag.setObjectList("ench", newEnch); this.tag.setList("ench", newEnch);
} }
return true; return true;
} }
@ -1076,7 +1074,7 @@ public final class ItemStack
if(this.tag == null) { if(this.tag == null) {
return false; return false;
} }
if(!this.tag.hasObjectList("ench")) { if(!this.tag.hasList("ench")) {
return false; return false;
} }
this.tag.remove("ench"); this.tag.remove("ench");
@ -1091,17 +1089,27 @@ public final class ItemStack
*/ */
public boolean isItemEnchanted() public boolean isItemEnchanted()
{ {
return this.tag != null && this.tag.hasObjectList("ench"); return this.tag != null && this.tag.hasList("ench");
} }
public void setTagInfo(String key, Tag value) public void setTagInfo(String key, TagObject value)
{ {
if (this.tag == null) if (this.tag == null)
{ {
this.setTagCompound(new TagObject()); this.setTagCompound(new TagObject());
} }
this.tag.set(key, value); this.tag.setObject(key, value);
}
public void setTagInfo(String key, List<TagObject> value)
{
if (this.tag == null)
{
this.setTagCompound(new TagObject());
}
this.tag.setList(key, value);
} }
// public boolean canEditBlocks() // public boolean canEditBlocks()

View file

@ -10,8 +10,6 @@ import common.net.buffer.ByteBufInputStream;
import common.net.buffer.ByteBufOutputStream; import common.net.buffer.ByteBufOutputStream;
import common.net.handler.codec.DecoderException; import common.net.handler.codec.DecoderException;
import common.net.handler.codec.EncoderException; import common.net.handler.codec.EncoderException;
import common.tags.SizeTracker;
import common.tags.TagLoader;
import common.tags.TagObject; import common.tags.TagObject;
import common.util.BlockPos; import common.util.BlockPos;
@ -98,7 +96,7 @@ public class PacketBuffer {
return; return;
} }
try { try {
TagLoader.write(tag, new ByteBufOutputStream(this.buf)); TagObject.write(tag, new ByteBufOutputStream(this.buf));
} }
catch(IOException e) { catch(IOException e) {
throw new EncoderException(e); throw new EncoderException(e);
@ -111,7 +109,7 @@ public class PacketBuffer {
if(b == 0) if(b == 0)
return null; return null;
this.buf.readerIndex(i); this.buf.readerIndex(i);
return TagLoader.read(new ByteBufInputStream(this.buf), new SizeTracker(2097152)); return TagObject.read(new ByteBufInputStream(this.buf), 2097152);
} }
public void writeItemStack(ItemStack stack) { public void writeItemStack(ItemStack stack) {

View file

@ -1,6 +1,6 @@
package common.tags; package common.tags;
public class SizeTracker { class SizeTracker {
public static final SizeTracker INFINITE = new SizeTracker(0) { public static final SizeTracker INFINITE = new SizeTracker(0) {
public void read(int bytes) { public void read(int bytes) {
} }

View file

@ -4,7 +4,7 @@ import java.io.DataInput;
import java.io.DataOutput; import java.io.DataOutput;
import java.io.IOException; import java.io.IOException;
public abstract class Tag { abstract class Tag {
abstract void write(DataOutput output) throws IOException; abstract void write(DataOutput output) throws IOException;
abstract void read(DataInput input, int depth, SizeTracker tracker) throws IOException; abstract void read(DataInput input, int depth, SizeTracker tracker) throws IOException;
public abstract String toString(); public abstract String toString();

View file

@ -1,6 +1,6 @@
package common.tags; package common.tags;
public class TagException extends Exception { class TagException extends IllegalArgumentException {
public TagException(String message) { public TagException(String message) {
super(message); super(message);
} }

View file

@ -17,8 +17,8 @@ class TagIntArray extends Tag {
void write(DataOutput output) throws IOException { void write(DataOutput output) throws IOException {
output.writeInt(this.data.length); output.writeInt(this.data.length);
for(int i = 0; i < this.data.length; ++i) { for(int z = 0; z < this.data.length; z++) {
output.writeInt(this.data[i]); output.writeInt(this.data[z]);
} }
} }
@ -38,8 +38,10 @@ class TagIntArray extends Tag {
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("["); StringBuilder sb = new StringBuilder("[");
for(int i : this.data) { for(int z = 0; z < this.data.length; z++) {
sb.append(i + ","); if(z != 0)
sb.append(',');
sb.append(this.data[z]);
} }
return sb.append("]").toString(); return sb.append("]").toString();
} }

View file

@ -1,29 +1,28 @@
package common.tags; package common.tags;
import java.util.ArrayList;
import java.util.Stack; import java.util.Stack;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import common.collect.Lists; import common.collect.Lists;
public class TagInterpreter class TagInterpreter
{ {
private static final Pattern PATTERN = Pattern.compile("\\[[-+\\d|,\\s]+\\]"); private static final Pattern PATTERN = Pattern.compile("\\[[-+\\d|,\\s]+\\]");
public static TagObject parseTag(String jsonString) throws TagException static TagObject parseTag(String tag) throws TagException
{ {
jsonString = jsonString.trim(); if (!tag.startsWith("{"))
if (!jsonString.startsWith("{"))
{ {
throw new TagException("Invalid tag encountered, expected \'{\' as first char."); throw new TagException("Invalid tag encountered, expected \'{\' as first char.");
} }
else if (func_150310_b(jsonString) != 1) else if (func_150310_b(tag) != 1)
{ {
throw new TagException("Encountered multiple top tags, only one expected"); throw new TagException("Encountered multiple top tags, only one expected");
} }
else else
{ {
return (TagObject)func_150316_a("tag", jsonString).parse(); return (TagObject)func_150316_a("tag", tag).parse();
} }
} }
@ -144,7 +143,7 @@ public class TagInterpreter
if (s.length() > 0) if (s.length() > 0)
{ {
boolean flag = true; boolean flag = true;
list.field_150492_b.add(func_179270_a(s, flag)); list.data.add(func_179270_a(s, flag));
} }
if (p_150316_1_.length() < s.length() + 1) if (p_150316_1_.length() < s.length() + 1)
@ -405,7 +404,7 @@ public class TagInterpreter
static class List extends TagInterpreter.Any static class List extends TagInterpreter.Any
{ {
protected java.util.List<TagInterpreter.Any> field_150492_b = Lists.<TagInterpreter.Any>newArrayList(); protected java.util.List<TagInterpreter.Any> data = Lists.<TagInterpreter.Any>newArrayList();
public List(String json) public List(String json)
{ {
@ -415,24 +414,31 @@ public class TagInterpreter
public Tag parse() throws TagException public Tag parse() throws TagException
{ {
TagList list = null; TagList list = null;
java.util.List<String> strs = null;
for (TagInterpreter.Any any : this.field_150492_b) for (TagInterpreter.Any any : this.data)
{ {
Tag tag = any.parse(); Tag tag = any.parse();
if(list == null) { if(tag.getType() == TagType.STRING) {
switch(tag.getType()) { if(list != null)
case STRING_LIST: throw new TagException("Cannot use mixed types for list: " + any.json);
list = new TagStringList(); if(strs == null)
case OBJECT_LIST: strs = new ArrayList<String>(this.data.size());
list = new TagObjectList(); strs.add(((TagString)tag).getString());
default: }
else if(tag.getType() == TagType.OBJECT) {
if(strs != null)
throw new TagException("Cannot use mixed types for list: " + any.json);
if(list == null)
list = new TagList(new ArrayList<TagObject>(this.data.size()));
list.getList().add(((TagObject)tag));
}
else {
throw new TagException("Type cannot be put in a list: " + any.json); throw new TagException("Type cannot be put in a list: " + any.json);
} }
} }
list.addElem(tag);
}
return list; return strs != null ? new TagStringArray(strs.toArray(new String[strs.size()])) : (list != null ? list : new TagList(Lists.newArrayList()));
} }
} }

61
common/src/main/java/common/tags/TagList.java Executable file → Normal file
View file

@ -6,11 +6,15 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import common.collect.Lists; class TagList extends Tag {
import common.log.Log; private List<TagObject> list;
abstract class TagList<K extends Tag> extends Tag { TagList() {
private List<K> list = Lists.newArrayList(); }
public TagList(List<TagObject> list) {
this.list = list;
}
void write(DataOutput output) throws IOException { void write(DataOutput output) throws IOException {
output.writeInt(this.list.size()); output.writeInt(this.list.size());
@ -25,18 +29,17 @@ abstract class TagList<K extends Tag> extends Tag {
throw new RuntimeException("Objekt ist zu komplex, die Tiefe ist größer als 512"); throw new RuntimeException("Objekt ist zu komplex, die Tiefe ist größer als 512");
int len = input.readInt(); int len = input.readInt();
tracker.read(4 * len); tracker.read(4 * len);
this.list = new ArrayList<K>(len); this.list = new ArrayList<TagObject>(len);
for(int z = 0; z < len; z++) { for(int z = 0; z < len; z++) {
K tag = (K)this.getElemType().createTag(); TagObject tag = new TagObject();
tag.read(input, depth + 1, tracker); tag.read(input, depth + 1, tracker);
this.list.add(tag); this.list.add(tag);
} }
} }
protected abstract TagType getType(); protected TagType getType() {
protected abstract TagType getElemType(); return TagType.LIST;
protected abstract TagList<K> createInstance(); }
protected abstract K getDefault();
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("["); StringBuilder sb = new StringBuilder("[");
@ -48,38 +51,10 @@ abstract class TagList<K extends Tag> extends Tag {
return sb.append(']').toString(); return sb.append(']').toString();
} }
protected void addElem(K tag) {
this.list.add(tag);
}
protected void set(int index, K tag) {
if(index < 0 || index >= this.list.size()) {
Log.IO.error("Index außerhalb des Bereiches um Tag in Tag-Liste zu setzen");
return;
}
this.list.set(index, tag);
}
public void remove(int index) {
this.list.remove(index);
}
public boolean isEmpty() {
return this.list.isEmpty();
}
protected K getElem(int index) {
return index >= 0 && index < this.list.size() ? this.list.get(index) : this.getDefault();
}
public int size() {
return this.list.size();
}
public Tag copy() { public Tag copy() {
TagList<K> list = this.createInstance(); TagList list = new TagList(new ArrayList<TagObject>(this.list.size()));
for(K tag : this.list) { for(TagObject tag : this.list) {
list.list.add((K)tag.copy()); list.list.add(tag.copy());
} }
return list; return list;
} }
@ -91,4 +66,8 @@ abstract class TagList<K extends Tag> extends Tag {
public int hashCode() { public int hashCode() {
return super.hashCode() ^ this.list.hashCode(); return super.hashCode() ^ this.list.hashCode();
} }
public List<TagObject> getList() {
return this.list;
}
} }

View file

@ -1,52 +0,0 @@
package common.tags;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* compressed data tree / CDT loader
* (ids 0..15)
*/
public class TagLoader {
public static TagObject readGZip(File file) throws IOException {
DataInputStream in = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file))));
TagObject tag;
try {
tag = read(in, SizeTracker.INFINITE);
}
finally {
in.close();
}
return tag;
}
public static void writeGZip(TagObject tag, File file) throws IOException {
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file))));
try {
write(tag, out);
}
finally {
out.close();
}
}
public static TagObject read(DataInput in, SizeTracker tracker) throws IOException {
TagObject tag = new TagObject();
tag.read(in, 0, tracker);
return tag;
}
public static void write(TagObject tag, DataOutput out) throws IOException {
tag.write(out);
}
}

View file

@ -1,15 +1,30 @@
package common.tags; package common.tags;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInput; import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput; import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import common.collect.Lists;
import common.collect.Maps; import common.collect.Maps;
import java.util.Set; import java.util.Set;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* compressed data tree / CDT
* (ids 0..15)
*/
public class TagObject extends Tag { public class TagObject extends Tag {
private Map<String, Tag> tags = Maps.<String, Tag>newHashMap(); private Map<String, Tag> tags = Maps.<String, Tag>newHashMap();
@ -41,7 +56,7 @@ public class TagObject extends Tag {
} }
} }
public Set<String> getKeySet() { public Set<String> keySet() {
return this.tags.keySet(); return this.tags.keySet();
} }
@ -49,7 +64,7 @@ public class TagObject extends Tag {
return TagType.OBJECT; return TagType.OBJECT;
} }
public void set(String key, Tag value) { void set(String key, Tag value) {
this.tags.put(key, value); this.tags.put(key, value);
} }
@ -57,12 +72,12 @@ public class TagObject extends Tag {
this.tags.put(key, value); this.tags.put(key, value);
} }
public void setStringList(String key, TagStringList value) { public void setStringArray(String key, String[] value) {
this.tags.put(key, value); this.tags.put(key, new TagStringArray(value));
} }
public void setObjectList(String key, TagObjectList value) { public void setList(String key, List<TagObject> value) {
this.tags.put(key, value); this.tags.put(key, new TagList(value));
} }
public void setBool(String key, boolean value) { public void setBool(String key, boolean value) {
@ -109,7 +124,7 @@ public class TagObject extends Tag {
this.tags.put(key, new TagIntArray(value)); this.tags.put(key, new TagIntArray(value));
} }
public Tag get(String key) { Tag get(String key) {
return this.tags.get(key); return this.tags.get(key);
} }
@ -166,12 +181,12 @@ public class TagObject extends Tag {
return this.has(key, TagType.OBJECT); return this.has(key, TagType.OBJECT);
} }
public boolean hasStringList(String key) { public boolean hasStringArray(String key) {
return this.has(key, TagType.STRING_LIST); return this.has(key, TagType.STRING_ARRAY);
} }
public boolean hasObjectList(String key) { public boolean hasList(String key) {
return this.has(key, TagType.OBJECT_LIST); return this.has(key, TagType.LIST);
} }
public boolean getBool(String key) { public boolean getBool(String key) {
@ -199,11 +214,11 @@ public class TagObject extends Tag {
} }
public float getFloat(String key) { public float getFloat(String key) {
return !this.has(key, TagType.FLOAT) ? 0.0F : ((TagFloat)this.tags.get(key)).getFloat(); return !this.has(key, TagType.FLOAT) ? 0.0f : ((TagFloat)this.tags.get(key)).getFloat();
} }
public double getDouble(String key) { public double getDouble(String key) {
return !this.has(key, TagType.DOUBLE) ? 0.0D : ((TagDouble)this.tags.get(key)).getDouble(); return !this.has(key, TagType.DOUBLE) ? 0.0 : ((TagDouble)this.tags.get(key)).getDouble();
} }
public String getString(String key) { public String getString(String key) {
@ -222,12 +237,12 @@ public class TagObject extends Tag {
return !this.has(key, TagType.OBJECT) ? new TagObject() : (TagObject)this.tags.get(key); return !this.has(key, TagType.OBJECT) ? new TagObject() : (TagObject)this.tags.get(key);
} }
public TagStringList getStringList(String key) { public String[] getStringArray(String key) {
return !this.has(key, TagType.STRING_LIST) ? new TagStringList() : (TagStringList)this.tags.get(key); return !this.has(key, TagType.STRING_ARRAY) ? new String[0] : ((TagStringArray)this.tags.get(key)).getStringArray();
} }
public TagObjectList getObjectList(String key) { public List<TagObject> getList(String key) {
return !this.has(key, TagType.OBJECT_LIST) ? new TagObjectList() : (TagObjectList)this.tags.get(key); return !this.has(key, TagType.LIST) ? Lists.newArrayList() : ((TagList)this.tags.get(key)).getList();
} }
public void remove(String key) { public void remove(String key) {
@ -248,7 +263,7 @@ public class TagObject extends Tag {
return this.tags.isEmpty(); return this.tags.isEmpty();
} }
public Tag copy() { public TagObject copy() {
TagObject tag = new TagObject(); TagObject tag = new TagObject();
for(String s : this.tags.keySet()) { for(String s : this.tags.keySet()) {
tag.set(s, this.tags.get(s).copy()); tag.set(s, this.tags.get(s).copy());
@ -286,4 +301,70 @@ public class TagObject extends Tag {
} }
} }
} }
public static void write(TagObject tag, DataOutput out) throws IOException {
tag.write(out);
}
public static TagObject read(DataInput in) throws IOException {
return read(in, SizeTracker.INFINITE);
}
public static TagObject read(DataInput in, int limit) throws IOException {
return read(in, new SizeTracker(limit));
}
private static TagObject read(DataInput in, SizeTracker tracker) throws IOException {
TagObject tag = new TagObject();
tag.read(in, 0, tracker);
return tag;
}
public static void writeGZip(TagObject tag, File file) throws IOException {
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file))));
try {
TagObject.write(tag, out);
}
finally {
out.close();
}
}
public static TagObject readGZip(File file) throws IOException {
DataInputStream in = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file))));
TagObject tag;
try {
tag = TagObject.read(in, SizeTracker.INFINITE);
}
finally {
in.close();
}
return tag;
}
public static boolean compare(TagObject tag1, TagObject tag2) {
return compareTags(tag1, tag2);
}
private static boolean compareTags(Tag tag1, Tag tag2) {
if(tag1 == tag2 || tag1 == null)
return true;
else if(tag2 == null || !tag1.getClass().equals(tag2.getClass()))
return false;
else if(tag1 instanceof TagObject) {
TagObject comp1 = (TagObject)tag1;
TagObject comp2 = (TagObject)tag2;
for(String key : comp1.keySet()) {
Tag tag = comp1.get(key);
if(!compareTags(tag, comp2.get(key)))
return false;
}
return true;
}
return tag1.equals(tag2);
}
public static TagObject parse(String tag) throws IllegalArgumentException {
return TagInterpreter.parseTag(tag.trim());
}
} }

View file

@ -1,27 +0,0 @@
package common.tags;
public class TagObjectList extends TagList<TagObject> {
protected TagType getType() {
return TagType.OBJECT_LIST;
}
protected TagType getElemType() {
return TagType.OBJECT;
}
protected TagList<TagObject> createInstance() {
return new TagObjectList();
}
protected TagObject getDefault() {
return new TagObject();
}
public TagObject get(int index) {
return this.getElem(index);
}
public void add(TagObject value) {
this.addElem(value);
}
}

View file

@ -0,0 +1,66 @@
package common.tags;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;
class TagStringArray extends Tag {
private String[] data;
TagStringArray() {
}
public TagStringArray(String[] data) {
this.data = data;
}
void write(DataOutput output) throws IOException {
output.writeInt(this.data.length);
for(int z = 0; z < this.data.length; z++) {
output.writeUTF(this.data[z]);
}
}
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
tracker.read(24);
int len = input.readInt();
this.data = new String[len];
for(int z = 0; z < len; z++) {
this.data[z] = input.readUTF();
tracker.read(2 * this.data[z].length());
}
}
protected TagType getType() {
return TagType.STRING_ARRAY;
}
public String toString() {
StringBuilder sb = new StringBuilder("[");
for(int z = 0; z < this.data.length; z++) {
if(z != 0)
sb.append(',');
sb.append("\"" + this.data[z].replace("\"", "\\\"") + "\"");
}
return sb.append("]").toString();
}
public Tag copy() {
String[] data = new String[this.data.length];
System.arraycopy(this.data, 0, data, 0, this.data.length);
return new TagStringArray(data);
}
public boolean equals(Object other) {
return super.equals(other) && Arrays.equals(this.data, ((TagStringArray)other).data);
}
public int hashCode() {
return super.hashCode() ^ Arrays.hashCode(this.data);
}
public String[] getStringArray() {
return this.data;
}
}

View file

@ -1,27 +0,0 @@
package common.tags;
public class TagStringList extends TagList<TagString> {
protected TagType getType() {
return TagType.STRING_LIST;
}
protected TagType getElemType() {
return TagType.STRING;
}
protected TagList<TagString> createInstance() {
return new TagStringList();
}
protected TagString getDefault() {
return new TagString("");
}
public String get(int index) {
return this.getElem(index).getString();
}
public void add(String value) {
this.addElem(new TagString(value));
}
}

View file

@ -4,80 +4,80 @@ import java.io.DataInput;
import java.io.DataOutput; import java.io.DataOutput;
import java.io.IOException; import java.io.IOException;
public enum TagType { enum TagType {
NULL { // 0 NULL { // 0
public Tag createTag() { protected Tag createTag() {
return new TagNull(); return new TagNull();
} }
}, },
OBJECT { // 1 OBJECT { // 1
public Tag createTag() { protected Tag createTag() {
return new TagObject(); return new TagObject();
} }
}, },
BOOLEAN { // 2 BOOLEAN { // 2
public Tag createTag() { protected Tag createTag() {
return new TagBool(); return new TagBool();
} }
}, },
BYTE { // 3 BYTE { // 3
public Tag createTag() { protected Tag createTag() {
return new TagByte(); return new TagByte();
} }
}, },
SHORT { // 4 SHORT { // 4
public Tag createTag() { protected Tag createTag() {
return new TagShort(); return new TagShort();
} }
}, },
CHAR { // 5 CHAR { // 5
public Tag createTag() { protected Tag createTag() {
return new TagChar(); return new TagChar();
} }
}, },
INT { // 6 INT { // 6
public Tag createTag() { protected Tag createTag() {
return new TagInt(); return new TagInt();
} }
}, },
LONG { // 7 LONG { // 7
public Tag createTag() { protected Tag createTag() {
return new TagLong(); return new TagLong();
} }
}, },
FLOAT { // 8 FLOAT { // 8
public Tag createTag() { protected Tag createTag() {
return new TagFloat(); return new TagFloat();
} }
}, },
DOUBLE { // 9 DOUBLE { // 9
public Tag createTag() { protected Tag createTag() {
return new TagDouble(); return new TagDouble();
} }
}, },
STRING { // 10 STRING { // 10
public Tag createTag() { protected Tag createTag() {
return new TagString(); return new TagString();
} }
}, },
OBJECT_LIST { // 11 LIST { // 11
public Tag createTag() { protected Tag createTag() {
return new TagObjectList(); return new TagList();
} }
}, },
BYTE_ARRAY { // 12 BYTE_ARRAY { // 12
public Tag createTag() { protected Tag createTag() {
return new TagByteArray(); return new TagByteArray();
} }
}, },
INT_ARRAY { // 13 INT_ARRAY { // 13
public Tag createTag() { protected Tag createTag() {
return new TagIntArray(); return new TagIntArray();
} }
}, },
STRING_LIST { // 14 STRING_ARRAY { // 14
public Tag createTag() { protected Tag createTag() {
return new TagStringList(); return new TagStringArray();
} }
}; };
@ -117,7 +117,7 @@ public enum TagType {
this.id = (byte)this.ordinal(); this.id = (byte)this.ordinal();
} }
public abstract Tag createTag(); protected abstract Tag createTag();
public byte getId() { public byte getId() {
return this.id; return this.id;

View file

@ -11,14 +11,13 @@ import common.item.ItemStack;
import common.network.Packet; import common.network.Packet;
import common.packet.SPacketUpdateTileEntity; import common.packet.SPacketUpdateTileEntity;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
public class TileEntityBanner extends TileEntity public class TileEntityBanner extends TileEntity
{ {
private int baseColor; private int baseColor;
/** A list of all the banner patterns. */ /** A list of all the banner patterns. */
private TagObjectList patterns; private List<TagObject> patterns;
private boolean field_175119_g; private boolean field_175119_g;
private List<TileEntityBanner.EnumBannerPattern> patternList; private List<TileEntityBanner.EnumBannerPattern> patternList;
private List<DyeColor> colorList; private List<DyeColor> colorList;
@ -36,9 +35,12 @@ public class TileEntityBanner extends TileEntity
{ {
TagObject nbttagcompound = stack.getTagCompound().getObject("BlockEntityTag"); TagObject nbttagcompound = stack.getTagCompound().getObject("BlockEntityTag");
if (nbttagcompound.hasObjectList("Patterns")) if (nbttagcompound.hasList("Patterns"))
{ {
this.patterns = (TagObjectList)nbttagcompound.getObjectList("Patterns").copy(); this.patterns = Lists.newArrayList();
for(TagObject pattern : nbttagcompound.getList("Patterns")) {
this.patterns.add(pattern.copy());
}
} }
if (nbttagcompound.hasInt("Base")) if (nbttagcompound.hasInt("Base"))
@ -67,13 +69,13 @@ public class TileEntityBanner extends TileEntity
setBaseColorAndPatterns(compound, this.baseColor, this.patterns); setBaseColorAndPatterns(compound, this.baseColor, this.patterns);
} }
public static void setBaseColorAndPatterns(TagObject compound, int baseColorIn, TagObjectList patternsIn) public static void setBaseColorAndPatterns(TagObject compound, int baseColorIn, List<TagObject> patternsIn)
{ {
compound.setInt("Base", baseColorIn); compound.setInt("Base", baseColorIn);
if (patternsIn != null) if (patternsIn != null)
{ {
compound.setObjectList("Patterns", patternsIn); compound.setList("Patterns", patternsIn);
} }
} }
@ -81,7 +83,7 @@ public class TileEntityBanner extends TileEntity
{ {
super.readTags(compound); super.readTags(compound);
this.baseColor = compound.getInt("Base"); this.baseColor = compound.getInt("Base");
this.patterns = compound.getObjectList("Patterns"); this.patterns = compound.getList("Patterns");
this.patternList = null; this.patternList = null;
this.colorList = null; this.colorList = null;
this.patternResourceLocation = null; this.patternResourceLocation = null;
@ -114,7 +116,7 @@ public class TileEntityBanner extends TileEntity
public static int getPatterns(ItemStack stack) public static int getPatterns(ItemStack stack)
{ {
TagObject nbttagcompound = stack.getSubCompound("BlockEntityTag", false); TagObject nbttagcompound = stack.getSubCompound("BlockEntityTag", false);
return nbttagcompound != null && nbttagcompound.hasObjectList("Patterns") ? nbttagcompound.getObjectList("Patterns").size() : 0; return nbttagcompound != null && nbttagcompound.hasList("Patterns") ? nbttagcompound.getList("Patterns").size() : 0;
} }
public List<TileEntityBanner.EnumBannerPattern> getPatternList() public List<TileEntityBanner.EnumBannerPattern> getPatternList()
@ -123,7 +125,7 @@ public class TileEntityBanner extends TileEntity
return this.patternList; return this.patternList;
} }
public TagObjectList getPatterns() public List<TagObject> getPatterns()
{ {
return this.patterns; return this.patterns;
} }
@ -191,9 +193,9 @@ public class TileEntityBanner extends TileEntity
{ {
TagObject nbttagcompound = stack.getSubCompound("BlockEntityTag", false); TagObject nbttagcompound = stack.getSubCompound("BlockEntityTag", false);
if (nbttagcompound != null && nbttagcompound.hasObjectList("Patterns")) if (nbttagcompound != null && nbttagcompound.hasList("Patterns"))
{ {
TagObjectList nbttaglist = nbttagcompound.getObjectList("Patterns"); List<TagObject> nbttaglist = nbttagcompound.getList("Patterns");
if (nbttaglist.size() > 0) if (nbttaglist.size() > 0)
{ {

View file

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import common.block.tech.BlockBrewingStand; import common.block.tech.BlockBrewingStand;
import common.collect.Lists;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
import common.init.Items; import common.init.Items;
import common.inventory.Container; import common.inventory.Container;
@ -16,7 +17,6 @@ import common.item.ItemStack;
import common.potion.PotionEffect; import common.potion.PotionEffect;
import common.potion.PotionHelper; import common.potion.PotionHelper;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.util.Facing; import common.util.Facing;
import common.world.State; import common.world.State;
@ -230,7 +230,7 @@ public class TileEntityBrewingStand extends TileEntityLockable implements ITicka
public void readTags(TagObject compound) public void readTags(TagObject compound)
{ {
super.readTags(compound); super.readTags(compound);
TagObjectList nbttaglist = compound.getObjectList("Items"); List<TagObject> nbttaglist = compound.getList("Items");
this.brewingItemStacks = new ItemStack[this.getSizeInventory()]; this.brewingItemStacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.size(); ++i) for (int i = 0; i < nbttaglist.size(); ++i)
@ -256,7 +256,7 @@ public class TileEntityBrewingStand extends TileEntityLockable implements ITicka
{ {
super.writeTags(compound); super.writeTags(compound);
compound.setShort("BrewTime", (short)this.brewTime); compound.setShort("BrewTime", (short)this.brewTime);
TagObjectList nbttaglist = new TagObjectList(); List<TagObject> nbttaglist = Lists.newArrayList();
for (int i = 0; i < this.brewingItemStacks.length; ++i) for (int i = 0; i < this.brewingItemStacks.length; ++i)
{ {
@ -269,7 +269,7 @@ public class TileEntityBrewingStand extends TileEntityLockable implements ITicka
} }
} }
compound.setObjectList("Items", nbttaglist); compound.setList("Items", nbttaglist);
if (this.hasCustomName()) if (this.hasCustomName())
{ {

View file

@ -2,6 +2,7 @@ package common.tileentity;
import common.block.Block; import common.block.Block;
import common.block.tech.BlockChest; import common.block.tech.BlockChest;
import common.collect.Lists;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
import common.init.SoundEvent; import common.init.SoundEvent;
import common.inventory.Container; import common.inventory.Container;
@ -11,7 +12,7 @@ import common.inventory.InventoryLargeChest;
import common.inventory.InventoryPlayer; import common.inventory.InventoryPlayer;
import common.item.ItemStack; import common.item.ItemStack;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList; import java.util.List;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.BoundingBox; import common.util.BoundingBox;
import common.util.Facing; import common.util.Facing;
@ -164,7 +165,7 @@ public class TileEntityChest extends TileEntityLockable implements ITickable, II
public void readTags(TagObject compound) public void readTags(TagObject compound)
{ {
super.readTags(compound); super.readTags(compound);
TagObjectList nbttaglist = compound.getObjectList("Items"); List<TagObject> nbttaglist = compound.getList("Items");
this.chestContents = new ItemStack[this.getSizeInventory()]; this.chestContents = new ItemStack[this.getSizeInventory()];
if (compound.hasString("CustomName")) if (compound.hasString("CustomName"))
@ -187,7 +188,7 @@ public class TileEntityChest extends TileEntityLockable implements ITickable, II
public void writeTags(TagObject compound) public void writeTags(TagObject compound)
{ {
super.writeTags(compound); super.writeTags(compound);
TagObjectList nbttaglist = new TagObjectList(); List<TagObject> nbttaglist = Lists.newArrayList();
for (int i = 0; i < this.chestContents.length; ++i) for (int i = 0; i < this.chestContents.length; ++i)
{ {
@ -200,7 +201,7 @@ public class TileEntityChest extends TileEntityLockable implements ITickable, II
} }
} }
compound.setObjectList("Items", nbttaglist); compound.setList("Items", nbttaglist);
if (this.hasCustomName()) if (this.hasCustomName())
{ {

View file

@ -1,5 +1,6 @@
package common.tileentity; package common.tileentity;
import common.collect.Lists;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
import common.inventory.Container; import common.inventory.Container;
import common.inventory.ContainerDispenser; import common.inventory.ContainerDispenser;
@ -8,7 +9,7 @@ import common.inventory.InventoryPlayer;
import common.item.ItemStack; import common.item.ItemStack;
import common.rng.Random; import common.rng.Random;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList; import java.util.List;
public class TileEntityDispenser extends TileEntityLockable implements IInventory public class TileEntityDispenser extends TileEntityLockable implements IInventory
{ {
@ -155,7 +156,7 @@ public class TileEntityDispenser extends TileEntityLockable implements IInventor
public void readTags(TagObject compound) public void readTags(TagObject compound)
{ {
super.readTags(compound); super.readTags(compound);
TagObjectList nbttaglist = compound.getObjectList("Items"); List<TagObject> nbttaglist = compound.getList("Items");
this.stacks = new ItemStack[this.getSizeInventory()]; this.stacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.size(); ++i) for (int i = 0; i < nbttaglist.size(); ++i)
@ -178,7 +179,7 @@ public class TileEntityDispenser extends TileEntityLockable implements IInventor
public void writeTags(TagObject compound) public void writeTags(TagObject compound)
{ {
super.writeTags(compound); super.writeTags(compound);
TagObjectList nbttaglist = new TagObjectList(); List<TagObject> nbttaglist = Lists.newArrayList();
for (int i = 0; i < this.stacks.length; ++i) for (int i = 0; i < this.stacks.length; ++i)
{ {
@ -191,7 +192,7 @@ public class TileEntityDispenser extends TileEntityLockable implements IInventor
} }
} }
compound.setObjectList("Items", nbttaglist); compound.setList("Items", nbttaglist);
if (this.hasCustomName()) if (this.hasCustomName())
{ {

View file

@ -5,6 +5,7 @@ import common.block.Material;
import common.block.artificial.BlockSlab; import common.block.artificial.BlockSlab;
import common.block.foliage.BlockSapling; import common.block.foliage.BlockSapling;
import common.block.tech.BlockFurnace; import common.block.tech.BlockFurnace;
import common.collect.Lists;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
import common.init.Blocks; import common.init.Blocks;
import common.init.Items; import common.init.Items;
@ -24,7 +25,7 @@ import common.item.ItemStack;
import common.item.ItemSword; import common.item.ItemSword;
import common.item.ItemTool; import common.item.ItemTool;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList; import java.util.List;
import common.util.ExtMath; import common.util.ExtMath;
import common.util.Facing; import common.util.Facing;
@ -159,7 +160,7 @@ public class TileEntityFurnace extends TileEntityLockable implements ITickable,
public void readTags(TagObject compound) public void readTags(TagObject compound)
{ {
super.readTags(compound); super.readTags(compound);
TagObjectList nbttaglist = compound.getObjectList("Items"); List<TagObject> nbttaglist = compound.getList("Items");
this.furnaceItemStacks = new ItemStack[this.getSizeInventory()]; this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.size(); ++i) for (int i = 0; i < nbttaglist.size(); ++i)
@ -190,7 +191,7 @@ public class TileEntityFurnace extends TileEntityLockable implements ITickable,
compound.setShort("BurnTime", (short)this.furnaceBurnTime); compound.setShort("BurnTime", (short)this.furnaceBurnTime);
compound.setShort("CookTime", (short)this.cookTime); compound.setShort("CookTime", (short)this.cookTime);
compound.setShort("CookTimeTotal", (short)this.totalCookTime); compound.setShort("CookTimeTotal", (short)this.totalCookTime);
TagObjectList nbttaglist = new TagObjectList(); List<TagObject> nbttaglist = Lists.newArrayList();
for (int i = 0; i < this.furnaceItemStacks.length; ++i) for (int i = 0; i < this.furnaceItemStacks.length; ++i)
{ {
@ -203,7 +204,7 @@ public class TileEntityFurnace extends TileEntityLockable implements ITickable,
} }
} }
compound.setObjectList("Items", nbttaglist); compound.setList("Items", nbttaglist);
if (this.hasCustomName()) if (this.hasCustomName())
{ {

View file

@ -6,6 +6,7 @@ import java.util.function.Predicate;
import common.block.Block; import common.block.Block;
import common.block.tech.BlockChest; import common.block.tech.BlockChest;
import common.block.tech.BlockHopper; import common.block.tech.BlockHopper;
import common.collect.Lists;
import common.entity.Entity; import common.entity.Entity;
import common.entity.item.EntityItem; import common.entity.item.EntityItem;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
@ -17,7 +18,6 @@ import common.inventory.ISidedInventory;
import common.inventory.InventoryPlayer; import common.inventory.InventoryPlayer;
import common.item.ItemStack; import common.item.ItemStack;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.BoundingBox; import common.util.BoundingBox;
import common.util.ExtMath; import common.util.ExtMath;
@ -33,7 +33,7 @@ public class TileEntityHopper extends TileEntityLockable implements IHopper, ITi
public void readTags(TagObject compound) public void readTags(TagObject compound)
{ {
super.readTags(compound); super.readTags(compound);
TagObjectList nbttaglist = compound.getObjectList("Items"); List<TagObject> nbttaglist = compound.getList("Items");
this.inventory = new ItemStack[this.getSizeInventory()]; this.inventory = new ItemStack[this.getSizeInventory()];
if (compound.hasString("CustomName")) if (compound.hasString("CustomName"))
@ -58,7 +58,7 @@ public class TileEntityHopper extends TileEntityLockable implements IHopper, ITi
public void writeTags(TagObject compound) public void writeTags(TagObject compound)
{ {
super.writeTags(compound); super.writeTags(compound);
TagObjectList nbttaglist = new TagObjectList(); List<TagObject> nbttaglist = Lists.newArrayList();
for (int i = 0; i < this.inventory.length; ++i) for (int i = 0; i < this.inventory.length; ++i)
{ {
@ -71,7 +71,7 @@ public class TileEntityHopper extends TileEntityLockable implements IHopper, ITi
} }
} }
compound.setObjectList("Items", nbttaglist); compound.setList("Items", nbttaglist);
compound.setInt("TransferCooldown", this.transferCooldown); compound.setInt("TransferCooldown", this.transferCooldown);
if (this.hasCustomName()) if (this.hasCustomName())

View file

@ -1,5 +1,6 @@
package common.tileentity; package common.tileentity;
import common.collect.Lists;
import common.color.TextColor; import common.color.TextColor;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
import common.inventory.Container; import common.inventory.Container;
@ -10,7 +11,7 @@ import common.network.Packet;
import common.packet.SPacketUpdateTileEntity; import common.packet.SPacketUpdateTileEntity;
import common.rng.Random; import common.rng.Random;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList; import java.util.List;
import common.util.ExtMath; import common.util.ExtMath;
public abstract class TileEntityMachine extends TileEntityLockable implements IHopper, ITickable { public abstract class TileEntityMachine extends TileEntityLockable implements IHopper, ITickable {
@ -82,7 +83,7 @@ public abstract class TileEntityMachine extends TileEntityLockable implements IH
public void readTags(TagObject compound) { public void readTags(TagObject compound) {
super.readTags(compound); super.readTags(compound);
TagObjectList nbttaglist = compound.getObjectList("Items"); List<TagObject> nbttaglist = compound.getList("Items");
this.clear(); this.clear();
for(int i = 0; i < nbttaglist.size(); ++i) { for(int i = 0; i < nbttaglist.size(); ++i) {
TagObject nbttagcompound = nbttaglist.get(i); TagObject nbttagcompound = nbttaglist.get(i);
@ -93,7 +94,7 @@ public abstract class TileEntityMachine extends TileEntityLockable implements IH
} }
} }
nbttaglist = compound.getObjectList("Resources"); nbttaglist = compound.getList("Resources");
for(MachineResource res : this.resources) { for(MachineResource res : this.resources) {
res.reset(); res.reset();
} }
@ -109,7 +110,7 @@ public abstract class TileEntityMachine extends TileEntityLockable implements IH
public void writeTags(TagObject compound) { public void writeTags(TagObject compound) {
super.writeTags(compound); super.writeTags(compound);
TagObjectList nbttaglist = new TagObjectList(); List<TagObject> nbttaglist = Lists.newArrayList();
for(int i = 0; i < this.inventory.length; ++i) { for(int i = 0; i < this.inventory.length; ++i) {
if(this.inventory[i] != null) { if(this.inventory[i] != null) {
TagObject nbttagcompound = new TagObject(); TagObject nbttagcompound = new TagObject();
@ -118,15 +119,15 @@ public abstract class TileEntityMachine extends TileEntityLockable implements IH
nbttaglist.add(nbttagcompound); nbttaglist.add(nbttagcompound);
} }
} }
compound.setObjectList("Items", nbttaglist); compound.setList("Items", nbttaglist);
nbttaglist = new TagObjectList(); nbttaglist = Lists.newArrayList();
for(int z = 0; z < this.resources.length; z++) { for(int z = 0; z < this.resources.length; z++) {
TagObject res = new TagObject(); TagObject res = new TagObject();
this.resources[z].writeToNbt(res); this.resources[z].writeToNbt(res);
nbttaglist.add(res); nbttaglist.add(res);
} }
compound.setObjectList("Resources", nbttaglist); compound.setList("Resources", nbttaglist);
// compound.setBoolean("Creative", this.isCreative); // compound.setBoolean("Creative", this.isCreative);
compound.setInt("Temperature", this.temperature); compound.setInt("Temperature", this.temperature);

View file

@ -2,10 +2,10 @@ package common.village;
import java.util.ArrayList; import java.util.ArrayList;
import common.collect.Lists;
import common.item.ItemStack; import common.item.ItemStack;
import common.tags.Tag;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList; import java.util.List;
public class MerchantRecipeList extends ArrayList<MerchantRecipe> { public class MerchantRecipeList extends ArrayList<MerchantRecipe> {
public MerchantRecipe canUse(ItemStack stack1, ItemStack stack2, int index) { public MerchantRecipe canUse(ItemStack stack1, ItemStack stack2, int index) {
@ -33,36 +33,18 @@ public class MerchantRecipeList extends ArrayList<MerchantRecipe> {
private static boolean areItemsSimilar(ItemStack stack1, ItemStack stack2) { private static boolean areItemsSimilar(ItemStack stack1, ItemStack stack2) {
return ItemStack.areItemsEqual(stack1, stack2) return ItemStack.areItemsEqual(stack1, stack2)
&& (!stack2.hasTagCompound() || stack1.hasTagCompound() && compareTags(stack2.getTagCompound(), stack1.getTagCompound())); && (!stack2.hasTagCompound() || stack1.hasTagCompound() && TagObject.compare(stack2.getTagCompound(), stack1.getTagCompound()));
} }
private static boolean compareTags(Tag tag1, Tag tag2) { public void fromTags(List<TagObject> list) {
if(tag1 == tag2 || tag1 == null)
return true;
else if(tag2 == null || !tag1.getClass().equals(tag2.getClass()))
return false;
else if(tag1 instanceof TagObject) {
TagObject comp1 = (TagObject)tag1;
TagObject comp2 = (TagObject)tag2;
for(String key : comp1.getKeySet()) {
Tag tag = comp1.get(key);
if(!compareTags(tag, comp2.get(key)))
return false;
}
return true;
}
return tag1.equals(tag2);
}
public void fromTags(TagObjectList list) {
this.clear(); this.clear();
for(int z = 0; z < list.size(); z++) { for(int z = 0; z < list.size(); z++) {
this.add(new MerchantRecipe(list.get(z))); this.add(new MerchantRecipe(list.get(z)));
} }
} }
public TagObjectList toTags() { public List<TagObject> toTags() {
TagObjectList list = new TagObjectList(); List<TagObject> list = Lists.newArrayList();
for(int z = 0; z < this.size(); z++) { for(int z = 0; z < this.size(); z++) {
list.add(this.get(z).toTags()); list.add(this.get(z).toTags());
} }

View file

@ -8,7 +8,6 @@ import common.block.Material;
import common.block.artificial.BlockDoor; import common.block.artificial.BlockDoor;
import common.collect.Lists; import common.collect.Lists;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.util.BlockPos; import common.util.BlockPos;
import common.world.AWorldServer; import common.world.AWorldServer;
@ -214,7 +213,7 @@ public class Village
this.radius = tag.getInt("Radius"); this.radius = tag.getInt("Radius");
this.center = new BlockPos(tag.getInt("CX"), tag.getInt("CY"), tag.getInt("CZ")); this.center = new BlockPos(tag.getInt("CX"), tag.getInt("CY"), tag.getInt("CZ"));
this.doorRange = new BlockPos(tag.getInt("ACX"), tag.getInt("ACY"), tag.getInt("ACZ")); this.doorRange = new BlockPos(tag.getInt("ACX"), tag.getInt("ACY"), tag.getInt("ACZ"));
TagObjectList doors = tag.getObjectList("Doors"); List<TagObject> doors = tag.getList("Doors");
for (int i = 0; i < doors.size(); ++i) for (int i = 0; i < doors.size(); ++i)
{ {
@ -233,7 +232,7 @@ public class Village
tag.setInt("ACX", this.doorRange.getX()); tag.setInt("ACX", this.doorRange.getX());
tag.setInt("ACY", this.doorRange.getY()); tag.setInt("ACY", this.doorRange.getY());
tag.setInt("ACZ", this.doorRange.getZ()); tag.setInt("ACZ", this.doorRange.getZ());
TagObjectList doors = new TagObjectList(); List<TagObject> doors = Lists.newArrayList();
for (VillageDoorInfo info : this.doors) for (VillageDoorInfo info : this.doors)
{ {
@ -247,6 +246,6 @@ public class Village
doors.add(door); doors.add(door);
} }
tag.setObjectList("Doors", doors); tag.setList("Doors", doors);
} }
} }

View file

@ -80,7 +80,6 @@ import common.packet.SPacketSkin;
import common.packet.SPacketTimeUpdate; import common.packet.SPacketTimeUpdate;
import common.packet.SPacketWorld; import common.packet.SPacketWorld;
import common.potion.PotionEffect; import common.potion.PotionEffect;
import common.tags.TagLoader;
import common.tags.TagObject; import common.tags.TagObject;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.EncryptUtil; import common.util.EncryptUtil;
@ -186,7 +185,7 @@ public final class Server implements IThreadListener {
File nfile = new File("server.cdt.tmp"); File nfile = new File("server.cdt.tmp");
File lfile = new File("server.cdt"); File lfile = new File("server.cdt");
try { try {
TagLoader.writeGZip(data, nfile); TagObject.writeGZip(data, nfile);
if(lfile.exists()) if(lfile.exists())
lfile.delete(); lfile.delete();
nfile.renameTo(lfile); nfile.renameTo(lfile);
@ -204,9 +203,9 @@ public final class Server implements IThreadListener {
file = new File("server.cdt.tmp"); file = new File("server.cdt.tmp");
if(file.exists()) { if(file.exists()) {
try { try {
TagObject tag = TagLoader.readGZip(file); TagObject tag = TagObject.readGZip(file);
TagObject cfg = tag.getObject("Config"); TagObject cfg = tag.getObject("Config");
for(String key : cfg.getKeySet()) { for(String key : cfg.keySet()) {
Config.set(key, cfg.getString(key), false); Config.set(key, cfg.getString(key), false);
} }
UniverseRegistry.fromTags(tag.getObject("Universe")); UniverseRegistry.fromTags(tag.getObject("Universe"));
@ -297,7 +296,7 @@ public final class Server implements IThreadListener {
File dat = new File(new File("players"), user + ".cdt"); File dat = new File(new File("players"), user + ".cdt");
if(dat.exists() && dat.isFile()) { if(dat.exists() && dat.isFile()) {
tag = TagLoader.readGZip(dat); tag = TagObject.readGZip(dat);
} }
} }
catch(Exception e) { catch(Exception e) {
@ -312,7 +311,7 @@ public final class Server implements IThreadListener {
try { try {
File tmp = new File(new File("players"), user + ".cdt.tmp"); File tmp = new File(new File("players"), user + ".cdt.tmp");
File dat = new File(new File("players"), user + ".cdt"); File dat = new File(new File("players"), user + ".cdt");
TagLoader.writeGZip(tag, tmp); TagObject.writeGZip(tag, tmp);
if(dat.exists()) { if(dat.exists()) {
dat.delete(); dat.delete();
} }
@ -938,7 +937,7 @@ public final class Server implements IThreadListener {
File dat = new File(new File("players"), user + ".cdt"); File dat = new File(new File("players"), user + ".cdt");
if(dat.exists() && dat.isFile()) { if(dat.exists() && dat.isFile()) {
tag = TagLoader.readGZip(dat); tag = TagObject.readGZip(dat);
} }
} }
catch(Exception e) { catch(Exception e) {
@ -963,7 +962,7 @@ public final class Server implements IThreadListener {
conn.writeTags(tag); conn.writeTags(tag);
File tmp = new File(new File("players"), conn.getUser() + ".cdt.tmp"); File tmp = new File(new File("players"), conn.getUser() + ".cdt.tmp");
File dat = new File(new File("players"), conn.getUser() + ".cdt"); File dat = new File(new File("players"), conn.getUser() + ".cdt");
TagLoader.writeGZip(tag, tmp); TagObject.writeGZip(tag, tmp);
if(dat.exists()) { if(dat.exists()) {
dat.delete(); dat.delete();
} }

View file

@ -1,7 +1,5 @@
package server.command; package server.command;
import common.tags.TagException;
import common.tags.TagInterpreter;
import common.tags.TagObject; import common.tags.TagObject;
public class TagParser extends DefaultingParser { public class TagParser extends DefaultingParser {
@ -12,9 +10,9 @@ public class TagParser extends DefaultingParser {
public TagObject parse(CommandEnvironment env, String input) { public TagObject parse(CommandEnvironment env, String input) {
TagObject value; TagObject value;
try { try {
value = TagInterpreter.parseTag(input); value = TagObject.parse(input);
} }
catch(TagException e) { catch(IllegalArgumentException e) {
throw new RunException(e, "Ungültiger Tag '%s'", input); throw new RunException(e, "Ungültiger Tag '%s'", input);
} }
return value; return value;

View file

@ -102,7 +102,6 @@ import common.packet.SPacketMessage.Type;
import common.potion.Potion; import common.potion.Potion;
import common.potion.PotionEffect; import common.potion.PotionEffect;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.tileentity.IInteractionObject; import common.tileentity.IInteractionObject;
import common.tileentity.ILockableContainer; import common.tileentity.ILockableContainer;
import common.tileentity.TileEntity; import common.tileentity.TileEntity;
@ -621,7 +620,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer
if(tag.hasString("password")) if(tag.hasString("password"))
this.password = tag.getString("password"); this.password = tag.getString("password");
this.selected = tag.getInt("selected"); this.selected = tag.getInt("selected");
TagObjectList list = tag.getObjectList("characters"); List<TagObject> list = tag.getList("characters");
for(int z = 0; z < list.size(); z++) { for(int z = 0; z < list.size(); z++) {
this.characters.add(list.get(z)); this.characters.add(list.get(z));
} }
@ -636,11 +635,11 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer
tag.setString("password", this.password); tag.setString("password", this.password);
if(!this.characters.isEmpty()) { if(!this.characters.isEmpty()) {
tag.setInt("selected", this.selected); tag.setInt("selected", this.selected);
TagObjectList list = new TagObjectList(); List<TagObject> list = Lists.newArrayList();
for(TagObject etag : this.characters) { for(TagObject etag : this.characters) {
list.add(etag); list.add(etag);
} }
tag.setObjectList("characters", list); tag.setList("characters", list);
} }
} }

View file

@ -8,7 +8,6 @@ import common.block.Material;
import common.block.artificial.BlockDoor; import common.block.artificial.BlockDoor;
import common.collect.Lists; import common.collect.Lists;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.Facing; import common.util.Facing;
import common.village.Village; import common.village.Village;
@ -26,7 +25,7 @@ public class VillageCollection
public VillageCollection(TagObject tag) { public VillageCollection(TagObject tag) {
if(tag != null) { if(tag != null) {
this.tickCounter = tag.getInt("Tick"); this.tickCounter = tag.getInt("Tick");
TagObjectList list = tag.getObjectList("Villages"); List<TagObject> list = tag.getList("Villages");
for (int i = 0; i < list.size(); ++i) for (int i = 0; i < list.size(); ++i)
{ {
@ -252,7 +251,7 @@ public class VillageCollection
{ {
TagObject tag = new TagObject(); TagObject tag = new TagObject();
tag.setInt("Tick", this.tickCounter); tag.setInt("Tick", this.tickCounter);
TagObjectList list = new TagObjectList(); List<TagObject> list = Lists.newArrayList();
for (Village village : this.villageList) for (Village village : this.villageList)
{ {
@ -261,7 +260,7 @@ public class VillageCollection
list.add(obj); list.add(obj);
} }
tag.setObjectList("Villages", list); tag.setList("Villages", list);
this.dirty = false; this.dirty = false;
return tag; return tag;
} }

View file

@ -68,9 +68,7 @@ import common.init.TileRegistry;
import common.init.UniverseRegistry; import common.init.UniverseRegistry;
import common.log.Log; import common.log.Log;
import common.rng.Random; import common.rng.Random;
import common.tags.TagLoader;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.tileentity.TileEntity; import common.tileentity.TileEntity;
import common.tileentity.TileEntityBanner; import common.tileentity.TileEntityBanner;
import common.tileentity.TileEntityBeacon; import common.tileentity.TileEntityBeacon;
@ -1009,7 +1007,7 @@ public abstract class Converter {
byte[] olddata = tag.getByteArray("Data"); byte[] olddata = tag.getByteArray("Data");
byte[] oldsky = tag.getByteArray("SkyLight"); byte[] oldsky = tag.getByteArray("SkyLight");
byte[] oldlight = tag.getByteArray("BlockLight"); byte[] oldlight = tag.getByteArray("BlockLight");
TagObjectList sections = new TagObjectList(); List<TagObject> sections = Lists.newArrayList();
for(int n = 0; n < 8; ++n) { for(int n = 0; n < 8; ++n) {
boolean empty = true; boolean empty = true;
for(int x = 0; x < 16 && empty; ++x) { for(int x = 0; x < 16 && empty; ++x) {
@ -1050,7 +1048,7 @@ public abstract class Converter {
sections.add(section); sections.add(section);
} }
} }
ntag.setObjectList("Sections", sections); ntag.setList("Sections", sections);
byte[] biomes = new byte[256]; byte[] biomes = new byte[256];
Arrays.fill(biomes, (byte)(Biome.DEF_BIOME.id & 255)); Arrays.fill(biomes, (byte)(Biome.DEF_BIOME.id & 255));
ntag.setByteArray("Biomes", biomes); ntag.setByteArray("Biomes", biomes);
@ -1063,7 +1061,7 @@ public abstract class Converter {
ntag.setBool("LightPopulated", tag.getByte("LightPopulated") != 0); ntag.setBool("LightPopulated", tag.getByte("LightPopulated") != 0);
NbtTag[] ents = tag.getTagList("Entities"); NbtTag[] ents = tag.getTagList("Entities");
TagObjectList entities = new TagObjectList(); List<TagObject> entities = Lists.newArrayList();
for(NbtTag ent : ents) { for(NbtTag ent : ents) {
TagObject nent = new TagObject(); TagObject nent = new TagObject();
String mapped = ENTITY_MAP.get(trimColon(ent.getString("id"))); String mapped = ENTITY_MAP.get(trimColon(ent.getString("id")));
@ -1088,10 +1086,10 @@ public abstract class Converter {
entities.add(nent); entities.add(nent);
} }
} }
ntag.setObjectList("Entities", entities); ntag.setList("Entities", entities);
ents = tag.getTagList("TileEntities"); ents = tag.getTagList("TileEntities");
entities = new TagObjectList(); entities = Lists.newArrayList();
for(NbtTag ent : ents) { for(NbtTag ent : ents) {
TagObject nent = new TagObject(); TagObject nent = new TagObject();
String mapped = TILE_MAP.get(trimColon(ent.getString("id"))); String mapped = TILE_MAP.get(trimColon(ent.getString("id")));
@ -1104,10 +1102,10 @@ public abstract class Converter {
entities.add(nent); entities.add(nent);
} }
} }
ntag.setObjectList("TileEntities", entities); ntag.setList("TileEntities", entities);
NbtTag[] sects = tag.getTagList("Sections"); NbtTag[] sects = tag.getTagList("Sections");
entities = new TagObjectList(); entities = Lists.newArrayList();
for(NbtTag sect : sects) { for(NbtTag sect : sects) {
TagObject nsect = new TagObject(); TagObject nsect = new TagObject();
nsect.setInt("Y", sect.getByte("Y")); nsect.setInt("Y", sect.getByte("Y"));
@ -1151,7 +1149,7 @@ public abstract class Converter {
nsect.setByteArray("Add", adddata.getData()); nsect.setByteArray("Add", adddata.getData());
entities.add(nsect); entities.add(nsect);
} }
ntag.setObjectList("Sections", entities); ntag.setList("Sections", entities);
return ntag; return ntag;
} }
@ -1318,7 +1316,7 @@ public abstract class Converter {
Log.IO.info("Speichere neue data.cdt ..."); Log.IO.info("Speichere neue data.cdt ...");
File dataFile = new File(new File(new File("chunk"), "terra"), "data.cdt"); File dataFile = new File(new File(new File("chunk"), "terra"), "data.cdt");
try { try {
TagLoader.writeGZip(dataTag, dataFile); TagObject.writeGZip(dataTag, dataFile);
} }
catch(Exception e) { catch(Exception e) {
Log.IO.error(e, "Konnte Weltdaten nicht speichern"); Log.IO.error(e, "Konnte Weltdaten nicht speichern");

View file

@ -25,10 +25,7 @@ import common.entity.Entity;
import common.init.BlockRegistry; import common.init.BlockRegistry;
import common.init.EntityRegistry; import common.init.EntityRegistry;
import common.log.Log; import common.log.Log;
import common.tags.SizeTracker;
import common.tags.TagLoader;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.tileentity.TileEntity; import common.tileentity.TileEntity;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.NextTickListEntry; import common.util.NextTickListEntry;
@ -276,7 +273,7 @@ public class Region {
public void writeTag(int x, int z, TagObject tag) throws IOException { public void writeTag(int x, int z, TagObject tag) throws IOException {
ChunkBuffer buf = new ChunkBuffer(); ChunkBuffer buf = new ChunkBuffer();
DataOutputStream out = new DataOutputStream(new DeflaterOutputStream(buf)); DataOutputStream out = new DataOutputStream(new DeflaterOutputStream(buf));
TagLoader.write(tag, out); TagObject.write(tag, out);
out.close(); out.close();
this.write(x, z, buf.getData(), buf.size()); this.write(x, z, buf.getData(), buf.size());
} }
@ -348,13 +345,13 @@ public class Region {
byte[] data = getRegionFile(dir, x >> 3, z >> 3).read(x & 7, z & 7); byte[] data = getRegionFile(dir, x >> 3, z >> 3).read(x & 7, z & 7);
if(data == null) if(data == null)
return null; return null;
return TagLoader.read(new DataInputStream(new BufferedInputStream(new InflaterInputStream(new ByteArrayInputStream(data)))), SizeTracker.INFINITE); return TagObject.read(new DataInputStream(new BufferedInputStream(new InflaterInputStream(new ByteArrayInputStream(data)))));
} }
public static /* synchronized */ void writeChunk(File dir, int x, int z, TagObject tag) throws IOException { public static /* synchronized */ void writeChunk(File dir, int x, int z, TagObject tag) throws IOException {
ChunkBuffer buf = new ChunkBuffer(); ChunkBuffer buf = new ChunkBuffer();
DataOutputStream out = new DataOutputStream(new DeflaterOutputStream(buf)); DataOutputStream out = new DataOutputStream(new DeflaterOutputStream(buf));
TagLoader.write(tag, out); TagObject.write(tag, out);
out.close(); out.close();
getRegionFile(dir, x >> 3, z >> 3).write(x & 7, z & 7, buf.getData(), buf.size()); getRegionFile(dir, x >> 3, z >> 3).write(x & 7, z & 7, buf.getData(), buf.size());
// getRegionFile(dir, x >> 3, z >> 3).writeTag(x & 7, z & 7, tag); // getRegionFile(dir, x >> 3, z >> 3).writeTag(x & 7, z & 7, tag);
@ -366,7 +363,7 @@ public class Region {
// return null; // return null;
// } // }
// tag = tag.getCompoundTag("Level"); // tag = tag.getCompoundTag("Level");
if(!tag.hasObjectList("Sections")) { if(!tag.hasList("Sections")) {
Log.IO.warn("Chunk-Datei bei " + x + "," + z + " hat keine Block-Daten, überspringe"); Log.IO.warn("Chunk-Datei bei " + x + "," + z + " hat keine Block-Daten, überspringe");
return null; return null;
} }
@ -375,7 +372,7 @@ public class Region {
chunk.setTerrainPopulated(tag.getBool("TerrainPopulated")); chunk.setTerrainPopulated(tag.getBool("TerrainPopulated"));
chunk.setLightPopulated(tag.getBool("LightPopulated")); chunk.setLightPopulated(tag.getBool("LightPopulated"));
chunk.setInhabited(tag.getLong("InhabitedTime")); chunk.setInhabited(tag.getLong("InhabitedTime"));
TagObjectList sects = tag.getObjectList("Sections"); List<TagObject> sects = tag.getList("Sections");
BlockArray[] sections = new BlockArray[sects.size()]; BlockArray[] sections = new BlockArray[sects.size()];
boolean light = !world.dimension.hasNoLight(); boolean light = !world.dimension.hasNoLight();
@ -413,7 +410,7 @@ public class Region {
chunk.setBiomes(tag.getByteArray("Biomes")); chunk.setBiomes(tag.getByteArray("Biomes"));
} }
TagObjectList entities = tag.getObjectList("Entities"); List<TagObject> entities = tag.getList("Entities");
if(entities != null) { if(entities != null) {
for(int n = 0; n < entities.size(); ++n) { for(int n = 0; n < entities.size(); ++n) {
@ -439,7 +436,7 @@ public class Region {
} }
} }
TagObjectList tiles = tag.getObjectList("TileEntities"); List<TagObject> tiles = tag.getList("TileEntities");
if(tiles != null) { if(tiles != null) {
for(int n = 0; n < tiles.size(); ++n) { for(int n = 0; n < tiles.size(); ++n) {
@ -452,8 +449,8 @@ public class Region {
} }
} }
if(tag.hasObjectList("TileTicks")) { if(tag.hasList("TileTicks")) {
TagObjectList ticks = tag.getObjectList("TileTicks"); List<TagObject> ticks = tag.getList("TileTicks");
if(ticks != null) { if(ticks != null) {
int invalid = 0; int invalid = 0;
@ -495,7 +492,7 @@ public class Region {
tag.setBool("LightPopulated", chunk.isLightPopulated()); tag.setBool("LightPopulated", chunk.isLightPopulated());
tag.setLong("InhabitedTime", chunk.getInhabited()); tag.setLong("InhabitedTime", chunk.getInhabited());
Set<BlockArray> sections = chunk.getStorage(); Set<BlockArray> sections = chunk.getStorage();
TagObjectList sects = new TagObjectList(); List<TagObject> sects = Lists.newArrayList();
boolean light = !world.dimension.hasNoLight(); boolean light = !world.dimension.hasNoLight();
for(BlockArray storage : sections) { for(BlockArray storage : sections) {
@ -544,10 +541,10 @@ public class Region {
} }
} }
tag.setObjectList("Sections", sects); tag.setList("Sections", sects);
tag.setByteArray("Biomes", chunk.getBiomes()); tag.setByteArray("Biomes", chunk.getBiomes());
chunk.setHasEntities(false); chunk.setHasEntities(false);
TagObjectList entities = new TagObjectList(); List<TagObject> entities = Lists.newArrayList();
for(int n = 0; n < chunk.getEntities().length; ++n) { for(int n = 0; n < chunk.getEntities().length; ++n) {
for(Entity entity : chunk.getEntities()[n]) { for(Entity entity : chunk.getEntities()[n]) {
@ -560,8 +557,8 @@ public class Region {
} }
} }
tag.setObjectList("Entities", entities); tag.setList("Entities", entities);
TagObjectList tiles = new TagObjectList(); List<TagObject> tiles = Lists.newArrayList();
for(TileEntity tileentity : chunk.getTiles().values()) { for(TileEntity tileentity : chunk.getTiles().values()) {
TagObject tile = new TagObject(); TagObject tile = new TagObject();
@ -569,12 +566,12 @@ public class Region {
tiles.add(tile); tiles.add(tile);
} }
tag.setObjectList("TileEntities", tiles); tag.setList("TileEntities", tiles);
List<NextTickListEntry> tics = world.getPendingBlockUpdates(chunk); List<NextTickListEntry> tics = world.getPendingBlockUpdates(chunk);
if(tics != null) { if(tics != null) {
long time = world.getTime(); long time = world.getTime();
TagObjectList ticks = new TagObjectList(); List<TagObject> ticks = Lists.newArrayList();
for(NextTickListEntry tic : tics) { for(NextTickListEntry tic : tics) {
TagObject tick = new TagObject(); TagObject tick = new TagObject();
@ -588,7 +585,7 @@ public class Region {
ticks.add(tick); ticks.add(tick);
} }
tag.setObjectList("TileTicks", ticks); tag.setList("TileTicks", ticks);
} }
return tag; return tag;

View file

@ -56,9 +56,7 @@ import common.packet.SPacketBlockChange;
import common.packet.SPacketMultiBlockChange; import common.packet.SPacketMultiBlockChange;
import common.rng.Random; import common.rng.Random;
import common.rng.WeightedList; import common.rng.WeightedList;
import common.tags.TagLoader;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList;
import common.tileentity.TileEntity; import common.tileentity.TileEntity;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.BoundingBox; import common.util.BoundingBox;
@ -301,7 +299,7 @@ public final class WorldServer extends AWorldServer {
try { try {
File dat = new File(this.chunkDir, "data.cdt"); File dat = new File(this.chunkDir, "data.cdt");
if(dat.exists() && dat.isFile()) if(dat.exists() && dat.isFile())
tag = TagLoader.readGZip(dat); tag = TagObject.readGZip(dat);
} }
catch(Exception e) { catch(Exception e) {
Log.IO.error(e, "Konnte Weltdaten nicht laden"); Log.IO.error(e, "Konnte Weltdaten nicht laden");
@ -443,13 +441,13 @@ public final class WorldServer extends AWorldServer {
try { try {
File dat = new File(this.chunkDir, "loaders.cdt"); File dat = new File(this.chunkDir, "loaders.cdt");
if(dat.exists() && dat.isFile()) if(dat.exists() && dat.isFile())
tag = TagLoader.readGZip(dat); tag = TagObject.readGZip(dat);
} }
catch(Exception e) { catch(Exception e) {
Log.IO.error(e, "Konnte Ladeliste nicht laden"); Log.IO.error(e, "Konnte Ladeliste nicht laden");
} }
if(tag != null && tag.hasObjectList("Loaders")) { if(tag != null && tag.hasList("Loaders")) {
TagObjectList list = tag.getObjectList("Loaders"); List<TagObject> list = tag.getList("Loaders");
for(int z = 0; z < list.size(); z++) { for(int z = 0; z < list.size(); z++) {
TagObject pos = list.get(z); TagObject pos = list.get(z);
this.addLoader(new BlockPos(pos.getInt("X"), pos.getInt("Y"), pos.getInt("Z"))); this.addLoader(new BlockPos(pos.getInt("X"), pos.getInt("Y"), pos.getInt("Z")));
@ -461,7 +459,7 @@ public final class WorldServer extends AWorldServer {
try { try {
File dat = new File(this.chunkDir, "villages.cdt"); File dat = new File(this.chunkDir, "villages.cdt");
if(dat.exists() && dat.isFile()) if(dat.exists() && dat.isFile())
tag = TagLoader.readGZip(dat); tag = TagObject.readGZip(dat);
} }
catch(Exception e) { catch(Exception e) {
Log.IO.error(e, "Konnte Dorfliste nicht laden"); Log.IO.error(e, "Konnte Dorfliste nicht laden");
@ -914,12 +912,12 @@ public final class WorldServer extends AWorldServer {
try { try {
File dat = new File(new File(new File("chunk"), dim.getDimensionName()), "loaders.cdt"); File dat = new File(new File(new File("chunk"), dim.getDimensionName()), "loaders.cdt");
if(dat.exists() && dat.isFile()) if(dat.exists() && dat.isFile())
tag = TagLoader.readGZip(dat); tag = TagObject.readGZip(dat);
} }
catch(Exception e) { catch(Exception e) {
return false; return false;
} }
return tag != null && tag.hasObjectList("Loaders") && !tag.getObjectList("Loaders").isEmpty(); return tag != null && tag.hasList("Loaders") && !tag.getList("Loaders").isEmpty();
} }
public static void loadWarps(Dimension dim, Map<String, Position> warps) { public static void loadWarps(Dimension dim, Map<String, Position> warps) {
@ -927,14 +925,14 @@ public final class WorldServer extends AWorldServer {
try { try {
File dat = new File(new File(new File("chunk"), dim.getDimensionName()), "warps.cdt"); File dat = new File(new File(new File("chunk"), dim.getDimensionName()), "warps.cdt");
if(dat.exists() && dat.isFile()) if(dat.exists() && dat.isFile())
tag = TagLoader.readGZip(dat); tag = TagObject.readGZip(dat);
} }
catch(Exception e) { catch(Exception e) {
Log.IO.error(e, "Konnte Warpliste nicht laden"); Log.IO.error(e, "Konnte Warpliste nicht laden");
return; return;
} }
if(tag != null && tag.hasObjectList("Warps")) { if(tag != null && tag.hasList("Warps")) {
TagObjectList list = tag.getObjectList("Warps"); List<TagObject> list = tag.getList("Warps");
for(int z = 0; z < list.size(); z++) { for(int z = 0; z < list.size(); z++) {
TagObject pos = list.get(z); TagObject pos = list.get(z);
warps.put(pos.getString("Name"), new Position(pos.getDouble("X"), pos.getDouble("Y"), pos.getDouble("Z"), warps.put(pos.getString("Name"), new Position(pos.getDouble("X"), pos.getDouble("Y"), pos.getDouble("Z"),
@ -944,13 +942,13 @@ public final class WorldServer extends AWorldServer {
} }
public static void saveWarps(Map<String, Position> warps) { public static void saveWarps(Map<String, Position> warps) {
Map<Integer, TagObjectList> map = Maps.newHashMap(); Map<Integer, List<TagObject>> map = Maps.newHashMap();
for(Entry<String, Position> pos : warps.entrySet()) { for(Entry<String, Position> pos : warps.entrySet()) {
Dimension dim = UniverseRegistry.getDimension(pos.getValue().dim); Dimension dim = UniverseRegistry.getDimension(pos.getValue().dim);
if(dim != null) { if(dim != null) {
TagObjectList list = map.get(pos.getValue().dim); List<TagObject> list = map.get(pos.getValue().dim);
if(list == null) if(list == null)
map.put(pos.getValue().dim, list = new TagObjectList()); map.put(pos.getValue().dim, list = Lists.newArrayList());
TagObject warp = new TagObject(); TagObject warp = new TagObject();
warp.setString("Name", pos.getKey()); warp.setString("Name", pos.getKey());
warp.setDouble("X", pos.getValue().x); warp.setDouble("X", pos.getValue().x);
@ -962,16 +960,16 @@ public final class WorldServer extends AWorldServer {
} }
} }
for(Dimension dim : UniverseRegistry.getDimensions()) { for(Dimension dim : UniverseRegistry.getDimensions()) {
TagObjectList list = map.get(dim.getDimensionId()); List<TagObject> list = map.get(dim.getDimensionId());
File file = new File(new File(new File("chunk"), dim.getDimensionName()), "warps.cdt"); File file = new File(new File(new File("chunk"), dim.getDimensionName()), "warps.cdt");
if(list == null) { if(list == null) {
file.delete(); file.delete();
} }
else { else {
TagObject tag = new TagObject(); TagObject tag = new TagObject();
tag.setObjectList("Warps", list); tag.setList("Warps", list);
try { try {
TagLoader.writeGZip(tag, file); TagObject.writeGZip(tag, file);
} }
catch(Exception e) { catch(Exception e) {
Log.IO.error(e, "Konnte Warpliste nicht speichern"); Log.IO.error(e, "Konnte Warpliste nicht speichern");
@ -1013,7 +1011,7 @@ public final class WorldServer extends AWorldServer {
if(this.loadersModified) { if(this.loadersModified) {
this.loadersModified = false; this.loadersModified = false;
TagObject loaders = new TagObject(); TagObject loaders = new TagObject();
TagObjectList list = new TagObjectList(); List<TagObject> list = Lists.newArrayList();
for(BlockPos pos : this.loaderList) { for(BlockPos pos : this.loaderList) {
TagObject loader = new TagObject(); TagObject loader = new TagObject();
loader.setInt("X", pos.getX()); loader.setInt("X", pos.getX());
@ -1021,14 +1019,14 @@ public final class WorldServer extends AWorldServer {
loader.setInt("Z", pos.getZ()); loader.setInt("Z", pos.getZ());
list.add(loader); list.add(loader);
} }
loaders.setObjectList("Loaders", list); loaders.setList("Loaders", list);
File file = new File(this.chunkDir, "loaders.cdt"); File file = new File(this.chunkDir, "loaders.cdt");
if(list.isEmpty()) { if(list.isEmpty()) {
file.delete(); file.delete();
} }
else { else {
try { try {
TagLoader.writeGZip(loaders, file); TagObject.writeGZip(loaders, file);
} }
catch(Exception e) { catch(Exception e) {
Log.IO.error(e, "Konnte Ladeliste nicht speichern"); Log.IO.error(e, "Konnte Ladeliste nicht speichern");
@ -1049,7 +1047,7 @@ public final class WorldServer extends AWorldServer {
// ... // ...
File file = new File(this.chunkDir, "data.cdt"); File file = new File(this.chunkDir, "data.cdt");
try { try {
TagLoader.writeGZip(data, file); TagObject.writeGZip(data, file);
} }
catch(Exception e) { catch(Exception e) {
Log.IO.error(e, "Konnte Weltdaten nicht speichern"); Log.IO.error(e, "Konnte Weltdaten nicht speichern");
@ -1066,7 +1064,7 @@ public final class WorldServer extends AWorldServer {
TagObject tag = this.villageStorage.toTags(); TagObject tag = this.villageStorage.toTags();
File dat = new File(this.chunkDir, "villages.cdt"); File dat = new File(this.chunkDir, "villages.cdt");
try { try {
TagLoader.writeGZip(tag, dat); TagObject.writeGZip(tag, dat);
} }
catch(Exception e) { catch(Exception e) {
Log.IO.error(e, "Konnte Dorfliste nicht speichern"); Log.IO.error(e, "Konnte Dorfliste nicht speichern");
@ -2459,7 +2457,7 @@ public final class WorldServer extends AWorldServer {
try { try {
File file = this.getSaveFile(id); File file = this.getSaveFile(id);
if(file.exists()) { if(file.exists()) {
data = new WorldSavedData(id, TagLoader.readGZip(file)); data = new WorldSavedData(id, TagObject.readGZip(file));
} }
} }
catch(Exception e) { catch(Exception e) {
@ -2483,7 +2481,7 @@ public final class WorldServer extends AWorldServer {
private void saveData(WorldSavedData data) { private void saveData(WorldSavedData data) {
try { try {
File file = this.getSaveFile(data.id); File file = this.getSaveFile(data.id);
TagLoader.writeGZip(data.tag, file); TagObject.writeGZip(data.tag, file);
} }
catch(Exception e) { catch(Exception e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -5,7 +5,6 @@ import java.util.Map;
import common.collect.Maps; import common.collect.Maps;
import common.rng.Random; import common.rng.Random;
import common.tags.Tag;
import common.tags.TagObject; import common.tags.TagObject;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.ChunkPos; import common.util.ChunkPos;
@ -205,13 +204,11 @@ public abstract class MapGenStructure extends MapGenBase
{ {
TagObject tag = this.structureData.tag; TagObject tag = this.structureData.tag;
for (String s : tag.getKeySet()) for (String s : tag.keySet())
{ {
Tag sub = tag.get(s); if (tag.hasObject(s))
if (sub instanceof TagObject)
{ {
TagObject start = (TagObject)sub; TagObject start = tag.getObject(s);
if (start.hasInt("ChunkX") && start.hasInt("ChunkZ")) if (start.hasInt("ChunkX") && start.hasInt("ChunkZ"))
{ {

View file

@ -3,9 +3,10 @@ package server.worldgen.structure;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import common.collect.Lists;
import common.rng.Random; import common.rng.Random;
import common.tags.TagObject; import common.tags.TagObject;
import common.tags.TagObjectList; import java.util.List;
import common.util.ChunkPos; import common.util.ChunkPos;
import server.world.WorldServer; import server.world.WorldServer;
@ -74,14 +75,14 @@ public abstract class StructureStart
tag.setInt("ChunkX", chunkX); tag.setInt("ChunkX", chunkX);
tag.setInt("ChunkZ", chunkZ); tag.setInt("ChunkZ", chunkZ);
tag.setIntArray("BB", this.boundingBox.toIntArray()); tag.setIntArray("BB", this.boundingBox.toIntArray());
TagObjectList list = new TagObjectList(); List<TagObject> list = Lists.newArrayList();
for (StructureComponent comp : this.components) for (StructureComponent comp : this.components)
{ {
list.add(comp.writeBase()); list.add(comp.writeBase());
} }
tag.setObjectList("Children", list); tag.setList("Children", list);
this.writeTags(tag); this.writeTags(tag);
return tag; return tag;
} }
@ -100,7 +101,7 @@ public abstract class StructureStart
this.boundingBox = new StructureBoundingBox(tag.getIntArray("BB")); this.boundingBox = new StructureBoundingBox(tag.getIntArray("BB"));
} }
TagObjectList list = tag.getObjectList("Children"); List<TagObject> list = tag.getList("Children");
for (int i = 0; i < list.size(); ++i) for (int i = 0; i < list.size(); ++i)
{ {