Jump to content

Recommended Posts

Posted

Hey, i want to create a new bar above the armor that displays the players armor weight. I cant find any good tutorials on this at all, and would really appreciate some help, examples encouraged. Heres my current code for applying armor weight and such:

 

package MinecraftRPGOverhaul.items;

import java.awt.List;
import java.util.ArrayList;
import java.util.Arrays;

import cpw.mods.fml.common.ObfuscationReflectionHelper;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.PlayerCapabilities;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;

public class ModArmor extends ItemArmor{

//set the different weight classes
private static final float DIAMOND = 6.25f;
private static final float IRON = 5.00f;
private static final float GOLD = 3.75f;
private static final float CHAIN = 2.50f;
private static final float LEATHER = 1.25f;

//weight for each armor piece
private static float bootWeight = 0.0f;
private static float chestplateWeight = 0.0f;
private static float helmetWeight = 0.0f;
private static float leggingWeight = 0.0f;

//total armor weight
public static float totalWeight = 0.0f;

public static Item diamondArmor[] = new Item[] { 
	Items.diamond_boots, 
	Items.diamond_chestplate, 
	Items.diamond_leggings, 
	Items.diamond_helmet };

public static Item ironArmor[] = new Item[] { 
	Items.iron_boots, 
	Items.iron_chestplate, 
	Items.iron_leggings, 
	Items.iron_helmet };

public static Item goldArmor[] = new Item[] { 
	Items.golden_boots, 
	Items.golden_chestplate, 
	Items.golden_leggings, 
	Items.golden_helmet };

public static Item chainArmor[] = new Item[] { 
	Items.chainmail_boots, 
	Items.chainmail_chestplate, 
	Items.chainmail_leggings, 
	Items.chainmail_helmet };
public static Item leatherArmor[] = new Item[] { 
	Items.leather_boots, 
	Items.leather_chestplate, 
	Items.leather_leggings, 
	Items.leather_helmet };

public String textureName; //The texture name, the name is passed in via the 'ModArmor' method

public ModArmor(String unlocalizedName, ArmorMaterial material, String textureName, int type){ //ModArmor method, passes in all pertinent information to create a piece of armor
    
	super(material, 0, type);
    this.textureName = textureName;
    this.setTextureName(unlocalizedName);
}

@Override
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type){ //getArmorTexture method, uses previous information passed in to assure you have the right texture

	return "rpgmod" + ":armor/" + this.textureName + "_" + (this.armorType == 2 ? "2" : "1") + ".png";

}

public static float armorCall(EntityPlayer player) {

	totalWeight = setCurrentArmorWeight(player);

    return (((100f - totalWeight) / 1000));
    

}

