Skip to content

Commit

Permalink
Merge pull request #1 from GrowthcraftCE/3.0.0.5-Growthcraft-Milk
Browse files Browse the repository at this point in the history
3.0.0.5 growthcraft milk
  • Loading branch information
Avatair committed Dec 28, 2017
2 parents 4163efe + 8541564 commit e0ede0c
Show file tree
Hide file tree
Showing 33 changed files with 1,691 additions and 11 deletions.
145 changes: 145 additions & 0 deletions src/main/java/cjminecraft/bitofeverything/client/gui/ProgressBar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package cjminecraft.bitofeverything.client.gui;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;

/**
* An easy way to draw a {@link ProgressBar}
*
* @author CJMinecraft
*/
public class ProgressBar extends Gui {

private ResourceLocation texture;
private ProgressBarDirection direction;
private int positionX, positionY;
private int width, height;
private int textureX, textureY;

private float min, max = 0;

/**
* Create a {@link ProgressBar} with all the details set
*
* @param texture The texture of the {@link ProgressBar}
* @param direction The way in which the {@link ProgressBar} will move
* @param width The width of the {@link ProgressBar}
* @param height The height of the {@link ProgressBar}
* @param positonX The x position
* @param positionY The y position
* @param textureX The x position of the texture
* @param textureY The y position of the texture
*/
public ProgressBar(ResourceLocation texture, ProgressBarDirection direction, int width, int height, int positonX,
int positionY, int textureX, int textureY) {
this.texture = texture;
this.direction = direction;
this.width = width;
this.height = height;
this.positionX = positonX;
this.positionY = positionY;
this.textureX = textureX;
this.textureY = textureY;
}

/**
* Set the minimum value (aka the <strong>this</strong> out of something)
*
* @param min The <strong>this</strong> out of something
* @return The {@link ProgressBar}
*/
public ProgressBar setMin(int min) {
this.min = min;
return this;
}

/**
* Set the maximum value (aka the cap or the something out of
* <strong>this</strong>)
*
* @param max The <strong>this</strong> out of something
* @return The {@link ProgressBar}
*/
public ProgressBar setMax(int max) {
this.max = max;
return this;
}

/**
* Get the width based on the min and max values
*
* @return The width
*/
private int getAdjustedWidth() {
return (int) (min != 0 && max != 0 ? min / max * width : 0);
}

/**
* Get the height based on the min and max values
*
* @return The height
*/
private int getAdjustedHeight() {
return (int) (min != 0 && max != 0 ? min / max * height : 0);
}

/**
* Draw the {@link ProgressBar}
*
* @param mc So that the code can bind the texture
*/
public void draw(Minecraft mc) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(texture);
switch (direction) {
case DIAGONAL_UP_LEFT:
this.drawTexturedModalRect(positionX, positionY, textureX, textureY, width, height);
this.drawTexturedModalRect(positionX, positionY, positionX, positionY, width - getAdjustedWidth(),
height - getAdjustedHeight());
break;
case DIAGONAL_UP_RIGHT:
this.drawTexturedModalRect(positionX, positionY, textureX, textureY, width, height);
this.drawTexturedModalRect(positionX + getAdjustedWidth(), positionY, positionX + getAdjustedWidth(),
positionY, width - getAdjustedWidth(), height - getAdjustedHeight());
break;
case DIAGONAL_DOWN_LEFT:
this.drawTexturedModalRect(positionX, positionY, textureX, textureY, width, height);
this.drawTexturedModalRect(positionX, positionY + getAdjustedHeight(), positionX,
positionY + getAdjustedHeight(), width - getAdjustedWidth(), height - getAdjustedHeight());
break;
case DIAGONAL_DOWN_RIGHT:
this.drawTexturedModalRect(positionX, positionY, textureX, textureY, getAdjustedWidth(),
getAdjustedHeight());
break;
case DOWN_TO_UP:
this.drawTexturedModalRect(positionX, positionY, textureX, textureY, width, height);
this.drawTexturedModalRect(positionX, positionY, positionX, positionY, width, height - getAdjustedHeight());
break;
case LEFT_TO_RIGHT:
this.drawTexturedModalRect(positionX, positionY, textureX, textureY, getAdjustedWidth(), height);
break;
case RIGHT_TO_LEFT:
this.drawTexturedModalRect(positionX, positionY, textureX, textureY, width, height);
this.drawTexturedModalRect(positionX, positionY, positionX, positionY, width - getAdjustedWidth(), height);
break;
case UP_TO_DOWN:
this.drawTexturedModalRect(positionX, positionY, textureX, textureY, width, getAdjustedHeight());
break;
default:
this.drawTexturedModalRect(positionX, positionY, textureX, textureY, width, height);
break;
}
}

/**
* Which way the {@link ProgressBar} will move
*
* @author CJMinecraft
*/
public enum ProgressBarDirection {
LEFT_TO_RIGHT, RIGHT_TO_LEFT, UP_TO_DOWN, DOWN_TO_UP, DIAGONAL_UP_RIGHT, DIAGONAL_UP_LEFT, DIAGONAL_DOWN_RIGHT, DIAGONAL_DOWN_LEFT
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import growthcraft.bamboo.Reference;
import growthcraft.bamboo.blocks.*;
import growthcraft.bamboo.handler.ColorHandlerBlockBambooLeaves;
import growthcraft.core.utils.GrowthcraftLogger;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFenceGate;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -86,7 +85,6 @@ public static void setCustomStateMappers() {

@SideOnly(Side.CLIENT)
public static void registerBlockColorHandler(Block block) {
GrowthcraftLogger.getLogger().info("[DEBUG::DEBUG] Registering " + block.getUnlocalizedName() + " color handlers.");
BlockColors blockColors = Minecraft.getMinecraft().getBlockColors();
blockColors.registerBlockColorHandler(new ColorHandlerBlockBambooLeaves(), block);
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/growthcraft/cellar/GrowthcraftCellar.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package growthcraft.cellar;

import growthcraft.cellar.client.gui.GuiHandler;
import growthcraft.cellar.init.GrowthcraftCellarBlocks;
import growthcraft.cellar.proxy.CommonProxy;
import net.minecraftforge.fluids.FluidRegistry;
Expand All @@ -8,9 +9,11 @@
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;

@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION)
public class GrowthcraftCellar {

@Mod.Instance(Reference.MODID)
public static GrowthcraftCellar instance;

Expand All @@ -25,16 +28,17 @@ public class GrowthcraftCellar {
public static void preInit(FMLPreInitializationEvent event) {
// Fluids First


GrowthcraftCellarBlocks.init();

GrowthcraftCellarBlocks.register();

proxy.preInit();
proxy.registerTitleEntities();
}

@Mod.EventHandler
public static void init(FMLInitializationEvent event) {
NetworkRegistry.INSTANCE.registerGuiHandler(Reference.MODID, new GuiHandler());
proxy.registerModelBakeryVariants();
}

Expand Down
137 changes: 137 additions & 0 deletions src/main/java/growthcraft/cellar/blocks/BlockBrewKettle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package growthcraft.cellar.blocks;

import growthcraft.cellar.Reference;
import growthcraft.cellar.client.gui.GuiHandler;
import growthcraft.cellar.tileentity.TileEntityBrewKettle;
import growthcraft.core.handlers.FluidHandler;
import growthcraft.core.utils.GrowthcraftLogger;
import growthcraft.milk.blocks.fluids.FluidRennet;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;

import javax.annotation.Nullable;
import java.util.List;

public class BlockBrewKettle extends Block implements ITileEntityProvider {

private static final AxisAlignedBB AABB_FULL_BLOCK = new AxisAlignedBB(
0.0625 * 0, 0.0625 * 0, 0.0625 * 0,
0.0625 * 16, 0.0625 * 16, 0.0625 * 16);

private static final AxisAlignedBB AABB_BASE = new AxisAlignedBB(
0.0625 * 0, 0.0625 * 0, 0.0625 * 0,
0.0625 * 16, 0.0625 * 4, 0.0625 * 16);
private static final AxisAlignedBB AABB_WALL_NORTH = new AxisAlignedBB(
0.0625 * 14, 0.0625 * 0, 0.0625 * 0,
0.0625 * 16, 0.0625 * 16, 0.0625 * 16);
private static final AxisAlignedBB AABB_WALL_EAST = new AxisAlignedBB(
0.0625 * 14, 0.0625 * 0, 0.0625 * 0,
0.0625 * 16, 0.0625 * 16, 0.0625 * 16);
private static final AxisAlignedBB AABB_WALL_SOUTH = new AxisAlignedBB(
0.0625 * 0, 0.0625 * 0, 0.0625 * 14,
0.0625 * 2, 0.0625 * 16, 0.0625 * 16);
private static final AxisAlignedBB AABB_WALL_WEST = new AxisAlignedBB(
0.0625 * 0, 0.0625 * 0, 0.0625 * 0,
0.0625 * 2, 0.0625 * 16, 0.0625 * 16);

public BlockBrewKettle(String unlocalizedName) {
super(Material.IRON);
this.setUnlocalizedName(unlocalizedName);
this.setRegistryName(new ResourceLocation(Reference.MODID, unlocalizedName));
}

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!worldIn.isRemote) {

FluidStack fluidStack = FluidUtil.getFluidContained(playerIn.getHeldItem(hand));
TileEntityBrewKettle tileEntity = (TileEntityBrewKettle) worldIn.getTileEntity(pos);

if (fluidStack != null) {
GrowthcraftLogger.getLogger().info("Holding " + fluidStack.getUnlocalizedName() + " which is a " + fluidStack.getFluid().getClass().toString());
}

if (fluidStack != null && fluidStack.getFluid() instanceof FluidRennet) {
FluidHandler fluidHandler = (FluidHandler) tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);

if (fluidHandler.getFluidTank().getFluidAmount() + fluidStack.amount <= fluidHandler.getFluidTank().getCapacity()) {
fluidHandler.fill(fluidStack, true);

if (!playerIn.capabilities.isCreativeMode) {
playerIn.setHeldItem(hand, new ItemStack(Items.BUCKET));
}
return true;
}
}

playerIn.openGui(Reference.MODID, GuiHandler.BREW_KETTLE, worldIn, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}

@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean p_185477_7_) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_BASE);
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_NORTH);
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_EAST);
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_SOUTH);
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_WEST);
}

@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return AABB_FULL_BLOCK;
}

@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);
// TODO: If brew kettle is full and player is on fire, extinguish the player.0
}

@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}

@Override
public boolean isFullCube(IBlockState state) {
return false;
}

@Override
public boolean isFullBlock(IBlockState state) {
return false;
}

/* -- ITileEntityProvider -- */

@Nullable
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileEntityBrewKettle();
}

@Nullable
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new TileEntityBrewKettle();
}
}
Loading

0 comments on commit e0ede0c

Please sign in to comment.