Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.kennethsmedievalmod.init.blocks.barrel.yewbarrel;
- import com.kennethsmedievalmod.init.blocks.barrel.BarrelRecipe;
- import com.kennethsmedievalmod.init.blocks.barrel.BarrelRecipes;
- import ibxm.Player;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.ITickable;
- import scala.collection.concurrent.Debug;
- public class YewBarrelDataTileEntity extends TileEntity implements ITickable {
- public ItemStack selectedInput;
- public Item selectedOutput;
- public boolean aging = false;
- public float agingTimer = 0f;
- public int DrinksLeft = 0;
- int id;
- public ItemStack SetRecipeInput (ItemStack selectedInputItem) {
- selectedInput = selectedInputItem;
- SetOutput();
- StartAging();
- markDirty();
- return selectedInput;
- }
- public void SetOutput () {
- for (BarrelRecipe recipe : BarrelRecipes.barrelRecipes) {
- if(recipe.input == selectedInput) {
- selectedOutput = recipe.output.getItem();
- }
- }
- }
- public int GetRecipeID () {
- for(int i = 0; i < BarrelRecipes.barrelRecipes.size(); i++) {
- if(BarrelRecipes.barrelRecipes.get(i).input == selectedInput) {
- id = BarrelRecipes.barrelRecipes.get(i).recipeID;
- }
- }
- return id;
- }
- public int TakeDrink() {
- DrinksLeft--;
- if(DrinksLeft == 0) {
- selectedInput = null;
- selectedOutput = null;
- }
- markDirty();
- return DrinksLeft;
- }
- public int AddDrink() {
- DrinksLeft++;
- markDirty();
- return DrinksLeft;
- }
- public void StartAging () {
- aging = true;
- agingTimer = 0f;
- DrinksLeft = 0;
- markDirty();
- }
- @Override
- public void readFromNBT(NBTTagCompound compound) {
- super.readFromNBT(compound);
- aging = compound.getBoolean("aging");
- agingTimer = compound.getFloat("agingTimer");
- DrinksLeft = compound.getInteger("drinks_left");
- }
- @Override
- public NBTTagCompound writeToNBT(NBTTagCompound compound) {
- super.writeToNBT(compound);
- compound.setBoolean("aging", aging);
- compound.setFloat("agingTimer", agingTimer);
- compound.setInteger("drinks_left", DrinksLeft);
- return compound;
- }
- @Override
- public void update() {
- if(!this.world.isRemote) {
- if (aging == true) {
- if(agingTimer < 240) {
- agingTimer += 1;
- } else if (agingTimer >= 240) {
- StopAging();
- }
- }
- }
- markDirty();
- }
- public void StopAging () {
- agingTimer = 0;
- DrinksLeft = 10;
- aging = false;
- markDirty();
- }
- }
- package com.kennethsmedievalmod.init.blocks.barrel.yewbarrel;
- import java.util.Random;
- import com.kennethsmedievalmod.init.BlockInit;
- import com.kennethsmedievalmod.init.ItemInit;
- import com.kennethsmedievalmod.init.blocks.barrel.BarrelRecipes;
- import net.minecraft.block.Block;
- import net.minecraft.block.ITileEntityProvider;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.PropertyDirection;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.client.renderer.block.model.ModelResourceLocation;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Items;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.EnumHand;
- import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.text.TextComponentString;
- import net.minecraft.util.text.TextFormatting;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraftforge.client.model.ModelLoader;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- public class YewBarrel extends Block implements ITileEntityProvider {
- public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
- public static AxisAlignedBB BARREL_AABB = new AxisAlignedBB(0, 0, 0, 1, 1, 1);
- public YewBarrel(String name) {
- super(Material.WOOD);
- setUnlocalizedName(name);
- setRegistryName(name);
- setHardness(4.0f);
- setResistance(20.0f);
- setHarvestLevel("axe", 1);
- }
- @Override
- public Item getItemDropped (IBlockState state, Random rand, int fortune) {
- return Item.getItemFromBlock(BlockInit.yew_barrel);
- }
- @Override
- public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
- return new ItemStack (BlockInit.yew_barrel);
- }
- @Override
- public boolean isOpaqueCube (IBlockState state) {
- return false;
- }
- @Override
- public boolean isFullCube (IBlockState state) {
- return false;
- }
- @Override
- public AxisAlignedBB getBoundingBox (IBlockState state, IBlockAccess source, BlockPos pos) {
- return BARREL_AABB;
- }
- @SideOnly(Side.CLIENT)
- public void initModel() {
- ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
- }
- @Override
- public TileEntity createNewTileEntity(World worldIn, int meta) {
- return new YewBarrelDataTileEntity();
- }
- private YewBarrelDataTileEntity getTE(World world, BlockPos pos) {
- return (YewBarrelDataTileEntity) world.getTileEntity(pos);
- }
- @Override
- public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
- if (!world.isRemote) {
- if(getTE(world, pos).selectedInput == null) {
- if(player.getHeldItemMainhand().getItem() != ItemInit.empty_beer_mug) {
- for(int i = 0; i < BarrelRecipes.acceptedInputs.size(); i++) {
- if(BarrelRecipes.acceptedInputs.get(i) == player.getHeldItemMainhand().getItem()) {
- ItemStack setInput = getTE(world, pos).SetRecipeInput(new ItemStack (player.getHeldItemMainhand().getItem(), 1));
- player.sendMessage(new TextComponentString(TextFormatting.GREEN + setInput.getItem().getUnlocalizedName() + " Input"));
- player.getHeldItemMainhand().setCount(player.getHeldItemMainhand().getCount() - 1);
- player.sendMessage(new TextComponentString(TextFormatting.GREEN + "You place the ingredient into the barrel and it starts to age. "));
- } else {
- if(player.getHeldItemMainhand().getItem() != null) {
- player.sendMessage(new TextComponentString(TextFormatting.GREEN + "That item cannot be brewed into beer. "));
- }
- }
- }
- }
- } else {
- for(int i = 0; i < BarrelRecipes.acceptedInputs.size(); i++) {
- if(player.getHeldItemMainhand().getItem() == BarrelRecipes.acceptedInputs.get(i)) {
- player.sendMessage(new TextComponentString(TextFormatting.GREEN + "Barrel is already aging and has an ingredient in it. "));
- }
- }
- }
- if(player.getHeldItemMainhand().getItem() == ItemInit.empty_beer_mug) {
- if(getTE(world, pos).agingTimer != 0) {
- float time_left = (240 - getTE(world, pos).agingTimer) / 20;
- player.sendMessage(new TextComponentString(TextFormatting.GREEN + "The contents of this barrel is still aging. " + time_left + " seconds left to go. "));
- } else {
- if(getTE(world, pos).DrinksLeft > 0) {
- int drinks_left;
- drinks_left = getTE(world, pos).TakeDrink();
- player.sendMessage(new TextComponentString(TextFormatting.GREEN + BarrelRecipes.barrelRecipes.get(0).output.getItem().getUnlocalizedName()));
- int toGetId = getTE(world, pos).GetRecipeID();
- player.sendMessage(new TextComponentString(TextFormatting.GREEN + "Test1" + toGetId));
- player.sendMessage(new TextComponentString(TextFormatting.GREEN + "Barrel now has " + drinks_left + " refils of beer in it. "));
- }
- }
- }
- }
- return true;
- }
- @Override
- public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
- world.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
- }
- @Override
- public IBlockState getStateFromMeta(int meta) {
- // Since we only allow horizontal rotation we need only 2 bits for facing. North, South, West, East start at index 2 so we have to add 2 here.
- return getDefaultState().withProperty(FACING, EnumFacing.getFront((meta & 3) + 2));
- }
- @Override
- public int getMetaFromState(IBlockState state) {
- // Since we only allow horizontal rotation we need only 2 bits for facing. North, South, West, East start at index 2 so we have to subtract 2 here.
- return state.getValue(FACING).getIndex()-2;
- }
- @Override
- protected BlockStateContainer createBlockState() {
- return new BlockStateContainer(this, FACING);
- }
- }
- package com.kennethsmedievalmod.init.blocks.barrel;
- import java.util.ArrayList;
- import java.util.List;
- import com.kennethsmedievalmod.init.ItemInit;
- import net.minecraft.init.Items;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- public class BarrelRecipes {
- public static List<Item> acceptedInputs = new ArrayList<Item>();
- public static List<BarrelRecipe> barrelRecipes = new ArrayList<BarrelRecipe>();
- public static BarrelRecipe basicBeer;
- public static void init () {
- basicBeer = new BarrelRecipe (new ItemStack (Items.WHEAT, 1), new ItemStack(ItemInit.basic_beer_mug, 1), 1);
- acceptedInputs.add(Items.WHEAT);
- }
- public static void register () {
- barrelRecipes.add(basicBeer);
- }
- }
- package com.kennethsmedievalmod.init.blocks.barrel;
- import net.minecraft.item.ItemStack;
- public class BarrelRecipe {
- public ItemStack input;
- public ItemStack output;
- public int recipeID;
- public BarrelRecipe (ItemStack inputItem, ItemStack outputItem, int newID) {
- input = inputItem;
- output = outputItem;
- recipeID = newID;
- }
- }
Add Comment
Please, Sign In to add comment