mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 11:05:40 +00:00
Add shouldCauseBlockBreakReset callback to Item. This allows to keep breaking blocks if the NBT or similar changes.
This commit is contained in:
1 parent
d7245c5ffe
commit
bc27f0e204
4 files changed
+61
-3
No files matched your search
@@ -2,8 +2,12 @@ package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
@@ -11,6 +15,8 @@ import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Mod(modid = ItemLayerModelDebug.MODID, version = ItemLayerModelDebug.VERSION)
|
||||
public class ItemLayerModelDebug
|
||||
{
|
||||
@@ -55,5 +61,30 @@ public class ItemLayerModelDebug
|
||||
setUnlocalizedName(MODID + ":" + name);
|
||||
setRegistryName(new ResourceLocation(MODID, name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger("foo", new Random().nextInt());
|
||||
stack.setTagCompound(tag);
|
||||
stack.setStackDisplayName(String.valueOf(new Random().nextInt()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCauseBlockBreakReset(ItemStack oldStack, ItemStack newStack)
|
||||
{
|
||||
return shouldCauseReequipAnimation(oldStack, newStack, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
|
||||
{
|
||||
oldStack = oldStack.copy();
|
||||
oldStack.setTagCompound(null);
|
||||
newStack = newStack.copy();
|
||||
newStack.setTagCompound(null);
|
||||
return !ItemStack.areItemStacksEqual(oldStack, newStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user