remove arbitary item data

This commit is contained in:
Sen 2025-07-07 00:38:38 +02:00
parent 97b708bb23
commit 4e94a660ff
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
18 changed files with 210 additions and 392 deletions

View file

@ -181,7 +181,7 @@ public class EntityAIControlledByPlayer extends EntityAIBase
if (itemstack.size == 0)
{
ItemStack itemstack1 = new ItemStack(Items.fishing_rod);
itemstack1.setTag(itemstack.getTag());
itemstack1.copyData(itemstack);
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = itemstack1;
}
}

View file

@ -3,6 +3,7 @@ package common.enchantment;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import common.collect.Lists;
@ -16,7 +17,6 @@ import common.item.ItemStack;
import common.item.material.ItemEnchantedBook;
import common.rng.Random;
import common.rng.WeightedList;
import common.tags.TagObject;
public class EnchantmentHelper
{
@ -34,7 +34,7 @@ public class EnchantmentHelper
}
else
{
List<TagObject> list = stack.getEnchantmentTagList();
Integer list = stack.getEnchantment(enchID);
if (list == null)
{
@ -42,18 +42,7 @@ public class EnchantmentHelper
}
else
{
for (int i = 0; i < list.size(); ++i)
{
Enchantment j = Enchantment.getEnchantment(list.get(i).getString("id"));
if (j == enchID)
{
int k = list.get(i).getShort("lvl");
return k;
}
}
return 0;
return list.intValue();
}
}
}
@ -65,17 +54,13 @@ public class EnchantmentHelper
map.put(book.getEnchantment(), book.getLevel());
return map;
}
List<TagObject> list = stack.getEnchantmentTagList();
Set<Entry<Enchantment, Integer>> list = stack.getEnchantments();
if (list != null)
{
for (int i = 0; i < list.size(); ++i)
for (Entry<Enchantment, Integer> enc : list)
{
Enchantment j = Enchantment.getEnchantment(list.get(i).getString("id"));
if(j != null) {
int k = list.get(i).getShort("lvl");
map.put(j, k);
}
map.put(enc.getKey(), enc.getValue());
}
}
@ -88,34 +73,9 @@ public class EnchantmentHelper
{
Entry<Enchantment, Integer> entry = new Random().pick(Lists.newArrayList(enchMap.entrySet()));
stack.setItem(ItemEnchantedBook.getEnchantedBook(entry.getKey(), entry.getValue()));
if(stack.hasTag())
stack.getTag().remove("ench");
}
else {
List<TagObject> list = Lists.newArrayList();
Iterator<Enchantment> iterator = enchMap.keySet().iterator();
while (iterator.hasNext())
{
Enchantment enchantment = iterator.next();
TagObject tag = new TagObject();
tag.setString("id", enchantment.getName());
tag.setShort("lvl", (short)enchMap.get(enchantment).intValue());
list.add(tag);
}
if (list.size() > 0)
{
if (!(stack.getItem() instanceof ItemEnchantedBook))
{
stack.setTagInfo("ench", list);
}
}
else if (stack.hasTag())
{
stack.getTag().remove("ench");
}
stack.setEnchantments(enchMap);
}
}
@ -153,19 +113,13 @@ public class EnchantmentHelper
{
if (stack != null)
{
List<TagObject> list = stack.getEnchantmentTagList();
Set<Entry<Enchantment, Integer>> list = stack.getEnchantments();
if (list != null)
{
for (int i = 0; i < list.size(); ++i)
for (Entry<Enchantment, Integer> enc : list)
{
String j = list.get(i).getString("id");
int k = list.get(i).getShort("lvl");
if (Enchantment.getEnchantment(j) != null)
{
modifier.calculateModifier(Enchantment.getEnchantment(j), k);
}
modifier.calculateModifier(enc.getKey(), enc.getValue());
}
}
}

View file

@ -223,11 +223,7 @@ public class EntityItem extends Entity
{
return false;
}
else if (itemstack1.hasTag() ^ itemstack.hasTag())
{
return false;
}
else if (itemstack1.hasTag() && !itemstack1.getTag().equals(itemstack.getTag()))
else if (!itemstack1.dataEquals(itemstack))
{
return false;
}

View file

@ -1368,11 +1368,11 @@ public abstract class EntityNPC extends EntityLiving
flag = itemsword.getDamageVsEntity() > itemsword1.getDamageVsEntity();
}
else {
flag = stack.getItemDamage() > old.getItemDamage() || stack.hasTag() && !old.hasTag();
flag = stack.getItemDamage() > old.getItemDamage() || stack.isItemEnchanted() && !old.isItemEnchanted();
}
}
else if(stack.getItem() instanceof ItemBow && old.getItem() instanceof ItemBow) {
flag = stack.hasTag() && !old.hasTag();
flag = stack.isItemEnchanted() && !old.isItemEnchanted();
}
else if(stack.getItem() instanceof ItemGunBase && !(old.getItem() instanceof ItemBow)) {
flag = true;
@ -1395,7 +1395,7 @@ public abstract class EntityNPC extends EntityLiving
flag = itemarmor.damageReduceAmount > itemarmor1.damageReduceAmount;
}
else {
flag = stack.getItemDamage() > old.getItemDamage() || stack.hasTag() && !old.hasTag();
flag = stack.getItemDamage() > old.getItemDamage() || stack.isItemEnchanted() && !old.isItemEnchanted();
}
}
else {

View file

@ -787,7 +787,6 @@ public abstract class CraftingRegistry
/** Is the ItemStack that you get when craft the recipe. */
private final ItemStack recipeOutput;
private boolean copyIngredientTag;
public ShapedRecipes(int width, int height, ItemStack[] p_i1917_3_, ItemStack output)
{
@ -893,22 +892,7 @@ public abstract class CraftingRegistry
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
ItemStack itemstack = this.getRecipeOutput().copy();
if (this.copyIngredientTag)
{
for (int i = 0; i < inv.getSizeInventory(); ++i)
{
ItemStack itemstack1 = inv.getStackInSlot(i);
if (itemstack1 != null && itemstack1.hasTag())
{
itemstack.setTag(itemstack1.getTag().copy());
}
}
}
return itemstack;
return this.getRecipeOutput().copy();
}
/**

View file

@ -330,14 +330,11 @@ public class ContainerEnchantment extends Container
return null;
}
if (itemstack1.hasTag() && itemstack1.size == 1)
if (itemstack1.size >= 1)
{
((Slot)this.inventorySlots.get(0)).putStack(itemstack1.copy());
itemstack1.size = 0;
}
else if (itemstack1.size >= 1)
{
((Slot)this.inventorySlots.get(0)).putStack(new ItemStack(itemstack1.getItem()));
ItemStack st = itemstack1.copy();
st.size = 1;
((Slot)this.inventorySlots.get(0)).putStack(st);
--itemstack1.size;
}
}

View file

@ -52,10 +52,7 @@ public class InventoryHelper
stack.size -= i;
EntityItem entityitem = new EntityItem(worldIn, x + (double)f, y + (double)f1, z + (double)f2, new ItemStack(stack.getItem(), i));
if (stack.hasTag())
{
entityitem.getEntityItem().setTag(stack.getTag().copy());
}
entityitem.getEntityItem().copyData(stack);
float f3 = 0.05F;
entityitem.motionX = RANDOM.gaussian() * (double)f3;

View file

@ -201,10 +201,7 @@ public class InventoryPlayer implements IInventory
{
this.mainInventory[j] = new ItemStack(item, 0);
if (itemStackIn.hasTag())
{
this.mainInventory[j].setTag(itemStackIn.getTag().copy());
}
this.mainInventory[j].copyData(itemStackIn);
}
int k = i;

View file

@ -87,7 +87,7 @@ public class Item {
return this.maxDamage > 0;
}
public final String getDisplay(ItemStack stack) {
public final String getDisplay() {
return this.display;
}

View file

@ -4,6 +4,7 @@ import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import common.attributes.Attribute;
import common.attributes.UsageSlot;
@ -30,7 +31,11 @@ public final class ItemStack
public int size;
private Item item;
private TagObject tag;
private String name;
private int color = 0xffffffff;
private int damage;
private int repairCost;
private Map<Enchantment, Integer> enchantments;
public ItemStack(Item item)
{
@ -62,9 +67,13 @@ public final class ItemStack
public static ItemStack readFromTag(TagObject tag)
{
ItemStack itemstack = new ItemStack();
itemstack.readTags(tag);
return itemstack.getItem() != null ? itemstack : null;
Item item = tag.hasString("id") ? ItemRegistry.byName(tag.getString("id")) : null;
int size = tag.hasInt("size") ? tag.getInt("size") : 1;
if(item == null || size < 1)
return null;
ItemStack stack = new ItemStack(item, Math.min(item.getMaxAmount(), size));
stack.readTag(tag);
return stack;
}
public static ItemStack getStack(String name, ItemStack def) {
@ -73,9 +82,27 @@ public final class ItemStack
Item item = ItemRegistry.byName(name);
return item == null ? def : new ItemStack(item);
}
public boolean dataEquals(ItemStack other) {
if(this.color != other.color || this.damage != other.damage || this.repairCost != other.repairCost || (this.name != null) != (other.name != null) || (this.name != null && !this.name.equals(other.name)) || (this.enchantments != null) != (other.enchantments != null) || (this.enchantments != null && this.enchantments.size() != other.enchantments.size()))
return false;
if(this.enchantments == null)
return true;
for(Entry<Enchantment, Integer> ench : this.enchantments.entrySet()) {
if(!ench.getValue().equals(other.enchantments.get(ench.getKey())))
return false;
}
return true;
}
private ItemStack()
{
public void copyData(ItemStack stack) {
this.color = stack.color;
this.damage = stack.damage;
this.repairCost = stack.repairCost;
this.name = stack.name;
this.enchantments = stack.enchantments == null ? null : Maps.newEnumMap(Enchantment.class);
if(this.enchantments != null)
this.enchantments.putAll(stack.enchantments);
}
/**
@ -85,10 +112,7 @@ public final class ItemStack
{
ItemStack itemstack = new ItemStack(this.item, amount);
if (this.tag != null)
{
itemstack.tag = this.tag.copy();
}
itemstack.copyData(this);
this.size -= amount;
return itemstack;
@ -146,21 +170,54 @@ public final class ItemStack
tag.setString("id", ItemRegistry.getName(this.item));
if(this.size != 1)
tag.setInt("size", this.size);
if(this.tag != null)
tag.setObject("tag", this.tag);
if(this.color != 0xffffffff)
tag.setInt("color", this.color);
if(this.damage != 0)
tag.setInt("dmg", this.damage);
if(this.repairCost != 0)
tag.setInt("cost", this.repairCost);
if(this.name != null)
tag.setString("name", this.name);
if(this.enchantments != null) {
List<TagObject> list = Lists.newArrayList();
for(Entry<Enchantment, Integer> ench : this.enchantments.entrySet()) {
TagObject enc = new TagObject();
enc.setString("id", ench.getKey().getName());
if(ench.getValue() != 1)
enc.setShort("lvl", ench.getValue().shortValue());
list.add(enc);
}
tag.setList("ench", list);
}
return tag;
}
private void readTags(TagObject tag)
public void readTag(TagObject tag)
{
this.item = tag.hasString("id") ? ItemRegistry.byName(tag.getString("id")) : null;
this.size = tag.hasInt("size") ? tag.getInt("size") : 1;
this.tag = tag.hasObject("tag") ? tag.getObject("tag") : null;
this.color = tag.hasInt("color") ? tag.getInt("color") : 0xffffffff;
this.color = (this.color & 0xff000000) != 0 ? 0xffffffff : this.color;
this.damage = tag.hasInt("dmg") ? Math.max(0, tag.getInt("dmg")) : 0;
this.repairCost = tag.hasInt("cost") ? Math.max(0, tag.getInt("cost")) : 0;
this.name = tag.hasString("name") ? tag.getString("name") : null;
this.name = this.name != null && this.name.length() > 32 ? this.name.substring(0, 32) : this.name;
this.enchantments = tag.hasList("ench") ? Maps.newEnumMap(Enchantment.class) : null;
if(this.enchantments != null) {
List<TagObject> list = tag.getList("ench");
for(TagObject enc : list) {
if(!enc.hasString("id"))
continue;
Enchantment ench = Enchantment.getEnchantment(enc.getString("id"));
if(ench != null)
this.enchantments.put(ench, enc.hasShort("lvl") ? (int)enc.getShort("lvl") : 1);
}
if(this.enchantments.isEmpty())
this.enchantments = null;
}
}
public int getMaxStackSize()
{
return this.getItem().getMaxAmount();
return this.item.getMaxAmount();
}
public boolean isStackable()
@ -178,29 +235,6 @@ public final class ItemStack
return this.isItemStackDamageable() && this.getItemDamage() > 0;
}
public int getItemDamage()
{
return this.isItemStackDamageable() && this.tag != null && this.tag.hasInt("dmg") ? this.tag.getInt("dmg") : 0;
}
public void setItemDamage(int damage)
{
if(!this.isItemStackDamageable())
return;
if(damage <= 0) {
if(this.tag != null) {
this.tag.remove("dmg");
if(this.tag.isEmpty())
this.tag = null;
}
}
else {
if(this.tag == null)
this.tag = new TagObject();
this.tag.setInt("dmg", damage);
}
}
public int getMaxDamage()
{
return this.item.getMaxDamage();
@ -319,17 +353,14 @@ public final class ItemStack
{
ItemStack itemstack = new ItemStack(this.item, this.size);
if (this.tag != null)
{
itemstack.tag = this.tag.copy();
}
itemstack.copyData(this);
return itemstack;
}
public static boolean areItemStackTagsEqual(ItemStack stackA, ItemStack stackB)
{
return stackA == null && stackB == null ? true : (stackA != null && stackB != null ? (stackA.tag == null && stackB.tag != null ? false : stackA.tag == null || stackA.tag.equals(stackB.tag)) : false);
return stackA == null && stackB == null ? true : (stackA != null && stackB != null ? stackA.dataEquals(stackB) : false);
}
/**
@ -345,7 +376,7 @@ public final class ItemStack
*/
private boolean isItemStackEqual(ItemStack other)
{
return this.size != other.size ? false : (this.item != other.item ? false : (this.tag == null && other.tag != null ? false : this.tag == null || this.tag.equals(other.tag)));
return this.size != other.size ? false : (this.item != other.item ? false : this.dataEquals(other));
}
/**
@ -431,36 +462,21 @@ public final class ItemStack
this.getItem().onPlayerStoppedUsing(this, worldIn, playerIn, timeLeft);
}
public boolean hasTag()
public int getItemDamage()
{
return this.tag != null;
return this.isItemStackDamageable() ? this.damage : 0;
}
public TagObject getTag()
public void setItemDamage(int damage)
{
return this.tag;
}
public List<TagObject> getEnchantmentTagList()
{
return this.tag == null ? null : this.tag.getList("ench");
}
public void setTag(TagObject tag)
{
this.tag = tag;
if(!this.isItemStackDamageable())
return;
this.damage = Math.max(0, damage);
}
public String getDisplayName()
{
String s = this.getItem().getDisplay(this);
if (this.tag != null && this.tag.hasString("Name"))
{
s = this.tag.getString("Name");
}
return s;
return this.name != null ? this.name : this.getItem().getDisplay();
}
public String getColoredName() {
@ -471,36 +487,20 @@ public final class ItemStack
return TextColor.DGRAY + "[" + this.getColor() + this.getDisplayName() + TextColor.DGRAY + "]" + reset;
}
public ItemStack setStackDisplayName(String displayName)
public void setStackDisplayName(String displayName)
{
if (this.tag == null)
{
this.tag = new TagObject();
}
this.tag.setString("Name", displayName);
return this;
this.name = displayName != null && !displayName.isEmpty() ? displayName : null;
this.name = this.name != null && this.name.length() > 32 ? this.name.substring(0, 32) : this.name;
}
public void clearCustomName()
{
if (this.tag != null)
{
if (this.tag.hasString("Name"))
{
this.tag.remove("Name");
if (this.tag.isEmpty())
{
this.setTag(null);
}
}
}
this.name = null;
}
public boolean hasDisplayName()
{
return this.tag != null && this.tag.hasString("Name");
return this.name != null;
}
public List<String> getTooltip(EntityNPC playerIn)
@ -515,22 +515,11 @@ public final class ItemStack
if(this.item.canBeDyed())
list.add("Farbe: #" + Integer.toHexString(this.getDyeColor()).toUpperCase());
if (this.hasTag())
if (this.enchantments != null)
{
List<TagObject> ench = this.getEnchantmentTagList();
if (ench != null)
for (Entry<Enchantment, Integer> enc : this.enchantments.entrySet())
{
for (int j = 0; j < ench.size(); ++j)
{
Enchantment k = Enchantment.getEnchantment(ench.get(j).getString("id"));
if (k != null)
{
int l = ench.get(j).getShort("lvl");
list.add(k.getFormattedName(l));
}
}
list.add(enc.getKey().getFormattedName(enc.getValue()));
}
}
@ -567,27 +556,22 @@ public final class ItemStack
}
}
if (this.isItemStackDamageable())
if (this.item.getMaxDamage() > 0)
{
list.add(String.format("Haltbarkeit: %d" + (this.isItemDamaged() ? " / %d" : ""),
this.isItemDamaged() ? (this.getMaxDamage() - this.getItemDamage()) : this.getMaxDamage(), this.getMaxDamage()));
list.add(String.format("Haltbarkeit: %d" + (this.damage > 0 ? " / %d" : ""),
this.damage > 0 ? (this.item.getMaxDamage() - this.damage) : this.item.getMaxDamage(), this.item.getMaxDamage()));
}
if(this.getRepairCost() > 0)
list.add("Reparaturkosten: " + this.getRepairCost() + " Mana");
if(this.repairCost > 0)
list.add("Reparaturkosten: " + this.repairCost + " Mana");
if(this.getMaxStackSize() == 1)
if(this.item.getMaxAmount() == 1)
list.add("Nicht stapelbar");
else
list.add("Stapelbar bis " + this.getMaxStackSize());
list.add("Stapelbar bis " + this.item.getMaxAmount());
list.add(TextColor.GRAY + ItemRegistry.getName(this.item));
if (this.hasTag())
{
list.add(TextColor.GRAY + String.format("Tags: %d", this.getTag().keySet().size()));
}
return list;
}
@ -601,146 +585,70 @@ public final class ItemStack
return this.getItem().getColor(this);
}
/**
* True if it is a tool and has no enchantments to begin with
*/
public boolean isItemEnchantable()
{
return !this.getItem().canEnchant(this) ? false : !this.isItemEnchanted();
}
/**
* Adds an enchantment with a desired level on the ItemStack.
*/
public void addEnchantment(Enchantment ench, int level)
public Set<Entry<Enchantment, Integer>> getEnchantments()
{
if (this.tag == null)
{
this.setTag(new TagObject());
}
if (!this.tag.hasList("ench"))
{
this.tag.setList("ench", Lists.newArrayList());
}
List<TagObject> list = this.tag.getList("ench");
TagObject tag = new TagObject();
tag.setString("id", ench.getName());
tag.setShort("lvl", (short)(/* (byte) */ level));
list.add(tag);
return this.enchantments == null ? null : this.enchantments.entrySet();
}
public Integer getEnchantment(Enchantment ench)
{
return this.enchantments == null ? null : this.enchantments.get(ench);
}
public void addEnchantment(Enchantment ench, int level)
{
if (this.enchantments == null)
this.enchantments = Maps.newEnumMap(Enchantment.class);
this.enchantments.put(ench, level);
}
/**
* Removes an enchantment from the ItemStack.
*/
public boolean removeEnchantment(Enchantment ench) {
if(this.tag == null) {
return false;
}
if(!this.tag.hasList("ench")) {
return false;
}
List<TagObject> oldEnch = this.tag.getList("ench");
List<TagObject> newEnch = Lists.newArrayList();
boolean changed = false;
TagObject tag;
for(int z = 0; z < oldEnch.size(); z++) {
tag = oldEnch.get(z);
if(Enchantment.getEnchantment(tag.getString("id")) != ench) {
newEnch.add(tag);
}
else {
changed = true;
}
}
if(!changed) {
if(this.enchantments == null || this.enchantments.remove(ench) == null)
return false;
}
if(newEnch.size() == 0) {
this.tag.remove("ench");
if(this.tag.isEmpty()) {
this.tag = null;
}
}
else {
this.tag.setList("ench", newEnch);
}
if(this.enchantments.isEmpty())
this.enchantments = null;
return true;
}
/**
* Removes all enchantments from the ItemStack.
*/
public boolean clearEnchantments() {
if(this.tag == null) {
return false;
if(this.enchantments != null) {
this.enchantments = null;
return true;
}
if(!this.tag.hasList("ench")) {
return false;
}
this.tag.remove("ench");
if(this.tag.isEmpty()) {
this.tag = null;
}
return true;
return false;
}
/**
* True if the item has enchantment data
*/
public boolean isItemEnchanted()
{
return this.tag != null && this.tag.hasList("ench");
return this.enchantments != null;
}
public void setTagInfo(String key, TagObject value)
public void setEnchantments(Map<Enchantment, Integer> enchMap)
{
if (this.tag == null)
{
this.setTag(new TagObject());
}
this.tag.setObject(key, value);
}
public void setTagInfo(String key, List<TagObject> value)
{
if (this.tag == null)
{
this.setTag(new TagObject());
}
this.tag.setList(key, value);
if(enchMap == null || enchMap.isEmpty()) {
this.enchantments = null;
return;
}
if(this.enchantments == null)
this.enchantments = Maps.newEnumMap(Enchantment.class);
else
this.enchantments.clear();
this.enchantments.putAll(enchMap);
}
public int getRepairCost()
{
return this.hasTag() && this.tag.hasInt("RepairCost") ? this.tag.getInt("RepairCost") : 0;
return this.repairCost;
}
public void setRepairCost(int cost)
{
if(cost == 0) {
if(this.tag == null) {
return;
}
if(!this.tag.hasInt("RepairCost")) {
return;
}
this.tag.remove("RepairCost");
if(this.tag.isEmpty()) {
this.tag = null;
}
return;
}
if (!this.hasTag())
{
this.tag = new TagObject();
}
this.tag.setInt("RepairCost", cost);
this.repairCost = Math.max(0, cost);
}
public Map<Attribute, Float> getAttributeModifiers(UsageSlot slot) {
@ -754,45 +662,41 @@ public final class ItemStack
this.item = newItem;
}
public boolean canBeDyed()
{
return this.item.canBeDyed();
}
public boolean hasColor()
{
return this.item.canBeDyed() && this.tag != null && this.tag.hasInt("color");
return this.item.canBeDyed() && this.color != 0xffffffff;
}
public int getRawColor()
{
if(!this.item.canBeDyed())
return -1;
return this.color;
}
public int getDyeColor()
{
if (!this.item.canBeDyed())
if(!this.item.canBeDyed())
return -1;
if (this.tag != null && this.tag.hasInt("color"))
{
return this.tag.getInt("color");
}
return this.item.getDefaultColor();
return this.color != 0xffffffff ? this.color : this.item.getDefaultColor();
}
public void removeColor()
{
if (!this.item.canBeDyed())
if(!this.item.canBeDyed())
throw new UnsupportedOperationException("Kann diesen Gegenstand nicht entfärben!");
if (this.tag != null)
{
if (this.tag.hasInt("color"))
{
this.tag.remove("color");
if(this.tag.isEmpty())
this.tag = null;
}
}
this.color = 0xffffffff;
}
public void setColor(int color)
{
if (!this.item.canBeDyed())
if(!this.item.canBeDyed())
throw new UnsupportedOperationException("Kann diesen Gegenstand nicht einfärben!");
if (this.tag == null)
this.tag = new TagObject();
this.tag.setInt("color", color);
this.color = (color & 0xff000000) != 0 ? 0xffffffff : color;
}
}

View file

@ -11,8 +11,6 @@ import common.item.ItemStack;
import common.model.Model;
import common.model.ModelProvider;
import common.model.Transforms;
import common.tags.TagObject;
import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.util.Facing;
import common.world.State;
@ -81,7 +79,6 @@ public class ItemBlock extends Item
if (iblockstate1.getBlock() == this.block)
{
setTileData(worldIn, playerIn, pos, stack);
this.block.onBlockPlacedBy(worldIn, pos, iblockstate1, playerIn, stack);
}
@ -97,37 +94,6 @@ public class ItemBlock extends Item
}
}
public static boolean setTileData(World world, EntityNPC player, BlockPos pos, ItemStack stack)
{
if (stack.hasTag() && stack.getTag().hasObject("BlockEntityTag"))
{
TileEntity tile = world.getTileEntity(pos);
if (tile != null)
{
if (!world.client && !player.connection.isAdmin())
{
return false;
}
TagObject tag = new TagObject();
TagObject tileTag = tag.copy();
tile.writeTags(tag);
TagObject stackTag = stack.getTag().getObject("BlockEntityTag");
tag.merge(stackTag);
if (!tag.equals(tileTag))
{
tile.readTags(tag);
tile.markDirty();
return true;
}
}
}
return false;
}
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, Facing side, EntityNPC player, ItemStack stack)
{
Block block = worldIn.getState(pos).getBlock();

View file

@ -74,7 +74,7 @@ public class ItemSign extends Item
--stack.size;
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntitySign && !ItemBlock.setTileData(worldIn, playerIn, pos, stack))
if (tileentity instanceof TileEntitySign)
{
playerIn.openEditSign((TileEntitySign)tileentity);
}

