forked from AE2-UEL/AE2FluidCraft-Rework
-
Notifications
You must be signed in to change notification settings - Fork 52
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 #47 from asdflj/fluidBuffer
add Fluid Buffer
- Loading branch information
Showing
18 changed files
with
425 additions
and
57 deletions.
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
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
69 changes: 69 additions & 0 deletions
69
src/main/java/com/glodblock/github/client/render/RenderBlockFluidBuffer.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,69 @@ | ||
package com.glodblock.github.client.render; | ||
|
||
import appeng.client.render.BaseBlockRender; | ||
import appeng.client.render.BlockRenderInfo; | ||
import com.glodblock.github.common.block.BlockFluidBuffer; | ||
import com.glodblock.github.common.tile.TileFluidBuffer; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.client.renderer.RenderBlocks; | ||
import net.minecraft.client.renderer.Tessellator; | ||
import net.minecraft.util.IIcon; | ||
import net.minecraft.world.IBlockAccess; | ||
import net.minecraftforge.fluids.Fluid; | ||
import net.minecraftforge.fluids.FluidRegistry; | ||
import org.lwjgl.opengl.GL11; | ||
|
||
public class RenderBlockFluidBuffer extends BaseBlockRender<BlockFluidBuffer, TileFluidBuffer> { | ||
|
||
public RenderBlockFluidBuffer() { | ||
super(false, 20); | ||
} | ||
|
||
@Override | ||
public boolean renderInWorld( | ||
final BlockFluidBuffer block, | ||
final IBlockAccess world, | ||
final int x, | ||
final int y, | ||
final int z, | ||
final RenderBlocks renderer) { | ||
final TileFluidBuffer ti = block.getTileEntity(world, x, y, z); | ||
final BlockRenderInfo info = block.getRendererInstance(); | ||
this.renderFluid(ti, x, y, z, renderer); | ||
final boolean fz = super.renderInWorld(block, world, x, y, z, renderer); | ||
info.setTemporaryRenderIcon(null); | ||
return fz; | ||
} | ||
|
||
private void renderFluid(TileFluidBuffer tileEntity, double x, double y, double z, RenderBlocks renderer) { | ||
Tessellator tessellator = Tessellator.instance; | ||
if (tileEntity != null && tileEntity.getFluidStack() != null) { | ||
Fluid storedFluid = tileEntity.getFluidStack().getFluid(); | ||
if (storedFluid != null) { | ||
GL11.glEnable(GL11.GL_BLEND); | ||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); | ||
Block id = Block.getBlockById(FluidRegistry.WATER.getID()); | ||
IIcon fluidIcon = storedFluid.getIcon(); | ||
if (fluidIcon == null) fluidIcon = FluidRegistry.LAVA.getIcon(); | ||
tessellator.setColorRGBA_F( | ||
(storedFluid.getColor() >> 16 & 0xFF) / 255.0F, | ||
(storedFluid.getColor() >> 8 & 0xFF) / 255.0F, | ||
(storedFluid.getColor() & 0xFF) / 255.0F, | ||
1.0F); | ||
tessellator.setNormal(0.0F, -1F, 0.0F); | ||
renderer.renderFaceYNeg(id, x, y, z, fluidIcon); | ||
tessellator.setNormal(0.0F, 1.0F, 0.0F); | ||
renderer.renderFaceYPos(id, x, y, z, fluidIcon); | ||
tessellator.setNormal(0.0F, 0.0F, -1F); | ||
renderer.renderFaceZNeg(id, x, y, z, fluidIcon); | ||
tessellator.setNormal(0.0F, 0.0F, 1.0F); | ||
renderer.renderFaceZPos(id, x, y, z, fluidIcon); | ||
tessellator.setNormal(-1F, 0.0F, 0.0F); | ||
renderer.renderFaceXNeg(id, x, y, z, fluidIcon); | ||
tessellator.setNormal(1.0F, 0.0F, 0.0F); | ||
renderer.renderFaceXPos(id, x, y, z, fluidIcon); | ||
GL11.glDisable(GL11.GL_BLEND); | ||
} | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/com/glodblock/github/common/block/BlockFluidBuffer.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,74 @@ | ||
package com.glodblock.github.common.block; | ||
|
||
import appeng.api.storage.data.IAEFluidStack; | ||
import appeng.block.AEBaseItemBlock; | ||
import appeng.util.Platform; | ||
import com.glodblock.github.client.render.RenderBlockFluidBuffer; | ||
import com.glodblock.github.common.tabs.FluidCraftingTabs; | ||
import com.glodblock.github.common.tile.TileFluidBuffer; | ||
import com.glodblock.github.crossmod.waila.Tooltip; | ||
import com.glodblock.github.util.NameConst; | ||
import com.glodblock.github.util.Util; | ||
import cpw.mods.fml.common.registry.GameRegistry; | ||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ChatComponentText; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.fluids.FluidStack; | ||
|
||
public class BlockFluidBuffer extends FCBaseBlock { | ||
|
||
public BlockFluidBuffer() { | ||
super(Material.iron, NameConst.BLOCK_FLUID_BUFFER); | ||
setTileEntity(TileFluidBuffer.class); | ||
setFullBlock(false); | ||
setOpaque(false); | ||
this.lightOpacity = 3; | ||
} | ||
|
||
@Override | ||
public boolean onActivated( | ||
World world, int x, int y, int z, EntityPlayer player, int facing, float hitX, float hitY, float hitZ) { | ||
ItemStack itemStack = player.inventory.getCurrentItem(); | ||
FluidStack fs = Util.getFluidFromItem(itemStack); | ||
if (Platform.isServer()) { | ||
TileFluidBuffer tile = getTileEntity(world, x, y, z); | ||
if (tile == null) return false; | ||
if (player.isSneaking() && itemStack == null) return !tile.setFluid(null); | ||
IAEFluidStack ias = tile.getAEStoreFluidStack(); | ||
if (fs == null && ias != null) { | ||
player.addChatMessage(new ChatComponentText( | ||
Tooltip.fluidFormat(ias.getFluid().getLocalizedName(), ias.getStackSize()))); | ||
return false; | ||
} else { | ||
tile.setFluid(fs); | ||
return true; | ||
} | ||
} | ||
return fs != null || (player.isSneaking() && itemStack == null); | ||
} | ||
|
||
public BlockFluidBuffer register() { | ||
GameRegistry.registerBlock(this, AEBaseItemBlock.class, NameConst.BLOCK_FLUID_BUFFER); | ||
GameRegistry.registerTileEntity(TileFluidBuffer.class, NameConst.BLOCK_FLUID_BUFFER); | ||
setCreativeTab(FluidCraftingTabs.INSTANCE); | ||
return this; | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
protected RenderBlockFluidBuffer getRenderer() { | ||
return new RenderBlockFluidBuffer(); | ||
} | ||
|
||
public ItemStack stack(int size) { | ||
return new ItemStack(this, size); | ||
} | ||
|
||
public ItemStack stack() { | ||
return new ItemStack(this, 1); | ||
} | ||
} |
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
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
Oops, something went wrong.