Jump to content

[1.9] Custom Shield quirkiness


p455w0rd

Recommended Posts

Well, the shield I made is functional. It blocks arrows and in 3rd person plays the correct animation. My model also loads fine. I'm having 2 issues:

1) when right-clicking, the first person animation doesn't play (just does a similar animation to what happens when you right-click an empty bucket on a block in creative)

2) the shield doesn't take damage when hit

 

I've tried adding "textures" and "elements" to p455w0rdshield_blocking.json and this had no effect.

I thought maybe I needed a custom IItemPropertyGetter as you do with ItemBow, but ItemShield doesn't check for an instanceof ItemShield

 

ItemPShield.java

public class ItemPShield extends ItemShield
{
private final String name = "p455w0rdshield";

    public ItemPShield()
    {
    	setRegistryName(this.name);
setUnlocalizedName(this.name);
GameRegistry.register(this);
        this.setMaxStackSize(1);
        this.setMaxDamage(336);
        this.setCreativeTab(CreativeTabs.tabCombat);
        this.setCreativeTab(CommonProxy.creativeTab);
        this.addPropertyOverride(new ResourceLocation(Globals.MODID, "blocking"), new IItemPropertyGetter()
        {
            @SideOnly(Side.CLIENT)
            public float apply(ItemStack stack, World worldIn, EntityLivingBase entityIn)
            {
                return entityIn != null && entityIn.isHandActive() && entityIn.getActiveItemStack() == stack ? 1.0F : 0.0F;
            }
        });
    }
    
    @SideOnly(Side.CLIENT)
    public void initModel() {
    	ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(this.getRegistryName(), "inventory"));
    }

    @Override
    public String getItemStackDisplayName(ItemStack stack)
    {
        return LocaleHandler.p455w0rdshield.getLocal();
    }

    /**
     * allows items to add custom lines of information to the mouseover description
     */
    @SideOnly(Side.CLIENT)
    @Override
    public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
    {
        //ItemBanner.func_185054_a(stack, tooltip);
    	tooltip.add("Tooltip");
    }

}

 

models/item/p455w0rdshield.json

