Fabric API

Fabric API

106M Downloads

Player ticking out while standing on poisonous block

Pironielsje opened this issue ยท 4 comments

commented

Hi, I'm making a mod with a block that damages you when you step on it except when you have special boots on your feet. But whenever i step on the block i get ticked out.

My code:

package net.pironielsje.informatiekunde.blocks;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.pironielsje.informatiekunde.ModItems;

public class VenomDirt extends Block {

    public VenomDirt(Settings settings) {
        super(settings);
    }

    @Override
    public void onSteppedOn(World world, BlockPos pos, Entity entity) {
        super.onSteppedOn(world, pos, entity);

        if (entity instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) entity;
            if(player.inventory.getArmorStack(4) != ModItems.HAZMAT_BOOTS.getDefaultStack()){
                    player.damage(DamageSource.WITHER, 1.5f);
            }
        }
    }
}

commented

For such practical questions, Discord should be preferred to get a quick answer.

commented

This is not a mod development help forum.
It is for bug reports related to the fabric api.
Use the discussions tab or discord to ask for help.

commented

You need to compare the item of the leg stack with <snip>.getArmorStack(4).isOf(ModItems.HAZMAT_BOOTS) instead of comparing the item stack references, which will always fail (getDefaultStack creates a new instance since item stacks are mutable).

commented

You need to compare the item of the leg stack with <snip>.getArmorStack(4).isOf(ModItems.HAZMAT_BOOTS) instead of comparing the item stack references, which will always fail (getDefaultStack creates a new instance since item stacks are mutable).

I can't do player.getArmorStack there has to be an .inventory in between for 1.16.5