Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
765 additions
and
1 deletion.
There are no files selected for viewing
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
63 changes: 63 additions & 0 deletions
63
src/main/java/net/dries007/tfc/client/render/TESRBarrel.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,63 @@ | ||
package net.dries007.tfc.client.render; | ||
|
||
import org.lwjgl.opengl.GL11; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.BufferBuilder; | ||
import net.minecraft.client.renderer.GlStateManager; | ||
import net.minecraft.client.renderer.Tessellator; | ||
import net.minecraft.client.renderer.texture.TextureAtlasSprite; | ||
import net.minecraft.client.renderer.texture.TextureMap; | ||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; | ||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; | ||
import net.minecraftforge.fluids.FluidStack; | ||
|
||
import net.dries007.tfc.objects.te.TEBarrel; | ||
|
||
public class TESRBarrel extends TileEntitySpecialRenderer<TEBarrel> | ||
{ | ||
@Override | ||
public void render(TEBarrel te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) | ||
{ | ||
FluidStack fluid = te.tank.getFluid(); | ||
|
||
if (fluid == null) | ||
{ | ||
return; | ||
} | ||
|
||
TextureAtlasSprite texture = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(fluid.getFluid().getStill().toString()); | ||
|
||
GlStateManager.pushMatrix(); | ||
GlStateManager.translate(x, y, z); | ||
|
||
GlStateManager.enableAlpha(); | ||
GlStateManager.enableBlend(); | ||
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); | ||
|
||
int color = fluid.getFluid().getColor(); | ||
|
||
float r = ((color >> 16) & 0xFF) / 255f; // red | ||
float g = ((color >> 8) & 0xFF) / 255f; // green | ||
float b = (color & 0xFF) / 255f; // blue | ||
float a = ((color >> 24) & 0xFF) / 255f; // alpha | ||
|
||
GlStateManager.color(r, g, b, a); | ||
|
||
//rendererDispatcher.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); | ||
|
||
BufferBuilder buffer = Tessellator.getInstance().getBuffer(); | ||
|
||
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); | ||
|
||
double height = te.fillHeightForRender; | ||
|
||
buffer.pos(0.1875, height, 0.1875).tex(texture.getInterpolatedU(3), texture.getInterpolatedV(3)).normal(0, 0, 1).endVertex(); | ||
buffer.pos(0.1875, height, 0.8125).tex(texture.getInterpolatedU(3), texture.getInterpolatedV(13)).normal(0, 0, 1).endVertex(); | ||
buffer.pos(0.8125, height, 0.8125).tex(texture.getInterpolatedU(13), texture.getInterpolatedV(13)).normal(0, 0, 1).endVertex(); | ||
buffer.pos(0.8125, height, 0.1875).tex(texture.getInterpolatedU(13), texture.getInterpolatedV(3)).normal(0, 0, 1).endVertex(); | ||
|
||
Tessellator.getInstance().draw(); | ||
|
||
GlStateManager.popMatrix(); | ||
} | ||
} |
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
135 changes: 135 additions & 0 deletions
135
src/main/java/net/dries007/tfc/objects/blocks/wood/BlockBarrel.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,135 @@ | ||
package net.dries007.tfc.objects.blocks.wood; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.ITileEntityProvider; | ||
import net.minecraft.block.SoundType; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.block.properties.PropertyBool; | ||
import net.minecraft.block.state.BlockStateContainer; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.tileentity.TileEntity; | ||
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.text.TextComponentString; | ||
import net.minecraft.world.IBlockAccess; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.fluids.FluidUtil; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
import net.dries007.tfc.objects.te.TEBarrel; | ||
|
||
public class BlockBarrel extends Block implements ITileEntityProvider | ||
{ | ||
public static final PropertyBool SEALED = PropertyBool.create("sealed"); | ||
private static final AxisAlignedBB bounds = new AxisAlignedBB(0.125D, 0.0D, 0.125D, 0.875D, 1.0D, 0.875D); | ||
|
||
public BlockBarrel() | ||
{ | ||
super(Material.WOOD); | ||
setSoundType(SoundType.WOOD); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("deprecation") | ||
public boolean isFullCube(IBlockState state) | ||
{ | ||
return false; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("deprecation") | ||
public boolean isOpaqueCube(IBlockState state) | ||
{ | ||
return false; | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public BlockRenderLayer getRenderLayer() | ||
{ | ||
return BlockRenderLayer.CUTOUT; | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) | ||
{ | ||
return bounds; | ||
} | ||
|
||
@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) | ||
{ | ||
return true; | ||
} | ||
|
||
ItemStack heldItem = playerIn.getHeldItem(hand); | ||
|
||
TEBarrel te = (TEBarrel)worldIn.getTileEntity(pos); | ||
|
||
if (heldItem != ItemStack.EMPTY) | ||
{ | ||
FluidUtil.interactWithFluidHandler(playerIn, hand, te.tank); | ||
te.markDirty(); | ||
worldIn.notifyBlockUpdate(pos, state, state, 3); | ||
} | ||
else if (playerIn.isSneaking()) | ||
{ | ||
te.sealed = !te.sealed; | ||
te.markDirty(); | ||
worldIn.notifyBlockUpdate(pos, state, state, 3); | ||
|
||
return false; | ||
} | ||
else | ||
{ | ||
playerIn.sendMessage(new TextComponentString("Content: " + te.tank.getFluidAmount())); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public TileEntity createNewTileEntity(World worldIn, int meta) | ||
{ | ||
return new TEBarrel(); | ||
} | ||
|
||
@Override | ||
public BlockStateContainer createBlockState() | ||
{ | ||
return new BlockStateContainer(this, SEALED); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("deprecation") | ||
public IBlockState getStateFromMeta(int meta) | ||
{ | ||
return this.getDefaultState(); | ||
} | ||
|
||
@Override | ||
public int getMetaFromState(IBlockState state) | ||
{ | ||
return 0; | ||
} | ||
|
||
|
||
@Override | ||
@SuppressWarnings("deprecation") | ||
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) | ||
{ | ||
return super.getActualState(state, worldIn, pos).withProperty(SEALED, ((TEBarrel)worldIn.getTileEntity(pos)).sealed); | ||
} | ||
} |
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,74 @@ | ||
package net.dries007.tfc.objects.te; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.network.NetworkManager; | ||
import net.minecraft.network.play.server.SPacketUpdateTileEntity; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraftforge.fluids.FluidStack; | ||
import net.minecraftforge.fluids.FluidTank; | ||
|
||
public class TEBarrel extends TileEntity | ||
{ | ||
public double fillHeightForRender; | ||
|
||
public FluidTank tank = new FluidTank(10000); | ||
public boolean sealed; | ||
|
||
@Override | ||
public void readFromNBT(NBTTagCompound compound) | ||
{ | ||
super.readFromNBT(compound); | ||
|
||
tank.readFromNBT(compound.getCompoundTag("tank")); | ||
sealed = compound.getBoolean("sealed"); | ||
} | ||
|
||
@Override | ||
public NBTTagCompound writeToNBT(NBTTagCompound compound) | ||
{ | ||
NBTTagCompound tankTag = new NBTTagCompound(); | ||
|
||
tank.writeToNBT(tankTag); | ||
compound.setTag("tank", tankTag); | ||
compound.setBoolean("sealed", sealed); | ||
|
||
return super.writeToNBT(compound); | ||
} | ||
|
||
@Override | ||
public NBTTagCompound getUpdateTag() | ||
{ | ||
return writeToNBT(new NBTTagCompound()); | ||
} | ||
|
||
@Override | ||
public void handleUpdateTag(NBTTagCompound tag) | ||
{ | ||
this.readFromNBT(tag); | ||
|
||
if (tank.getFluid() != null) | ||
{ | ||
fillHeightForRender = 0.140625D + (0.75D - 0.015625D) * tank.getFluidAmount() / tank.getCapacity(); | ||
} | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public SPacketUpdateTileEntity getUpdatePacket() | ||
{ | ||
if (world != null) | ||
{ | ||
return new SPacketUpdateTileEntity(this.getPos(), 0, this.writeToNBT(new NBTTagCompound())); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) | ||
{ | ||
this.handleUpdateTag(packet.getNbtCompound()); | ||
} | ||
} |
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,26 @@ | ||
{ | ||
"forge_marker": 1, | ||
"defaults": { | ||
"model": "tfc:barrel", | ||
"textures": { | ||
"particle": "tfc:blocks/wood/planks/oak", | ||
"planks": "tfc:blocks/wood/planks/oak", | ||
"sheet": "tfc:blocks/wood/sheets/oak", | ||
"hoop": "tfc:blocks/barrelhoop" | ||
} | ||
}, | ||
"variants": { | ||
"normal": [ | ||
{} | ||
], | ||
"sealed": { | ||
"true": { | ||
"model": "tfc:barrel_sealed" | ||
}, | ||
"false": {} | ||
}, | ||
"inventory": [ | ||
{} | ||
] | ||
} | ||
} |
Oops, something went wrong.