Done all the placement requirements for flowers, plants and grass.

This commit is contained in:
Amnet 2013-04-20 22:38:33 +02:00
parent 5a8adb1dc8
commit f581bdc38b
6 changed files with 231 additions and 28 deletions

View File

@ -3,6 +3,7 @@ package biomesoplenty.blocks;
import java.util.List; import java.util.List;
import biomesoplenty.BiomesOPlenty; import biomesoplenty.BiomesOPlenty;
import biomesoplenty.api.Blocks;
import biomesoplenty.blocks.renderers.FoliageRenderer; import biomesoplenty.blocks.renderers.FoliageRenderer;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -105,6 +106,50 @@ public class BlockBOPFlower extends BlockFlower
list.add(new ItemStack(blockID, 1, i)); list.add(new ItemStack(blockID, 1, i));
} }
protected boolean canThisPlantGrowOnThisBlockID(int id, int meta)
{
switch (meta)
{
case 10: // Toadstool
return id == Block.grass.blockID || id == Block.dirt.blockID || id == Block.mycelium.blockID;
case 11: // Cactus
return id == Block.sand.blockID;
default:
return id == Block.grass.blockID || id == Block.dirt.blockID || id == Block.tilledField.blockID;
}
}
@Override
public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int side, ItemStack itemStack)
{
int id = world.getBlockId(x, y - 1, z);
int meta = itemStack.getItemDamage();
if (itemStack.itemID == this.blockID)
switch (meta)
{
case 10: // Toadstool
return id == Block.grass.blockID || id == Block.dirt.blockID || id == Block.mycelium.blockID;
case 11: // Cactus
return id == Block.sand.blockID;
default:
return id == Block.grass.blockID || id == Block.dirt.blockID || id == Block.tilledField.blockID;
}
else
return this.canPlaceBlockOnSide(world, x, y, z, side);
}
@Override
public boolean canBlockStay(World world, int x, int y, int z)
{
return (world.getFullBlockLightValue(x, y, z) >= 8 || world.canBlockSeeTheSky(x, y, z))
&& this.canThisPlantGrowOnThisBlockID(world.getBlockId(x, y - 1, z), world.getBlockMetadata(x, y, z));
}
@Override @Override
public int damageDropped(int meta) public int damageDropped(int meta)
{ {

View File

@ -5,6 +5,7 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import biomesoplenty.BiomesOPlenty; import biomesoplenty.BiomesOPlenty;
import biomesoplenty.api.Blocks;
import biomesoplenty.blocks.renderers.FoliageRenderer; import biomesoplenty.blocks.renderers.FoliageRenderer;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -74,15 +75,30 @@ public class BlockBOPFoliage extends BlockFlower implements IShearable
} }
@Override @Override
public boolean canPlaceBlockAt(World world, int x, int y, int z) public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int side, ItemStack itemStack)
{ {
return super.canPlaceBlockAt(world, x, y, z) && this.canThisPlantGrowOnThisBlockID(world.getBlockId(x, y - 1, z), world.getBlockMetadata(x, y, z)); int id = world.getBlockId(x, y - 1, z);
int meta = itemStack.getItemDamage();
if (itemStack.itemID == this.blockID)
switch (meta)
{
case ALGAE: // Dead Grass
return id == Block.waterStill.blockID;
default:
return id == Block.grass.blockID || id == Block.dirt.blockID || id == Block.tilledField.blockID;
}
else
return this.canPlaceBlockOnSide(world, x, y, z, side);
} }
protected boolean canThisPlantGrowOnThisBlockID(int blockID, int metadata) protected boolean canThisPlantGrowOnThisBlockID(int blockID, int metadata)
{ {
if (metadata == GRASSTOP) if (metadata == GRASSTOP)
return blockID == this.blockID; return blockID == this.blockID;
else if (metadata == ALGAE)
return blockID == Block.waterStill.blockID;
else else
return blockID == Block.grass.blockID || blockID == Block.dirt.blockID || blockID == Block.tilledField.blockID; return blockID == Block.grass.blockID || blockID == Block.dirt.blockID || blockID == Block.tilledField.blockID;
} }
@ -90,7 +106,8 @@ public class BlockBOPFoliage extends BlockFlower implements IShearable
@Override @Override
public boolean canBlockStay(World world, int x, int y, int z) public boolean canBlockStay(World world, int x, int y, int z)
{ {
return (world.getFullBlockLightValue(x, y, z) >= 8 || world.canBlockSeeTheSky(x, y, z)) && this.canThisPlantGrowOnThisBlockID(world.getBlockId(x, y - 1, z), world.getBlockMetadata(x, y, z)); return (world.getFullBlockLightValue(x, y, z) >= 8 || world.canBlockSeeTheSky(x, y, z))
&& this.canThisPlantGrowOnThisBlockID(world.getBlockId(x, y - 1, z), world.getBlockMetadata(x, y, z));
} }
@Override @Override
@ -98,6 +115,10 @@ public class BlockBOPFoliage extends BlockFlower implements IShearable
{ {
super.onNeighborBlockChange(world, x, y, z, neighborID); super.onNeighborBlockChange(world, x, y, z, neighborID);
this.checkFlowerChange(world, x, y, z); this.checkFlowerChange(world, x, y, z);
if (world.getBlockMetadata(x, y, z) == GRASSTOP && world.getBlockId(x, y - 1, z) == this.blockID && world.getBlockMetadata(x, y - 1, z) != GRASSBOTTOM)
world.setBlockToAir(x, y, z);
if (world.getBlockMetadata(x, y, z) == GRASSBOTTOM && world.getBlockId(x, y + 1, z) != this.blockID)
world.setBlockToAir(x, y, z);
} }
@Override @Override