{
"textures": {
        "0": "minecraft:blocks/diamond_block",
        "1": "minecraft:blocks/iron_block"
    },
    "elements": [
        {
            "name": "Cube",
            "from": [ 6.0, 0.0, 8.0 ], 
            "to": [ 10.0, 1.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 6.0, 14.0, 10.0, 15.0 ] },
                "east": { "texture": "#0", "uv": [ 10.0, 14.0, 11.0, 15.0 ] },
                "south": { "texture": "#0", "uv": [ 6.0, 14.0, 10.0, 15.0 ] },
                "west": { "texture": "#0", "uv": [ 5.0, 14.0, 6.0, 15.0 ] },
                "up": { "texture": "#-1", "uv": [ 1.0, 2.0, 5.0, 3.0 ] },
                "down": { "texture": "#0", "uv": [ 6.0, 14.0, 10.0, 15.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 5.0, 1.0, 8.0 ], 
            "to": [ 11.0, 2.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 5.0, 13.0, 11.0, 14.0 ] },
                "east": { "texture": "#0", "uv": [ 11.0, 13.0, 12.0, 14.0 ] },
                "south": { "texture": "#0", "uv": [ 5.0, 13.0, 11.0, 14.0 ] },
                "west": { "texture": "#0", "uv": [ 4.0, 13.0, 5.0, 14.0 ] },
                "up": { "texture": "#-1", "uv": [ 0.0, 0.0, 6.0, 1.0 ] },
                "down": { "texture": "#0", "uv": [ 5.0, 13.0, 11.0, 14.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 3.0, 2.0, 8.0 ], 
            "to": [ 13.0, 3.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 3.0, 12.0, 13.0, 13.0 ] },
                "east": { "texture": "#0", "uv": [ 13.0, 12.0, 14.0, 13.0 ] },
                "south": { "texture": "#0", "uv": [ 3.0, 12.0, 13.0, 13.0 ] },
                "west": { "texture": "#0", "uv": [ 2.0, 12.0, 3.0, 13.0 ] },
                "up": { "texture": "#-1", "uv": [ 0.0, 0.0, 10.0, 1.0 ] },
                "down": { "texture": "#0", "uv": [ 3.0, 12.0, 13.0, 13.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 2.0, 3.0, 8.0 ], 
            "to": [ 14.0, 4.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 2.0, 11.0, 14.0, 12.0 ] },
                "east": { "texture": "#0", "uv": [ 14.0, 11.0, 15.0, 12.0 ] },
                "south": { "texture": "#0", "uv": [ 2.0, 11.0, 14.0, 12.0 ] },
                "west": { "texture": "#0", "uv": [ 1.0, 11.0, 2.0, 12.0 ] },
                "up": { "texture": "#-1", "uv": [ 0.0, 0.0, 12.0, 1.0 ] },
                "down": { "texture": "#0", "uv": [ 2.0, 11.0, 14.0, 12.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 1.0, 4.0, 8.0 ], 
            "to": [ 15.0, 14.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 1.0, 1.0, 15.0, 11.0 ] },
                "east": { "texture": "#0", "uv": [ 14.0, 2.0, 15.0, 12.0 ] },
                "south": { "texture": "#0", "uv": [ 1.0, 1.0, 15.0, 11.0 ] },
                "west": { "texture": "#0", "uv": [ 1.0, 12.0, 2.0, 2.0 ] },
                "up": { "texture": "#0", "uv": [ 2.0, 2.0, 15.0, 1.0 ] },
                "down": { "texture": "#0", "uv": [ 1.0, 11.0, 15.0, 12.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 2.0, 14.0, 8.0 ], 
            "to": [ 14.0, 15.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 2.0, 1.0, 14.0, 2.0 ] },
                "east": { "texture": "#0", "uv": [ 14.0, 1.0, 15.0, 2.0 ] },
                "south": { "texture": "#0", "uv": [ 2.0, 1.0, 14.0, 2.0 ] },
                "west": { "texture": "#0", "uv": [ 1.0, 1.0, 2.0, 2.0 ] },
                "up": { "texture": "#0", "uv": [ 2.0, 1.0, 14.0, 2.0 ] },
                "down": { "texture": "#-1", "uv": [ 0.0, 0.0, 12.0, 1.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 7.0, 6.0, 4.0 ], 
            "to": [ 9.0, 7.0, 8.0 ], 
            "faces": {
                "north": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 1.0 ] },
                "east": { "texture": "#1", "uv": [ 1.0, 14.0, 5.0, 15.0 ] },
                "south": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 1.0 ] },
                "west": { "texture": "#1", "uv": [ 1.0, 14.0, 5.0, 15.0 ] },
                "up": { "texture": "#1", "uv": [ 1.0, 1.0, 3.0, 5.0 ] },
                "down": { "texture": "#1", "uv": [ 1.0, 1.0, 3.0, 5.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 7.0, 11.0, 4.0 ], 
            "to": [ 9.0, 12.0, 8.0 ], 
            "faces": {
                "north": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 1.0 ] },
                "east": { "texture": "#1", "uv": [ 1.0, 11.0, 5.0, 12.0 ] },
                "south": { "texture": "#-1", "uv": [ 0.0, 0.0, 2.0, 1.0 ] },
                "west": { "texture": "#1", "uv": [ 1.0, 11.0, 5.0, 12.0 ] },
                "up": { "texture": "#1", "uv": [ 2.0, 2.0, 4.0, 6.0 ] },
                "down": { "texture": "#1", "uv": [ 1.0, 1.0, 3.0, 5.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 7.0, 6.0, 3.0 ], 
            "to": [ 9.0, 12.0, 4.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 1.0, 11.0, 3.0, 17.0 ] },
                "east": { "texture": "#1", "uv": [ 3.0, 11.0, 4.0, 17.0 ] },
                "south": { "texture": "#1", "uv": [ 1.0, 2.0, 3.0, 8.0 ] },
                "west": { "texture": "#1", "uv": [ 3.0, 11.0, 4.0, 17.0 ] },
                "up": { "texture": "#1", "uv": [ 2.0, 1.0, 4.0, 2.0 ] },
                "down": { "texture": "#1", "uv": [ 1.0, 1.0, 3.0, 2.0 ] }
            }
        }
    ],
    "display": {
        "thirdperson_righthand": {
            "rotation": [ 0, 90, 0 ],
            "translation": [ 2, -3, 3 ],
            "scale": [ 1, 1, 1 ]
        },
        "thirdperson_lefthand": {
            "rotation": [ 0, 90, 0 ],
            "translation": [ 2, -3, 3 ],
            "scale": [ 1, 1, 1 ]
        },
        "firstperson_righthand": {
            "rotation": [ 0, 180, 5 ],
            "translation": [ -4, -1, 6 ],
            "scale": [ 1, 1, 1 ]
        },
        "firstperson_lefthand": {
            "rotation": [ 0, 180, 5 ],
            "translation": [ -2, -2, 6 ],
            "scale": [ 1.25, 1.25, 1.25 ]
        },
        "gui": {
            "rotation": [ 15, -25, -5 ],
            "translation": [ 2, 1, 0 ],
            "scale": [ 1, 1, 1 ]
        },
        "fixed": {
            "rotation": [ 0, 180, 0 ],
            "translation": [ 0, 0, -2],
            "scale":[ 1, 1, 1]
        },
        "ground": {
            "rotation": [ 0, 0, 0 ],
            "translation": [ 0, 5, 0],
            "scale":[ 0.5, 0.5, 0.5]
        }
    },
    "overrides": [
        {
            "predicate": {
                "blocking": 1
            },
            "model": "p455w0rdsthings:item/p455w0rdshield_blocking"
        }
    ]
}

 

