Jump to content

Recommended Posts

Posted

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

Posted

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

 

 

Posted

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

  • 2 weeks later...
Posted

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

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello! I have been having a problem with Forgematica, Embeddium, Oculus, and create. I wanted to download litematica so I could see which blocks are in my creative mode build, so that I could collect them all in survival. However, litematica is a fabric mod. I found a port called forgematica, which I added (along with it's dependency) to my mods folder. I loaded into a new world, and built a structure. Then, I added a part from the create mod, and the game crashed instantly, with exit code -1. Thanks for any help! Crash Report and mods list: https://pastebin.com/rtzh6LAi
    • To say that losing 40,000 BTC was a devastating blow would be an understatement. It was an emotional and financial crisis that left me feeling hopeless and utterly lost. For weeks, I was trapped in a whirlwind of regret, second-guessing every decision that led me to that point. The fear that I would never be able to recover such a significant sum of cryptocurrency consumed me, and with each passing day, my despair deepened. I had all but given up on ever regaining my wealth. Then I happened to stumble onto Tech Cyber Force Recovery. In the beginning, I was hesitant. It looked too good to be true: could someone get back so much of their lost Bitcoin? After trying several different approaches and programs without success, I was hesitant to put my trust in another recovery agency. However, I changed my mind after reading Tech Cyber Force Recovery's stellar reviews and reputation. Reaching out to their team was a risk I made. They were courteous and professional from the first time I got in touch with them. I felt like I wasn't just another case to be solved by the staff at Tech Cyber Force Recovery; they truly cared about getting me my lost Bitcoin back. They listened carefully to my circumstances and guided me through each stage, giving me succinct and understandable explanations as I went. Their passion gave me new hope, and their openness instantly made me feel better. As the recovery process began, I still had my doubts, but I knew I had placed my trust in the right hands. The Tech Cyber Force Recovery team kept me informed and updated on their progress, ensuring I never felt in the dark. Despite the complexity of my case, they worked tirelessly, and their expertise became evident at every turn. The level of professionalism and attention to detail they demonstrated throughout the process was beyond impressive. And then, after what felt like an eternity of anticipation, the moment I had been waiting for arrived. I received the news that my 40,000 BTC had been successfully recovered. It was hard to believe at first—it felt like a dream. The weight that had been dragging me down for so long was suddenly lifted, and I could breathe again. The financial loss I had feared would define my future was no longer a reality. I can’t fully express the emotions I felt during that moment. It was a mix of relief, joy, and an overwhelming sense of gratitude. I had gone from a place of utter despair to a complete resurgence of wealth, both emotionally and financially. The Tech Cyber Force Recovery team didn’t just restore my Bitcoin—they restored my faith in the possibility of recovery and gave me back something far more valuable: peace of mind. I will urge anyone in this same predicament to.  
    • Have you found a modder for this vehicle project? Because it will be really hard and I want to know that hero who can create all this
    • and what?????????
  • Topics

×
×
  • Create New...

Important Information

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