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.filled_beer_mug, 1));
acceptedInputs.add(Items.WHEAT);
}
public static void register () {
registerRecipe (basicBeer);
}
public static void registerRecipe (BarrelRecipe recipe) {
barrelRecipes.add(recipe);
}
}
And here is the BarrelRecipe class:
package com.kennethsmedievalmod.init.blocks.barrel;
import net.minecraft.item.ItemStack;
public class BarrelRecipe {
public static ItemStack input;
public static ItemStack output;
public BarrelRecipe (ItemStack inputItem, ItemStack outputItem) {
input = inputItem;
output = outputItem;
}
}
And here is the Barrel Block class:
package com.kennethsmedievalmod.init.blocks.barrel;
import java.util.Random;
import com.kennethsmedievalmod.init.BlockInit;
import com.kennethsmedievalmod.init.ItemInit;
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.getHeldItemOffhand().getItem(), 1));
player.sendMessage(new TextComponentString(TextFormatting.GREEN + setInput.getItem().getUnlocalizedName() + " Input"));
for(int j = 0; j < BarrelRecipes.barrelRecipes.size(); j++) {
if(BarrelRecipes.barrelRecipes.get(j).input == getTE(world, pos).selectedInput) {
ItemStack setOutput = getTE(world, pos).SetOutput(BarrelRecipes.barrelRecipes.get(i).output);
player.sendMessage(new TextComponentString(TextFormatting.GREEN + setOutput.getItem().getUnlocalizedName() + " Output"));
}
}
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(BarrelRecipes.acceptedInputs.get(i) == player.getHeldItemMainhand().getItem()) {
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.addItemStackToInventory(getTE(world, pos).selectedOutput);
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);
}
}
And finally the barrel tile entity:
package com.kennethsmedievalmod.init.blocks.barrel;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable;
public class YewBarrelDataTileEntity extends TileEntity implements ITickable {
public ItemStack selectedInput;
public ItemStack selectedOutput;
public boolean aging = false;
public float agingTimer = 0f;
public int DrinksLeft = 0;
public ItemStack SetRecipeInput (ItemStack selectedInputItem) {
selectedInput = selectedInputItem;
StartAging();
markDirty();
return selectedInput;
}
public ItemStack SetOutput (ItemStack selectedOutputItem) {
selectedOutput = selectedOutputItem;
markDirty();
return selectedOutput;
}
public int TakeDrink() {
DrinksLeft--;
markDirty();
return DrinksLeft;
}
public int AddDrink() {
DrinksLeft++;
markDirty();
return DrinksLeft;
}
public void StartAging () {
aging = true;
agingTimer = 0f;
DrinksLeft = 0;
}
@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();
}
}
}
}
public void StopAging () {
agingTimer = 0;
DrinksLeft = 10;
aging = false;
}
}
On line 84 and 85 in the barrel block class, it sends the message, but it says the input was set to "tile.air" and it does not send the message on line 89. What is going on?
Rollback Post to RevisionRollBack
Finds a server that says "No PvP"
*Pushes AFK player off cliff*
Steals Player's Stuff
Admin Can't do anything cause I didn't hit him so "no actual PvP".
Here is the barrel recipes class:
And here is the BarrelRecipe class:
And here is the Barrel Block class:
And finally the barrel tile entity:
On line 84 and 85 in the barrel block class, it sends the message, but it says the input was set to "tile.air" and it does not send the message on line 89. What is going on?
Finds a server that says "No PvP"
*Pushes AFK player off cliff*
Steals Player's Stuff
Admin Can't do anything cause I didn't hit him so "no actual PvP".