public static float setCurrentArmorWeight(EntityPlayer player) {

	player.capabilities.setFlySpeed(0);

		if (player.getCurrentArmor(0) != null) {
			for(int x = 0; x < 4; x = x+1) {
				if (player.getCurrentArmor(0).getItem().equals(diamondArmor[x])) {					
					bootWeight = DIAMOND;			
				}
				if (player.getCurrentArmor(0).getItem().equals(ironArmor[x])) {					
					bootWeight = IRON;			
				}
				if (player.getCurrentArmor(0).getItem().equals(goldArmor[x])) {					
					bootWeight = GOLD;			
				}
				if (player.getCurrentArmor(0).getItem().equals(chainArmor[x])) {					
					bootWeight = CHAIN;			
				}
				if (player.getCurrentArmor(0).getItem().equals(leatherArmor[x])) {					
					bootWeight = LEATHER;			
				}
			}
		}

		else {
			bootWeight = 0;
		}
		if (player.getCurrentArmor(1) != null) {
			for(int x = 0; x < 4; x = x+1) {
				if (player.getCurrentArmor(1).getItem().equals(diamondArmor[x])) {					
					leggingWeight = DIAMOND;			
				}
				if (player.getCurrentArmor(1).getItem().equals(ironArmor[x])) {					
					leggingWeight = IRON;			
				}
				if (player.getCurrentArmor(1).getItem().equals(goldArmor[x])) {					
					leggingWeight = GOLD;			
				}
				if (player.getCurrentArmor(1).getItem().equals(chainArmor[x])) {					
					leggingWeight = CHAIN;			
				}
				if (player.getCurrentArmor(1).getItem().equals(leatherArmor[x])) {					
					leggingWeight = LEATHER;			
				}
			}
		}
			else {
				leggingWeight = 0;

		}
		if (player.getCurrentArmor(2) != null) {
			for(int x = 0; x < 4; x = x+1) {
				if (player.getCurrentArmor(2).getItem().equals(diamondArmor[x])) {					
					chestplateWeight = DIAMOND;			
				}
				if (player.getCurrentArmor(2).getItem().equals(ironArmor[x])) {					
					chestplateWeight = IRON;			
				}
				if (player.getCurrentArmor(2).getItem().equals(goldArmor[x])) {					
					chestplateWeight = GOLD;			
				}
				if (player.getCurrentArmor(2).getItem().equals(chainArmor[x])) {					
					chestplateWeight = CHAIN;			
				}
				if (player.getCurrentArmor(2).getItem().equals(leatherArmor[x])) {					
					chestplateWeight = LEATHER;			
				}
			}
		}
			else {
				chestplateWeight = 0;

		}
		if (player.getCurrentArmor(3) != null) {
			for(int x = 0; x < 4; x = x+1) {
				if (player.getCurrentArmor(3).getItem().equals(diamondArmor[x])) {					
					helmetWeight = DIAMOND;			
				}
				if (player.getCurrentArmor(3).getItem().equals(ironArmor[x])) {					
					helmetWeight = IRON;			
				}
				if (player.getCurrentArmor(3).getItem().equals(goldArmor[x])) {					
					helmetWeight = GOLD;			
				}
				if (player.getCurrentArmor(3).getItem().equals(chainArmor[x])) {					
					helmetWeight = CHAIN;			
				}
				if (player.getCurrentArmor(3).getItem().equals(leatherArmor[x])) {					
					helmetWeight = LEATHER;			
				}
			}
		}
			else {
				helmetWeight = 0;

		}

		return bootWeight + helmetWeight + chestplateWeight
				+ leggingWeight;

}

}

 

And heres the event that modifies the players speed and a little test GUI i did:

 

package MinecraftRPGOverhaul.events;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.PlayerCapabilities;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import MinecraftRPGOverhaul.ModGUI.ModGUI;
import MinecraftRPGOverhaul.items.ModArmor;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;

public class ModEventHandler {

@SubscribeEvent
public void onEntityUpdate(PlayerTickEvent event) {

	event.player.capabilities.setPlayerWalkSpeed(ModArmor.armorCall(event.player));
	System.out.println((ModArmor.armorCall(event.player)));

}

@SubscribeEvent
public void onOverlayRender(RenderGameOverlayEvent event) {

	if (event.type == RenderGameOverlayEvent.ElementType.ALL) {
		FMLClientHandler.instance().getClient().fontRenderer.drawStringWithShadow("Armor Weight(Speed): " + String.format("%.2f", (100 - ModArmor.totalWeight)) + " Percent", 0, 0,16777215);
	}
}

}

 

I know its not the best code but im still figuring things out, I believe currently it wouldn't work with SMP but thats okay for now! Basically i want to have a bar that has 10 little weights, and for ever 2.5 "weight" (The totalWeight variable), i would like to display half a GUI weight as a visual representation! If someone could help me figure this out or point me to a tutorial that is more relevant to this, then that would be great!

 

Thanks in advance as i know its quite the big question/undertaking.

Posted

That only seems to be events, which i do know how to use. I need help with how to render and such! Thanks though, I bookmarked it in-case i ever need it!

 

Edit: By know how to use events, i mean i know how to use the render event and such, I just don't know how to create a functioning bar akin to the armor bar.

Posted

That only seems to be events, which i do know how to use. I need help with how to render and such! Thanks though, I bookmarked it in-case i ever need it!

 

Edit: By know how to use events, i mean i know how to use the render event and such, I just don't know how to create a functioning bar akin to the armor bar.

You didn't read the post did you?

 

The post has the extended properties tutorial below it and how to make the gui overlay.

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

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.