Implement the new model for the Blood Tank
- Texture needs some tinkering. Will bother @InsomniaKitten about it - Minor cleanup and improvements
This commit is contained in:
parent
aac2623440
commit
b7e2730bcc
8 changed files with 438 additions and 108 deletions
|
@ -2,14 +2,11 @@ package WayofTime.bloodmagic.block;
|
|||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.block.base.BlockInteger;
|
||||
import WayofTime.bloodmagic.client.IVariantProvider;
|
||||
import WayofTime.bloodmagic.tile.TileBloodTank;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -20,6 +17,7 @@ import net.minecraft.util.BlockRenderLayer;
|
|||
import net.minecraft.util.EnumBlockRenderType;
|
||||
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.math.RayTraceResult;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
@ -31,16 +29,17 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
|||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockBloodTank extends BlockContainer implements IVariantProvider
|
||||
public class BlockBloodTank extends BlockInteger implements IVariantProvider
|
||||
{
|
||||
public static final PropertyInteger TIER = PropertyInteger.create("tier", 0, TileBloodTank.capacities.length - 1);
|
||||
public static final AxisAlignedBB BOX = new AxisAlignedBB(0.25, 0, 0.25, 0.75, 0.8, 0.75);
|
||||
|
||||
public BlockBloodTank()
|
||||
{
|
||||
super(Material.IRON);
|
||||
super(Material.IRON, TileBloodTank.CAPACITIES.length - 1, "tier");
|
||||
|
||||
setUnlocalizedName(Constants.Mod.MODID + ".bloodTank");
|
||||
setHardness(2.0F);
|
||||
|
@ -49,21 +48,19 @@ public class BlockBloodTank extends BlockContainer implements IVariantProvider
|
|||
setHarvestLevel("pickaxe", 1);
|
||||
setCreativeTab(BloodMagic.tabBloodMagic);
|
||||
setLightOpacity(0);
|
||||
|
||||
setDefaultState(blockState.getBaseState().withProperty(TIER, 0));
|
||||
}
|
||||
|
||||
// This is important!!! - DON'T DELETE - idk why
|
||||
@Nullable
|
||||
@Override
|
||||
public TileEntity createTileEntity(World worldIn, IBlockState blockState)
|
||||
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos)
|
||||
{
|
||||
return new TileBloodTank(getMetaFromState(blockState));
|
||||
return BOX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta)
|
||||
public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos)
|
||||
{
|
||||
return new TileBloodTank(meta);
|
||||
return BOX;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -76,7 +73,7 @@ public class BlockBloodTank extends BlockContainer implements IVariantProvider
|
|||
@SideOnly(Side.CLIENT)
|
||||
public BlockRenderLayer getBlockLayer()
|
||||
{
|
||||
return BlockRenderLayer.TRANSLUCENT;
|
||||
return BlockRenderLayer.CUTOUT_MIPPED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -91,32 +88,6 @@ public class BlockBloodTank extends BlockContainer implements IVariantProvider
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
return this.getDefaultState().withProperty(TIER, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
return state.getValue(TIER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
if (world.getTileEntity(pos) == null)
|
||||
return state;
|
||||
return state.withProperty(TIER, world.getTileEntity(pos).getBlockMetadata());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState()
|
||||
{
|
||||
return new BlockStateContainer(this, new IProperty[] { TIER });
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
|
@ -129,7 +100,7 @@ public class BlockBloodTank extends BlockContainer implements IVariantProvider
|
|||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -141,13 +112,14 @@ public class BlockBloodTank extends BlockContainer implements IVariantProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos blockPos, IBlockState blockState, int fortune)
|
||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState blockState, int fortune)
|
||||
{
|
||||
ArrayList<ItemStack> list = new ArrayList<ItemStack>();
|
||||
|
||||
if (world.getTileEntity(blockPos) instanceof TileBloodTank)
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile instanceof TileBloodTank)
|
||||
{
|
||||
TileBloodTank bloodTank = (TileBloodTank) world.getTileEntity(blockPos);
|
||||
TileBloodTank bloodTank = (TileBloodTank) tile;
|
||||
ItemStack drop = new ItemStack(this);
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
bloodTank.serialize(tag);
|
||||
|
@ -160,21 +132,22 @@ public class BlockBloodTank extends BlockContainer implements IVariantProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, BlockPos blockPos, IBlockState blockState, EntityLivingBase placer, ItemStack stack)
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState blockState, EntityLivingBase placer, ItemStack stack)
|
||||
{
|
||||
if (world.getTileEntity(blockPos) != null && world.getTileEntity(blockPos) instanceof TileBloodTank)
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile instanceof TileBloodTank)
|
||||
{
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
if (tag != null)
|
||||
{
|
||||
((TileBloodTank) world.getTileEntity(blockPos)).deserialize(tag);
|
||||
blockState.withProperty(TIER, stack.getMetadata());
|
||||
((TileBloodTank) tile).deserialize(tag);
|
||||
blockState.withProperty(getProperty(), stack.getMetadata());
|
||||
}
|
||||
}
|
||||
|
||||
world.checkLight(blockPos);
|
||||
world.updateComparatorOutputLevel(blockPos, this);
|
||||
world.markAndNotifyBlock(blockPos, world.getChunkFromBlockCoords(blockPos), blockState, blockState, 3);
|
||||
world.checkLight(pos);
|
||||
world.updateComparatorOutputLevel(pos, this);
|
||||
world.markAndNotifyBlock(pos, world.getChunkFromBlockCoords(pos), blockState, blockState, 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -193,7 +166,7 @@ public class BlockBloodTank extends BlockContainer implements IVariantProvider
|
|||
@Override
|
||||
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
|
||||
{
|
||||
return getDrops(world, pos, world.getBlockState(pos), 0).get(0);
|
||||
return new ItemStack(this, 1, getMetaFromState(state));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -203,19 +176,33 @@ public class BlockBloodTank extends BlockContainer implements IVariantProvider
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(IBlockState state, World w, BlockPos pos)
|
||||
public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos)
|
||||
{
|
||||
TileEntity tile = w.getTileEntity(pos);
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile instanceof TileBloodTank)
|
||||
return ((TileBloodTank) tile).getComparatorOutput();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World worldIn, IBlockState blockState)
|
||||
{
|
||||
return new TileBloodTank(getMetaFromState(blockState));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(IBlockState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// IVariantProvider
|
||||
|
||||
@Override
|
||||
public List<Pair<Integer, String>> getVariants()
|
||||
{
|
||||
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>();
|
||||
for (int i = 0; i < TileBloodTank.capacities.length; i++)
|
||||
for (int i = 0; i < TileBloodTank.CAPACITIES.length; i++)
|
||||
ret.add(new ImmutablePair<Integer, String>(i, "inventory"));
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -39,8 +39,10 @@ public class RenderBloodTank extends TileEntitySpecialRenderer<TileBloodTank>
|
|||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
public void renderFluid(float scale, Fluid renderFluid, double x, double y, double z)
|
||||
public void renderFluid(float maxHeight, Fluid renderFluid, double x, double y, double z)
|
||||
{
|
||||
maxHeight = maxHeight * 0.575F;
|
||||
|
||||
GlStateManager.translate(x, y, z);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
|
||||
|
@ -69,56 +71,40 @@ public class RenderBloodTank extends TileEntitySpecialRenderer<TileBloodTank>
|
|||
float u2 = fluid.getMaxU();
|
||||
float v2 = fluid.getMaxV();
|
||||
|
||||
if (scale > 0)
|
||||
{
|
||||
float edge = 0.9375F;
|
||||
float otherEdge = 0.0625F;
|
||||
float offset = 0.002F;
|
||||
if (maxHeight > 0) {
|
||||
float texWidth = u2 - u1;
|
||||
|
||||
// Top
|
||||
buffer.pos(0, scale - offset, 0).tex(u1, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0, scale - offset, 1).tex(u1, v2).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(1, scale - offset, 1).tex(u2, v2).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(1, scale - offset, 0).tex(u2, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
// TOP
|
||||
buffer.pos(0.25, maxHeight + 0.05, 0.25).tex(u1 + 0.75 * texWidth, v1 + (maxHeight + 0.05) * texWidth).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.25, maxHeight + 0.05, 0.75).tex(u1 + 0.75 * texWidth, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.75, maxHeight + 0.05, 0.75).tex(u1 + 0.25 * texWidth, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.75, maxHeight + 0.05, 0.25).tex(u1 + 0.25 * texWidth, v1 + (maxHeight + 0.05) * texWidth).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
|
||||
// Bottom
|
||||
buffer.pos(1, offset, 0).tex(u1, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(1, offset, 1).tex(u1, v2).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0, offset, 1).tex(u2, v2).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0, offset, 0).tex(u2, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
// NORTH
|
||||
buffer.pos(0.75, maxHeight + 0.05, 0.25).tex(u1 + 0.75 * texWidth, v1 + (maxHeight + 0.05) * texWidth).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.75, 0, 0.25).tex(u1 + 0.75 * texWidth, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.25, 0, 0.25).tex(u1 + 0.25 * texWidth, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.25, maxHeight + 0.05, 0.25).tex(u1 + 0.25 * texWidth, v1 + (maxHeight + 0.05) * texWidth).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
|
||||
if (scale > otherEdge)
|
||||
{
|
||||
if (scale > edge)
|
||||
scale = edge;
|
||||
// EAST
|
||||
buffer.pos(0.25, 0, 0.75).tex(u1 + 0.75 * texWidth, v1 + (maxHeight + 0.05) * texWidth).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.25, maxHeight + 0.05, 0.75).tex(u1 + 0.75 * texWidth, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.25, maxHeight + 0.05, 0.25).tex(u1 + 0.25 * texWidth, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.25, 0, 0.25).tex(u1 + 0.25 * texWidth, v1 + (maxHeight + 0.05) * texWidth).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
|
||||
v2 -= (fluid.getMaxV() - fluid.getMinV()) * (1 - scale);
|
||||
// SOUTH
|
||||
buffer.pos(0.75, 0, 0.75).tex(u1 + 0.75 * texWidth, v1 + (maxHeight + 0.05) * texWidth).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.75, maxHeight + 0.05, 0.75).tex(u1 + 0.75 * texWidth, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.25, maxHeight + 0.05, 0.75).tex(u1 + 0.25 * texWidth, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.25, 0, 0.75).tex(u1 + 0.25 * texWidth, v1 + (maxHeight + 0.05) * texWidth).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
|
||||
//NORTH
|
||||
buffer.pos(1, scale, offset).tex(u1, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(1, 0, offset).tex(u1, v2).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0, 0, offset).tex(u2, v2).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0, scale, offset).tex(u2, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
|
||||
//EAST
|
||||
buffer.pos(offset, 0, 1).tex(u1, v2).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(offset, scale, 1).tex(u1, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(offset, scale, 0).tex(u2, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(offset, 0, 0).tex(u2, v2).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
|
||||
//SOUTH
|
||||
buffer.pos(1, 0, 1 - offset).tex(u1, v2).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(1, scale, 1 - offset).tex(u1, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0, scale, 1 - offset).tex(u2, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0, 0, 1 - offset).tex(u2, v2).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
|
||||
//WEST
|
||||
buffer.pos(1 - offset, scale, 1).tex(u1, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(1 - offset, 0, 1).tex(u1, v2).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(1 - offset, 0, 0).tex(u2, v2).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(1 - offset, scale, 0).tex(u2, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
}
|
||||
// WEST
|
||||
buffer.pos(0.75, maxHeight + 0.05, 0.75).tex(u1 + 0.75 * texWidth, v1 + (maxHeight + 0.05) * texWidth).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.75, 0, 0.75).tex(u1 + 0.75 * texWidth, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.75, 0, 0.25).tex(u1 + 0.25 * texWidth, v1).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
buffer.pos(0.75, maxHeight + 0.05, 0.25).tex(u1 + 0.25 * texWidth, v1 + (maxHeight + 0.05) * texWidth).color(rColor, gColor, bColor, aColor).endVertex();
|
||||
}
|
||||
|
||||
tessellator.draw();
|
||||
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
|
|
|
@ -71,7 +71,7 @@ public class BakedCustomItemModel implements IPerspectiveAwareModel
|
|||
GlStateManager.pushMatrix();
|
||||
|
||||
FluidStack fluid = null;
|
||||
float capacity = TileBloodTank.capacities[stack.getItemDamage()] * Fluid.BUCKET_VOLUME;
|
||||
float capacity = TileBloodTank.CAPACITIES[stack.getItemDamage()] * Fluid.BUCKET_VOLUME;
|
||||
int amount = 0;
|
||||
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(Constants.NBT.TANK))
|
||||
{
|
||||
|
|
|
@ -70,7 +70,7 @@ public class ItemBlockBloodTank extends ItemBlock implements IFluidContainerItem
|
|||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item id, CreativeTabs creativeTab, List<ItemStack> list)
|
||||
{
|
||||
for (int i = 0; i < TileBloodTank.capacities.length; i++)
|
||||
for (int i = 0; i < TileBloodTank.CAPACITIES.length; i++)
|
||||
list.add(new ItemStack(id, 1, i));
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ public class ItemBlockBloodTank extends ItemBlock implements IFluidContainerItem
|
|||
@Override
|
||||
public int getCapacity(ItemStack container)
|
||||
{
|
||||
return container != null && Block.getBlockFromItem(container.getItem()) instanceof BlockBloodTank ? TileBloodTank.capacities[container.getMetadata()] * Fluid.BUCKET_VOLUME : 0;
|
||||
return container != null && Block.getBlockFromItem(container.getItem()) instanceof BlockBloodTank ? TileBloodTank.CAPACITIES[container.getMetadata()] * Fluid.BUCKET_VOLUME : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,17 +14,17 @@ public class TileBloodTank extends TileBase
|
|||
public int capacity;
|
||||
protected FluidTank tank;
|
||||
|
||||
public static int[] capacities = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65336, 131072, 262144, 524288 };
|
||||
public static final int[] CAPACITIES = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65336, 131072, 262144, 524288 };
|
||||
|
||||
public TileBloodTank(int meta)
|
||||
{
|
||||
capacity = capacities[meta] * Fluid.BUCKET_VOLUME;
|
||||
capacity = CAPACITIES[meta] * Fluid.BUCKET_VOLUME;
|
||||
tank = new FluidTank(capacity);
|
||||
}
|
||||
|
||||
public TileBloodTank()
|
||||
{
|
||||
capacity = capacities[0] * Fluid.BUCKET_VOLUME;
|
||||
capacity = CAPACITIES[0] * Fluid.BUCKET_VOLUME;
|
||||
tank = new FluidTank(capacity);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue