mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-28 07:55:53 +00:00
Add NPE protection to ItemStack delegates. Closes #601
Also cleaned up the names of said delegates, we do not have to follow MCP's crowdsourced names as they are very bad. Redirected damage through setItemDamage to allow items to have finder control of breaking.
This commit is contained in:
1 parent
2bbb3ee0ca
commit
9034862024
2 files changed
+69
-27
No files matched your search
@@ -1,56 +1,72 @@
|
||||
--- ../src_base/minecraft/net/minecraft/item/ItemStack.java
|
||||
+++ ../src_work/minecraft/net/minecraft/item/ItemStack.java
|
||||
@@ -249,7 +249,7 @@
|
||||
@@ -249,7 +249,9 @@
|
||||
*/
|
||||
public boolean isItemDamaged()
|
||||
{
|
||||
- return this.isItemStackDamageable() && this.itemDamage > 0;
|
||||
+ return this.isItemStackDamageable() && this.getItem().isItemStackDamaged(this);
|
||||
+ boolean damaged = itemDamage > 0;
|
||||
+ if (getItem() != null) damaged = getItem().isDamaged(this);
|
||||
+ return this.isItemStackDamageable() && damaged;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,7 +257,7 @@
|
||||
@@ -257,6 +259,10 @@
|
||||
*/
|
||||
public int getItemDamageForDisplay()
|
||||
{
|
||||
- return this.itemDamage;
|
||||
+ return this.getItem().getItemDamageFromStackForDisplay(this);
|
||||
+ if (getItem() != null)
|
||||
+ {
|
||||
+ return getItem().getDisplayDamage(this);
|
||||
+ }
|
||||
return this.itemDamage;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,7 +265,7 @@
|
||||
@@ -265,6 +271,10 @@
|
||||
*/
|
||||
public int getItemDamage()
|
||||
{
|
||||
- return this.itemDamage;
|
||||
+ return this.getItem().getItemDamageFromStack(this);
|
||||
+ if (getItem() != null)
|
||||
+ {
|
||||
+ return getItem().getDamage(this);
|
||||
+ }
|
||||
return this.itemDamage;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,12 +273,7 @@
|
||||
@@ -273,6 +283,12 @@
|
||||
*/
|
||||
public void setItemDamage(int par1)
|
||||
{
|
||||
- this.itemDamage = par1;
|
||||
-
|
||||
- if (this.itemDamage < 0)
|
||||
- {
|
||||
- this.itemDamage = 0;
|
||||
- }
|
||||
+ this.getItem().setItemDamageForStack(this, par1);
|
||||
}
|
||||
+ if (getItem() != null)
|
||||
+ {
|
||||
+ getItem().setDamage(this, par1);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
this.itemDamage = par1;
|
||||
|
||||
/**
|
||||
@@ -286,7 +281,7 @@
|
||||
if (this.itemDamage < 0)
|
||||
@@ -286,7 +302,7 @@
|
||||
*/
|
||||
public int getMaxDamage()
|
||||
{
|
||||
- return Item.itemsList[this.itemID].getMaxDamage();
|
||||
+ return this.getItem().getItemMaxDamageFromStack(this);
|
||||
+ return this.getItem().getMaxDamage(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -388,7 +383,7 @@
|
||||
@@ -324,8 +340,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
- this.itemDamage += par1;
|
||||
- return this.itemDamage > this.getMaxDamage();
|
||||
+ setItemDamage(getItemDamage() + par1); //Redirect through Item's callback if applicable.
|
||||
+ return getItemDamage() > getMaxDamage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,7 +404,7 @@
|
||||
*/
|
||||
public int getDamageVsEntity(Entity par1Entity)
|
||||
{
|
||||
@@ -59,7 +75,7 @@
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,7 +391,7 @@
|
||||
@@ -396,7 +412,7 @@
|
||||
*/
|
||||
public boolean canHarvestBlock(Block par1Block)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user