MC Modding
Please register and join the community!

[1.8.1] Explosive Block

View previous topic View next topic Go down

[1.8.1] Explosive Block

Post by Strengthowns on Sun Oct 16, 2011 6:44 am

Explosive Block
Spoiler:
mod_Namehere
Code:
package net.minecraft.src;

import java.util.*;

public class mod_Namehere extends BaseMod
{
    public static final Block Namehere;

    public mod_Namehere()
    {
      ModLoader.AddName(Namehere, "Namehere Explosive");
        ModLoader.RegisterBlock(Namehere);
    }
   
   public void AddRenderer(Map map)
    {
        map.put(net.minecraft.src.EntityNameherePrimed.class, new RenderNameherePrimed());
    }
   
   public String Version()
    {
        return "1.8.1";
    }

    static
    {
        Namehere = (new BlockNamehere(170, ModLoader.addOverride("/terrain.png", "/Namehere.png"))).setHardness(0.0F).setStepSound(Block.soundGrassFootstep).setBlockName("Namehere");   
    }
}

BlockNamehere
Code:
package net.minecraft.src;

import java.util.Random;

public class BlockNamehere extends Block
{

    public BlockNamehere(int i, int j)
    {
        super(i, j, Material.tnt);
    }

    public void onBlockAdded(World world, int i, int j, int k)
    {
        super.onBlockAdded(world, i, j, k);
        if(world.isBlockIndirectlyGettingPowered(i, j, k))
        {
            onBlockDestroyedByPlayer(world, i, j, k, 1);
            world.setBlockWithNotify(i, j, k, 0);
        }
    }

    public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
        if(l > 0 && Block.blocksList[l].canProvidePower() && world.isBlockIndirectlyGettingPowered(i, j, k))
        {
            onBlockDestroyedByPlayer(world, i, j, k, 1);
            world.setBlockWithNotify(i, j, k, 0);
        }
    }

    public int quantityDropped(Random random)
    {
        return 0;
    }

    public void onBlockDestroyedByExplosion(World world, int i, int j, int k)
    {
        EntityNameherePrimed entitynamehereprimed = new EntityNameherePrimed(world, (float)i + 0.5F, (float)j + 0.5F, (float)k + 0.5F);
        entitynamehereprimed.fuse = world.rand.nextInt(entitynamehereprimed.fuse / 4) + entitynamehereprimed.fuse / 8;
        world.entityJoinedWorld(entitynamehereprimed);
    }

    public void onBlockDestroyedByPlayer(World world, int i, int j, int k, int l)
    {
        if(world.multiplayerWorld)
        {
            return;
        }
        if((l & 1) == 0)
        {
            dropBlockAsItem_do(world, i, j, k, new ItemStack(mod_Namehere.Namehere.blockID, 1, 0));
        } else
        {
            EntityNameherePrimed entitynamehereprimed = new EntityNameherePrimed(world, (float)i + 0.5F, (float)j + 0.5F, (float)k + 0.5F);
            world.entityJoinedWorld(entitynamehereprimed);
            world.playSoundAtEntity(entitynamehereprimed, "random.fuse", 1.0F, 1.0F);
        }
    }

    public void onBlockClicked(World world, int i, int j, int k, EntityPlayer entityplayer)
    {
        if(entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().itemID == Item.flintAndSteel.shiftedIndex)
        {
            world.setBlockMetadata(i, j, k, 1);
        }
        super.onBlockClicked(world, i, j, k, entityplayer);
    }

    public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
    {
        return super.blockActivated(world, i, j, k, entityplayer);
    }
}

EntityNameherePrimed
Code:
package net.minecraft.src;

public class EntityNameherePrimed extends Entity
{

    public EntityNameherePrimed(World world)
    {
        super(world);
        fuse = 0;
        preventEntitySpawning = true;
        setSize(0.98F, 0.98F);
        yOffset = height / 2.0F;
    }

    public EntityNameherePrimed(World world, double d, double d1, double d2)
    {
        this(world);
        setPosition(d, d1, d2);
        float f = (float)(Math.random() * 3.1415927410125732D * 2D);
        motionX = -MathHelper.sin((f * 3.141593F) / 180F) * 0.02F;
        motionY = 0.20000000298023224D;
        motionZ = -MathHelper.cos((f * 3.141593F) / 180F) * 0.02F;
        fuse = 80;
        prevPosX = d;
        prevPosY = d1;
        prevPosZ = d2;
    }

    protected void entityInit()
    {
    }

    protected boolean canTriggerWalking()
    {
        return false;
    }

    public boolean canBeCollidedWith()
    {
        return !isDead;
    }

