2015-03-07 12:51:28 +01:00
|
|
|
package ellpeck.actuallyadditions.blocks;
|
2015-02-09 17:25:05 +01:00
|
|
|
|
2015-02-17 16:15:16 +01:00
|
|
|
import cpw.mods.fml.client.registry.RenderingRegistry;
|
2015-03-07 02:23:31 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-04-24 19:22:03 +02:00
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
2015-03-07 12:51:28 +01:00
|
|
|
import ellpeck.actuallyadditions.items.ItemFertilizer;
|
|
|
|
import ellpeck.actuallyadditions.items.ItemMisc;
|
|
|
|
import ellpeck.actuallyadditions.items.metalists.TheMiscItems;
|
|
|
|
import ellpeck.actuallyadditions.tile.TileEntityCompost;
|
2015-06-18 13:14:57 +02:00
|
|
|
import ellpeck.actuallyadditions.util.BlockUtil;
|
2015-04-06 15:51:59 +02:00
|
|
|
import ellpeck.actuallyadditions.util.INameableItem;
|
2015-02-17 16:15:16 +01:00
|
|
|
import net.minecraft.block.Block;
|
2015-02-09 17:25:05 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
2015-03-07 02:23:31 +01:00
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
2015-02-09 17:25:05 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-03-07 02:23:31 +01:00
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.ItemBlock;
|
2015-02-09 17:25:05 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2015-03-07 02:23:31 +01:00
|
|
|
import net.minecraft.util.IIcon;
|
2015-02-09 17:25:05 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-04-04 05:20:19 +02:00
|
|
|
public class BlockCompost extends BlockContainerBase implements INameableItem{
|
2015-02-09 17:25:05 +01:00
|
|
|
|
|
|
|
public BlockCompost(){
|
|
|
|
super(Material.wood);
|
|
|
|
this.setHarvestLevel("axe", 0);
|
2015-07-07 01:13:39 +02:00
|
|
|
this.setHardness(0.5F);
|
|
|
|
this.setResistance(5.0F);
|
2015-02-09 17:25:05 +01:00
|
|
|
this.setStepSound(soundTypeWood);
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
this.setBlockBoundsForItemRender();
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|
|
|
|
|
2015-02-20 22:45:33 +01:00
|
|
|
@Override
|
2015-02-17 16:15:16 +01:00
|
|
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int f6, float f7, float f8, float f9){
|
2015-02-09 17:25:05 +01:00
|
|
|
if(!world.isRemote){
|
|
|
|
ItemStack stackPlayer = player.getCurrentEquippedItem();
|
2015-02-17 16:15:16 +01:00
|
|
|
TileEntityCompost tile = (TileEntityCompost)world.getTileEntity(x, y, z);
|
2015-02-09 17:25:05 +01:00
|
|
|
//Add items to be composted
|
2015-04-24 19:22:03 +02:00
|
|
|
if(stackPlayer != null && stackPlayer.getItem() instanceof ItemMisc && stackPlayer.getItemDamage() == TheMiscItems.MASHED_FOOD.ordinal() && (tile.slots[0] == null || (!(tile.slots[0].getItem() instanceof ItemFertilizer) && tile.slots[0].stackSize < ConfigIntValues.COMPOST_AMOUNT.getValue()))){
|
2015-02-09 17:25:05 +01:00
|
|
|
if(tile.slots[0] == null) tile.slots[0] = new ItemStack(stackPlayer.getItem(), 1, TheMiscItems.MASHED_FOOD.ordinal());
|
|
|
|
else tile.slots[0].stackSize++;
|
|
|
|
if(!player.capabilities.isCreativeMode) player.inventory.getCurrentItem().stackSize--;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-02-09 17:25:05 +01:00
|
|
|
//Add Fertilizer to player's inventory
|
2015-02-17 16:15:16 +01:00
|
|
|
else if(tile.slots[0] != null && (stackPlayer == null || (stackPlayer.getItem() instanceof ItemFertilizer && stackPlayer.stackSize <= stackPlayer.getMaxStackSize() - tile.slots[0].stackSize)) && tile.slots[0].getItem() instanceof ItemFertilizer){
|
|
|
|
if(stackPlayer == null) player.inventory.setInventorySlotContents(player.inventory.currentItem, tile.slots[0].copy());
|
|
|
|
else player.getCurrentEquippedItem().stackSize+=tile.slots[0].stackSize;
|
2015-02-09 17:25:05 +01:00
|
|
|
tile.slots[0] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-20 22:45:33 +01:00
|
|
|
@Override
|
2015-02-17 16:15:16 +01:00
|
|
|
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB mask, List list, Entity collidingEntity){
|
2015-02-09 17:25:05 +01:00
|
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.3125F, 1.0F);
|
2015-02-17 16:15:16 +01:00
|
|
|
super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
|
2015-02-09 17:25:05 +01:00
|
|
|
float f = 0.125F;
|
|
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
|
2015-02-17 16:15:16 +01:00
|
|
|
super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
|
2015-02-09 17:25:05 +01:00
|
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
|
2015-02-17 16:15:16 +01:00
|
|
|
super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
|
2015-02-09 17:25:05 +01:00
|
|
|
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
|
2015-02-17 16:15:16 +01:00
|
|
|
super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
|
2015-02-09 17:25:05 +01:00
|
|
|
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
|
2015-02-17 16:15:16 +01:00
|
|
|
super.addCollisionBoxesToList(world, x, y, z, mask, list, collidingEntity);
|
2015-02-09 17:25:05 +01:00
|
|
|
this.setBlockBoundsForItemRender();
|
|
|
|
}
|
|
|
|
|
2015-03-07 02:23:31 +01:00
|
|
|
@Override
|
|
|
|
public IIcon getIcon(int side, int metadata){
|
|
|
|
return this.blockIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void registerBlockIcons(IIconRegister iconReg){
|
|
|
|
this.blockIcon = Blocks.planks.getIcon(0, 0);
|
|
|
|
}
|
|
|
|
|
2015-02-20 22:45:33 +01:00
|
|
|
@Override
|
2015-02-09 17:25:05 +01:00
|
|
|
public void setBlockBoundsForItemRender(){
|
2015-03-07 02:23:31 +01:00
|
|
|
float f = 1.0F/16.0F;
|
|
|
|
this.setBlockBounds(f, 0.0F, f, 1.0F-f, 1.0F, 1.0F-f);
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|
|
|
|
|
2015-02-20 22:45:33 +01:00
|
|
|
@Override
|
2015-02-09 17:25:05 +01:00
|
|
|
public boolean isOpaqueCube(){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-20 22:45:33 +01:00
|
|
|
@Override
|
2015-02-17 16:15:16 +01:00
|
|
|
public boolean renderAsNormalBlock(){
|
2015-02-09 17:25:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-20 22:45:33 +01:00
|
|
|
@Override
|
2015-02-09 17:25:05 +01:00
|
|
|
public int getRenderType(){
|
2015-02-17 16:15:16 +01:00
|
|
|
return RenderingRegistry.getNextAvailableRenderId();
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|
|
|
|
|
2015-02-20 22:45:33 +01:00
|
|
|
@Override
|
2015-02-09 17:25:05 +01:00
|
|
|
public TileEntity createNewTileEntity(World world, int meta){
|
|
|
|
return new TileEntityCompost();
|
|
|
|
}
|
2015-02-17 16:15:16 +01:00
|
|
|
|
2015-02-20 22:45:33 +01:00
|
|
|
@Override
|
2015-02-17 16:15:16 +01:00
|
|
|
public void breakBlock(World world, int x, int y, int z, Block block, int par6){
|
|
|
|
this.dropInventory(world, x, y, z);
|
|
|
|
super.breakBlock(world, x, y, z, block, par6);
|
|
|
|
}
|
2015-02-20 22:45:33 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName(){
|
|
|
|
return "blockCompost";
|
|
|
|
}
|
2015-03-07 02:23:31 +01:00
|
|
|
|
|
|
|
public static class TheItemBlock extends ItemBlock{
|
|
|
|
|
|
|
|
private Block theBlock;
|
|
|
|
|
|
|
|
public TheItemBlock(Block block){
|
|
|
|
super(block);
|
|
|
|
this.theBlock = block;
|
|
|
|
this.setHasSubtypes(false);
|
|
|
|
this.setMaxDamage(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
|
|
|
return EnumRarity.uncommon;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName(ItemStack stack){
|
|
|
|
return this.getUnlocalizedName();
|
|
|
|
}
|
|
|
|
|
2015-06-18 13:14:57 +02:00
|
|
|
@Override
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld) {
|
|
|
|
BlockUtil.addInformation(theBlock, list, 1, "");
|
|
|
|
}
|
|
|
|
|
2015-03-07 02:23:31 +01:00
|
|
|
@Override
|
|
|
|
public int getMetadata(int damage){
|
|
|
|
return damage;
|
|
|
|
}
|
|
|
|
}
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|