Files
CatServer/patches/net/minecraft/item/ItemStack.java.patch

203 lines
7.3 KiB
Diff

--- ../src-base/minecraft/net/minecraft/item/ItemStack.java
+++ ../src-work/minecraft/net/minecraft/item/ItemStack.java
@@ -1,13 +1,19 @@
package net.minecraft.item;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
import java.text.DecimalFormat;
import java.util.List;
-import java.util.Random;
import java.util.Map.Entry;
+import java.util.Random;
+
import javax.annotation.Nullable;
+
+import org.bukkit.entity.Player;
+
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
+
+import luohuayu.CatServer.capture.WorldCapture;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.Enchantment;
@@ -20,6 +26,7 @@
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Enchantments;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
@@ -54,7 +61,8 @@
private Item item;
private NBTTagCompound stackTagCompound;
int itemDamage;
- private EntityItemFrame itemFrame;
+ private transient EntityItemFrame itemFrame;
+ public static EntityPlayer currentPlayer; // Cauldron - reference to current player calling onItemUse
private Block canDestroyCacheBlock;
private boolean canDestroyCacheResult;
private Block canPlaceOnCacheBlock;
@@ -101,8 +109,15 @@
{
this.itemDamage = 0;
}
+ sizeCheck(this);
}
+ private static void sizeCheck(ItemStack itemStack) {
+ if(itemStack.stackSize < -1){
+ itemStack.stackSize = 0;
+ }
+ }
+
public static ItemStack loadItemStackFromNBT(NBTTagCompound nbt)
{
if (nbt.hasNoTags()) return null; // Deserialized inventories can have empty ItemStack compounds. Fixes tons of NumberFormatExceptions
@@ -160,7 +175,16 @@
public ActionResult<ItemStack> useItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand)
{
- return this.getItem().onItemRightClick(this, worldIn, playerIn, hand);
+ sizeCheck(this);
+ WorldCapture tCapture=worldIn.mCapture;
+ tCapture.startCapture(playerIn,this,EnumFacing.DOWN,hand);
+ ActionResult<ItemStack> tAfterUse=this.getItem().onItemRightClick(this,worldIn,playerIn,hand);
+ tCapture.endCapture();
+ if(tAfterUse.getType()==EnumActionResult.SUCCESS){
+ EnumActionResult tResult=tCapture.handleCapture(tAfterUse.getResult());
+ tAfterUse=new ActionResult<ItemStack>(tResult,tAfterUse.getResult());
+ }
+ return tAfterUse;
}
@Nullable
@@ -172,13 +196,14 @@
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
ResourceLocation resourcelocation = (ResourceLocation)Item.REGISTRY.getNameForObject(this.item);
+ sizeCheck(this);
nbt.setString("id", resourcelocation == null ? "minecraft:air" : resourcelocation.toString());
nbt.setByte("Count", (byte)this.stackSize);
nbt.setShort("Damage", (short)this.itemDamage);
if (this.stackTagCompound != null)
{
- nbt.setTag("tag", this.stackTagCompound);
+ nbt.setTag("tag", this.stackTagCompound.copy());
}
if (this.capabilities != null)
@@ -202,10 +227,11 @@
{
this.itemDamage = 0;
}
+ sizeCheck(this);
if (nbt.hasKey("tag", 10))
{
- this.stackTagCompound = nbt.getCompoundTag("tag");
+ this.stackTagCompound = nbt.getCompoundTag("tag").copy();
if (this.item != null)
{
@@ -217,11 +243,13 @@
public int getMaxStackSize()
{
+ sizeCheck(this);
return this.getItem().getItemStackLimit(this);
}
public boolean isStackable()
{
+ sizeCheck(this);
return this.getMaxStackSize() > 1 && (!this.isItemStackDamageable() || !this.isItemDamaged());
}
@@ -260,8 +288,10 @@
return this.item == null ? 0 : this.item.getMaxDamage(this);
}
- public boolean attemptDamageItem(int amount, Random rand)
- {
+ public boolean attemptDamageItem(int amount, Random rand) {
+ return attemptDamageItem(amount, rand, null);
+ }
+ public boolean attemptDamageItem(int amount, Random rand, EntityLivingBase entityLivingBase){
if (!this.isItemStackDamageable())
{
return false;
@@ -282,7 +312,20 @@
}
amount -= j;
+ // Spigot start
+ if (entityLivingBase instanceof EntityPlayerMP) {
+ org.bukkit.craftbukkit.inventory.CraftItemStack item = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this);
+ org.bukkit.event.player.PlayerItemDamageEvent event = new org.bukkit.event.player.PlayerItemDamageEvent((Player) entityLivingBase.getBukkitEntity(), item, amount);
+ org.bukkit.Bukkit.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled())
+ {
+ return false;
+ }
+
+ amount = event.getDamage();
+ }
+ // Spigot end
if (amount <= 0)
{
return false;
@@ -300,7 +343,7 @@
{
if (this.isItemStackDamageable())
{
- if (this.attemptDamageItem(amount, entityIn.getRNG()))
+ if (this.attemptDamageItem(amount, entityIn.getRNG(), entityIn))
{
entityIn.renderBrokenItemStack(this);
--this.stackSize;
@@ -310,10 +353,10 @@
EntityPlayer entityplayer = (EntityPlayer)entityIn;
entityplayer.addStat(StatList.getObjectBreakStats(this.item));
}
-
- if (this.stackSize < 0)
+ sizeCheck(this);
+ if (this.stackSize == 0 && entityIn instanceof EntityPlayer)
{
- this.stackSize = 0;
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent((EntityPlayer)entityIn,this);
}
this.itemDamage = 0;
@@ -354,6 +397,7 @@
public ItemStack copy()
{
+ sizeCheck(this);
ItemStack itemstack = new ItemStack(this.item, this.stackSize, this.itemDamage, this.capabilities != null ? this.capabilities.serializeNBT() : null);
if (this.stackTagCompound != null)
@@ -1075,4 +1119,15 @@
return this.capabilities.areCompatible(other.capabilities);
}
}
+ // Spigot start
+ public static boolean fastMatches(ItemStack itemstack, ItemStack itemstack1) {
+ if (itemstack == null && itemstack1 == null) {
+ return true;
+ }
+ if (itemstack != null && itemstack1 != null) {
+ return itemstack.stackSize == itemstack1.stackSize && itemstack.item == itemstack1.item && itemstack.itemDamage == itemstack1.itemDamage;
+ }
+ return false;
+ }
+ // Spigot end
}