    public void onUpdate()
    {
        prevPosX = posX;
        prevPosY = posY;
        prevPosZ = posZ;
        motionY -= 0.039999999105930328D;
        moveEntity(motionX, motionY, motionZ);
        motionX *= 0.98000001907348633D;
        motionY *= 0.98000001907348633D;
        motionZ *= 0.98000001907348633D;
        if(onGround)
        {
            motionX *= 0.69999998807907104D;
            motionZ *= 0.69999998807907104D;
            motionY *= -0.5D;
        }
        if(fuse-- <= 0)
        {
            if(!worldObj.multiplayerWorld)
            {
                setEntityDead();
                explode();
            } else
            {
                setEntityDead();
            }
        } else
        {
            worldObj.spawnParticle("smoke", posX, posY + 0.5D, posZ, 0.0D, 0.0D, 0.0D);
        }
    }

    private void explode()
    {
        float f = 9F;
        worldObj.createExplosion(null, posX, posY, posZ, f);
    }

    protected void writeEntityToNBT(NBTTagCompound nbttagcompound)
    {
        nbttagcompound.setByte("Fuse", (byte)fuse);
    }

    protected void readEntityFromNBT(NBTTagCompound nbttagcompound)
    {
        fuse = nbttagcompound.getByte("Fuse");
    }

    public float getShadowSize()
    {
        return 0.0F;
    }

    public int fuse;
}

RenderNameherePrimed
Code:
package net.minecraft.src;

import org.lwjgl.opengl.GL11;

public class RenderNameherePrimed extends Render
{

    public RenderNameherePrimed()
    {
        blockRenderer = new RenderBlocks();
        shadowSize = 0.5F;
    }

    public void func_153_a(EntityNameherePrimed entitynamehereprimed, double d, double d1, double d2, float f, float f1)
    {
        GL11.glPushMatrix();
        GL11.glTranslatef((float)d, (float)d1, (float)d2);
        if(((float)entitynamehereprimed.fuse - f1) + 1.0F < 10F)
        {
            float f2 = 1.0F - (((float)entitynamehereprimed.fuse - f1) + 1.0F) / 10F;
            if(f2 < 0.0F)
            {
                f2 = 0.0F;
            }
            if(f2 > 1.0F)
            {
                f2 = 1.0F;
            }
            f2 *= f2;
            f2 *= f2;
            float f4 = 1.0F + f2 * 0.3F;
            GL11.glScalef(f4, f4, f4);
        }
        float f3 = (1.0F - (((float)entitynamehereprimed.fuse - f1) + 1.0F) / 100F) * 0.8F;
        loadTexture("/terrain.png");
        blockRenderer.renderBlockOnInventory(mod_Namehere.Namehere, 0, entitynamehereprimed.getEntityBrightness(f1));
        if((entitynamehereprimed.fuse / 5) % 2 == 0)
        {
            GL11.glDisable(3553 /*GL_TEXTURE_2D*/);
            GL11.glDisable(2896 /*GL_LIGHTING*/);
            GL11.glEnable(3042 /*GL_BLEND*/);
            GL11.glBlendFunc(770, 772);
            GL11.glColor4f(1.0F, 1.0F, 1.0F, f3);
            blockRenderer.renderBlockOnInventory(mod_Namehere.Namehere, 0, 1.0F);
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            GL11.glDisable(3042 /*GL_BLEND*/);
            GL11.glEnable(2896 /*GL_LIGHTING*/);
            GL11.glEnable(3553 /*GL_TEXTURE_2D*/);
        }
        GL11.glPopMatrix();
    }

    public void doRender(Entity entity, double d, double d1, double d2, float f, float f1)
    {
        func_153_a((EntityNameherePrimed)entity, d, d1, d2, f, f1);
    }

    private RenderBlocks blockRenderer;
}

Help: mod_Namehere

1. Everything here is the same as normal.

2. The "AddRenderer" is just a way of making sure it loads the texture when the block is primed.

Help: BlockNamehere

1. Nothing important in here. Just change the "Namehere" parts.

2. Almost all of this code is just about it activating from redstone or switches etc.

Help: EntityNameherePrimed

1. A little bit in it has this: "fuse = 80;" Don't change the first one you see, change this one. This is how long it takes after activated to explode.

2. Scroll down the the "private void explode()" method. Change the 9F to how big you want it to explode.

3. Leave everything else unless you know what you're doing.

Help: RenderNameherePrimed

1. Everything here is just name-changing except for one thing.

2. Don't change the "loadTexture" part, as everything still works fine without changing it.
avatar
Strengthowns
Admin

Posts : 79
Join date : 2011-06-14
Location : Right here!

View user profile http://www.mcmodding.4umer.com

Back to top Go down

Re: [1.8.1] Explosive Block

Post by MrCreeper07 on Tue Nov 15, 2011 8:17 pm

where does the recipe go? and how would you combine the mod_.java file with the throwable explosion tutorial and the npc tutorial? Its all very complicated to me!!!
avatar
MrCreeper07
Member

Posts : 18
Join date : 2011-10-23

View user profile

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum