Jump to content

Recommended Posts

Posted

Hey guys im trying to add a bunch of cosmetic armor slots to the player, where if there is an armor present it will override your actual armor texture. so you can wear the fancy armor for show and wear your normal armor for its effectiveness.

 

i found the cosmetic armor reworked mod, and looked at its source code to get an idea of how they did it link to its source.

but it feels very hacky to me and not a good way to go about it. so im hoping anyone here knows a better way.

 

ItemStackHandler localInv = new ItemStackHandler (4);
		
		private void SwapInv (EntityPlayer p) {
			if (p.hasCapability(CapabilityCosmeticArmor.Cosmetic_Armor_Capability, null) && p.inventory.armorInventory.size() <= 4 ) {
		    	   IItemHandler cosInv = p.getCapability(CapabilityCosmeticArmor.Cosmetic_Armor_Capability, null);
		    	   for (int i = 0; i < cosInv.getSlots(); i++) {
		    		   localInv.insertItem(i, cosInv.extractItem(i, 1, false), false);
		    	   }
		    	   
		    	   NonNullList<ItemStack> armor =  p.inventory.armorInventory;
		    	   for (int i = 0; i < armor.size(); i++) {
		    		   cosInv.insertItem(cosInv.getSlots() - 1 - i, armor.get(i), false);
		    	   }
		    	   
		    	   for (int i = 0; i < localInv.getSlots(); i++) {
		    		   armor.set(localInv.getSlots() - i - 1, localInv.extractItem(i, 1, false));
		    	   }
		       }
		}
		
		@SubscribeEvent
	    public void handleCanceledEvent(RenderPlayerEvent.Pre event)
	    {
			
	    }

	    @SubscribeEvent
	    public void handleEvent(RenderPlayerEvent.Post event)
	    {
			SwapInv(event.getEntityPlayer());

	        
	    }

	    @SubscribeEvent
	    public void handleEvent(RenderPlayerEvent.Pre event)
	    {
			SwapInv(event.getEntityPlayer());


	    }

 

this is my current code, and it kinda works. it has some sync issues but thats because i havent added the packet handling yet for the Capability i added. to sync it between clients.

 

2018-02-22_03_04_09.thumb.png.7acd285bd1e476757003a505bed256e5.png

this is what it looks like in game, i render the armor on the right and i have the armor on the left equipped.but right now every time the render player event gets called the items in those slots get swapped and then swapped back after. is there a smoother way of doing this?

 

 

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.

Announcements



×
×
  • Create New...

Important Information

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