Jump to content

[1.7.10][SOLVED]'Melting' armor issues


The_Fireplace

Recommended Posts

I've created a set of armor that, if worn, will take damage when the player is on fire. However, when it is broken, a new one appears in the same armor slot as the one that was broken. The second problem with it is that it randomly repairs itself instead of taking damage. Here is my code:

 

public class IceArmor extends ItemArmor {

public IceArmor(ArmorMaterial p_i45325_1_, int p_i45325_2_, int p_i45325_3_) {
	super(p_i45325_1_, p_i45325_2_, p_i45325_3_);
}
@Override
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) {
	if(stack.getItem() == unbase.IceHelmet || stack.getItem() == unbase.IceChestplate || stack.getItem() == unbase.IceBoots) {
		return "unlogic:textures/models/armor/ice1.png";
	}
	if(stack.getItem() == unbase.IceLeggings) {
		return "unlogic:textures/models/armor/ice2.png";
	}
	return null;
}
private static int tickCounter = 0;
@Override
    public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
	ItemStack helmet = player.getCurrentArmor(3);
	ItemStack plate = player.getCurrentArmor(2);
	ItemStack legs = player.getCurrentArmor(1);
	ItemStack boots = player.getCurrentArmor(0);
	int a = 0; 
	int b = 0; 
	int c = 0; 
	int d = 0;
	if(helmet != null){
		if(helmet.getItem() == unbase.IceHelmet){
			a = 1;
		}else{
			a = 0;
		}
	}
	if(plate != null){
		if(plate.getItem() == unbase.IceChestplate){
			b = 1;
		}else{
			b = 0;
		}
	}
	if(legs != null){
		if(legs.getItem() == unbase.IceLeggings){
			c = 1;
		}else{
			c = 0;
		}
	}
	if(boots != null){
		if(boots.getItem() == unbase.IceBoots){
			d = 1;
		}else{
			d = 0;
		}
	}
	if(a+b+c+d > 0){
	player.addPotionEffect(new PotionEffect(Potion.fireResistance.getId(), 20));
	if((player.getDataWatcher().getWatchableObjectByte(0) & 1 << 0) != 0){
		tickCounter = tickCounter + 1;
		if(tickCounter >= 40){
			tickCounter = tickCounter - 40;
			if(a == 1){
				helmet.damageItem(4-(b+c+d), player);
				if(helmet.getItemDamage() <= 0){
					a = 0;
				}//TODO: Make it so it doesn't re-appear after breaking
			}
			if(b == 1){
				plate.damageItem(4-(a+c+d), player);
				if(helmet.getItemDamage() <= 0){
					b = 0;
				}//TODO: Make it so it doesn't re-appear after breaking
			}
			if(c == 1){
				legs.damageItem(4-(b+a+d), player);
				if(helmet.getItemDamage() <= 0){
					c = 0;
				}//TODO: Make it so it doesn't re-appear after breaking
			}
			if(d == 1){
				boots.damageItem(4-(b+c+a), player);
				if(helmet.getItemDamage() <= 0){
					d = 0;
				}//TODO: Make it so it doesn't re-appear after breaking
			}
		}
	}
	}
}
}

 

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

Hi

 

onArmorTick is called on the client side only (it's intended for animations / rendering updates).  You are doing damage etc on the client side, but not the server side, so the server just overwrites the client copy a short time later.

 

You need to move your damage logic into something that ticks on the server side.  For example, PlayerTickEvent - on the server side, each tick check the player inventory to see if they're burning and wearing the armour and if so do your damage to the armour there.

 

-TGG

 

 

Link to comment
Share on other sites

onArmorTick is called on the client side only (it's intended for animations / rendering updates).
That is not actually true. It fires on both sides.

Hi DieSieben

 

Are you sure?  The only caller appears to be InventoryPlayer.decrementAnimations(), which says

    /**

    * Decrement the number of animations remaining. Only called on client side. This is used to handle the animation of

    * receiving a block.

    */

 

Let's see what a breakpoint in my debugger says...

[....]

Ah well you're right, it breaks on both client and server.

 

Sorry about that Fireplace.

onArmorTick() is probably fine.  I'd suggest wrapping your damage code in

if (!world.isRemote) {

}

and getting rid of the datawatcher (you don't need it on the server (not even sure it works on server), use isBurning() instead) and seeing if that helps.

 

-TGG

Link to comment
Share on other sites

  • 2 weeks later...

onArmorTick is called on the client side only (it's intended for animations / rendering updates).
That is not actually true. It fires on both sides.

Hi DieSieben

 

Are you sure?  The only caller appears to be InventoryPlayer.decrementAnimations(), which says

    /**

    * Decrement the number of animations remaining. Only called on client side. This is used to handle the animation of

    * receiving a block.

    */

 

Let's see what a breakpoint in my debugger says...

[....]

Ah well you're right, it breaks on both client and server.

 

Sorry about that Fireplace.

onArmorTick() is probably fine.  I'd suggest wrapping your damage code in

if (!world.isRemote) {

}

and getting rid of the datawatcher (you don't need it on the server (not even sure it works on server), use isBurning() instead) and seeing if that helps.

 

-TGG

Ah, that makes sense. Fixed that part of it.

It still, instead of going away when broken, spawns back in the same slot again, fully restored. Anyone know why it is doing that?

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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