mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-20 12:19:55 +00:00
New 'fill bar' rendering done.
This commit is contained in:
1 parent
1856abcc14
commit
c55a5b8209
14 files changed
+745
-143
No files matched your search
@@ -65,7 +65,8 @@ import crazypants.enderio.machine.attractor.AttractorRenderer;
|
||||
import crazypants.enderio.machine.attractor.BlockAttractor;
|
||||
import crazypants.enderio.machine.attractor.TileAttractor;
|
||||
import crazypants.enderio.machine.capbank.BlockCapBank;
|
||||
import crazypants.enderio.machine.capbank.CapBankRenderer;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.render.CapBankRenderer;
|
||||
import crazypants.enderio.machine.enchanter.EnchanterModelRenderer;
|
||||
import crazypants.enderio.machine.enchanter.TileEnchanter;
|
||||
import crazypants.enderio.machine.farm.BlockFarmStation;
|
||||
@@ -280,6 +281,7 @@ public class ClientProxy extends CommonProxy {
|
||||
CapBankRenderer newCbr = new CapBankRenderer();
|
||||
RenderingRegistry.registerBlockHandler(newCbr);
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockCapBank), newCbr);
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileCapBank.class, newCbr);
|
||||
}
|
||||
|
||||
CapacitorBankRenderer capr = new CapacitorBankRenderer();
|
||||
|
||||
@@ -156,6 +156,9 @@ public class ItemDarkSteelSword extends ItemSword implements IEnergyContainerIte
|
||||
}
|
||||
|
||||
private double getSkullDropChance(EntityPlayer player, LivingDropsEvent evt) {
|
||||
|
||||
//TODO: <boni> stack.getTagCompound().getCompoundTag("InfiTool").getInteger("Beheading")
|
||||
|
||||
if(evt.entityLiving instanceof EntitySkeleton && ((EntitySkeleton) evt.entityLiving).getSkeletonType() == 1) {
|
||||
if(isEquippedAndPowered(player, Config.darkSteelSwordPowerUsePerHit)) {
|
||||
return Config.darkSteelSwordWitherSkullChance + (Config.darkSteelSwordWitherSkullLootingModifier * evt.lootingLevel);
|
||||
|
||||
@@ -32,6 +32,7 @@ import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.gui.IAdvancedTooltipProvider;
|
||||
import crazypants.enderio.gui.TooltipAddera;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
|
||||
import crazypants.enderio.machine.capbank.network.ICapBankNetwork;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketGuiChange;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkEnergyRequest;
|
||||
@@ -69,9 +70,9 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
IIcon overlayIcon;
|
||||
private IIcon gaugeIcon;
|
||||
@SideOnly(Side.CLIENT)
|
||||
IIcon fillBarIcon;
|
||||
private IIcon fillBarIcon;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[] blockIcons;
|
||||
@@ -141,23 +142,50 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) {
|
||||
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(!(te instanceof TileCapBank)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(ToolUtil.breakBlockWithTool(this, world, x, y, z, entityPlayer)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TileCapBank tcb = (TileCapBank) te;
|
||||
ForgeDirection faceHit = ForgeDirection.getOrientation(side);
|
||||
|
||||
if(entityPlayer.isSneaking() && entityPlayer.getCurrentEquippedItem() == null && faceHit.offsetY == 0) {
|
||||
InfoDisplayType newDisplayType = tcb.getDisplayType(faceHit).next();
|
||||
if(newDisplayType == InfoDisplayType.NONE) {
|
||||
tcb.setDefaultIoMode(faceHit);
|
||||
} else {
|
||||
tcb.setIoMode(faceHit, IoMode.DISABLED);
|
||||
}
|
||||
tcb.setDisplayType(faceHit, newDisplayType);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(entityPlayer.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(!(te instanceof TileCapBank)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(ToolUtil.isToolEquipped(entityPlayer)) {
|
||||
|
||||
ForgeDirection faceHit = ForgeDirection.getOrientation(side);
|
||||
TileCapBank tcb = (TileCapBank) te;
|
||||
tcb.toggleIoModeForFace(faceHit);
|
||||
IoMode ioMode = tcb.getIoMode(faceHit);
|
||||
if(faceHit.offsetY == 0) {
|
||||
if(ioMode == IoMode.DISABLED) {
|
||||
InfoDisplayType newDisplayType = tcb.getDisplayType(faceHit).next();
|
||||
tcb.setDisplayType(faceHit, newDisplayType);
|
||||
if(newDisplayType == InfoDisplayType.NONE) {
|
||||
tcb.setDefaultIoMode(faceHit);
|
||||
}
|
||||
} else {
|
||||
tcb.toggleIoModeForFace(faceHit);
|
||||
}
|
||||
} else {
|
||||
tcb.toggleIoModeForFace(faceHit);
|
||||
}
|
||||
|
||||
if(world.isRemote) {
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
} else {
|
||||
@@ -196,7 +224,7 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister IIconRegister) {
|
||||
blockIcon = IIconRegister.registerIcon("enderio:capacitorBank");
|
||||
overlayIcon = IIconRegister.registerIcon("enderio:capacitorBankOverlays");
|
||||
gaugeIcon = IIconRegister.registerIcon("enderio:capacitorBankOverlays");
|
||||
fillBarIcon = IIconRegister.registerIcon("enderio:capacitorBankFillBar");
|
||||
|
||||
blockIcons = new IIcon[CapBankType.types().size()];
|
||||
@@ -208,11 +236,9 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
for (CapBankType type : CapBankType.types()) {
|
||||
blockIcons[index] = IIconRegister.registerIcon(type.getIcon());
|
||||
borderIcons[index] = IIconRegister.registerIcon(type.getBorderIcon());
|
||||
|
||||
inputIcons[index] = IIconRegister.registerIcon(type.getInputIcon());
|
||||
outputIcons[index] = IIconRegister.registerIcon(type.getOutputIcon());
|
||||
lockedIcons[index] = IIconRegister.registerIcon(type.getLockedIcon());
|
||||
|
||||
++index;
|
||||
}
|
||||
|
||||
@@ -264,12 +290,14 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
if(!(te instanceof TileCapBank)) {
|
||||
return blockIcons[0];
|
||||
}
|
||||
TileCapBank cb = (TileCapBank) te;
|
||||
ForgeDirection face = ForgeDirection.values()[side];
|
||||
|
||||
int meta = ba.getBlockMetadata(x, y, z);
|
||||
meta = MathHelper.clamp_int(meta, 0, CapBankType.types().size() - 1);
|
||||
|
||||
TileCapBank cb = (TileCapBank) te;
|
||||
IoMode mode = cb.getIoMode(ForgeDirection.values()[side]);
|
||||
if(mode == null || mode == IoMode.NONE) {
|
||||
IoMode mode = cb.getIoMode(face);
|
||||
if(mode == null || mode == IoMode.NONE || cb.getDisplayType(face) != InfoDisplayType.NONE) {
|
||||
return blockIcons[meta];
|
||||
}
|
||||
if(mode == IoMode.PULL) {
|
||||
@@ -281,6 +309,14 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
return lockedIcons[meta];
|
||||
}
|
||||
|
||||
public IIcon getGaugeIcon() {
|
||||
return gaugeIcon;
|
||||
}
|
||||
|
||||
public IIcon getFillBarIcon() {
|
||||
return fillBarIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block blockId) {
|
||||
if(world.isRemote) {
|
||||
@@ -432,10 +468,11 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
if(cap.getNetwork() != null) {
|
||||
if(world.isRemote && world.getTotalWorldTime() % 20 == 0) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketNetworkStateRequest(cap));
|
||||
} else if(world.isRemote && world.getTotalWorldTime() % 2 == 0) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketNetworkEnergyRequest(cap));
|
||||
}
|
||||
ICapBankNetwork nw = cap.getNetwork();
|
||||
if(world.isRemote) {
|
||||
((CapBankClientNetwork) nw).requestPowerUpdate(cap, 2);
|
||||
}
|
||||
|
||||
String format = Util.TAB + Util.ALIGNRIGHT + EnumChatFormatting.WHITE;
|
||||
if(TooltipAddera.showAdvancedTooltips()) {
|
||||
@@ -464,8 +501,6 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
tooltip
|
||||
.add(String.format("%s%s%sRF/t ", color, fmt.format(change), " " + EnumChatFormatting.RESET.toString()));
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.render.ConnectedTextureRenderer;
|
||||
import crazypants.render.CubeRenderer;
|
||||
import crazypants.render.CustomCubeRenderer;
|
||||
import crazypants.render.RenderUtil;
|
||||
|
||||
public class CapBankRenderer implements ISimpleBlockRenderingHandler, IItemRenderer {
|
||||
|
||||
private ConnectedTextureRenderer connectedTexRenderer;
|
||||
|
||||
public CapBankRenderer() {
|
||||
connectedTexRenderer = new ConnectedTextureRenderer();
|
||||
connectedTexRenderer.setMatchMeta(true);
|
||||
}
|
||||
|
||||
//------- Block
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
meta = MathHelper.clamp_int(meta, 0, CapBankType.types().size() - 1);
|
||||
CapBankType type = CapBankType.getTypeFromMeta(meta);
|
||||
if(!type.isMultiblock()) {
|
||||
connectedTexRenderer.setForceAllEdges(true);
|
||||
} else {
|
||||
connectedTexRenderer.setForceAllEdges(false);
|
||||
}
|
||||
connectedTexRenderer.setEdgeTexture(EnderIO.blockCapBank.getBorderIcon(0, meta));
|
||||
CustomCubeRenderer.instance.renderBlock(world, block, x, y, z, connectedTexRenderer);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory(int modelId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderId() {
|
||||
return BlockCapBank.renderId;
|
||||
}
|
||||
|
||||
//------- Item
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
||||
|
||||
RenderUtil.bindBlockTexture();
|
||||
Tessellator tes = Tessellator.instance;
|
||||
|
||||
tes.startDrawingQuads();
|
||||
CubeRenderer.render(EnderIO.blockCapBank, item.getItemDamage());
|
||||
tes.draw();
|
||||
|
||||
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
GL11.glPolygonOffset(-1.0f, -1.0f);
|
||||
|
||||
tes.startDrawingQuads();
|
||||
tes.setColorRGBA_F(1, 1, 1, 1);
|
||||
renderBorder(null, 0, 0, 0, item.getItemDamage());
|
||||
tes.draw();
|
||||
|
||||
GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
}
|
||||
|
||||
private void renderBorder(IBlockAccess blockAccess, int x, int y, int z, int meta) {
|
||||
IIcon texture = EnderIO.blockCapBank.getBorderIcon(0, meta);
|
||||
for (ForgeDirection face : ForgeDirection.VALID_DIRECTIONS) {
|
||||
RenderUtil.renderConnectedTextureFace(blockAccess, x, y, z, face, texture,
|
||||
blockAccess == null, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import crazypants.enderio.config.Config;
|
||||
|
||||
public class CapBankType {
|
||||
|
||||
|
||||
private static final CapBankType CREATIVE = new CapBankType("CREATIVE", "tile.blockCapBank.creative", 500000, Config.capacitorBankMaxStorageRF, false, true,
|
||||
"enderio:capacitorBank", "enderio:capacitorBankCreativeBorder", "enderio:capacitorBankInput", "enderio:capacitorBankOutput",
|
||||
"enderio:capacitorBankLocked");
|
||||
|
||||
@@ -26,7 +26,6 @@ import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
|
||||
import crazypants.enderio.machine.capbank.network.NetworkState;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketGuiChange;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkEnergyRequest;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkStateRequest;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
@@ -380,7 +379,7 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
private void requestStateUpdate() {
|
||||
if(EnderIO.proxy.getTickCount() % 2 == 0) {
|
||||
if(!updateState()) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketNetworkEnergyRequest(capBank));
|
||||
network.requestPowerUpdate(capBank, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
|
||||
public enum InfoDisplayType {
|
||||
|
||||
NONE,
|
||||
LEVEL_BAR;
|
||||
|
||||
public InfoDisplayType next() {
|
||||
int ord = ordinal();
|
||||
++ord;
|
||||
if(ord >= values().length) {
|
||||
ord = 0;
|
||||
}
|
||||
return values()[ord];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package crazypants.enderio.machine.capbank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -44,6 +45,7 @@ import crazypants.vecmath.Vector3d;
|
||||
public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor, IInventory, IIoConfigurable, IPowerStorage {
|
||||
|
||||
private Map<ForgeDirection, IoMode> faceModes;
|
||||
private Map<ForgeDirection, InfoDisplayType> faceDisplayTypes;
|
||||
|
||||
private CapBankType type;
|
||||
|
||||
@@ -73,6 +75,8 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
private int idRequestTimer = 0;
|
||||
|
||||
private boolean dropItems;
|
||||
private boolean displayTypesDirty;
|
||||
private boolean revalidateDisplayTypes;
|
||||
|
||||
@Override
|
||||
public BlockCoord getLocation() {
|
||||
@@ -89,6 +93,7 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
public void onNeighborBlockChange(Block blockId) {
|
||||
redstoneStateDirty = true;
|
||||
receptorsDirty = true;
|
||||
revalidateDisplayTypes = true;
|
||||
}
|
||||
|
||||
//---------- Multiblock
|
||||
@@ -186,6 +191,15 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
if(receptorsDirty) {
|
||||
updateReceptors();
|
||||
}
|
||||
if(revalidateDisplayTypes) {
|
||||
checkDisplayTypesValid();
|
||||
revalidateDisplayTypes = false;
|
||||
}
|
||||
if(displayTypesDirty) {
|
||||
displayTypesDirty = false;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
|
||||
}
|
||||
|
||||
doDropItems();
|
||||
}
|
||||
@@ -255,6 +269,19 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
}
|
||||
}
|
||||
|
||||
public void setDefaultIoMode(ForgeDirection faceHit) {
|
||||
EnergyReceptor er = getEnergyReceptorForFace(faceHit);
|
||||
if(er == null || er.getConduit() != null) {
|
||||
setIoMode(faceHit, IoMode.NONE);
|
||||
} else if(er.getReceptor().isInputOnly()) {
|
||||
setIoMode(faceHit, IoMode.PUSH);
|
||||
} else if(er.getReceptor().isOutputOnly()) {
|
||||
setIoMode(faceHit, IoMode.PULL);
|
||||
} else {
|
||||
setIoMode(faceHit, IoMode.PUSH);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IoMode getIoMode(ForgeDirection face) {
|
||||
if(faceModes == null) {
|
||||
@@ -267,22 +294,77 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
return res;
|
||||
}
|
||||
|
||||
private IPowerInterface getReceptorForFace(ForgeDirection faceHit) {
|
||||
BlockCoord checkLoc = new BlockCoord(this).getLocation(faceHit);
|
||||
TileEntity te = worldObj.getTileEntity(checkLoc.x, checkLoc.y, checkLoc.z);
|
||||
if(!(te instanceof TileCapBank)) {
|
||||
return PowerHandlerUtil.create(te);
|
||||
} else {
|
||||
TileCapBank other = (TileCapBank) te;
|
||||
if(other.getType() != getType()) {
|
||||
return PowerHandlerUtil.create(te);
|
||||
}
|
||||
//----- Info Display
|
||||
|
||||
public InfoDisplayType getDisplayType(ForgeDirection face) {
|
||||
if(faceDisplayTypes == null) {
|
||||
return InfoDisplayType.NONE;
|
||||
}
|
||||
return null;
|
||||
InfoDisplayType res = faceDisplayTypes.get(face);
|
||||
return res == null ? InfoDisplayType.NONE : res;
|
||||
}
|
||||
|
||||
public void setDisplayType(ForgeDirection face, InfoDisplayType type) {
|
||||
setDisplayType(face, type, true);
|
||||
}
|
||||
|
||||
public void setDisplayType(ForgeDirection face, InfoDisplayType type, boolean markDirty) {
|
||||
if(type == null) {
|
||||
type = InfoDisplayType.NONE;
|
||||
}
|
||||
if(faceDisplayTypes == null && type == InfoDisplayType.NONE) {
|
||||
return;
|
||||
}
|
||||
InfoDisplayType cur = getDisplayType(face);
|
||||
if(cur == type) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(faceDisplayTypes == null) {
|
||||
faceDisplayTypes = new HashMap<ForgeDirection, InfoDisplayType>();
|
||||
}
|
||||
|
||||
if(type == InfoDisplayType.NONE) {
|
||||
faceDisplayTypes.remove(face);
|
||||
} else {
|
||||
faceDisplayTypes.put(face, type);
|
||||
}
|
||||
|
||||
if(faceDisplayTypes.isEmpty()) {
|
||||
faceDisplayTypes = null;
|
||||
}
|
||||
displayTypesDirty = markDirty;
|
||||
}
|
||||
|
||||
private void checkDisplayTypesValid() {
|
||||
if(faceDisplayTypes == null) {
|
||||
return;
|
||||
}
|
||||
List<ForgeDirection> reset = new ArrayList<ForgeDirection>();
|
||||
for (Entry<ForgeDirection, InfoDisplayType> entry : faceDisplayTypes.entrySet()) {
|
||||
BlockCoord bc = getLocation().getLocation(entry.getKey());
|
||||
Block block = worldObj.getBlock(bc.x, bc.y, bc.z);
|
||||
if(block != null && block.isOpaqueCube()) {
|
||||
reset.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
for (ForgeDirection dir : reset) {
|
||||
setDisplayType(dir, InfoDisplayType.NONE);
|
||||
setDefaultIoMode(dir);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----------- Redstone
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderInPass(int pass) {
|
||||
if(faceDisplayTypes == null) {
|
||||
return false;
|
||||
}
|
||||
return pass == 0;
|
||||
}
|
||||
|
||||
public RedstoneControlMode getInputControlMode() {
|
||||
return inputControlMode;
|
||||
}
|
||||
@@ -384,9 +466,31 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
receptorsDirty = false;
|
||||
}
|
||||
|
||||
private IPowerInterface getReceptorForFace(ForgeDirection faceHit) {
|
||||
BlockCoord checkLoc = new BlockCoord(this).getLocation(faceHit);
|
||||
TileEntity te = worldObj.getTileEntity(checkLoc.x, checkLoc.y, checkLoc.z);
|
||||
if(!(te instanceof TileCapBank)) {
|
||||
return PowerHandlerUtil.create(te);
|
||||
} else {
|
||||
TileCapBank other = (TileCapBank) te;
|
||||
if(other.getType() != getType()) {
|
||||
return PowerHandlerUtil.create(te);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private EnergyReceptor getEnergyReceptorForFace(ForgeDirection dir) {
|
||||
IPowerInterface pi = getReceptorForFace(dir);
|
||||
if(pi == null || pi.getDelegate() instanceof TileCapBank) {
|
||||
return null;
|
||||
}
|
||||
return new EnergyReceptor(this, pi, dir);
|
||||
}
|
||||
|
||||
private void validateModeForReceptor(EnergyReceptor er) {
|
||||
IoMode ioMode = getIoMode(er.getDir());
|
||||
if(ioMode == IoMode.PUSH_PULL && er.getConduit() == null) {
|
||||
if((ioMode == IoMode.PUSH_PULL || ioMode == IoMode.NONE) && er.getConduit() == null) {
|
||||
if(er.getReceptor().isOutputOnly()) {
|
||||
setIoMode(er.getDir(), IoMode.PULL, false);
|
||||
} else {
|
||||
@@ -634,16 +738,30 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
}
|
||||
}
|
||||
|
||||
//display type
|
||||
if(faceDisplayTypes != null) {
|
||||
nbtRoot.setByte("hasDisplayTypes", (byte) 1);
|
||||
for (Entry<ForgeDirection, InfoDisplayType> e : faceDisplayTypes.entrySet()) {
|
||||
if(e.getValue() != InfoDisplayType.NONE) {
|
||||
nbtRoot.setShort("faceDisplay" + e.getKey().ordinal(), (short) e.getValue().ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasItems = false;
|
||||
NBTTagList itemList = new NBTTagList();
|
||||
for (int i = 0; i < inventory.length; i++) {
|
||||
if(inventory[i] != null) {
|
||||
hasItems = true;
|
||||
NBTTagCompound itemStackNBT = new NBTTagCompound();
|
||||
itemStackNBT.setByte("Slot", (byte) i);
|
||||
inventory[i].writeToNBT(itemStackNBT);
|
||||
itemList.appendTag(itemStackNBT);
|
||||
}
|
||||
}
|
||||
nbtRoot.setTag("Items", itemList);
|
||||
if(hasItems) {
|
||||
nbtRoot.setTag("Items", itemList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -655,6 +773,7 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
public void readCommonNBT(NBTTagCompound nbtRoot) {
|
||||
type = CapBankType.readTypeFromNBT(nbtRoot);
|
||||
energyStored = nbtRoot.getInteger(PowerHandlerUtil.STORED_ENERGY_NBT_KEY);
|
||||
setEnergyStored(energyStored); //Call this to clamp values in case config changed
|
||||
|
||||
if(nbtRoot.hasKey("maxInput")) {
|
||||
maxInput = nbtRoot.getInteger("maxInput");
|
||||
@@ -680,10 +799,24 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
|
||||
if(nbtRoot.hasKey("hasFaces")) {
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if(nbtRoot.hasKey("face" + dir.ordinal())) {
|
||||
setIoMode(dir, IoMode.values()[nbtRoot.getShort("face" + dir.ordinal())], false);
|
||||
String key = "face" + dir.ordinal();
|
||||
if(nbtRoot.hasKey(key)) {
|
||||
setIoMode(dir, IoMode.values()[nbtRoot.getShort(key)], false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
faceModes = null;
|
||||
}
|
||||
|
||||
if(nbtRoot.hasKey("hasDisplayTypes")) {
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
String key = "faceDisplay" + dir.ordinal();
|
||||
if(nbtRoot.hasKey(key)) {
|
||||
setDisplayType(dir, InfoDisplayType.values()[nbtRoot.getShort(key)], false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
faceDisplayTypes = null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.length; i++) {
|
||||
|
||||
@@ -8,8 +8,11 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkEnergyRequest;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
@@ -32,6 +35,8 @@ public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
|
||||
private float aveChange;
|
||||
|
||||
private long lastPowerRequestTick = -1;
|
||||
|
||||
public CapBankClientNetwork(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
@@ -41,6 +46,14 @@ public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void requestPowerUpdate(TileCapBank capBank, int interval) {
|
||||
long curTick = EnderIO.proxy.getTickCount();
|
||||
if(lastPowerRequestTick == -1 || curTick - lastPowerRequestTick >= interval) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketNetworkEnergyRequest(capBank));
|
||||
lastPowerRequestTick = curTick;
|
||||
}
|
||||
}
|
||||
|
||||
public void setState(World world, NetworkState state) {
|
||||
maxEnergyRecieved = state.getMaxInput();
|
||||
maxEnergySent = state.getMaxOutput();
|
||||
|
||||
@@ -21,6 +21,7 @@ import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.CapBankType;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkEnergyResponse;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkStateResponse;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
@@ -68,6 +69,8 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
|
||||
private final InventoryImpl inventory = new InventoryImpl();
|
||||
|
||||
private boolean firstUpate = true;
|
||||
|
||||
public CapBankNetwork(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
@@ -91,7 +94,6 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
}
|
||||
}
|
||||
setNetwork(world, cap);
|
||||
EnderIO.packetPipeline.sendToAllAround(new PacketNetworkStateResponse(this), cap);
|
||||
}
|
||||
|
||||
|
||||
@@ -216,6 +218,14 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
}
|
||||
prevEnergyStored = energyStored;
|
||||
|
||||
if(firstUpate) {
|
||||
if(!capBanks.isEmpty()) {
|
||||
EnderIO.packetPipeline.sendToAllAround(new PacketNetworkStateResponse(this), capBanks.get(0));
|
||||
EnderIO.packetPipeline.sendToAllAround(new PacketNetworkEnergyResponse(this), capBanks.get(0));
|
||||
}
|
||||
firstUpate = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void transmitEnergy() {
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
package crazypants.enderio.machine.capbank.render;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.capbank.BlockCapBank;
|
||||
import crazypants.enderio.machine.capbank.CapBankType;
|
||||
import crazypants.enderio.machine.capbank.InfoDisplayType;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
|
||||
import crazypants.render.BoundingBox;
|
||||
import crazypants.render.ConnectedTextureRenderer;
|
||||
import crazypants.render.CubeRenderer;
|
||||
import crazypants.render.CustomCubeRenderer;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.ForgeDirectionOffsets;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
|
||||
public class CapBankRenderer extends TileEntitySpecialRenderer implements ISimpleBlockRenderingHandler, IItemRenderer {
|
||||
|
||||
private ConnectedTextureRenderer connectedTexRenderer;
|
||||
private FillGauge fillGauge;
|
||||
|
||||
public CapBankRenderer() {
|
||||
connectedTexRenderer = new ConnectedTextureRenderer();
|
||||
connectedTexRenderer.setMatchMeta(true);
|
||||
fillGauge = new FillGauge();
|
||||
}
|
||||
|
||||
//------- Block
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
meta = MathHelper.clamp_int(meta, 0, CapBankType.types().size() - 1);
|
||||
CapBankType type = CapBankType.getTypeFromMeta(meta);
|
||||
if(!type.isMultiblock()) {
|
||||
connectedTexRenderer.setForceAllEdges(true);
|
||||
} else {
|
||||
connectedTexRenderer.setForceAllEdges(false);
|
||||
}
|
||||
connectedTexRenderer.setEdgeTexture(EnderIO.blockCapBank.getBorderIcon(0, meta));
|
||||
CustomCubeRenderer.instance.renderBlock(world, block, x, y, z, connectedTexRenderer);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory(int modelId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderId() {
|
||||
return BlockCapBank.renderId;
|
||||
}
|
||||
|
||||
//------- Item
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
||||
|
||||
RenderUtil.bindBlockTexture();
|
||||
Tessellator tes = Tessellator.instance;
|
||||
|
||||
tes.startDrawingQuads();
|
||||
CubeRenderer.render(EnderIO.blockCapBank, item.getItemDamage());
|
||||
tes.draw();
|
||||
|
||||
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
GL11.glPolygonOffset(-1.0f, -1.0f);
|
||||
|
||||
tes.startDrawingQuads();
|
||||
tes.setColorRGBA_F(1, 1, 1, 1);
|
||||
renderBorder(null, 0, 0, 0, item.getItemDamage());
|
||||
tes.draw();
|
||||
|
||||
GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
}
|
||||
|
||||
private void renderBorder(IBlockAccess blockAccess, int x, int y, int z, int meta) {
|
||||
IIcon texture = EnderIO.blockCapBank.getBorderIcon(0, meta);
|
||||
for (ForgeDirection face : ForgeDirection.VALID_DIRECTIONS) {
|
||||
RenderUtil.renderConnectedTextureFace(blockAccess, x, y, z, face, texture,
|
||||
blockAccess == null, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
//---- Info Display
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTick) {
|
||||
|
||||
TileCapBank cb = (TileCapBank) te;
|
||||
|
||||
float f = cb.getWorldObj().getBlockLightValue(te.xCoord, te.yCoord, te.zCoord);
|
||||
int l = cb.getWorldObj().getLightBrightnessForSkyBlocks(te.xCoord, te.yCoord, te.zCoord, 0);
|
||||
int l1 = l % 65536;
|
||||
int l2 = l / 65536;
|
||||
Tessellator.instance.setColorOpaque_F(f, f, f);
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, l1, l2);
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
GL11.glPolygonOffset(-1.0f, -1.0f);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
|
||||
// GL11.glEnable(GL11.GL_BLEND);
|
||||
// GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((float) x, (float) y, (float) z);
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
InfoDisplayType type = cb.getDisplayType(dir);
|
||||
if(type != InfoDisplayType.NONE) {
|
||||
renderInfoDisplay(cb, dir, type, x, y, z, partialTick);
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
GL11.glPopAttrib();
|
||||
//GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
}
|
||||
|
||||
private void renderInfoDisplay(TileCapBank cb, ForgeDirection dir, InfoDisplayType type, double x, double y, double z, float partialTick) {
|
||||
CapBankClientNetwork nw = (CapBankClientNetwork) cb.getNetwork();
|
||||
if(type == InfoDisplayType.LEVEL_BAR && nw != null) {
|
||||
nw.requestPowerUpdate(cb, 20);
|
||||
}
|
||||
|
||||
RenderUtil.bindBlockTexture();
|
||||
|
||||
int brightness = cb.getWorldObj().getLightBrightnessForSkyBlocks(cb.xCoord + dir.offsetX, cb.yCoord + dir.offsetY, cb.zCoord + dir.offsetZ, 0);
|
||||
|
||||
Tessellator tes = Tessellator.instance;
|
||||
tes.startDrawingQuads();
|
||||
tes.setBrightness(brightness);
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
|
||||
if(type == InfoDisplayType.LEVEL_BAR) {
|
||||
fillGauge.render(cb, nw, dir);
|
||||
}
|
||||
|
||||
tes.draw();
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected BoundingBox getBoundForFace(ForgeDirection dir) {
|
||||
|
||||
double widthScale = 0.25;
|
||||
double heightScale = 0.8;
|
||||
;
|
||||
boolean isUp = dir.offsetY != 0;
|
||||
|
||||
double xScale = dir.offsetX == 0 ? widthScale : 1;
|
||||
double yScale = isUp ? widthScale : heightScale;
|
||||
double zScale = isUp ? heightScale : (dir.offsetZ == 0 ? widthScale : 1);
|
||||
|
||||
BoundingBox bb = BoundingBox.UNIT_CUBE;
|
||||
Vector3d off = ForgeDirectionOffsets.forDirCopy(dir);
|
||||
off.scale(-1);
|
||||
bb = bb.translate(off);
|
||||
bb = bb.scale(xScale, yScale, zScale);
|
||||
off.scale(-1);
|
||||
bb = bb.translate(off);
|
||||
return bb;
|
||||
}
|
||||
|
||||
// private int getEnergyStoredScaled(CapBankClientNetwork network, int scale) {
|
||||
// return (int) VecmathUtil.clamp(Math.round(scale * network.getEnergyStoredRatio()), 0, scale);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
package crazypants.enderio.machine.capbank.render;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.machine.capbank.InfoDisplayType;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
|
||||
import crazypants.render.BoundingBox;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.ForgeDirectionOffsets;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
import crazypants.vecmath.Vector4f;
|
||||
import crazypants.vecmath.Vertex;
|
||||
|
||||
public class FillGauge {
|
||||
|
||||
private static final double HEIGHT = 0.75;
|
||||
private static final double VERT_BORDER = (1 - HEIGHT) / 2;
|
||||
private static final double WIDTH = 0.25;
|
||||
|
||||
enum Type {
|
||||
SINGLE,
|
||||
TOP,
|
||||
BOTTOM,
|
||||
MIDDLE
|
||||
}
|
||||
|
||||
private IIcon barIcon;
|
||||
private IIcon gaugeIcon;
|
||||
|
||||
private float barHeightV;
|
||||
|
||||
private Map<GaugeKey, List<Vertex>> gaugeVertexCache;
|
||||
private Map<GaugeKey, List<Vertex>> levelVertexCache;
|
||||
private float barMinV;
|
||||
|
||||
FillGauge() {
|
||||
}
|
||||
|
||||
public void render(TileCapBank cb, CapBankClientNetwork nw, ForgeDirection dir) {
|
||||
if(gaugeVertexCache == null) {
|
||||
createVertexCache();
|
||||
}
|
||||
GaugeInfo info = getGaugeInfo(cb, dir);
|
||||
GaugeKey key = new GaugeKey(dir, info.type);
|
||||
List<Vertex> verts = gaugeVertexCache.get(key);
|
||||
RenderUtil.addVerticesToTessellator(verts, Tessellator.instance);
|
||||
|
||||
renderFillBar(key, nw, info);
|
||||
|
||||
}
|
||||
|
||||
private void renderFillBar(GaugeKey key, CapBankClientNetwork nw, GaugeInfo info) {
|
||||
double ratio = 0;
|
||||
if(nw != null) {
|
||||
ratio = nw.getEnergyStoredRatio();
|
||||
}
|
||||
if(ratio <= 0) {
|
||||
return;
|
||||
}
|
||||
double maxY = ratio * info.height;
|
||||
if(maxY <= info.yPosition) {
|
||||
//empty
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3d offset = ForgeDirectionOffsets.offsetScaled(key.dir, 0.005);
|
||||
Tessellator.instance.addTranslation((float) offset.x, (float) offset.y, (float) offset.z);
|
||||
|
||||
List<Vertex> verts = levelVertexCache.get(key);
|
||||
if(maxY >= info.yPosition + 1) {
|
||||
//full bar
|
||||
RenderUtil.addVerticesToTessellator(verts, Tessellator.instance);
|
||||
|
||||
} else {
|
||||
//need to render partial bar
|
||||
double myMaxY = maxY - info.yPosition;
|
||||
|
||||
if(info.type == Type.BOTTOM || info.type == Type.SINGLE) {
|
||||
//If we have some power and we are the bottom bit of the display,
|
||||
//always show at least a little bit in the bar
|
||||
myMaxY = Math.max(0.2, myMaxY);
|
||||
}
|
||||
List<Vertex> newVerts = new ArrayList<Vertex>();
|
||||
for (Vertex v : verts) {
|
||||
v = new Vertex(v);
|
||||
newVerts.add(v);
|
||||
if(v.y() > myMaxY) {
|
||||
v.setXYZ(v.x(), myMaxY, v.z());
|
||||
v.setUV(v.u(), barMinV + (float) (myMaxY * barHeightV));
|
||||
}
|
||||
}
|
||||
RenderUtil.addVerticesToTessellator(newVerts, Tessellator.instance);
|
||||
}
|
||||
offset.scale(-1);
|
||||
Tessellator.instance.addTranslation((float) offset.x, (float) offset.y, (float) offset.z);
|
||||
|
||||
}
|
||||
|
||||
private GaugeInfo getGaugeInfo(TileCapBank cb, ForgeDirection dir) {
|
||||
int height = 1;
|
||||
int yPos = 0;
|
||||
BlockCoord loc = cb.getLocation();
|
||||
boolean found = true;
|
||||
while (found) {
|
||||
loc = loc.getLocation(ForgeDirection.UP);
|
||||
if(isGaugeType(cb.getWorldObj(), loc, dir)) {
|
||||
height++;
|
||||
} else {
|
||||
found = false;
|
||||
}
|
||||
}
|
||||
|
||||
loc = cb.getLocation();
|
||||
found = true;
|
||||
while (found) {
|
||||
loc = loc.getLocation(ForgeDirection.DOWN);
|
||||
if(isGaugeType(cb.getWorldObj(), loc, dir)) {
|
||||
height++;
|
||||
yPos++;
|
||||
} else {
|
||||
found = false;
|
||||
}
|
||||
}
|
||||
|
||||
return new GaugeInfo(height, yPos);
|
||||
|
||||
}
|
||||
|
||||
// private Type getType(TileCapBank cb, ForgeDirection dir) {
|
||||
// boolean hasAbove = isGaugeType(cb.getWorldObj(), cb.getLocation().getLocation(ForgeDirection.UP), dir);
|
||||
// boolean hasBellow = isGaugeType(cb.getWorldObj(), cb.getLocation().getLocation(ForgeDirection.DOWN), dir);
|
||||
//
|
||||
// if(!hasAbove && !hasBellow) {
|
||||
// return Type.SINGLE;
|
||||
// } else if(hasAbove && !hasBellow) {
|
||||
// return Type.TOP;
|
||||
// } else if(!hasAbove && hasBellow) {
|
||||
// return Type.BOTTOM;
|
||||
// }
|
||||
// return Type.MIDDLE;
|
||||
// }
|
||||
|
||||
private boolean isGaugeType(World worldObj, BlockCoord bc, ForgeDirection face) {
|
||||
TileEntity te = worldObj.getTileEntity(bc.x, bc.y, bc.z);
|
||||
if(te instanceof TileCapBank) {
|
||||
return ((TileCapBank) te).getDisplayType(face) == InfoDisplayType.LEVEL_BAR;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void createVertexCache() {
|
||||
barIcon = EnderIO.blockCapBank.getFillBarIcon();
|
||||
barMinV = barIcon.getMinV();
|
||||
barHeightV = barIcon.getMaxV() - barIcon.getMinV();
|
||||
gaugeIcon = EnderIO.blockCapBank.getGaugeIcon();
|
||||
|
||||
gaugeVertexCache = new HashMap<FillGauge.GaugeKey, List<Vertex>>();
|
||||
levelVertexCache = new HashMap<FillGauge.GaugeKey, List<Vertex>>();
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if(dir.offsetY == 0) {
|
||||
for (Type type : Type.values()) {
|
||||
GaugeKey key = new GaugeKey(dir, type);
|
||||
gaugeVertexCache.put(key, createGaugeBoundForFace(key, gaugeIcon));
|
||||
levelVertexCache.put(key, createGaugeBoundForFace(key, barIcon));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected List<Vertex> createGaugeBoundForFace(GaugeKey key, IIcon icon) {
|
||||
|
||||
ForgeDirection dir = key.dir;
|
||||
Type type = key.type;
|
||||
|
||||
double widthScale = 0.25;
|
||||
double heightScale = 0.8;
|
||||
|
||||
double xScale = dir.offsetX == 0 ? widthScale : 1;
|
||||
double yScale = 1;
|
||||
double zScale = dir.offsetZ == 0 ? widthScale : 1;
|
||||
|
||||
BoundingBox bb = BoundingBox.UNIT_CUBE;
|
||||
Vector3d off = ForgeDirectionOffsets.forDirCopy(dir);
|
||||
off.scale(-1);
|
||||
bb = bb.translate(off);
|
||||
bb = bb.scale(xScale, yScale, zScale);
|
||||
off.scale(-1);
|
||||
bb = bb.translate(off);
|
||||
|
||||
Vector4f uv = getUvForType(key.type, icon);
|
||||
|
||||
List<Vertex> result = bb.getCornersWithUvForFace(dir, uv.x, uv.y, uv.z, uv.w);
|
||||
return result;
|
||||
}
|
||||
|
||||
private Vector4f getUvForType(Type type, IIcon icon) {
|
||||
double uWidth = (icon.getMaxU() - icon.getMinU()) / 4;
|
||||
|
||||
Vector4f res = new Vector4f();
|
||||
res.x = (float) (icon.getMinU() + type.ordinal() * uWidth);
|
||||
res.y = (float) (res.x + uWidth);
|
||||
|
||||
res.z = icon.getMinV();
|
||||
res.w = icon.getMaxV();
|
||||
return res;
|
||||
}
|
||||
|
||||
private static class GaugeInfo {
|
||||
|
||||
int height;
|
||||
int yPosition;
|
||||
Type type;
|
||||
|
||||
GaugeInfo(int height, int position) {
|
||||
this.height = height;
|
||||
yPosition = position;
|
||||
type = calcType();
|
||||
}
|
||||
|
||||
Type calcType() {
|
||||
if(height == 1) {
|
||||
return Type.SINGLE;
|
||||
}
|
||||
if(yPosition == 0) {
|
||||
return Type.BOTTOM;
|
||||
}
|
||||
if(yPosition == height - 1) {
|
||||
return Type.TOP;
|
||||
}
|
||||
return Type.MIDDLE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class GaugeKey {
|
||||
|
||||
ForgeDirection dir;
|
||||
Type type;
|
||||
|
||||
public GaugeKey(ForgeDirection dir, Type type) {
|
||||
this.dir = dir;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((dir == null) ? 0 : dir.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(this == obj) {
|
||||
return true;
|
||||
}
|
||||
if(obj == null) {
|
||||
return false;
|
||||
}
|
||||
if(getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
GaugeKey other = (GaugeKey) obj;
|
||||
if(dir != other.dir) {
|
||||
return false;
|
||||
}
|
||||
if(type != other.type) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,6 +34,7 @@ public class IconUtil {
|
||||
public void registerIcons(IIconRegister register) {
|
||||
whiteTexture = register.registerIcon("enderio:white");
|
||||
errorTexture = register.registerIcon("enderio:error");
|
||||
blankTexture = register.registerIcon("enderio:blank");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user