2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("BlockCompost.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.blocks;
|
2015-02-09 17:25:05 +01:00
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.ItemFertilizer;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.ItemMisc;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityCompost;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2015-02-09 17:25:05 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-12-22 00:04:48 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.ScaledResolution;
|
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.item.EnumRarity;
|
2015-02-09 17:25:05 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-12-22 00:04:48 +01:00
|
|
|
import net.minecraft.profiler.Profiler;
|
2015-02-09 17:25:05 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.util.*;
|
2015-02-09 17:25:05 +01:00
|
|
|
import net.minecraft.world.World;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-02-09 17:25:05 +01:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-12-22 00:04:48 +01:00
|
|
|
public class BlockCompost extends BlockContainerBase implements IHudDisplay{
|
2015-02-09 17:25:05 +01:00
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public BlockCompost(String name){
|
|
|
|
super(Material.wood, name);
|
2015-02-09 17:25:05 +01:00
|
|
|
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-10-03 10:19:40 +02:00
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public void addCollisionBoxesToList(World world, BlockPos pos, IBlockState state, AxisAlignedBB mask, List list, Entity collidingEntity){
|
2015-10-03 10:19:40 +02:00
|
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.3125F, 1.0F);
|
2016-01-07 21:41:28 +01:00
|
|
|
super.addCollisionBoxesToList(world, pos, state, mask, list, collidingEntity);
|
2015-10-03 10:19:40 +02:00
|
|
|
float f = 0.125F;
|
|
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
|
2016-01-07 21:41:28 +01:00
|
|
|
super.addCollisionBoxesToList(world, pos, state, mask, list, collidingEntity);
|
2015-10-03 10:19:40 +02:00
|
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
|
2016-01-07 21:41:28 +01:00
|
|
|
super.addCollisionBoxesToList(world, pos, state, mask, list, collidingEntity);
|
2015-10-03 10:19:40 +02:00
|
|
|
this.setBlockBounds(1.0F-f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
|
2016-01-07 21:41:28 +01:00
|
|
|
super.addCollisionBoxesToList(world, pos, state, mask, list, collidingEntity);
|
2015-10-03 10:19:40 +02:00
|
|
|
this.setBlockBounds(0.0F, 0.0F, 1.0F-f, 1.0F, 1.0F, 1.0F);
|
2016-01-07 21:41:28 +01:00
|
|
|
super.addCollisionBoxesToList(world, pos, state, mask, list, collidingEntity);
|
2015-10-03 10:19:40 +02:00
|
|
|
this.setBlockBoundsForItemRender();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOpaqueCube(){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-20 22:45:33 +01:00
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing f6, float f7, float f8, float f9){
|
2015-02-09 17:25:05 +01:00
|
|
|
if(!world.isRemote){
|
|
|
|
ItemStack stackPlayer = player.getCurrentEquippedItem();
|
2016-01-07 21:41:28 +01:00
|
|
|
TileEntityCompost tile = (TileEntityCompost)world.getTileEntity(pos);
|
2015-02-09 17:25:05 +01:00
|
|
|
//Add items to be composted
|
2015-11-28 19:02:01 +01: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 < TileEntityCompost.AMOUNT))){
|
2015-10-02 16:48:01 +02:00
|
|
|
if(tile.slots[0] == null){
|
|
|
|
tile.slots[0] = new ItemStack(stackPlayer.getItem(), 1, TheMiscItems.MASHED_FOOD.ordinal());
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
tile.slots[0].stackSize++;
|
|
|
|
}
|
2015-10-03 10:16:18 +02:00
|
|
|
if(!player.capabilities.isCreativeMode){
|
|
|
|
player.inventory.getCurrentItem().stackSize--;
|
|
|
|
}
|
2016-02-01 17:43:14 +01:00
|
|
|
tile.markDirty();
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-02-09 17:25:05 +01:00
|
|
|
//Add Fertilizer to player's inventory
|
2015-10-02 16:48:01 +02: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;
|
2016-02-01 17:43:14 +01:00
|
|
|
tile.markDirty();
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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 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
|
2016-01-07 21:41:28 +01:00
|
|
|
public void breakBlock(World world, BlockPos pos, IBlockState state){
|
2016-01-08 13:31:58 +01:00
|
|
|
this.dropInventory(world, pos);
|
2016-01-07 21:41:28 +01:00
|
|
|
super.breakBlock(world, pos, state);
|
2015-02-17 16:15:16 +01:00
|
|
|
}
|
2015-02-20 22:45:33 +01:00
|
|
|
|
2015-10-23 16:48:56 +02:00
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
2016-01-07 21:41:28 +01:00
|
|
|
return EnumRarity.UNCOMMON;
|
2015-03-07 02:23:31 +01:00
|
|
|
}
|
2015-12-22 00:04:48 +01:00
|
|
|
|
|
|
|
@Override
|
2015-12-22 07:28:27 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-12-22 00:04:48 +01:00
|
|
|
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, MovingObjectPosition posHit, Profiler profiler, ScaledResolution resolution){
|
2016-01-07 21:41:28 +01:00
|
|
|
TileEntity tile = minecraft.theWorld.getTileEntity(posHit.getBlockPos());
|
2015-12-22 00:04:48 +01:00
|
|
|
if(tile instanceof TileEntityCompost){
|
|
|
|
ItemStack slot = ((TileEntityCompost)tile).getStackInSlot(0);
|
|
|
|
String strg;
|
|
|
|
if(slot == null){
|
|
|
|
strg = "Empty";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
strg = slot.getItem().getItemStackDisplayName(slot);
|
|
|
|
|
2015-12-22 14:58:25 +01:00
|
|
|
AssetUtil.renderStackToGui(slot, resolution.getScaledWidth()/2+15, resolution.getScaledHeight()/2-29, 1F);
|
2015-12-22 00:04:48 +01:00
|
|
|
}
|
2016-01-07 21:41:28 +01:00
|
|
|
minecraft.fontRendererObj.drawStringWithShadow(EnumChatFormatting.YELLOW+""+EnumChatFormatting.ITALIC+strg, resolution.getScaledWidth()/2+35, resolution.getScaledHeight()/2-25, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-22 00:04:48 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|