-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from GrowthcraftCE/3.0.0.5-Growthcraft-Milk
3.0.0.5 growthcraft milk
- Loading branch information
Showing
33 changed files
with
1,691 additions
and
11 deletions.
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
src/main/java/cjminecraft/bitofeverything/client/gui/ProgressBar.java
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
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 | ||
} | ||
|
||
} |
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
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
137 changes: 137 additions & 0 deletions
137
src/main/java/growthcraft/cellar/blocks/BlockBrewKettle.java
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
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(); | ||
} | ||
} |
Oops, something went wrong.