Jump to content

Recommended Posts

Posted

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]

Posted

Anyone ):

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]

Posted

Fixed - forgot to use worldObj.removeEntity(this);

 

-~*Locked*~-

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]

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • You would have better results asking a more specific question. What have you done? What exactly do you need help with? Please also read the FAQ regarding posting logs.
    • Hi, this is my second post with the same content as no one answered this and it's been a long time since I made the last post, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod I've already tried it with different shaders, but it didn't work with any of them and I really want to add support for shaders Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Same issue - I have no idea
    • I am trying to develop a modpack for me and my friends to use on our server. Does anyone know how to develop a modpack for a server or could they help take a look at my modpack to potentially help at all?
    • un server de armas realista.  
  • Topics

×
×
  • Create New...

Important Information

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