models/item/p455w0rdshield_blocking.json

{
    "display": {
        "thirdperson_righthand": {
            "rotation": [ 45, 135, 0 ],
            "translation": [ 3.51, 11, -2 ],
            "scale": [ 1, 1, 1 ]
        },
        "thirdperson_lefthand": {
            "rotation": [ 45, 135, 0 ],
            "translation": [ 13.51, 3, 5 ],
            "scale": [ 1, 1, 1 ]
        },
        "firstperson_righthand": {
            "rotation": [ 0, 180, -5 ],
            "translation": [ -15, 5, -11 ],
            "scale": [ 1.25, 1.25, 1.25 ]
        },
        "firstperson_lefthand": {
            "rotation": [ 0, 180, -5 ],
            "translation": [ 5, 5, -11 ],
            "scale": [ 1.25, 1.25, 1.25 ]
        },
        "gui": {
            "rotation": [ 15, -25, -5 ],
            "translation": [ 2, 3, 0 ],
            "scale": [ 0.65, 0.65, 0.65 ]
        }
    }
}

 

More possibly relevant info:

Item is registered in commonproxy on preinit

Custom model is loaded via ModelLoader.setCustomModelResourceLocation in clientproxy on preinit

Any help/guidence is greatly appreciated =]

 

============================

Okay, so I figured out why the shield isn't taking damage. It's tracked in EntityPlayer and doesn't check for instanceof, rather it checks for Items.shield. I'm now going to work on figuring out which event bus I should use to do the detection and will post back if/when I figure it out for anyone else who might have this same question.

Link to comment
Share on other sites

Figured I'd post my success thus far. I've solved the shield damage issue. As I stated in the edit of the OP, the shield damage is handled in EntityPlayer, so therefore an event handler must be used to calculate it for our custom shield. The event handler needed in this case is LivingAttackEvent. Here is my resulting code in which the shield takes damage. Feel free to criticize/inform me of better ways of doing this or if I have done something in error.

 

