Jump to content

[SOLVED]Thrown Explosion Issues


dude22072

Recommended Posts

I finally made a throw-able explosion, but i have 2 issues:

1.when it explodes it will explode again 1 second later

2.The entity visually stays in the world and you can't get rid of it, not even exiting and reloading the world works.

 

EntityBomb.class:

ackage dudesmods.lozmod;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class EntityBomb extends EntityItem
{

    public EntityBomb(World world)
    {
        super(world);
        setSize(0.5F, 0.5F);
        yOffset = height / 2.0F;
        bounceFactor = 0.6;
        exploded = false;
        stopped = false;
        fuse = 100;
    }
    public EntityBomb(World world, double x, double y, double z, float yaw, float pitch, double force, int fuseLength)
    {
        this(world);

       setRotation(yaw, 0);
       double xHeading = -MathHelper.sin((yaw * 3.141593F) / 180F);
       double zHeading = MathHelper.cos((yaw * 3.141593F) / 180F);
        motionX = force*xHeading*MathHelper.cos((pitch / 180F) * 3.141593F);
        motionY = -force*MathHelper.sin((pitch / 180F) * 3.141593F);
        motionZ = force*zHeading*MathHelper.cos((pitch / 180F) * 3.141593F);

        setPosition(x+xHeading*0.8, y, z+zHeading*0.;
        prevPosX = posX;
        prevPosY = posY;
        prevPosZ = posZ;

        fuse = fuseLength;
    }
    public EntityBomb(World world, Entity entity)
    {
        this(world, entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch, 0.5, 50);
    }
    
    protected boolean canTriggerWalking()
    {
        return false;
    }

    public void onUpdate()
    {
        if(fuse-- <= 0)
        {
            explode();
        }
        if(!(stopped) && !(exploded))
        {
           double prevVelX = motionX;
          double prevVelY = motionY;
          double prevVelZ = motionZ;
           prevPosX = posX;
           prevPosY = posY;
           prevPosZ = posZ;
           moveEntity(motionX, motionY, motionZ);
    
           boolean collided = false;
         
           if(motionX!=prevVelX)
           {
              motionX = -prevVelX;
              collided = true;
           }
           if(motionZ!=prevVelZ)
           {
              motionZ = -prevVelZ;
           }
    
           if(motionY!=prevVelY)
           {
              motionY = -prevVelY;
              collided = true;
           }
           else
           {
              motionY -= 0.04;
           }
    
           if(collided)
           {
              motionX *= bounceFactor;
              motionY *= bounceFactor;
              motionZ *= bounceFactor;
           }
    
           motionX *= 0.99;
           motionY *= 0.99;
           motionZ *= 0.99;
           if(onGround && (motionX*motionX+motionY*motionY+motionZ*motionZ)<0.02)
           {
              stopped = true;
              motionX = 0;
              motionY = 0;
              motionZ = 0;
           }
        }
    }
    public void onCollideWithPlayer(EntityPlayer entityplayer)
    {
   
    }
    protected void explode()
    {
       if(!exploded)
       {
          exploded = true;
           worldObj.createExplosion(this, posX, posY, posZ, 5F, true);
       }
    }

    public boolean attackEntity(Entity entity, int i)
    {
       super.attackEntityFrom(DamageSource.causeThrownDamage(entity, entity), i);
       explode();
       return false;
    }
    public void writeEntityToNBT(NBTTagCompound nbttagcompound)
    {
       super.writeEntityToNBT(nbttagcompound);
        nbttagcompound.setByte("Fuse", (byte)fuse);
    }

    public void readEntityFromNBT(NBTTagCompound nbttagcompound)
    {
       super.readEntityFromNBT(nbttagcompound);
        fuse = nbttagcompound.getByte("Fuse");
    }
    double bounceFactor;
    int fuse;
    boolean exploded;
    boolean collided;
    boolean stopped;
    
    public ItemStack getEntityItem()
    {
	return new ItemStack(LOZmod.bomb);
    	
    }
}

 

ItemBomb.class:

package dudesmods.lozmod;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class ItemBomb extends Item {

public ItemBomb(int par1) {
	super(par1);
	setMaxStackSize(32);
	setCreativeTab(LOZmod.tabLozMod);
	}

public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {

	if(!entityplayer.capabilities.isCreativeMode) {
		--itemstack.stackSize;
	}

	if (!world.isRemote) {
		world.spawnEntityInWorld(new EntityBomb(world, entityplayer));
	}

	return itemstack;
}


}

 

 

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have a problem, I am trying to put two different effects to two different armors but when I run it only the emerald armor effect works. This is the code public class ModArmorItem extends ArmorItem{ private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.HERO_OF_THE_VILLAGE,200, 1,false,false, true)) .put(ModArmorMaterials.OBSIDIAN, new MobEffectInstance(MobEffects.FIRE_RESISTANCE,200, 1,false,false, true)).build(); public ModArmorItem(ArmorMaterial pMaterial, Type pType, Properties pProperties) { super(pMaterial, pType, pProperties); } @Override public void onArmorTick(ItemStack stack, Level world, Player player){ if (!world.isClientSide()) { if (hasFullSuitOfArmorOn(player)) { evaluateArmorEffects(player); } } } private void evaluateArmorEffects(Player player) { for (Map.Entry<ArmorMaterial,MobEffectInstance> entry : MATERIAL_TO_EFFECT_MAP.entrySet()){ ArmorMaterial mapArmorMaterial = entry.getKey(); MobEffectInstance mapStatusEffect = entry.getValue(); if (hasCorrectArmorOn(mapArmorMaterial, player)) { addStatusEffectForMaterial(player, mapArmorMaterial, mapStatusEffect); } } } private void addStatusEffectForMaterial(Player player, ArmorMaterial mapArmorMaterial, MobEffectInstance mapStatusEffect) { boolean hasPlayerEffect = player.hasEffect(mapStatusEffect.getEffect()); if (hasCorrectArmorOn(mapArmorMaterial, player) && !hasPlayerEffect) { player.addEffect(new MobEffectInstance(mapStatusEffect)); } } private boolean hasCorrectArmorOn(ArmorMaterial material, Player player) { for (ItemStack armorStack : player.getInventory().armor){ if (!(armorStack.getItem() instanceof ArmorItem)) { return false; } } ArmorItem helmet = ((ArmorItem)player.getInventory().getArmor(3).getItem()); ArmorItem breastplace = ((ArmorItem)player.getInventory().getArmor(2).getItem()); ArmorItem leggins = ((ArmorItem)player.getInventory().getArmor(1).getItem()); ArmorItem boots = ((ArmorItem)player.getInventory().getArmor(0).getItem()); return helmet.getMaterial() == material && breastplace.getMaterial() == material && leggins.getMaterial() == material && boots.getMaterial() == material; } private boolean hasFullSuitOfArmorOn(Player player){ ItemStack helmet = player.getInventory().getArmor(3); ItemStack breastplace = player.getInventory().getArmor(2); ItemStack leggins = player.getInventory().getArmor(1); ItemStack boots = player.getInventory().getArmor(0); return !helmet.isEmpty() && !breastplace.isEmpty() && !leggins.isEmpty() && !boots.isEmpty(); } } Also when I place two effects on the same armor, the game crashes. Here is the crash file. The code is the same, only this part is different   private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.HERO_OF_THE_VILLAGE,200, 1,false,false, true)) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.FIRE_RESISTANCE,200, 1,false,false, true)).build(); I hope you guys can help me. Thanks.
    • I removed all related embeddium and oculus mods, i just tested it by disconnecting and the error happened again. heres the report https://pastebin.com/1kcR5wAt   EDIT: i tried removing xaeros and also smoothboot thinking there may be an issue there, nothing, heres that report too. https://pastebin.com/zQS7i9rM
    • Hi, I need suggestions. I am a beginner in Minecraft Modding. I would like to apply custom effects to some armors, something like: more chance to drop seeds, change zombie awareness, drop more pieces of wood when chopping logs, and things like that. How would you recommend me to do it, is there any library that has something similar and which ones would you recommend me?.
    • "downloading minecraft server failed, invalid Checksum. try again, or manually place server.jar to skip download"    
    • You have to create an Entity class called PlayerPart and use multiple of them to make the different parts of the player. See EnderDragonPart.java source code. The green hitboxes of the dragon are all EnderDragonParts
  • Topics

×
×
  • Create New...

Important Information

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