Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
All Test Working
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexeption committed Nov 29, 2020
1 parent 988854f commit 8cced61
Show file tree
Hide file tree
Showing 6 changed files with 378 additions and 282 deletions.
98 changes: 87 additions & 11 deletions patches/net/minecraft/item/ItemStack.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.enchantment.Enchantment;
@@ -49,14 +49,17 @@
@@ -30,6 +30,7 @@
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
+import net.minecraft.server.MinecraftServer;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
@@ -49,14 +50,17 @@
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand All @@ -29,8 +37,66 @@
private NBTTagCompound stackTagCompound;
private boolean isEmpty;
int itemDamage;
@@ -119,23 +122,33 @@
@@ -95,7 +99,10 @@
this(itemIn, amount, 0);
}

- public ItemStack(Item itemIn, int amount, int meta){ this(itemIn, amount, meta, null); }
+ public ItemStack(Item itemIn, int amount, int meta) {
+ this(itemIn, amount, meta, true);
+ }
+
public ItemStack(Item itemIn, int amount, int meta, @Nullable NBTTagCompound capNBT)
{
this.capNBT = capNBT;
@@ -112,30 +119,77 @@
this.forgeInit();
}

- private void updateEmptyState()
- {
+ public ItemStack(Item itemIn, int amount, int meta, boolean convert) {
+ this.item = itemIn;
+ this.itemDamage = meta;
+ this.stackSize = amount;
+
+ // CraftBukkit start - Pass to setData to do filtering
+ if (MinecraftServer.getServerCB() != null) {
+ this.setItemDamage(meta);
+ }
+ // CraftBukkit end
+
+ if (this.itemDamage < 0) {
+ // this.itemDamage = 0;
+ }
+
+ this.updateEmptyState();
+ this.forgeInit();
+ if (convert)
+ this.convertStack();
+ }
+
+ private void updateEmptyState() {
+ // if (this.isEmpty && this == ItemStack.EMPTY) throw new AssertionError("TRAP"); // CraftBukkit
this.isEmpty = this.isEmpty();
}

+ // Called to run this stack through the data converter to handle older storage methods and serialized items
+ public void convertStack() {
+ if (MinecraftServer.getServerCB() != null) {
+ // Don't convert beds - both the old and new data values are valid
+ // Conversion would make getting white beds (data value 0) impossible
+ if (this.item == Items.BED) {
+ return;
+ }
+
+ NBTTagCompound savedStack = new NBTTagCompound();
+ this.writeToNBT(savedStack);
+ MinecraftServer.getServerCB().dataFixer.process(FixTypes.ITEM_INSTANCE, savedStack);
+ this.load(savedStack);
+ }
+ }
+
public ItemStack(NBTTagCompound compound)
{
+ this.load(compound);
Expand Down Expand Up @@ -69,15 +135,15 @@
}

public boolean isEmpty()
@@ -160,6 +173,7 @@
@@ -160,6 +214,7 @@
return true;
}
}
+ // Paper end

public static void registerFixes(DataFixer fixer)
{
@@ -185,11 +199,10 @@
@@ -185,11 +240,10 @@
{
if (!worldIn.isRemote) return net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(this, playerIn, worldIn, pos, side, hitX, hitY, hitZ, hand);
EnumActionResult enumactionresult = this.getItem().onItemUse(playerIn, worldIn, pos, hand, side, hitX, hitY, hitZ);
Expand All @@ -91,7 +157,7 @@

return enumactionresult;
}
@@ -231,7 +244,8 @@
@@ -231,7 +285,8 @@

if (this.stackTagCompound != null)
{
Expand All @@ -101,7 +167,7 @@
}

if (this.capabilities != null)
@@ -291,6 +305,26 @@
@@ -291,6 +346,26 @@

public void setItemDamage(int meta)
{
Expand All @@ -128,7 +194,7 @@
getItem().setDamage(this, meta);
}

@@ -322,6 +356,19 @@
@@ -322,6 +397,19 @@

amount -= j;

Expand All @@ -148,7 +214,7 @@
if (amount <= 0)
{
return false;
@@ -347,6 +394,11 @@
@@ -347,6 +435,11 @@
if (this.attemptDamageItem(amount, entityIn.getRNG(), entityIn instanceof EntityPlayerMP ? (EntityPlayerMP)entityIn : null))
{
entityIn.renderBrokenItemStack(this);
Expand All @@ -160,7 +226,17 @@
this.shrink(1);

if (entityIn instanceof EntityPlayer)
@@ -983,6 +1035,14 @@
@@ -393,7 +486,8 @@

public ItemStack copy()
{
- ItemStack itemstack = new ItemStack(this.item, this.stackSize, this.itemDamage, this.capabilities != null ? this.capabilities.serializeNBT() : null);
+ // ItemStack itemstack = new ItemStack(this.item, this.stackSize, this.itemDamage, this.capabilities != null ? this.capabilities.serializeNBT() : null);
+ ItemStack itemstack = new ItemStack(this.item, this.stackSize, this.itemDamage, false);
itemstack.setAnimationsToGo(this.getAnimationsToGo());

if (this.stackTagCompound != null)
@@ -983,6 +1077,14 @@

public void setRepairCost(int cost)
{
Expand All @@ -175,7 +251,7 @@
if (!this.hasTagCompound())
{
this.stackTagCompound = new NBTTagCompound();
@@ -1043,6 +1103,14 @@
@@ -1043,6 +1145,14 @@
nbttaglist.appendTag(nbttagcompound);
}

Expand All @@ -190,7 +266,7 @@
public ITextComponent getTextComponent()
{
TextComponentString textcomponentstring = new TextComponentString(this.getDisplayName());
@@ -1280,4 +1348,16 @@
@@ -1280,4 +1390,16 @@
{
return this.isEmpty() || this.getItem().doesSneakBypassUse(this, world, pos, player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ public static net.minecraft.item.ItemStack asNMSCopy(ItemStack original) {
return net.minecraft.item.ItemStack.EMPTY;
}

net.minecraft.item.ItemStack stack = new net.minecraft.item.ItemStack(item, original.getAmount(), original.getDurability());
net.minecraft.item.ItemStack stack = new net.minecraft.item.ItemStack(item, original.getAmount(), original.getDurability(), false);
if (original.hasItemMeta()) {
setItemMeta(stack, original.getItemMeta());
} else {
// Converted after setItemMeta
stack.convertStack();
}
return stack;
}
Expand All @@ -60,15 +63,11 @@ public static ItemStack asBukkitCopy(net.minecraft.item.ItemStack original) {
if (original.isEmpty()) {
return new ItemStack(Material.AIR);
}
// Magma start - don't use strict Bukkit stacks as we don't have Bukkit Materials for modded item stacks, create wrapper? (Cauldron)
return asCraftMirror(copyNMSStack(original, original.getCount()));
/*
ItemStack stack = new ItemStack(CraftMagicNumbers.getMaterial(original.getItem()), original.getCount(), (short) original.getMetadata());
if (hasItemMeta(original)) {
stack.setItemMeta(getItemMeta(original));
}
return stack;
*/
}

public static CraftItemStack asCraftMirror(net.minecraft.item.ItemStack original) {
Expand Down
Loading

0 comments on commit 8cced61

Please sign in to comment.