View File

@ -91,15 +91,8 @@ public class BlockBOPPlant extends BlockFlower implements IShearable
list.add(new ItemStack(blockID, 1, i)); list.add(new ItemStack(blockID, 1, i));
} }
// @Override
// public boolean canPlaceBlockAt(World world, int x, int y, int z)
// {
// return true;//super.canPlaceBlockAt(world, x, y, z) && this.canThisPlantGrowOnThisBlockID(world.getBlockId(x, y - 1, z), world.getBlockMetadata(x, y, z));
// }
protected boolean canThisPlantGrowOnThisBlockID(int id, int meta) protected boolean canThisPlantGrowOnThisBlockID(int id, int meta)
{ {
// TODO
switch (meta) switch (meta)
{ {
case 0: // Dead Grass case 0: // Dead Grass

View File

@ -1,9 +1,12 @@
package biomesoplenty.items; package biomesoplenty.items;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon; import net.minecraft.util.Icon;
import net.minecraft.world.World;
public class ItemBOPFlower extends ItemBlock public class ItemBOPFlower extends ItemBlock
{ {
@ -33,4 +36,64 @@ public class ItemBOPFlower extends ItemBlock
{ {
return Block.blocksList[this.itemID].getIcon(0, meta); return Block.blocksList[this.itemID].getIcon(0, meta);
} }
@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{
int id = world.getBlockId(x, y, z);
if (id == Block.snow.blockID && (world.getBlockMetadata(x, y, z) & 7) < 1)
side = 1;
else if (!Block.blocksList[id].isBlockReplaceable(world, x, y, z))
{
if (side == 0)
--y;
if (side == 1)
++y;
if (side == 2)
--z;
if (side == 3)
++z;
if (side == 4)
--x;
if (side == 5)
++x;
}
if (!player.canPlayerEdit(x, y, z, side, itemStack))
{
return false;
}
else if (itemStack.stackSize == 0)
{
return false;
}
else
{
if (world.canPlaceEntityOnSide(this.getBlockID(), x, y, z, false, side, (Entity)null, itemStack))
{
Block block = Block.blocksList[this.getBlockID()];
int j1 = block.onBlockPlaced(world, x, y, z, side, hitX, hitY, hitZ, 0);
if (world.setBlock(x, y, z, this.getBlockID(), itemStack.getItemDamage(), 3))
{
if (world.getBlockId(x, y, z) == this.getBlockID())
{
Block.blocksList[this.getBlockID()].onBlockPlacedBy(world, x, y, z, player, itemStack);
Block.blocksList[this.getBlockID()].onPostBlockPlaced(world, x, y, z, j1);
}
world.playSoundEffect((double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
--itemStack.stackSize;
}
}
return true;
}
}
} }

View File

@ -1,11 +1,15 @@
package biomesoplenty.items; package biomesoplenty.items;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumMovingObjectType;
import net.minecraft.util.Icon; import net.minecraft.util.Icon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World; import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -52,29 +56,105 @@ public class ItemBOPFoliage extends ItemBlock
return textures[meta]; return textures[meta];
} }
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
{
if (itemStack.getItemDamage() != 0)
return super.onItemRightClick(itemStack, world, player);
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, true);
if (movingobjectposition == null)
return itemStack;
else
{
if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
{
int i = movingobjectposition.blockX;
int j = movingobjectposition.blockY;
int k = movingobjectposition.blockZ;
if (!world.canMineBlock(player, i, j, k))
return itemStack;
if (!player.canPlayerEdit(i, j, k, movingobjectposition.sideHit, itemStack))
return itemStack;
if (world.getBlockMaterial(i, j, k) == Material.water && world.getBlockMetadata(i, j, k) == 0 && world.isAirBlock(i, j + 1, k))
{
world.setBlock(i, j + 1, k, itemStack.itemID, 0, 2);
if (!player.capabilities.isCreativeMode)
{
--itemStack.stackSize;
}
}
}
return itemStack;
}
}
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{ {
if (itemStack.getItemDamage() == 0)
if (itemStack.getItemDamage() != 3)
{
return super.onItemUse(itemStack, player, world, x, y, z, side, hitX, hitY, hitZ); return super.onItemUse(itemStack, player, world, x, y, z, side, hitX, hitY, hitZ);
int id = world.getBlockId(x, y, z);
if (id == Block.snow.blockID && (world.getBlockMetadata(x, y, z) & 7) < 1)
side = 1;
else if (!Block.blocksList[id].isBlockReplaceable(world, x, y, z))
{
if (side == 0)
--y;
if (side == 1)
++y;
if (side == 2)
--z;
if (side == 3)
++z;
if (side == 4)
--x;
if (side == 5)
++x;
}
if (!player.canPlayerEdit(x, y, z, side, itemStack))
{
return false;
}
else if (itemStack.stackSize == 0)
{
return false;
} }
else else
{ {
++y; if (world.canPlaceEntityOnSide(this.getBlockID(), x, y, z, false, side, (Entity)null, itemStack))
if (!(player.canPlayerEdit(x, y, z, side, itemStack) || player.canPlayerEdit(x, y + 1, z, side, itemStack)))
return false;
else if (world.getBlockMaterial(x, y, z).isReplaceable() && world.getBlockMaterial(x, y + 1, z).isReplaceable())
{ {
world.setBlock(x, y, z, itemStack.itemID, 3, 2); Block block = Block.blocksList[this.getBlockID()];
world.setBlock(x, y + 1, z, itemStack.itemID, 6, 2); int j1 = block.onBlockPlaced(world, x, y, z, side, hitX, hitY, hitZ, 0);
world.notifyBlocksOfNeighborChange(x, y, z, itemStack.itemID);
world.notifyBlocksOfNeighborChange(x, y + 1, z, itemStack.itemID); if (world.setBlock(x, y, z, this.getBlockID(), itemStack.getItemDamage(), 3))
Block block = Block.blocksList[itemStack.itemID]; {
if (itemStack.getItemDamage() == 3 && world.getBlockMaterial(x, y + 1, z).isReplaceable())
world.setBlock(x, y + 1, z, this.getBlockID(), 6, 2);
if (world.getBlockId(x, y, z) == this.getBlockID())
{
Block.blocksList[this.getBlockID()].onBlockPlacedBy(world, x, y, z, player, itemStack);
Block.blocksList[this.getBlockID()].onPostBlockPlaced(world, x, y, z, j1);
}
world.playSoundEffect((double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F); world.playSoundEffect((double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
--itemStack.stackSize; --itemStack.stackSize;
} }
}
return true; return true;
} }
} }

View File

@ -56,6 +56,7 @@ public class ItemBOPPlant extends ItemBlock
return Block.blocksList[this.itemID].getIcon(0, meta); return Block.blocksList[this.itemID].getIcon(0, meta);
} }
@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{ {
int id = world.getBlockId(x, y, z); int id = world.getBlockId(x, y, z);