Jump to content

Recommended Posts

Posted

I'm developing a new block called crust. Basically it's the equivalent of ice melting to water where as crust melts to lava. It also has the properties of soulsand and netherrack, but I can't get it to stop melting into lava. Thoughts?

 

package com.lylac.podmod.block;

import static net.minecraftforge.common.util.ForgeDirection.UP;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockBreakable;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

import com.lylac.podmod.PODmod;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class Crust extends BlockBreakable{

public Crust(int id)
    {
    	super("Crust", Material.rock, false);
        setHardness(0.5F);
        setLightOpacity(15);
        setStepSound(soundTypeStone);
        setBlockTextureName(PODmod.MODID + ":crust");
        setCreativeTab(CreativeTabs.tabBlock);
        this.setTickRandomly(true);

    }

/**
     * Currently only called by fire when it is on top of this block.
     * Returning true will prevent the fire from naturally dying during updating.
     * Also prevents firing from dying from rain.
     *
     * @param world The current world
     * @param x The blocks X position
     * @param y The blocks Y position
     * @param z The blocks Z position
     * @param metadata The blocks current metadata
     * @param side The face that the fire is coming from
     * @return True if this block sustains fire, meaning it will never go out.
     */
    public boolean isFireSource(World world, int x, int y, int z, ForgeDirection side)
    {
        if (this == PODmod.Crust && side == UP)
        {
            return true;
        }
        return false;
    }
    
    /**
     * Soul Sand Code ~ For Slowness
     */
    
    /**
     * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
     * cleared to be reused)
     */
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_)
    {
        float f = 0.125F;
        return AxisAlignedBB.getAABBPool().getAABB((double)p_149668_2_, (double)p_149668_3_, (double)p_149668_4_, (double)(p_149668_2_ + 1), (double)((float)(p_149668_3_ + 1) - f), (double)(p_149668_4_ + 1));
    }

    /**
     * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
     */
    public void onEntityCollidedWithBlock (World par1World, int x, int y, int z, Entity entity)
    {
    	
        if (entity instanceof EntityPlayer)
        {
            //ItemStack stack = ((EntityPlayer) entity).inventory.getStackInSlot(36);
            //if (stack == null)
                entity.attackEntityFrom(DamageSource.inFire, 1);
        }
        else if (entity instanceof EntityLiving && !entity.isImmuneToFire())
        {
            entity.attackEntityFrom(DamageSource.inFire, 1);
        }
        
        entity.motionX *= 0.1D;
        entity.motionZ *= 0.1D;
    }
    
    /**
     * Ice Block Code ~ Melting into lava
     */
    
    /**
     * Returns which pass should this block be rendered on. 0 for solids and 1 for alpha
     */
    @SideOnly(Side.CLIENT)
    public int getRenderBlockPass()
    {
        return 0;
    }

    /**
     * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the
     * block and l is the block's subtype/damage.
     */
    public void harvestBlock(World p_149636_1_, EntityPlayer p_149636_2_, int p_149636_3_, int p_149636_4_, int p_149636_5_, int p_149636_6_)
    {
        p_149636_2_.addStat(StatList.mineBlockStatArray[block.getIdFromBlock(this)], 1);
        p_149636_2_.addExhaustion(0.025F);

        if (this.canSilkHarvest(p_149636_1_, p_149636_2_, p_149636_3_, p_149636_4_, p_149636_5_, p_149636_6_) && EnchantmentHelper.getSilkTouchModifier(p_149636_2_))
        {
            ItemStack itemstack = this.createStackedBlock(p_149636_6_);

            if (itemstack != null)
            {
                this.dropBlockAsItem(p_149636_1_, p_149636_3_, p_149636_4_, p_149636_5_, itemstack);
            }
        }
        else
        {
            if (p_149636_1_.provider.isHellWorld)//dont need this
            {
                p_149636_1_.setBlockToAir(p_149636_3_, p_149636_4_, p_149636_5_);
                return;
            }

            int i1 = EnchantmentHelper.getFortuneModifier(p_149636_2_);
            this.dropBlockAsItem(p_149636_1_, p_149636_3_, p_149636_4_, p_149636_5_, p_149636_6_, i1);
            Material material = p_149636_1_.getBlock(p_149636_3_, p_149636_4_ - 1, p_149636_5_).getMaterial();

            if (material.blocksMovement() || material.isLiquid())
            {
                p_149636_1_.setBlock(p_149636_3_, p_149636_4_, p_149636_5_, Blocks.flowing_lava);
            }
        }
    }

    /**
     * Returns the quantity of items to drop on block destruction.
     */
    public int quantityDropped(Random p_149745_1_)
    {
        return 0;
    }

    /**
     * Ticks the block if it's been scheduled
     */
    public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_)
    {
        if (p_149674_1_.getSavedLightValue(EnumSkyBlock.Block, p_149674_2_, p_149674_3_, p_149674_4_) > 11 - this.getLightOpacity())
        {
            if (p_149674_1_.provider.isHellWorld)//dont need this
            {
                p_149674_1_.setBlockToAir(p_149674_2_, p_149674_3_, p_149674_4_);
                return;
            }

            this.dropBlockAsItem(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_, p_149674_1_.getBlockMetadata(p_149674_2_, p_149674_3_, p_149674_4_), 0);
            p_149674_1_.setBlock(p_149674_2_, p_149674_3_, p_149674_4_, Blocks.lava);
        }
    }

    /**
     * Returns the mobility information of the block, 0 = free, 1 = can't push but can move over, 2 = total immobility
     * and stop pistons
     */
    public int getMobilityFlag()
    {
        return 0;
    }
    
}

 

(Sorry, img snippets don't seem to be working at the time of the post. Here is a link instead. Mind the texture bug, I'll have that fixed soon.)

 

https://24.media.tumblr.com/a1e594ad41b2a9807522ebfd59297ce9/tumblr_n5h217toyg1tnzqt4o1_500.png

Posted

if (p_149674_1_.getSavedLightValue(EnumSkyBlock.Block, p_149674_2_, p_149674_3_, p_149674_4_) > 11 - this.getLightOpacity())

 

You set the light opacity to 15 in your constructor, I'll let you do the math.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

That works, but I want the crust to melt at a light level of 14. (sorry for not clarifying before). There doesn't seem to be much for documentation out there on how ice works.

Posted

Like San said you are emitting a light level of 15 and your block melts at light level of 14. See the problem?

 

Light Level != Light Opacity!

It's just a math problem. Just check if the saved light value is >= 14

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

  • 2 weeks later...
Posted

Actually, getting rid of that stopped it. Also side note, it's a float int. Setting it to 15 with what I had there set the light level way beyond normal means. Using a value of 0.27F will set it to emit a level of 4, which adds a nice effect to the crust block.

 

width=500 height=281https://31.media.tumblr.com/1138f965af97e191009dd369b1c84d1d/tumblr_n5z82jAMGJ1tnzqt4o1_500.png[/img]

 

Is it too much that I am facinated by this? I mean this should be in the game.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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