Jump to content

Custom Sugar Canes Won't Grow And Can't Place On Eachother


Manslaughter777

Recommended Posts

The title pretty much explains it. I am having problems with my custom sugar cane plants. It doesnt grow and i cant place them on eachother. I have spent a good 8 hours trying to fix it but nothing. Plz help me cause im really close to finishing this mod and this stupid plant is letting me down. I am guessing its something to d with the canPlaceBlockAt part but i dont know what. Any help is appreciated :)

 

The MarijuanaPlant mod class (custom sugar cane)

 

 

package com.manslaughter777.weed;

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

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.common.IPlantable;

//Change MarijuanaPlantBackup to MarijuanaPlant

public class MarijuanaPlant extends Block implements IPlantable
{
private static final String __OBFID = "CL_00000300";

protected MarijuanaPlant()
{
super(Material.plants);
float f = 0.375F;
this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 1.0F, 0.5F + f);
this.setTickRandomly(true);
this.disableStats();
}

/**
* 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_.getBlock(p_149674_2_, p_149674_3_ - 1, p_149674_4_) == Main.marijuanaPlant || this.func_150170_e(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_))
{
if (p_149674_1_.isAirBlock(p_149674_2_, p_149674_3_ + 1, p_149674_4_))
{
int l;

for (l = 1; p_149674_1_.getBlock(p_149674_2_, p_149674_3_ - l, p_149674_4_) == this; ++l)
{
;
}

if (l < 3)
{
int i1 = p_149674_1_.getBlockMetadata(p_149674_2_, p_149674_3_, p_149674_4_);

if (i1 == 15)
{
p_149674_1_.setBlock(p_149674_2_, p_149674_3_ + 1, p_149674_4_, this);
p_149674_1_.setBlockMetadataWithNotify(p_149674_2_, p_149674_3_, p_149674_4_, 0, 4);
}
else
{
p_149674_1_.setBlockMetadataWithNotify(p_149674_2_, p_149674_3_, p_149674_4_, i1 + 1, 4);
}
}
}
}
}

/**
* Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
*/
public boolean canPlaceBlockAt(World p_149742_1_, int p_149742_2_, int p_149742_3_, int p_149742_4_)
{
Block block = p_149742_1_.getBlock(p_149742_2_, p_149742_3_ - 1, p_149742_4_);
return block.canSustainPlant(p_149742_1_, p_149742_2_, p_149742_3_ - 1, p_149742_4_, ForgeDirection.UP, this);
}

/**
* Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
* their own) Args: x, y, z, neighbor Block
*/
public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_)
{
this.func_150170_e(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_);
}

protected final boolean func_150170_e(World p_150170_1_, int p_150170_2_, int p_150170_3_, int p_150170_4_)
{
if (!this.canBlockStay(p_150170_1_, p_150170_2_, p_150170_3_, p_150170_4_))
{
this.dropBlockAsItem(p_150170_1_, p_150170_2_, p_150170_3_, p_150170_4_, p_150170_1_.getBlockMetadata(p_150170_2_, p_150170_3_, p_150170_4_), 0);
p_150170_1_.setBlockToAir(p_150170_2_, p_150170_3_, p_150170_4_);
return false;
}
else
{
return true;
}
}

/**
* Can this block stay at this position. Similar to canPlaceBlockAt except gets checked often with plants.
*/
public boolean canBlockStay(World p_149718_1_, int p_149718_2_, int p_149718_3_, int p_149718_4_)
{
return this.canPlaceBlockAt(p_149718_1_, p_149718_2_, p_149718_3_, p_149718_4_);

}


/**
* 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_)
{
return null;
}

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
{
return Main.marijuanaBranch;
}

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


/**
* Is this block (a) opaque and (B) a full 1m cube? This determines whether or not to render the shared face of two
* adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
*/
public boolean isOpaqueCube()
{
return false;
}

/**
* If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
*/
public boolean renderAsNormalBlock()
{
return false;
}

/**
* The type of render function that is called for this block
*/
public int getRenderType()
{
return 1;
}

/**
* Gets an item for the block being called on. Args: world, x, y, z
*/
@SideOnly(Side.CLIENT)
public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_)
{
return Main.marijuanaPlantItem;
}

/**
* Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called
* when first determining what to render.
*/
@SideOnly(Side.CLIENT)
public int colorMultiplier(IBlockAccess p_149720_1_, int p_149720_2_, int p_149720_3_, int p_149720_4_)
{
return p_149720_1_.getBiomeGenForCoords(p_149720_2_, p_149720_4_).getBiomeGrassColor(p_149720_2_, p_149720_3_, p_149720_4_);
}

@Override
public EnumPlantType getPlantType(IBlockAccess world, int x, int y, int z)
{
return EnumPlantType.Beach;
}

@Override
public Block getPlant(IBlockAccess world, int x, int y, int z)
{
return this;
}

@Override
public int getPlantMetadata(IBlockAccess world, int x, int y, int z)
{
return world.getBlockMetadata(x, y, z);
}
}

 

 

 

Link to comment
Share on other sites

Hi

 

Dude, the first thing I'd suggest is to rename your parameters to something sensible

Stuff like

(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_)

will do your head in if you try to debug it for too long.

Using the right indenting should help a lot too.

Putting @Override before the methods you're overriding from the base class will help pick up subtle problems where you think you're overriding a base class method but you've misspelled it.

 

I can't see an obvious problem but then I can't actually read the code either so that doesn't mean anything :-)

 

I'd suggest you put a breakpoint into some of these methods especially canBlockStay and canPlaceBlockAt to see if you can figure out why it won't let you place them on top of each other.

 

-TGG

 

 

 

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