@SubscribeEvent
public void attackEvent(LivingAttackEvent e) {
	float damage = e.getAmount();
	ItemStack activeItemStack;
	EntityPlayer player;
	if (!(e.getEntityLiving() instanceof EntityPlayer)) {
		return;
	}
	player = (EntityPlayer) e.getEntityLiving();
	if (player.getActiveItemStack() == null) {
		return;
	}
	activeItemStack = player.getActiveItemStack();

	if (damage > 0.0F && activeItemStack != null && activeItemStack.getItem() == ModItems.ItemShield) {
		int i = 1 + MathHelper.floor_float(damage);
		activeItemStack.damageItem(i, player);

		if (activeItemStack.stackSize <= 0) {
			EnumHand enumhand = player.getActiveHand();
			net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, activeItemStack, enumhand);

			if (enumhand == EnumHand.MAIN_HAND) {
				player.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, (ItemStack) null);
			}
			else {
				player.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, (ItemStack) null);
			}

			activeItemStack = null;
			if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
				player.playSound(SoundEvents.item_shield_break, 0.8F, 0.8F + player.worldObj.rand.nextFloat() * 0.4F);
			}
		}
	}
}

 

Replace ModItems.ItemShield with your mod's item.

Something else I've discovered worth mentioning: There is now a single forge event bus! FMLCommonHandler's bus is now deprecated, so use MinecraftForge.EVENT_BUS from here forward =]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Crash with the error: The game crashed whilst exception ticking world Error: java.util.ConcurrentModificationException pastebin crashlog the game worked for like 24h, then started to receive this error. Things I've tried: removing optifine or other performace mods. tried different versions (older) of the pack. set true to remove error entities and tiles in forge.cfg asked for help on the sevtech github, they said its fixed, its not. tried a different pc and still crashed happened only one time on another map although i cant make it happen again on that map.
    • no this one https://pastebin.com/5uMxHeWf
    • I am in such a mess. I have lost over 4.7m due to a scammer... It started as bank wires and then bitcoin. it is hard to imagine but it is true and can send any proof, then I tried to use a couple of recovery companies and was as well. Graphic design has been more than just a hobby for me since high school—it has become a thriving career. Starting in my parents' garage, I eventually expanded to my office, running a successful graphic design business. However, like many, I faced the need to diversify my investments due to inflation. This led me to invest 60.16 in Bitcoin, a decision that paid off handsomely as my investment grew to 4.7m over time. This financial windfall allowed me to upgrade my equipment and take on more ambitious projects, furthering the growth of my business. Unfortunately, my excitement was abruptly cut short when I fell victim to a hacking incident. Malware infected my computer, giving hackers access to my Bitcoin wallet. The devastation of potentially losing all my hard-earned savings and plans weighed heavily on me. At this dire moment, a fellow designer suggested Linux Cyber Security Company as a potential solution. Desperate for a lifeline, I reached out to them, hoping for a miracle. The response from Linux Cyber Security Company was prompt, incredibly professional, and effective. Their team quickly traced the hacker’s activities and recovered most of my funds, alleviating a significant amount of stress and uncertainty. Beyond the recovery, they took the time to educate me on essential practices to secure my Bitcoin holdings better. They emphasized using antivirus software to prevent malware infections, avoiding suspicious downloads, and the added security provided by hardware wallets. This experience served as a critical wake-up call for me. It highlighted the vulnerabilities inherent in digital assets and underscored the importance of robust security measures. Thanks to the guidance and expertise of Linux Cyber Security Company, I now feel more equipped to protect my digital assets proactively. Their insights have empowered me to implement stronger security protocols in my business operations and personal finances alike. With my Bitcoin funds securely recovered and a newfound understanding of digital security best practices, I am more confident in navigating future challenges. This journey has reinforced my commitment to safeguarding my hard-earned assets and leveraging technology responsibly. I am optimistic about the growth opportunities ahead, creatively in graphic design and prudently in investment strategies. In conclusion, while the hacking incident was a setback, it ultimately became a catalyst for enhancing my digital security awareness and resilience. I am grateful to Linux Cyber Security Company for their expertise and support during a challenging time, enabling me to continue pursuing my passion for graphic design with renewed confidence and financial stability. Contact a professional company I am sure they can help you with your case too, Website [www.linuxcybersecurity.com Email the team; info@)(linuxcybersecurity.com
    • https://pastebin.com/B2HnBZTa
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.