mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-20 20:22:35 +00:00
Add drink models
This commit is contained in:
1 parent
81f632168b
commit
a51bfd196c
20 files changed
+257
-267
No files matched your search
@@ -1,10 +1,13 @@
|
||||
package binnie.extratrees.alcohol;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import binnie.Binnie;
|
||||
import binnie.Constants;
|
||||
import binnie.extratrees.ExtraTrees;
|
||||
|
||||
public enum Glassware {
|
||||
@@ -27,16 +30,20 @@ public enum Glassware {
|
||||
float contentBottom;
|
||||
float contentHeight;
|
||||
private int capacity;
|
||||
//public IIcon glass;
|
||||
//public IIcon contents;
|
||||
private ModelResourceLocation location;
|
||||
|
||||
Glassware(final int capacity, final int contentBottom, final int contentHeight) {
|
||||
this.capacity = capacity;
|
||||
this.contentBottom = contentBottom / 32.0f;
|
||||
this.contentHeight = contentHeight / 32.0f;
|
||||
location = new ModelResourceLocation(Constants.EXTRA_TREES_MOD_ID + ":glassware/" + getName(),"inventory");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public String getName(@Nullable final String liquid) {
|
||||
public String getName(@Nullable String liquid) {
|
||||
if (liquid == null) {
|
||||
return ExtraTrees.proxy.localise("item.glassware." + this.name().toLowerCase());
|
||||
}
|
||||
@@ -46,11 +53,10 @@ public enum Glassware {
|
||||
public int getCapacity() {
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
/*public void registerIcons(final IIconRegister par1IconRegister) {
|
||||
this.glass = ExtraTrees.proxy.getIcon(par1IconRegister, "glassware/" + this.toString().toLowerCase() + ".glass");
|
||||
this.contents = ExtraTrees.proxy.getIcon(par1IconRegister, "glassware/" + this.toString().toLowerCase() + ".contents");
|
||||
}*/
|
||||
|
||||
public ModelResourceLocation getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public ItemStack get(final int i) {
|
||||
return ExtraTrees.alcohol().drink.getStack(this, null);
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
package binnie.extratrees.alcohol.drink;
|
||||
|
||||
public class CocktailRenderer //implements IItemRenderer
|
||||
{
|
||||
/*private void renderCocktail(final RenderBlocks renderBlocks, final ItemStack item, final float p, final float q, final float r) {
|
||||
final RenderItem renderItem = new RenderItem();
|
||||
GlStateManager.enableBlend();
|
||||
GL11.glBlendFunc(770, 771);
|
||||
final Glassware glass = ExtraTrees.drink.getGlassware(item);
|
||||
final FluidStack fluid = ExtraTrees.drink.getFluid(item);
|
||||
final IDrinkLiquid drink = (fluid == null) ? null : DrinkManager.getLiquid(fluid.getFluid());
|
||||
this.setColor(16777215, 0.8f);
|
||||
renderItem.renderIcon(0, 0, glass.glass, 16, 16);
|
||||
if (drink != null) {
|
||||
this.setColor(drink.getColour(), 1.2f * drink.getTransparency() + 0.3f);
|
||||
final IIcon icon = glass.contents;
|
||||
final float amount = fluid.amount / glass.getVolume();
|
||||
final float level = glass.getContentHeight() * (1.0f - amount);
|
||||
final float gapAtTop = 1.0f - (glass.getContentBottom() + glass.getContentHeight());
|
||||
final float x = 0.0f;
|
||||
final float y = 16.0f * (gapAtTop + level);
|
||||
final float w = 16.0f;
|
||||
final float h = 16.0f - y;
|
||||
final float minV = icon.getInterpolatedV(y);
|
||||
final float maxV = icon.getInterpolatedV(16.0);
|
||||
final Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.addVertexWithUV(x + 0.0f, y + h, renderItem.zLevel, icon.getMinU(), maxV);
|
||||
tessellator.addVertexWithUV(x + w, y + h, renderItem.zLevel, icon.getMaxU(), maxV);
|
||||
tessellator.addVertexWithUV(x + w, y + 0.0f, renderItem.zLevel, icon.getMaxU(), minV);
|
||||
tessellator.addVertexWithUV(x + 0.0f, y + 0.0f, renderItem.zLevel, icon.getMinU(), minV);
|
||||
tessellator.draw();
|
||||
}
|
||||
GlStateManager.disableBlend();
|
||||
}
|
||||
|
||||
private void setColor(final int i1, final float alpha) {
|
||||
final float f = (i1 >> 16 & 0xFF) / 255.0f;
|
||||
final float f2 = (i1 >> 8 & 0xFF) / 255.0f;
|
||||
final float f3 = (i1 & 0xFF) / 255.0f;
|
||||
GL11.glColor4f(f, f2, f3, (alpha > 1.0f) ? 1.0f : alpha);
|
||||
}
|
||||
|
||||
private void renderFace(final Tessellator tessellator, final ForgeDirection dir) {
|
||||
switch (dir) {
|
||||
case DOWN: {
|
||||
tessellator.addVertex(0.0, 0.0, 0.0);
|
||||
tessellator.addVertex(0.0, 0.0, 1.0);
|
||||
tessellator.addVertex(1.0, 0.0, 1.0);
|
||||
tessellator.addVertex(1.0, 0.0, 0.0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleRenderType(final ItemStack item, final IItemRenderer.ItemRenderType type) {
|
||||
switch (type) {
|
||||
case ENTITY: {
|
||||
return true;
|
||||
}
|
||||
case EQUIPPED: {
|
||||
return true;
|
||||
}
|
||||
case INVENTORY: {
|
||||
return true;
|
||||
}
|
||||
case EQUIPPED_FIRST_PERSON: {
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUseRenderHelper(final IItemRenderer.ItemRenderType type, final ItemStack item, final IItemRenderer.ItemRendererHelper helper) {
|
||||
return helper == IItemRenderer.ItemRendererHelper.ENTITY_ROTATION || helper == IItemRenderer.ItemRendererHelper.ENTITY_BOBBING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderItem(final IItemRenderer.ItemRenderType type, final ItemStack item, final Object... data) {
|
||||
switch (type) {
|
||||
case ENTITY:
|
||||
case EQUIPPED:
|
||||
case EQUIPPED_FIRST_PERSON: {
|
||||
if (type == IItemRenderer.ItemRenderType.ENTITY) {
|
||||
GlStateManager.translate(-0.5f, -0.25f, -0.0f);
|
||||
}
|
||||
final TextureManager texturemanager = BinnieCore.proxy.getMinecraftInstance().getTextureManager();
|
||||
final Glassware glass = ExtraTrees.drink.getGlassware(item);
|
||||
final FluidStack fluid = ExtraTrees.drink.getFluid(item);
|
||||
IIcon iicon = glass.glass;
|
||||
final float f = iicon.getMinU();
|
||||
final float f2 = iicon.getMaxU();
|
||||
final float f3 = iicon.getMinV();
|
||||
final float f4 = iicon.getMaxV();
|
||||
texturemanager.bindTexture(texturemanager.getResourceLocation(item.getItemSpriteNumber()));
|
||||
TextureUtil.func_152777_a(false, false, 1.0f);
|
||||
this.setColor(16777215, 0.8f);
|
||||
final IDrinkLiquid drink = (fluid == null) ? null : DrinkManager.getLiquid(fluid.getFluid());
|
||||
this.setColor(16777215, 0.8f);
|
||||
ItemRenderer.renderItemIn2D(Tessellator.instance, f2, f3, f, f4, iicon.getIconWidth(), iicon.getIconHeight(), 0.0625f);
|
||||
if (drink != null) {
|
||||
this.setColor(drink.getColour(), 1.2f * drink.getTransparency() + 0.3f);
|
||||
iicon = glass.contents;
|
||||
final IIcon icon = glass.contents;
|
||||
final float amount = fluid.amount / glass.getVolume();
|
||||
final float level = glass.getContentHeight() * (1.0f - amount);
|
||||
final float gapAtTop = 1.0f - (glass.getContentBottom() + glass.getContentHeight());
|
||||
final float x = 0.0f;
|
||||
final float y = 1.0f * (gapAtTop + level);
|
||||
final float w = 1.0f;
|
||||
final float h = 1.0f - y;
|
||||
final float minV = icon.getInterpolatedV(y * 16.0f);
|
||||
final float maxV = icon.getInterpolatedV(16.0);
|
||||
final float minU = icon.getMinU();
|
||||
final float maxU = icon.getMaxU();
|
||||
final Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.setNormal(0.0f, 0.0f, -1.0f);
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.addVertexWithUV(0.0, 1.0 - y, -0.03125, maxU, minV);
|
||||
tessellator.addVertexWithUV(1.0, 1.0 - y, -0.03125, minU, minV);
|
||||
tessellator.addVertexWithUV(1.0, 0.0, -0.03125, minU, maxV);
|
||||
tessellator.addVertexWithUV(0.0, 0.0, -0.03125, maxU, maxV);
|
||||
tessellator.draw();
|
||||
tessellator.setNormal(0.0f, 0.0f, 1.0f);
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.addVertexWithUV(0.0, 1.0 - y, -0.03125, maxU, minV);
|
||||
tessellator.addVertexWithUV(0.0, 0.0, -0.03125, maxU, maxV);
|
||||
tessellator.addVertexWithUV(1.0, 0.0, -0.03125, minU, maxV);
|
||||
tessellator.addVertexWithUV(1.0, 1.0 - y, -0.03125, minU, minV);
|
||||
tessellator.draw();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case INVENTORY: {
|
||||
this.renderCocktail((RenderBlocks) data[0], item, -0.5f, -0.5f, -0.5f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void renderItemIn2DPercentage(final Tessellator tesselator, final float maxU, final float minV, final float minU, float maxV, final int width, final int height, final float depth, final float percent) {
|
||||
maxV = minV + (maxV - minV) * 1.0f;
|
||||
tesselator.startDrawingQuads();
|
||||
tesselator.setNormal(0.0f, 0.0f, 1.0f);
|
||||
tesselator.addVertexWithUV(0.0, 0.0, 0.0, maxU, maxV);
|
||||
tesselator.addVertexWithUV(1.0, 0.0, 0.0, minU, maxV);
|
||||
tesselator.addVertexWithUV(1.0, 1.0, 0.0, minU, minV);
|
||||
tesselator.addVertexWithUV(0.0, 1.0, 0.0, maxU, minV);
|
||||
tesselator.draw();
|
||||
tesselator.startDrawingQuads();
|
||||
tesselator.setNormal(0.0f, 0.0f, -1.0f);
|
||||
tesselator.addVertexWithUV(0.0, percent, 0.0f - depth, maxU, minV);
|
||||
tesselator.addVertexWithUV(1.0, percent, 0.0f - depth, minU, minV);
|
||||
tesselator.addVertexWithUV(1.0, 0.0, 0.0f - depth, minU, maxV);
|
||||
tesselator.addVertexWithUV(0.0, 0.0, 0.0f - depth, maxU, maxV);
|
||||
tesselator.draw();
|
||||
final float f5 = 0.5f * (maxU - minU) / width;
|
||||
final float f6 = 0.5f * (maxV - minV) / height;
|
||||
tesselator.startDrawingQuads();
|
||||
tesselator.setNormal(-1.0f, 0.0f, 0.0f);
|
||||
for (int k = 0; k < width; ++k) {
|
||||
final float f7 = k / width;
|
||||
final float f8 = maxU + (minU - maxU) * f7 - f5;
|
||||
tesselator.addVertexWithUV(f7, 0.0, 0.0f - depth, f8, maxV);
|
||||
tesselator.addVertexWithUV(f7, 0.0, 0.0, f8, maxV);
|
||||
tesselator.addVertexWithUV(f7, 1.0, 0.0, f8, minV);
|
||||
tesselator.addVertexWithUV(f7, 1.0, 0.0f - depth, f8, minV);
|
||||
}
|
||||
tesselator.draw();
|
||||
tesselator.startDrawingQuads();
|
||||
tesselator.setNormal(1.0f, 0.0f, 0.0f);
|
||||
for (int k = 0; k < width; ++k) {
|
||||
final float f7 = k / width;
|
||||
final float f8 = maxU + (minU - maxU) * f7 - f5;
|
||||
final float f9 = f7 + 1.0f / width;
|
||||
tesselator.addVertexWithUV(f9, 1.0, 0.0f - depth, f8, minV);
|
||||
tesselator.addVertexWithUV(f9, 1.0, 0.0, f8, minV);
|
||||
tesselator.addVertexWithUV(f9, 0.0, 0.0, f8, maxV);
|
||||
tesselator.addVertexWithUV(f9, 0.0, 0.0f - depth, f8, maxV);
|
||||
}
|
||||
tesselator.draw();
|
||||
tesselator.startDrawingQuads();
|
||||
tesselator.setNormal(0.0f, 1.0f, 0.0f);
|
||||
for (int k = 0; k < height; ++k) {
|
||||
final float f7 = k / height;
|
||||
final float f8 = maxV + (minV - maxV) * f7 - f6;
|
||||
final float f9 = f7 + 1.0f / height;
|
||||
tesselator.addVertexWithUV(0.0, f9, 0.0, maxU, f8);
|
||||
tesselator.addVertexWithUV(1.0, f9, 0.0, minU, f8);
|
||||
tesselator.addVertexWithUV(1.0, f9, 0.0f - depth, minU, f8);
|
||||
tesselator.addVertexWithUV(0.0, f9, 0.0f - depth, maxU, f8);
|
||||
}
|
||||
tesselator.draw();
|
||||
tesselator.startDrawingQuads();
|
||||
tesselator.setNormal(0.0f, -1.0f, 0.0f);
|
||||
for (int k = 0; k < height; ++k) {
|
||||
final float f7 = k / height;
|
||||
final float f8 = maxV + (minV - maxV) * f7 - f6;
|
||||
tesselator.addVertexWithUV(1.0, f7, 0.0, minU, f8);
|
||||
tesselator.addVertexWithUV(0.0, f7, 0.0, maxU, f8);
|
||||
tesselator.addVertexWithUV(0.0, f7, 0.0f - depth, maxU, f8);
|
||||
tesselator.addVertexWithUV(1.0, f7, 0.0f - depth, minU, f8);
|
||||
}
|
||||
tesselator.draw();
|
||||
}*/
|
||||
}
|
||||
@@ -3,13 +3,19 @@ package binnie.extratrees.alcohol.drink;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemFood;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
@@ -17,12 +23,15 @@ import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.Tabs;
|
||||
|
||||
import binnie.extratrees.alcohol.Alcohol;
|
||||
import binnie.extratrees.alcohol.AlcoholEffect;
|
||||
import binnie.extratrees.alcohol.Glassware;
|
||||
|
||||
public class ItemDrink extends ItemFood {
|
||||
public class ItemDrink extends ItemFood implements IItemModelRegister {
|
||||
public ItemDrink() {
|
||||
super(0, 0.0f, false);
|
||||
this.setCreativeTab(Tabs.tabArboriculture);
|
||||
@@ -72,7 +81,19 @@ public class ItemDrink extends ItemFood {
|
||||
nbt.setTag("fluid", liq);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
for(Glassware glassware : Glassware.values()){
|
||||
ModelLoader.registerItemVariants(item, glassware.getLocation());
|
||||
}
|
||||
manager.registerItemModel(item, (ItemStack stack)->{
|
||||
Glassware glassware = getGlassware(stack);
|
||||
return glassware.getLocation();
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) {
|
||||
@@ -106,41 +127,18 @@ public class ItemDrink extends ItemFood {
|
||||
}
|
||||
return this.getGlassware(stack).getName(liquidName);
|
||||
}
|
||||
|
||||
/*@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(final IIconRegister par1IconRegister) {
|
||||
for (final Glassware glassware : Glassware.values()) {
|
||||
glassware.registerIcons(par1IconRegister);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(final ItemStack stack, final int pass) {
|
||||
final Glassware glass = this.getGlassware(stack);
|
||||
return (pass == 0) ? glass.glass : ((this.getFluid(stack) == null) ? glass.glass : glass.contents);
|
||||
protected void onFoodEaten(ItemStack stack, World world, EntityPlayer player) {
|
||||
super.onFoodEaten(stack, world, player);
|
||||
AlcoholEffect.makeDrunk(player, 2.1f);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getColorFromItemStack(final ItemStack stack, final int pass) {
|
||||
final FluidStack fluid = this.getFluid(stack);
|
||||
final IDrinkLiquid drink = (fluid == null) ? null : DrinkManager.getLiquid(fluid.getFluid());
|
||||
return (pass == 0) ? 16777215 : ((drink == null) ? 16777215 : drink.getColour());
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
|
||||
return super.onItemUseFinish(stack, worldIn, entityLiving);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderPasses(final int metadata) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onEaten(final ItemStack p_77654_1_, final World p_77654_2_, final EntityPlayer p_77654_3_) {
|
||||
this.drain(p_77654_1_, 30, true);
|
||||
AlcoholEffect.makeDrunk(p_77654_3_, 2.1f);
|
||||
return p_77654_1_;
|
||||
}*/
|
||||
|
||||
|
||||
@Override
|
||||
public EnumAction getItemUseAction(final ItemStack itemStack) {
|
||||
if (FluidUtil.getFluidContained(itemStack) != null) {
|
||||
@@ -150,20 +148,14 @@ public class ItemDrink extends ItemFood {
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean requiresMultipleRenderPasses() {
|
||||
return true;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public int getMaxItemUseDuration(final ItemStack p_77626_1_) {
|
||||
return 16;
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public ItemStack onItemRightClick(final ItemStack p_77659_1_, final World p_77659_2_, final EntityPlayer p_77659_3_) {
|
||||
p_77659_3_.setItemInUse(p_77659_1_, this.getMaxItemUseDuration(p_77659_1_));
|
||||
return p_77659_1_;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
||||
player.setActiveHand(hand);
|
||||
return super.onItemRightClick(world, player, hand);
|
||||
}
|
||||
}
|
||||
@@ -106,9 +106,6 @@ public class BlockETDoor extends BlockDoor implements IWoodTyped, IItemModelRegi
|
||||
return woodType.getHardness();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Item that this Block should drop when harvested.
|
||||
*/
|
||||
/**
|
||||
* Get the Item that this Block should drop when harvested.
|
||||
*/
|
||||
|
||||
@@ -3,6 +3,9 @@ package binnie.extratrees.integration.jei;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
|
||||
import binnie.core.integration.jei.Drawables;
|
||||
import binnie.extratrees.ExtraTrees;
|
||||
import binnie.extratrees.block.WoodManager;
|
||||
@@ -41,6 +44,14 @@ public class ExtraTreesJeiPlugin extends BlankModPlugin {
|
||||
}
|
||||
return Integer.toString(itemStack.getItemDamage());
|
||||
});
|
||||
subtypeRegistry.registerSubtypeInterpreter(ExtraTrees.alcohol().drink, (ItemStack itemStack) -> {
|
||||
String glassware = ExtraTrees.alcohol().drink.getGlassware(itemStack).getName();
|
||||
FluidStack fluidStack = FluidUtil.getFluidContained(itemStack);
|
||||
if(fluidStack == null){
|
||||
return glassware;
|
||||
}
|
||||
return glassware + ":" + fluidStack.getFluid().getName();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user