-
-
Save JayZX535/bb38f33944fe40ccb937a9b13b40ab68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wildcraft.wildcraft.block; | |
import java.util.Random; | |
import com.wildcraft.wildcraft.WildCraft; | |
import com.wildcraft.wildcraft.client.gui.GUIHandler; | |
import com.wildcraft.wildcraft.item.ItemKibble; | |
import com.wildcraft.wildcraft.tileentity.TileEntityFoodDish; | |
import com.wildcraft.wildcraft.util.WCBlocks; | |
import net.minecraft.block.BlockAnvil; | |
import net.minecraft.block.ITileEntityProvider; | |
import net.minecraft.block.material.Material; | |
import net.minecraft.block.properties.IProperty; | |
import net.minecraft.block.properties.PropertyInteger; | |
import net.minecraft.block.state.BlockStateContainer; | |
import net.minecraft.block.state.IBlockState; | |
import net.minecraft.creativetab.CreativeTabs; | |
import net.minecraft.entity.EntityLivingBase; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.entity.player.EntityPlayerMP; | |
import net.minecraft.init.Blocks; | |
import net.minecraft.init.Items; | |
import net.minecraft.init.PotionTypes; | |
import net.minecraft.init.SoundEvents; | |
import net.minecraft.inventory.InventoryHelper; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemArmor; | |
import net.minecraft.item.ItemBanner; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.potion.PotionUtils; | |
import net.minecraft.stats.StatList; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.tileentity.TileEntityBanner; | |
import net.minecraft.util.EnumFacing; | |
import net.minecraft.util.EnumHand; | |
import net.minecraft.util.SoundCategory; | |
import net.minecraft.util.math.AxisAlignedBB; | |
import net.minecraft.util.math.BlockPos; | |
import net.minecraft.util.math.MathHelper; | |
import net.minecraft.util.text.TextComponentTranslation; | |
import net.minecraft.world.IBlockAccess; | |
import net.minecraft.world.World; | |
import net.minecraftforge.items.CapabilityItemHandler; | |
import net.minecraftforge.items.IItemHandler; | |
public class BlockFoodDish extends BlockWildCraft implements ITileEntityProvider{ | |
protected static final AxisAlignedBB FOOD_DISH_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.375D, 0.9375D); | |
public static final PropertyInteger FULLNESS = PropertyInteger.create("fullness", 0, 3); | |
public static final PropertyInteger HEALTH = PropertyInteger.create("health", 0, 2); | |
/** The species that will use the food dish: | |
* 0 = Unassigned | |
* 1 = Canine | |
*/ | |
public BlockFoodDish(String name, Material mat, float hardness, float resistance, String tool, int harvest) | |
{ | |
super(name, mat, hardness, resistance, tool, harvest); | |
this.setCreativeTab(CreativeTabs.FOOD); | |
this.setDefaultState(this.blockState.getBaseState().withProperty(FULLNESS, Integer.valueOf(0)).withProperty(HEALTH, Integer.valueOf(0))); | |
} | |
@Override | |
public TileEntity createTileEntity(World world, IBlockState state) | |
{ | |
return new TileEntityFoodDish(); | |
} | |
@Override | |
public TileEntity createNewTileEntity(World worldIn, int meta) { | |
return new TileEntityFoodDish(); | |
} | |
@Override | |
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { | |
TileEntityFoodDish fooddish = (TileEntityFoodDish) worldIn.getTileEntity(pos); | |
IItemHandler handler = fooddish.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); | |
for (int slot = 0; slot < handler.getSlots(); slot++) | |
{ | |
ItemStack stack = handler.getStackInSlot(slot); | |
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack); | |
} | |
super.breakBlock(worldIn, pos, state); | |
} | |
/** | |
* Returns the quantity of items to drop on block destruction. | |
*/ | |
public int quantityDropped(Random random) | |
{ | |
return 1; | |
} | |
public boolean isFullCube(IBlockState state) | |
{ | |
return false; | |
} | |
public boolean isOpaqueCube(IBlockState state) | |
{ | |
return false; | |
} | |
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) | |
{ | |
return FOOD_DISH_AABB; | |
} | |
/** | |
* Called when the block is right clicked by a player. | |
*/ | |
@Override | |
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) | |
{ | |
System.out.println("Food dish clicked"); | |
System.out.println("World is remote? " + worldIn.isRemote); | |
playerIn.openGui(WildCraft.instance, GUIHandler.FOOD_DISH, worldIn, pos.getX(), pos.getY(), pos.getZ()); | |
return true; | |
} | |
public void setFoodLevel(World worldIn, BlockPos pos, IBlockState state, int level) | |
{ | |
if (level > 3){level = 3;} | |
else if (level < 0){level = 0;} | |
worldIn.setBlockState(pos, state.withProperty(FULLNESS, Integer.valueOf(MathHelper.clamp(level, 0, 3))), 2); | |
worldIn.updateComparatorOutputLevel(pos, this); | |
} | |
/** | |
* Convert the given metadata into a BlockState for this Block | |
*/ | |
public IBlockState getStateFromMeta(int meta) | |
{ | |
return this.getDefaultState().withProperty(FULLNESS, Integer.valueOf(meta)); | |
} | |
/** | |
* Convert the BlockState into the correct metadata value | |
*/ | |
public int getMetaFromState(IBlockState state) | |
{ | |
return ((Integer)state.getValue(FULLNESS)).intValue(); | |
} | |
protected BlockStateContainer createBlockState() | |
{ | |
return new BlockStateContainer(this, new IProperty[] {FULLNESS, HEALTH}); | |
} | |
public int getFullness(IBlockState state) | |
{ | |
return ((Integer)state.getValue(FULLNESS)).intValue(); | |
} | |
public void setFullness(int fullness) | |
{ | |
if (fullness > 3){fullness = 3;} | |
else if (fullness < 0){fullness = 0;} | |
this.FULLNESS.equals(fullness); | |
} | |
public int getHealth(IBlockState state) | |
{ | |
return ((Integer)state.getValue(HEALTH)).intValue(); | |
} | |
public void setHealth(int health) | |
{ | |
if (health > 2){health = 2;} | |
else if (health < 0){health = 0;} | |
this.HEALTH.equals(health); | |
} | |
public static void setState(int fullness, int species, int health, World worldIn, BlockPos pos) | |
{ | |
IBlockState iblockstate = worldIn.getBlockState(pos); | |
TileEntity tileentity = worldIn.getTileEntity(pos); | |
worldIn.setBlockState(pos, WCBlocks.blockFoodDish.getDefaultState().withProperty(FULLNESS, fullness).withProperty(HEALTH, health)); | |
if (tileentity != null) | |
{ | |
tileentity.validate(); | |
worldIn.setTileEntity(pos, tileentity); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment