Jump to content

[New Question] [1.5.2] Sand that Falls Up


Nethseaar
 Share

Recommended Posts

I'm trying to get my custom sand block to fall upwards, but changing things has zero effect on anything. I must be missing something obvious, but search as I might, I am not finding it. I've flipped what I thought were the relevant values from negative to positive, and even if that doesn't do what I want, I figure it ought to do something, but the block still acts just like normal sand. Is the normal sand entity being created, instead of mine?

 

Here's my code (red text is altered from sand's code EDIT: Or, ah, I suppose you can't change color in code tags):

 

Sand Block:

package nethseaar.bacon.blocks;

import java.util.Random;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSand;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityFallingSand;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import nethseaar.bacon.entities.EntityFallingAscender;

public class BlockUp extends BlockSand {

@SideOnly(Side.CLIENT)
    private Icon upTop;
@SideOnly(Side.CLIENT)
    private Icon upBottom;
    
        public BlockUp(int id, Material material) {
                super(id, material);
        }
        
        /**
         * If there is space to fall below will start this block falling
         */
        private void tryToFall(World par1World, int par2, int par3, int par4)
        {
            [color=red]if (canFallAbove(par1World, par2, par3 + 1, par4) && par3 >= 0)[/color]
            {
                byte b0 = 32;

                if (!fallInstantly && par1World.checkChunksExist(par2 - b0, par3 - b0, par4 - b0, par2 + b0, par3 + b0, par4 + b0))
                {
                    if (!par1World.isRemote)
                    {
                        [color=red]EntityFallingAscender entityfallingascender = new EntityFallingAscender(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), this.blockID, par1World.getBlockMetadata(par2, par3, par4));
                        this.onStartFalling(entityfallingascender);
                        par1World.spawnEntityInWorld(entityfallingascender);[/color]
                    }
                }
                else
                {
                    par1World.setBlockToAir(par2, par3, par4);

                 [color=red]   while (canFallBelow(par1World, par2, par3 + 1, par4) && par3 > 0)
                    {
                        ++par3;
                    }
[/color]
                    if (par3 > 0)
                    {
                        par1World.setBlock(par2, par3, par4, this.blockID);
                    }
                }
            }
        }
        
        public static boolean canFallAbove(World par0World, int par1, int par2, int par3)
        {
            int l = par0World.getBlockId(par1, par2, par3);

            if (par0World.isAirBlock(par1, par2, par3))
            {
                return true;
            }
            else if (l == Block.fire.blockID)
            {
                return true;
            }
            else
            {
                Material material = Block.blocksList[l].blockMaterial;
                return material == Material.water ? true : material == Material.lava;
            }
        }
        
        
        @SideOnly(Side.CLIENT)
        public Icon getIcon(int par1, int par2)
        {
            return par1 == 0 ? this.upBottom : (par1 == 1 ? this.upTop: this.blockIcon);
        }
        
        @SideOnly(Side.CLIENT)
        public void registerIcons(IconRegister par1IconRegister)
        {
            this.blockIcon = par1IconRegister.registerIcon("upDownSides");
            this.upTop = par1IconRegister.registerIcon("upTop");
            this.upBottom = par1IconRegister.registerIcon("upBottom");
        }
}

 

FallingSand Entity:

package nethseaar.bacon.entities;