View file

@ -40,7 +40,6 @@ public class ItemSmallBlock extends Item {
newState = world.getState(pos);
if(newState.getBlock() == this.block) {
ItemBlock.setTileData(world, player, pos, stack);
newState.getBlock().onBlockPlacedBy(world, pos, newState, player, stack);
}

View file

@ -51,7 +51,7 @@ public class ItemCarrotOnAStick extends Item
if (itemStackIn.size == 0)
{
ItemStack itemstack = new ItemStack(Items.fishing_rod);
itemstack.setTag(itemStackIn.getTag());
itemstack.copyData(itemStackIn);
return itemstack;
}
}

View file

@ -2,7 +2,10 @@ package common.network;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Set;
import java.util.Map.Entry;
import common.enchantment.Enchantment;
import common.init.ItemRegistry;
import common.item.ItemStack;
import common.net.buffer.ByteBuf;
@ -119,16 +122,38 @@ public class PacketBuffer {
}
this.writeShort(ItemRegistry.getId(stack.getItem()));
this.writeVarInt(stack.size);
this.writeTag(stack.getTag());
if(stack.canBeDyed())
this.writeVarInt(stack.getRawColor());
if(stack.isItemStackDamageable())
this.writeVarInt(stack.getItemDamage());
this.writeVarInt(stack.getRepairCost());
this.writeString(stack.hasDisplayName() ? stack.getDisplayName() : "");
Set<Entry<Enchantment, Integer>> ench = stack.getEnchantments();
this.writeVarInt(ench == null ? 0 : ench.size());
if(ench != null) {
for(Entry<Enchantment, Integer> entry : ench) {
this.writeEnumValue(entry.getKey());
this.writeShort(entry.getValue());
}
}
}
public ItemStack readItemStack() throws IOException {
int id = this.readShort();
if(id < 0)
return null;
int amt = this.readVarInt();
ItemStack stack = new ItemStack(ItemRegistry.byId(id), amt);
stack.setTag(this.readTag());
ItemStack stack = new ItemStack(ItemRegistry.byId(id), this.readVarInt());
if(stack.canBeDyed())
stack.setColor(this.readVarInt());
if(stack.isItemStackDamageable())
stack.setItemDamage(this.readVarInt());
stack.setRepairCost(this.readVarInt());
stack.setStackDisplayName(this.readString(32));
int num = this.readVarInt();
for(int z = 0; z < num; z++) {
Enchantment enc = this.readEnumValue(Enchantment.class);
stack.addEnchantment(enc, this.readShort());
}
return stack;
}

View file

@ -31,9 +31,8 @@ public class MerchantRecipeList extends ArrayList<MerchantRecipe> {
}
}
private static boolean areItemsSimilar(ItemStack stack1, ItemStack stack2) {
return ItemStack.areItemsEqual(stack1, stack2)
&& (!stack2.hasTag() || stack1.hasTag() && TagObject.compare(stack2.getTag(), stack1.getTag()));
private static boolean areItemsSimilar(ItemStack given, ItemStack offer) {
return ItemStack.areItemsEqual(given, offer) && given.dataEquals(offer);
}
public void fromTags(List<TagObject> list) {