Guest User

Untitled

a guest
Sep 19th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.03 KB | None | 0 0
  1. package com.kennethsmedievalmod.init.blocks.barrel.yewbarrel;
  2.  
  3. import com.kennethsmedievalmod.init.blocks.barrel.BarrelRecipe;
  4. import com.kennethsmedievalmod.init.blocks.barrel.BarrelRecipes;
  5.  
  6. import ibxm.Player;
  7. import net.minecraft.item.Item;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.nbt.NBTTagCompound;
  10. import net.minecraft.tileentity.TileEntity;
  11. import net.minecraft.util.ITickable;
  12. import scala.collection.concurrent.Debug;
  13.  
  14. public class YewBarrelDataTileEntity extends TileEntity implements ITickable {
  15.  
  16. public ItemStack selectedInput;
  17. public Item selectedOutput;
  18.  
  19. public boolean aging = false;
  20. public float agingTimer = 0f;
  21. public int DrinksLeft = 0;
  22.  
  23. int id;
  24.  
  25. public ItemStack SetRecipeInput (ItemStack selectedInputItem) {
  26. selectedInput = selectedInputItem;
  27. SetOutput();
  28. StartAging();
  29. markDirty();
  30. return selectedInput;
  31. }
  32. public void SetOutput () {
  33. for (BarrelRecipe recipe : BarrelRecipes.barrelRecipes) {
  34. if(recipe.input == selectedInput) {
  35. selectedOutput = recipe.output.getItem();
  36. }
  37. }
  38. }
  39.  
  40. public int GetRecipeID () {
  41. for(int i = 0; i < BarrelRecipes.barrelRecipes.size(); i++) {
  42. if(BarrelRecipes.barrelRecipes.get(i).input == selectedInput) {
  43. id = BarrelRecipes.barrelRecipes.get(i).recipeID;
  44. }
  45. }
  46. return id;
  47. }
  48.  
  49. public int TakeDrink() {
  50. DrinksLeft--;
  51. if(DrinksLeft == 0) {
  52. selectedInput = null;
  53. selectedOutput = null;
  54. }
  55. markDirty();
  56. return DrinksLeft;
  57. }
  58. public int AddDrink() {
  59. DrinksLeft++;
  60. markDirty();
  61. return DrinksLeft;
  62. }
  63. public void StartAging () {
  64. aging = true;
  65. agingTimer = 0f;
  66. DrinksLeft = 0;
  67. markDirty();
  68. }
  69. @Override
  70. public void readFromNBT(NBTTagCompound compound) {
  71. super.readFromNBT(compound);
  72. aging = compound.getBoolean("aging");
  73. agingTimer = compound.getFloat("agingTimer");
  74. DrinksLeft = compound.getInteger("drinks_left");
  75. }
  76. @Override
  77. public NBTTagCompound writeToNBT(NBTTagCompound compound) {
  78. super.writeToNBT(compound);
  79. compound.setBoolean("aging", aging);
  80. compound.setFloat("agingTimer", agingTimer);
  81. compound.setInteger("drinks_left", DrinksLeft);
  82. return compound;
  83. }
  84. @Override
  85. public void update() {
  86. if(!this.world.isRemote) {
  87. if (aging == true) {
  88. if(agingTimer < 240) {
  89. agingTimer += 1;
  90. } else if (agingTimer >= 240) {
  91. StopAging();
  92. }
  93. }
  94. }
  95. markDirty();
  96. }
  97. public void StopAging () {
  98. agingTimer = 0;
  99. DrinksLeft = 10;
  100. aging = false;
  101. markDirty();
  102. }
  103. }
  104.  
  105. package com.kennethsmedievalmod.init.blocks.barrel.yewbarrel;
  106.  
  107. import java.util.Random;
  108.  
  109. import com.kennethsmedievalmod.init.BlockInit;
  110. import com.kennethsmedievalmod.init.ItemInit;
  111. import com.kennethsmedievalmod.init.blocks.barrel.BarrelRecipes;
  112.  
  113. import net.minecraft.block.Block;
  114. import net.minecraft.block.ITileEntityProvider;
  115. import net.minecraft.block.material.Material;
  116. import net.minecraft.block.properties.PropertyDirection;
  117. import net.minecraft.block.state.BlockStateContainer;
  118. import net.minecraft.block.state.IBlockState;
  119. import net.minecraft.client.renderer.block.model.ModelResourceLocation;
  120. import net.minecraft.entity.EntityLivingBase;
  121. import net.minecraft.entity.player.EntityPlayer;
  122. import net.minecraft.init.Items;
  123. import net.minecraft.item.Item;
  124. import net.minecraft.item.ItemStack;
  125. import net.minecraft.tileentity.TileEntity;
  126. import net.minecraft.util.EnumFacing;
  127. import net.minecraft.util.EnumHand;
  128. import net.minecraft.util.math.AxisAlignedBB;
  129. import net.minecraft.util.math.BlockPos;
  130. import net.minecraft.util.text.TextComponentString;
  131. import net.minecraft.util.text.TextFormatting;
  132. import net.minecraft.world.IBlockAccess;
  133. import net.minecraft.world.World;
  134. import net.minecraftforge.client.model.ModelLoader;
  135. import net.minecraftforge.fml.relauncher.Side;
  136. import net.minecraftforge.fml.relauncher.SideOnly;
  137.  
  138. public class YewBarrel extends Block implements ITileEntityProvider {
  139.  
  140. public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
  141. public static AxisAlignedBB BARREL_AABB = new AxisAlignedBB(0, 0, 0, 1, 1, 1);
  142.  
  143. public YewBarrel(String name) {
  144. super(Material.WOOD);
  145. setUnlocalizedName(name);
  146. setRegistryName(name);
  147. setHardness(4.0f);
  148. setResistance(20.0f);
  149. setHarvestLevel("axe", 1);
  150. }
  151. @Override
  152. public Item getItemDropped (IBlockState state, Random rand, int fortune) {
  153. return Item.getItemFromBlock(BlockInit.yew_barrel);
  154. }
  155. @Override
  156. public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
  157. return new ItemStack (BlockInit.yew_barrel);
  158. }
  159. @Override
  160. public boolean isOpaqueCube (IBlockState state) {
  161. return false;
  162. }
  163. @Override
  164. public boolean isFullCube (IBlockState state) {
  165. return false;
  166. }
  167. @Override
  168. public AxisAlignedBB getBoundingBox (IBlockState state, IBlockAccess source, BlockPos pos) {
  169. return BARREL_AABB;
  170. }
  171. @SideOnly(Side.CLIENT)
  172. public void initModel() {
  173. ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
  174. }
  175. @Override
  176. public TileEntity createNewTileEntity(World worldIn, int meta) {
  177. return new YewBarrelDataTileEntity();
  178. }
  179. private YewBarrelDataTileEntity getTE(World world, BlockPos pos) {
  180. return (YewBarrelDataTileEntity) world.getTileEntity(pos);
  181. }
  182. @Override
  183. public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
  184. if (!world.isRemote) {
  185. if(getTE(world, pos).selectedInput == null) {
  186. if(player.getHeldItemMainhand().getItem() != ItemInit.empty_beer_mug) {
  187. for(int i = 0; i < BarrelRecipes.acceptedInputs.size(); i++) {
  188. if(BarrelRecipes.acceptedInputs.get(i) == player.getHeldItemMainhand().getItem()) {
  189. ItemStack setInput = getTE(world, pos).SetRecipeInput(new ItemStack (player.getHeldItemMainhand().getItem(), 1));
  190. player.sendMessage(new TextComponentString(TextFormatting.GREEN + setInput.getItem().getUnlocalizedName() + " Input"));
  191. player.getHeldItemMainhand().setCount(player.getHeldItemMainhand().getCount() - 1);
  192. player.sendMessage(new TextComponentString(TextFormatting.GREEN + "You place the ingredient into the barrel and it starts to age. "));
  193. } else {
  194. if(player.getHeldItemMainhand().getItem() != null) {
  195. player.sendMessage(new TextComponentString(TextFormatting.GREEN + "That item cannot be brewed into beer. "));
  196. }
  197. }
  198. }
  199. }
  200. } else {
  201. for(int i = 0; i < BarrelRecipes.acceptedInputs.size(); i++) {
  202. if(player.getHeldItemMainhand().getItem() == BarrelRecipes.acceptedInputs.get(i)) {
  203. player.sendMessage(new TextComponentString(TextFormatting.GREEN + "Barrel is already aging and has an ingredient in it. "));
  204. }
  205. }
  206. }
  207. if(player.getHeldItemMainhand().getItem() == ItemInit.empty_beer_mug) {
  208. if(getTE(world, pos).agingTimer != 0) {
  209. float time_left = (240 - getTE(world, pos).agingTimer) / 20;
  210. player.sendMessage(new TextComponentString(TextFormatting.GREEN + "The contents of this barrel is still aging. " + time_left + " seconds left to go. "));
  211. } else {
  212. if(getTE(world, pos).DrinksLeft > 0) {
  213. int drinks_left;
  214. drinks_left = getTE(world, pos).TakeDrink();
  215. player.sendMessage(new TextComponentString(TextFormatting.GREEN + BarrelRecipes.barrelRecipes.get(0).output.getItem().getUnlocalizedName()));
  216.  
  217. int toGetId = getTE(world, pos).GetRecipeID();
  218. player.sendMessage(new TextComponentString(TextFormatting.GREEN + "Test1" + toGetId));
  219.  
  220. player.sendMessage(new TextComponentString(TextFormatting.GREEN + "Barrel now has " + drinks_left + " refils of beer in it. "));
  221. }
  222. }
  223. }
  224. }
  225. return true;
  226. }
  227. @Override
  228. public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
  229. world.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
  230. }
  231. @Override
  232. public IBlockState getStateFromMeta(int meta) {
  233. // 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.
  234. return getDefaultState().withProperty(FACING, EnumFacing.getFront((meta & 3) + 2));
  235. }
  236. @Override
  237. public int getMetaFromState(IBlockState state) {
  238. // 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.
  239. return state.getValue(FACING).getIndex()-2;
  240. }
  241. @Override
  242. protected BlockStateContainer createBlockState() {
  243. return new BlockStateContainer(this, FACING);
  244. }
  245. }
  246.  
  247. package com.kennethsmedievalmod.init.blocks.barrel;
  248.  
  249. import java.util.ArrayList;
  250. import java.util.List;
  251.  
  252. import com.kennethsmedievalmod.init.ItemInit;
  253.  
  254. import net.minecraft.init.Items;
  255. import net.minecraft.item.Item;
  256. import net.minecraft.item.ItemStack;
  257.  
  258. public class BarrelRecipes {
  259. public static List<Item> acceptedInputs = new ArrayList<Item>();
  260. public static List<BarrelRecipe> barrelRecipes = new ArrayList<BarrelRecipe>();
  261. public static BarrelRecipe basicBeer;
  262. public static void init () {
  263. basicBeer = new BarrelRecipe (new ItemStack (Items.WHEAT, 1), new ItemStack(ItemInit.basic_beer_mug, 1), 1);
  264. acceptedInputs.add(Items.WHEAT);
  265. }
  266. public static void register () {
  267. barrelRecipes.add(basicBeer);
  268. }
  269. }
  270.  
  271. package com.kennethsmedievalmod.init.blocks.barrel;
  272.  
  273. import net.minecraft.item.ItemStack;
  274.  
  275. public class BarrelRecipe {
  276. public ItemStack input;
  277. public ItemStack output;
  278. public int recipeID;
  279. public BarrelRecipe (ItemStack inputItem, ItemStack outputItem, int newID) {
  280. input = inputItem;
  281. output = outputItem;
  282. recipeID = newID;
  283. }
  284. }
Add Comment
Please, Sign In to add comment