import java.util.Iterator;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSand;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityFallingSand;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class EntityFallingAscender extends EntityFallingSand {

 public int blockID;
    public int metadata;

    /** How long the block has been falling for. */
    public int fallTime;
    public boolean shouldDropItem;
    private boolean isBreakingAnvil;
    private boolean isAnvil;

    /** Maximum amount of damage dealt to entities hit by falling block */
    private int fallHurtMax;

    /** Actual damage dealt to entities hit by falling block */
    private float fallHurtAmount;
    public NBTTagCompound fallingBlockTileEntityData;

    public EntityFallingAscender(World par1World)
    {
        super(par1World);
        this.fallTime = 0;
        this.shouldDropItem = true;
        this.isBreakingAnvil = false;
        this.isAnvil = false;
        this.fallHurtMax = 40;
        this.fallHurtAmount = 2.0F;
        this.fallingBlockTileEntityData = null;
    }

    public EntityFallingAscender(World par1World, double par2, double par4, double par6, int par8)
    {
        this(par1World, par2, par4, par6, par8, 0);
    }

    public EntityFallingAscender(World par1World, double par2, double par4, double par6, int par8, int par9)
    {
        super(par1World);
        this.fallTime = 0;
        this.shouldDropItem = true;
        this.isBreakingAnvil = false;
        this.isAnvil = false;
        this.fallHurtMax = 40;
        this.fallHurtAmount = 2.0F;
        this.fallingBlockTileEntityData = null;
        this.blockID = par8;
        this.metadata = par9;
        this.preventEntitySpawning = true;
        this.setSize(0.98F, 0.98F);
        this.yOffset = this.height / 2.0F;
        this.setPosition(par2, par4, par6);
        this.motionX = 0.0D;
        this.motionY = 0.0D;
        this.motionZ = 0.0D;
        this.prevPosX = par2;
        this.prevPosY = par4;
        this.prevPosZ = par6;
    }

    public void onUpdate()
    {
        if (this.blockID == 0)
        {
            this.setDead();
        }
        else
        {
            this.prevPosX = this.posX;
            this.prevPosY = this.posY;
            this.prevPosZ = this.posZ;
            ++this.fallTime;
           [color=red] this.motionY += 0.03999999910593033D;[/color]
            this.moveEntity(this.motionX, this.motionY, this.motionZ);
            this.motionX *= 0.9800000190734863D;
            this.motionY *= 0.9800000190734863D;
            this.motionZ *= 0.9800000190734863D;

            if (!this.worldObj.isRemote)
            {
                int i = MathHelper.floor_double(this.posX);
                int j = MathHelper.floor_double(this.posY);
                int k = MathHelper.floor_double(this.posZ);

                if (this.fallTime == 1)
                {
                    if (this.worldObj.getBlockId(i, j, k) != this.blockID)
                    {
                        this.setDead();
                        return;
                    }

                    this.worldObj.setBlockToAir(i, j, k);
                }

                if (this.onGround)
                {
                    this.motionX *= 0.699999988079071D;
                    this.motionZ *= 0.699999988079071D;
                    this.motionY *= 0.5D;

                    if (this.worldObj.getBlockId(i, j, k) != Block.pistonMoving.blockID)
                    {
                        this.setDead();

                        if (!this.isBreakingAnvil && this.worldObj.canPlaceEntityOnSide(this.blockID, i, j, k, true, 1, (Entity)null, (ItemStack)null) && !BlockSand.canFallBelow(this.worldObj, i, j - 1, k) && this.worldObj.setBlock(i, j, k, this.blockID, this.metadata, 3))
                        {
                            if (Block.blocksList[this.blockID] instanceof BlockSand)
                            {
                                ((BlockSand)Block.blocksList[this.blockID]).onFinishFalling(this.worldObj, i, j, k, this.metadata);
                            }

                            if (this.fallingBlockTileEntityData != null && Block.blocksList[this.blockID] instanceof ITileEntityProvider)
                            {
                                TileEntity tileentity = this.worldObj.getBlockTileEntity(i, j, k);

                                if (tileentity != null)
                                {
                                    NBTTagCompound nbttagcompound = new NBTTagCompound();
                                    tileentity.writeToNBT(nbttagcompound);
                                    Iterator iterator = this.fallingBlockTileEntityData.getTags().iterator();

                                    while (iterator.hasNext())
                                    {
                                        NBTBase nbtbase = (NBTBase)iterator.next();

                                        if (!nbtbase.getName().equals("x") && !nbtbase.getName().equals("y") && !nbtbase.getName().equals("z"))
                                        {
                                            nbttagcompound.setTag(nbtbase.getName(), nbtbase.copy());
                                        }
                                    }

                                    tileentity.readFromNBT(nbttagcompound);
                                    tileentity.onInventoryChanged();
                                }
                            }
                        }
                        else if (this.shouldDropItem && !this.isBreakingAnvil)
                        {
                            this.entityDropItem(new ItemStack(this.blockID, 1, Block.blocksList[this.blockID].damageDropped(this.metadata)), 0.0F);
                        }
                    }
                }
                else if (this.fallTime > 100 && !this.worldObj.isRemote && (j < 1 || j > 256) || this.fallTime > 600)
                {
                    if (this.shouldDropItem)
                    {
                        this.entityDropItem(new ItemStack(this.blockID, 1, Block.blocksList[this.blockID].damageDropped(this.metadata)), 0.0F);
                    }

                    this.setDead();
                }
            }
        }
    }
    
}

Link to comment
Share on other sites

This is due to one of the basics of Java. You can't override a private method.

private void tryToFall(World par1World, int par2, int par3, int par4)

This method in your block will never be called, since it is the one in BlockSand that is declared first.

 

Solution: don't extend BlockSand :)

Link to comment
Share on other sites

There also is a possibility to override from the parent class (BlockSand).

public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
        if (!par1World.isRemote)
        {
            this.tryToFall(par1World, par2, par3, par4);
        }
    }

since this is the only call to tryToFall(args) ;)

Link to comment
Share on other sites

Are there any tutorials for creating and rendering entities like FallingSand? I've copied (and made appropriate changes to) the FallingSand code, and its renderer, but either my entity isn't spawning or it isn't rendering; the sand just disappears when it can fall, and then breaks (drops itself) at some point as it rises. I don't understand how renderers work at all, so I'm blaming the problem on my renderer.

Link to comment
Share on other sites

Might you point me toward them? I've searched, to no avail.

 

I've registered my renderer thusly, in Common Proxy:

 

 public void registerRenderers() {
        	   RenderingRegistry.registerEntityRenderingHandler(Entity.class, new RenderFallingAscender());
        }

 

But I haven't registered my entity! Where/how does one do that?

Link to comment
Share on other sites

Might you point me toward them? I've searched, to no avail.

 

I've registered my renderer thusly, in Common Proxy:

 

 public void registerRenderers() {
        	   RenderingRegistry.registerEntityRenderingHandler(Entity.class, new RenderFallingAscender());
        }

 

But I haven't registered my entity! Where/how does one do that?

You're registering renderers server sided? This is not correct. Register it only client sided instead.

Also why are you registering the renderer for all Entities (by calling the register with Entity.class)? Use your own entity instead.

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Link to comment
Share on other sites

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
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.

 Share



×
×
  • Create New...

Important Information

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