mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-20 12:19:55 +00:00
#32 Connected Photovoltaic Cells
- Have connected textures similar to cap banks - Form a cohesive unit that gains and emites power as a whole
This commit is contained in:
1 parent
18837b8050
commit
ff4ef4ffd3
22 files changed
+431
-49
No files matched your search
@@ -98,6 +98,8 @@ import crazypants.enderio.machine.ranged.RangeEntity;
|
||||
import crazypants.enderio.machine.ranged.RangeRenerer;
|
||||
import crazypants.enderio.machine.reservoir.ReservoirRenderer;
|
||||
import crazypants.enderio.machine.reservoir.TileReservoir;
|
||||
import crazypants.enderio.machine.solar.BlockSolarPanel;
|
||||
import crazypants.enderio.machine.solar.SolarPanelRenderer;
|
||||
import crazypants.enderio.machine.soul.BlockSoulBinder;
|
||||
import crazypants.enderio.machine.soul.SoulBinderRenderer;
|
||||
import crazypants.enderio.machine.spawner.BrokenSpawnerRenderer;
|
||||
@@ -217,6 +219,9 @@ public class ClientProxy extends CommonProxy {
|
||||
|
||||
MinecraftForgeClient.registerItemRenderer(EnderIO.itemBrokenSpawner, new BrokenSpawnerRenderer());
|
||||
|
||||
BlockSolarPanel.renderId = RenderingRegistry.getNextAvailableRenderId();
|
||||
RenderingRegistry.registerBlockHandler(new SolarPanelRenderer());
|
||||
|
||||
EnchanterModelRenderer emr = new EnchanterModelRenderer();
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEnchanter.class, emr);
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockEnchanter), emr);
|
||||
|
||||
@@ -96,7 +96,6 @@ public class TileBuffer extends AbstractPowerConsumerEntity implements IPaintabl
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
System.out.println("called " + worldObj.getTotalWorldTime() + " " + worldObj.isRemote);
|
||||
return hasPower() && getIoMode(from).canRecieveInput() ? super.receiveEnergy(from, maxReceive, isCreative() || simulate) : 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ public class CapBankRenderer extends TileEntitySpecialRenderer implements ISimpl
|
||||
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,
|
||||
RenderUtil.renderConnectedTextureFace(blockAccess, EnderIO.blockCapBank, x, y, z, face, texture,
|
||||
blockAccess == null, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ public class CapacitorBankRenderer extends TileEntitySpecialRenderer implements
|
||||
texture = IconUtil.whiteTexture;
|
||||
}
|
||||
for (ForgeDirection face : ForgeDirection.VALID_DIRECTIONS) {
|
||||
RenderUtil.renderConnectedTextureFace(blockAccess, x, y, z, face, texture,
|
||||
RenderUtil.renderConnectedTextureFace(blockAccess, EnderIO.blockCapacitorBank, x, y, z, face, texture,
|
||||
blockAccess == null, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,14 +49,17 @@ public class BlockItemSolarPanel extends ItemBlockWithMetadata implements IAdvan
|
||||
par3List.add(stack);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addCommonEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addBasicEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public void addDetailedEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
TooltipAddera.addDetailedTooltipFromResources(list, itemstack);
|
||||
|
||||
@@ -14,6 +14,7 @@ import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import crazypants.enderio.BlockEio;
|
||||
import crazypants.enderio.ModObject;
|
||||
@@ -22,11 +23,14 @@ import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.gui.IResourceTooltipProvider;
|
||||
import crazypants.enderio.tool.ToolUtil;
|
||||
import crazypants.enderio.waila.IWailaInfoProvider;
|
||||
import crazypants.enderio.waila.WailaCompat;
|
||||
import crazypants.util.Lang;
|
||||
import crazypants.util.Util;
|
||||
|
||||
public class BlockSolarPanel extends BlockEio implements IResourceTooltipProvider, IWailaInfoProvider {
|
||||
|
||||
public static int renderId;
|
||||
|
||||
public static BlockSolarPanel create() {
|
||||
BlockSolarPanel result = new BlockSolarPanel();
|
||||
result.init();
|
||||
@@ -38,6 +42,9 @@ public class BlockSolarPanel extends BlockEio implements IResourceTooltipProvide
|
||||
IIcon sideIcon;
|
||||
IIcon advancedSideIcon;
|
||||
IIcon advancedIcon;
|
||||
|
||||
IIcon borderIcon;
|
||||
IIcon advancedBorderIcon;
|
||||
|
||||
private BlockSolarPanel() {
|
||||
super(ModObject.blockSolarPanel.unlocalisedName, TileEntitySolarPanel.class);
|
||||
@@ -79,7 +86,7 @@ public class BlockSolarPanel extends BlockEio implements IResourceTooltipProvide
|
||||
ItemStack is = new ItemStack(this, 1, meta);
|
||||
Util.dropItems(world, is, x, y, z, true);
|
||||
}
|
||||
removedByPlayer(world, entityPlayer, x, y, z);
|
||||
removedByPlayer(world, entityPlayer, x, y, z, true);
|
||||
tool.used(entityPlayer.getCurrentEquippedItem(), entityPlayer, x, y, z);
|
||||
return true;
|
||||
}
|
||||
@@ -94,6 +101,15 @@ public class BlockSolarPanel extends BlockEio implements IResourceTooltipProvide
|
||||
return meta == 0 ? sideIcon : advancedSideIcon;
|
||||
}
|
||||
|
||||
public IIcon getBorderIcon(int i, int meta) {
|
||||
return meta == 0 ? borderIcon : advancedBorderIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return renderId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block par5) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
@@ -103,11 +119,13 @@ public class BlockSolarPanel extends BlockEio implements IResourceTooltipProvide
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister IIconRegister) {
|
||||
blockIcon = IIconRegister.registerIcon("enderio:solarPanelTop");
|
||||
advancedIcon = IIconRegister.registerIcon("enderio:solarPanelAdvancedTop");
|
||||
sideIcon = IIconRegister.registerIcon("enderio:solarPanelSide");
|
||||
advancedSideIcon = IIconRegister.registerIcon("enderio:solarPanelAdvancedSide");
|
||||
public void registerBlockIcons(IIconRegister register) {
|
||||
blockIcon = register.registerIcon("enderio:solarPanelTop");
|
||||
advancedIcon = register.registerIcon("enderio:solarPanelAdvancedTop");
|
||||
sideIcon = register.registerIcon("enderio:solarPanelSide");
|
||||
advancedSideIcon = register.registerIcon("enderio:solarPanelAdvancedSide");
|
||||
borderIcon = register.registerIcon("enderio:solarPanelBorder");
|
||||
advancedBorderIcon = register.registerIcon("enderio:solarPanelAdvancedBorder");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,6 +138,7 @@ public class BlockSolarPanel extends BlockEio implements IResourceTooltipProvide
|
||||
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, BLOCK_HEIGHT, 1.0F);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity) {
|
||||
setBlockBoundsBasedOnState(par1World, par2, par3, par4);
|
||||
@@ -143,7 +162,9 @@ public class BlockSolarPanel extends BlockEio implements IResourceTooltipProvide
|
||||
if(te instanceof TileEntitySolarPanel) {
|
||||
TileEntitySolarPanel solar = (TileEntitySolarPanel) te;
|
||||
float efficiency = solar.calculateLightRatio();
|
||||
|
||||
EnergyStorage storage = new EnergyStorage(Integer.MAX_VALUE);
|
||||
storage.readFromNBT(WailaCompat.getNBTData());
|
||||
tooltip.add(storage.getEnergyStored() + " / " + WailaCompat.getNBTData().getInteger("rfCap") + " RF");
|
||||
tooltip.add(String.format("%s : %s%.0f%%", EnumChatFormatting.WHITE + Lang.localize("tooltip.efficiency") + EnumChatFormatting.RESET,
|
||||
EnumChatFormatting.WHITE, efficiency * 100));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
package crazypants.enderio.machine.solar;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class SolarPanelNetwork {
|
||||
|
||||
private List<TileEntitySolarPanel> panels;
|
||||
private boolean empty = true;
|
||||
|
||||
private EnergyStorage energy;
|
||||
|
||||
public static final int ENERGY_PER = 10000;
|
||||
|
||||
public static final EnumSet<ForgeDirection> VALID_CONS = EnumSet.of(ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.EAST, ForgeDirection.WEST);
|
||||
|
||||
public SolarPanelNetwork() {
|
||||
panels = Lists.newArrayList();
|
||||
energy = new EnergyStorage(ENERGY_PER);
|
||||
}
|
||||
|
||||
SolarPanelNetwork(TileEntitySolarPanel initial) {
|
||||
this();
|
||||
panels.add(initial);
|
||||
empty = false;
|
||||
}
|
||||
|
||||
void onUpdate(TileEntitySolarPanel panel) {
|
||||
}
|
||||
|
||||
boolean addToNetwork(TileEntitySolarPanel panel) {
|
||||
if(panel.network == this && panel.network.isValid() && panels.contains(panel)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(panel.network == null || !panel.network.isValid() || panel.network == this) {
|
||||
if (!panels.contains(panel)) {
|
||||
panels.add(panel);
|
||||
}
|
||||
panel.setNetwork(this);
|
||||
updateEnergy();
|
||||
} else {
|
||||
SolarPanelNetwork other = panel.network;
|
||||
for (TileEntitySolarPanel otherPanel : other.panels) {
|
||||
panels.add(otherPanel);
|
||||
otherPanel.setNetwork(this);
|
||||
}
|
||||
updateEnergy();
|
||||
this.energy.setEnergyStored(energy.getEnergyStored() + other.energy.getEnergyStored());
|
||||
other.invalidate();
|
||||
}
|
||||
|
||||
empty = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void removeFromNetwork(TileEntitySolarPanel panel) {
|
||||
// build list of formerly connected neighbors
|
||||
List<TileEntitySolarPanel> neighbors = Lists.newArrayList();
|
||||
for (ForgeDirection dir : VALID_CONS) {
|
||||
TileEntity te = panel.getLocation().getLocation(dir).getTileEntity(panel.getWorldObj());
|
||||
if(te != null && te instanceof TileEntitySolarPanel) {
|
||||
neighbors.add((TileEntitySolarPanel) te);
|
||||
}
|
||||
}
|
||||
|
||||
// distribute power from split networks evenly to neighbors
|
||||
for (TileEntitySolarPanel te : neighbors) {
|
||||
int dist = energy.getEnergyStored() / neighbors.size();
|
||||
te.destroyedNetworkBuffer = new EnergyStorage(dist);
|
||||
te.destroyedNetworkBuffer.setEnergyStored(dist);
|
||||
}
|
||||
|
||||
// allow solars to reform networks
|
||||
destroyNetwork();
|
||||
}
|
||||
|
||||
private void updateEnergy() {
|
||||
energy.setCapacity(ENERGY_PER * panels.size());
|
||||
energy.setMaxExtract(energy.getMaxEnergyStored());
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually destroys all references to this network, creating an invalid
|
||||
* network for each panel on this current one.
|
||||
*/
|
||||
void destroyNetwork() {
|
||||
for (TileEntitySolarPanel te : panels) {
|
||||
te.setNetwork(new SolarPanelNetwork());
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing but clear this network, other panels may still hold a
|
||||
* reference to this network.
|
||||
*/
|
||||
private void invalidate() {
|
||||
panels.clear();
|
||||
empty = true;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return !empty;
|
||||
}
|
||||
|
||||
public int extractEnergy(int maxExtract, boolean simulate) {
|
||||
return isValid() ? energy.extractEnergy(maxExtract, simulate) : 0;
|
||||
}
|
||||
|
||||
public int getEnergyStored() {
|
||||
return energy.getEnergyStored();
|
||||
}
|
||||
|
||||
public int setEnergyStored(int energy) {
|
||||
if(isValid()) {
|
||||
this.energy.setEnergyStored(energy);
|
||||
}
|
||||
return this.energy.getEnergyStored();
|
||||
}
|
||||
|
||||
public int getMaxEnergyStored() {
|
||||
return energy.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
public int getMaxEnergyExtracted() {
|
||||
return energy.getMaxExtract();
|
||||
}
|
||||
|
||||
public void addBuffer(EnergyStorage destroyedNetworkBuffer) {
|
||||
energy.receiveEnergy(destroyedNetworkBuffer.getEnergyStored(), false);
|
||||
}
|
||||
|
||||
TileEntitySolarPanel getMaster() {
|
||||
return panels.get(0);
|
||||
}
|
||||
|
||||
boolean shouldSave(TileEntitySolarPanel panel) {
|
||||
return getMaster() == panel;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return panels.size();
|
||||
}
|
||||
|
||||
void writeToNBT(NBTTagCompound tag) {
|
||||
tag.setBoolean("validSolar", true);
|
||||
energy.writeToNBT(tag);
|
||||
}
|
||||
|
||||
void readFromNBT(TileEntitySolarPanel panel, NBTTagCompound tag) {
|
||||
if(tag.getBoolean("validSolar")) {
|
||||
energy.readFromNBT(tag);
|
||||
addToNetwork(panel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package crazypants.enderio.machine.solar;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
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.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
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.BoundingBox;
|
||||
import crazypants.render.ConnectedTextureRenderer;
|
||||
import crazypants.render.CubeRenderer;
|
||||
import crazypants.render.CustomCubeRenderer;
|
||||
import crazypants.render.IconUtil;
|
||||
import crazypants.render.RenderUtil;
|
||||
|
||||
public class SolarPanelRenderer implements ISimpleBlockRenderingHandler {
|
||||
|
||||
private ConnectedTextureRenderer ctr;
|
||||
|
||||
public SolarPanelRenderer() {
|
||||
ctr = new ConnectedTextureRenderer();
|
||||
ctr.setMatchMeta(true);
|
||||
ctr.setSidesToRender(EnumSet.of(ForgeDirection.UP));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
RenderUtil.bindBlockTexture();
|
||||
Tessellator tes = Tessellator.instance;
|
||||
|
||||
float offset = -0.5f;
|
||||
tes.addTranslation(offset, 0, offset);
|
||||
tes.startDrawingQuads();
|
||||
CubeRenderer.render(new BoundingBox(EnderIO.blockSolarPanel), RenderUtil.getBlockTextures(EnderIO.blockSolarPanel, metadata), false);
|
||||
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, metadata);
|
||||
tes.draw();
|
||||
|
||||
tes.addTranslation(-offset, 0, -offset);
|
||||
|
||||
GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
renderer.renderStandardBlock(block, x, y, z);
|
||||
Tessellator.instance.addTranslation(0, 0.0001f, 0);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
meta = MathHelper.clamp_int(meta, 0, 1);
|
||||
ctr.setEdgeTexture(EnderIO.blockSolarPanel.getBorderIcon(0, meta));
|
||||
CustomCubeRenderer.instance.setOverrideTexture(IconUtil.blankTexture);
|
||||
CustomCubeRenderer.instance.renderBlock(world, block, x, y, z, ctr);
|
||||
CustomCubeRenderer.instance.setOverrideTexture(null);
|
||||
Tessellator.instance.addTranslation(0, -0.0001f, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory(int modelId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void renderBorder(IBlockAccess blockAccess, int x, int y, int z, int meta) {
|
||||
IIcon texture = EnderIO.blockSolarPanel.getBorderIcon(0, meta);
|
||||
RenderUtil.renderConnectedTextureFace(blockAccess, EnderIO.blockSolarPanel, x, y, z, ForgeDirection.UP, texture, blockAccess == null, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderId() {
|
||||
return BlockSolarPanel.renderId;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
@@ -13,17 +14,16 @@ import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.TileEntityEio;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.power.BasicCapacitor;
|
||||
import crazypants.enderio.power.IInternalPowerProvider;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
import crazypants.enderio.waila.IWailaNBTProvider;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class TileEntitySolarPanel extends TileEntity implements IInternalPowerProvider {
|
||||
public class TileEntitySolarPanel extends TileEntityEio implements IInternalPowerProvider, IWailaNBTProvider {
|
||||
|
||||
private BasicCapacitor capacitor;
|
||||
|
||||
private final List<Receptor> receptors = new ArrayList<Receptor>();
|
||||
private ListIterator<Receptor> receptorIterator = receptors.listIterator();
|
||||
private boolean receptorsDirty = true;
|
||||
@@ -33,13 +33,13 @@ public class TileEntitySolarPanel extends TileEntity implements IInternalPowerPr
|
||||
private int checkOffset;
|
||||
private static final int CHECK_INTERVAL = 100;
|
||||
|
||||
private int storedEnergyRF;
|
||||
EnergyStorage destroyedNetworkBuffer = null;
|
||||
|
||||
protected SolarPanelNetwork network = new SolarPanelNetwork();
|
||||
|
||||
public TileEntitySolarPanel() {
|
||||
checkOffset = (int) (Math.random() * 20);
|
||||
capacitor = new BasicCapacitor(0, 10000, Config.maxPhotovoltaicAdvancedOutputRF * 5);
|
||||
}
|
||||
|
||||
|
||||
public void onNeighborBlockChange() {
|
||||
receptorsDirty = true;
|
||||
@@ -59,7 +59,7 @@ public class TileEntitySolarPanel extends TileEntity implements IInternalPowerPr
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
return from == ForgeDirection.DOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,31 +72,26 @@ public class TileEntitySolarPanel extends TileEntity implements IInternalPowerPr
|
||||
return getMaxEnergyStored();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyRecieved(ForgeDirection dir) {
|
||||
return capacitor.getMaxEnergyReceived();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
return storedEnergyRF;
|
||||
return network.getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return capacitor.getMaxEnergyStored();
|
||||
return network.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setEnergyStored(int stored) {
|
||||
storedEnergyRF = Math.max(stored, 0);
|
||||
network.setEnergyStored(stored);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if(worldObj == null || worldObj.isRemote) {
|
||||
@@ -104,6 +99,45 @@ public class TileEntitySolarPanel extends TileEntity implements IInternalPowerPr
|
||||
}
|
||||
collectEnergy();
|
||||
transmitEnergy();
|
||||
|
||||
if (network.isValid()) {
|
||||
if (destroyedNetworkBuffer != null) {
|
||||
network.addBuffer(destroyedNetworkBuffer);
|
||||
destroyedNetworkBuffer = null;
|
||||
}
|
||||
network.onUpdate(this);
|
||||
}
|
||||
|
||||
if (!network.isValid() || (worldObj.getTotalWorldTime() % 20 == 0 && network.addToNetwork(this))) {
|
||||
findNetwork();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
network.removeFromNetwork(this);
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
private void findNetwork() {
|
||||
System.out.println("searching for network");
|
||||
for (ForgeDirection dir : SolarPanelNetwork.VALID_CONS) {
|
||||
TileEntity te = new BlockCoord(this).getLocation(dir).getTileEntity(worldObj);
|
||||
if(te != null && te instanceof TileEntitySolarPanel && ((TileEntitySolarPanel) te).canConnect(this)) {
|
||||
SolarPanelNetwork network = ((TileEntitySolarPanel) te).network;
|
||||
if(network != null) {
|
||||
network.addToNetwork(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!network.isValid()) {
|
||||
network = new SolarPanelNetwork(this);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canConnect(TileEntitySolarPanel other) {
|
||||
return getBlockMetadata() == other.getBlockMetadata();
|
||||
}
|
||||
|
||||
private void collectEnergy() {
|
||||
@@ -116,7 +150,7 @@ public class TileEntitySolarPanel extends TileEntity implements IInternalPowerPr
|
||||
lastCollectionValue = Math.round(getEnergyPerTick() * fromSun);
|
||||
}
|
||||
if(lastCollectionValue > 0) {
|
||||
storedEnergyRF = Math.min(lastCollectionValue + storedEnergyRF, capacitor.getMaxEnergyStored());
|
||||
network.setEnergyStored(Math.min(lastCollectionValue + network.getEnergyStored(), network.getMaxEnergyStored()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +165,7 @@ public class TileEntitySolarPanel extends TileEntity implements IInternalPowerPr
|
||||
float calculateLightRatio() {
|
||||
return calculateLightRatio(worldObj, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
|
||||
public static float calculateLightRatio(World world, int x, int y, int z) {
|
||||
int lightValue = world.getSavedLightValue(EnumSkyBlock.Sky, x, y, z) - world.skylightSubtracted;
|
||||
float sunAngle = world.getCelestialAngleRadians(1.0F);
|
||||
@@ -151,7 +185,7 @@ public class TileEntitySolarPanel extends TileEntity implements IInternalPowerPr
|
||||
private boolean transmitEnergy() {
|
||||
|
||||
|
||||
int canTransmit = Math.min(getEnergyStored(), capacitor.getMaxEnergyExtracted());
|
||||
int canTransmit = Math.min(getEnergyStored(), network.getMaxEnergyExtracted());
|
||||
int transmitted = 0;
|
||||
|
||||
checkReceptors();
|
||||
@@ -217,15 +251,16 @@ public class TileEntitySolarPanel extends TileEntity implements IInternalPowerPr
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
storedEnergyRF = tag.getInteger("storedEnergyRF");
|
||||
public void readCustomNBT(NBTTagCompound tag) {
|
||||
network.readFromNBT(this, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
tag.setInteger("storedEnergyRF", storedEnergyRF);
|
||||
public void writeCustomNBT(NBTTagCompound tag) {
|
||||
if (network.isValid() && network.shouldSave(this)) {
|
||||
network.writeToNBT(tag);
|
||||
tag.setInteger("rfCap", network.getMaxEnergyStored()); // for WAILA
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -244,4 +279,19 @@ public class TileEntitySolarPanel extends TileEntity implements IInternalPowerPr
|
||||
public boolean displayPower() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setNetwork(SolarPanelNetwork network) {
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
public boolean isMaster() {
|
||||
return network.getMaster() == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getData(NBTTagCompound tag) {
|
||||
if (network.isValid()) {
|
||||
network.getMaster().writeToNBT(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class FusedQuartzRenderer implements ISimpleBlockRenderingHandler {
|
||||
if(tecb != null && tecb.getSourceBlock() != null) {
|
||||
texture = tecb.getSourceBlock().getIcon(face.ordinal(), tecb.getSourceBlockMetadata());
|
||||
}
|
||||
RenderUtil.renderConnectedTextureFace(blockAccess, x, y, z, face, texture, forceAllEdges);
|
||||
RenderUtil.renderConnectedTextureFace(blockAccess, EnderIO.blockFusedQuartz, x, y, z, face, texture, forceAllEdges);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package crazypants.enderio.waila;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Provides NBT info from a TE to be sent to the client
|
||||
*/
|
||||
public interface IWailaNBTProvider {
|
||||
|
||||
void getData(NBTTagCompound tag);
|
||||
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
package crazypants.enderio.waila;
|
||||
|
||||
import static crazypants.enderio.waila.IWailaInfoProvider.BIT_BASIC;
|
||||
import static crazypants.enderio.waila.IWailaInfoProvider.BIT_COMMON;
|
||||
import static crazypants.enderio.waila.IWailaInfoProvider.BIT_DETAILED;
|
||||
import static crazypants.enderio.waila.IWailaInfoProvider.fmt;
|
||||
import info.jbcs.minecraft.chisel.api.IFacade;
|
||||
|
||||
import java.util.List;
|
||||
@@ -25,6 +21,7 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.TileEntityEio;
|
||||
import crazypants.enderio.block.BlockDarkSteelAnvil;
|
||||
import crazypants.enderio.conduit.ConduitUtil;
|
||||
import crazypants.enderio.conduit.IConduit;
|
||||
@@ -40,6 +37,8 @@ import crazypants.enderio.machine.power.TileCapacitorBank;
|
||||
import crazypants.enderio.power.IInternalPoweredTile;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
import static crazypants.enderio.waila.IWailaInfoProvider.*;
|
||||
|
||||
public class WailaCompat implements IWailaDataProvider {
|
||||
|
||||
public static final WailaCompat INSTANCE = new WailaCompat();
|
||||
@@ -53,6 +52,8 @@ public class WailaCompat implements IWailaDataProvider {
|
||||
registrar.registerHeadProvider(INSTANCE, Block.class);
|
||||
registrar.registerBodyProvider(INSTANCE, Block.class);
|
||||
registrar.registerTailProvider(INSTANCE, Block.class);
|
||||
|
||||
registrar.registerNBTProvider(INSTANCE, TileEntityEio.class);
|
||||
|
||||
registrar.registerSyncedNBTKey("controllerStoredEnergyRF", TileCapacitorBank.class);
|
||||
|
||||
@@ -93,7 +94,7 @@ public class WailaCompat implements IWailaDataProvider {
|
||||
@Override
|
||||
public List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
|
||||
|
||||
_accessor = accessor;
|
||||
_accessor = accessor;
|
||||
|
||||
Block block = accessor.getBlock();
|
||||
TileEntity te = accessor.getTileEntity();
|
||||
@@ -201,6 +202,12 @@ public class WailaCompat implements IWailaDataProvider {
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTData(TileEntity te, NBTTagCompound tag, World world, int x, int y, int z) {
|
||||
if (te instanceof IWailaNBTProvider) {
|
||||
((IWailaNBTProvider) te).getData(tag);
|
||||
}
|
||||
tag.setInteger("x", x);
|
||||
tag.setInteger("y", y);
|
||||
tag.setInteger("z", z);
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package crazypants.render;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.util.BlockCoord;
|
||||
@@ -56,6 +57,10 @@ public final class BoundingBox {
|
||||
this(bc.x, bc.y, bc.z, bc.x + 1, bc.y + 1, bc.z + 1);
|
||||
}
|
||||
|
||||
public BoundingBox(Block block) {
|
||||
this(block.getBlockBoundsMinX(), block.getBlockBoundsMinY(), block.getBlockBoundsMinZ(), block.getBlockBoundsMaxX(), block.getBlockBoundsMaxY(), block.getBlockBoundsMaxZ());
|
||||
}
|
||||
|
||||
public BoundingBox expandBy(BoundingBox other) {
|
||||
return new BoundingBox(
|
||||
Math.min(minX, other.minX), Math.min(minY, other.minY), Math.min(minZ, other.minZ),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package crazypants.render;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -58,6 +59,8 @@ public class ConnectedTextureRenderer implements IRenderFace, IConnectedTextureR
|
||||
private TextureCallback edgeTexureCallback;
|
||||
|
||||
private boolean matchMetaData;
|
||||
|
||||
private EnumSet<ForgeDirection> sidesToRender = EnumSet.allOf(ForgeDirection.class);
|
||||
|
||||
public boolean isForceAllEdges() {
|
||||
return forceAllEdges;
|
||||
@@ -87,6 +90,10 @@ public class ConnectedTextureRenderer implements IRenderFace, IConnectedTextureR
|
||||
this.matchMetaData = matchMetaData;
|
||||
}
|
||||
|
||||
public void setSidesToRender(EnumSet<ForgeDirection> sides) {
|
||||
sidesToRender = sides.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesMetadata(int meta1, int meta2) {
|
||||
return !this.matchMetaData || meta1 == meta2;
|
||||
@@ -95,6 +102,10 @@ public class ConnectedTextureRenderer implements IRenderFace, IConnectedTextureR
|
||||
@Override
|
||||
public void renderFace(CustomRenderBlocks rb, ForgeDirection face, Block par1Block, double x, double y, double z, IIcon texture, List<Vertex> refVertices,
|
||||
boolean translateToXYZ) {
|
||||
|
||||
if (!sidesToRender.contains(face)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Vertex> finalVerts = new ArrayList<Vertex>();
|
||||
finalVerts.addAll(refVertices);
|
||||
@@ -126,6 +137,10 @@ public class ConnectedTextureRenderer implements IRenderFace, IConnectedTextureR
|
||||
float xLen = 1 - Math.abs(edge.offsetX) * scaleFactor;
|
||||
float yLen = 1 - Math.abs(edge.offsetY) * scaleFactor;
|
||||
float zLen = 1 - Math.abs(edge.offsetZ) * scaleFactor;
|
||||
|
||||
xLen -= 2* (1 - par1Block.getBlockBoundsMaxX()) - par1Block.getBlockBoundsMinX();
|
||||
yLen -= 2* (1 - par1Block.getBlockBoundsMaxY()) - par1Block.getBlockBoundsMinY();
|
||||
zLen -= 2* (1 - par1Block.getBlockBoundsMaxZ()) - par1Block.getBlockBoundsMinZ();
|
||||
|
||||
BoundingBox bb = BoundingBox.UNIT_CUBE.scale(xLen, yLen, zLen);
|
||||
|
||||
@@ -172,7 +187,11 @@ public class ConnectedTextureRenderer implements IRenderFace, IConnectedTextureR
|
||||
v.xyz.x = Math.max(-0.001, v.xyz.x);
|
||||
v.xyz.y = Math.max(-0.001, v.xyz.y);
|
||||
v.xyz.z = Math.max(-0.001, v.xyz.z);
|
||||
|
||||
|
||||
v.xyz.x -= (1 - par1Block.getBlockBoundsMaxX()) - par1Block.getBlockBoundsMinX();
|
||||
v.xyz.y -= (1 - par1Block.getBlockBoundsMaxY()) - par1Block.getBlockBoundsMinY();
|
||||
v.xyz.z -= (1 - par1Block.getBlockBoundsMaxZ()) - par1Block.getBlockBoundsMinZ();
|
||||
|
||||
if(ForgeDirectionOffsets.isPositiveOffset(face)) {
|
||||
v.xyz.add(ForgeDirectionOffsets.forDir(face));
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import crazypants.vecmath.Vertex;
|
||||
public class CustomRenderBlocks extends RenderBlocks {
|
||||
|
||||
boolean translateToXYZ = true;
|
||||
boolean shouldRenderBaseTexture = true;
|
||||
|
||||
private final List<IRenderFace> renderFaceCallbacks = new ArrayList<IRenderFace>();
|
||||
private IIcon overrideTexture;
|
||||
@@ -54,6 +55,10 @@ public class CustomRenderBlocks extends RenderBlocks {
|
||||
public void setOverrideTexture(IIcon overrideTexture) {
|
||||
this.overrideTexture = overrideTexture;
|
||||
}
|
||||
|
||||
public void setShouldRenderBaseTexture(boolean val) {
|
||||
shouldRenderBaseTexture = val;
|
||||
}
|
||||
|
||||
private void renderFace(ForgeDirection face, Block par1Block, double x, double y, double z, IIcon texture) {
|
||||
if(renderFaceCallbacks.isEmpty()) {
|
||||
|
||||
@@ -321,11 +321,11 @@ public class RenderUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderConnectedTextureFace(IBlockAccess blockAccess, int x, int y, int z, ForgeDirection face, IIcon texture, boolean forceAllEdges) {
|
||||
renderConnectedTextureFace(blockAccess, x, y, z, face, texture, forceAllEdges, true, true);
|
||||
public static void renderConnectedTextureFace(IBlockAccess blockAccess, Block block, int x, int y, int z, ForgeDirection face, IIcon texture, boolean forceAllEdges) {
|
||||
renderConnectedTextureFace(blockAccess, block, x, y, z, face, texture, forceAllEdges, true, true);
|
||||
}
|
||||
|
||||
public static void renderConnectedTextureFace(IBlockAccess blockAccess, int x, int y, int z, ForgeDirection face, IIcon texture, boolean forceAllEdges,
|
||||
public static void renderConnectedTextureFace(IBlockAccess blockAccess, Block block, int x, int y, int z, ForgeDirection face, IIcon texture, boolean forceAllEdges,
|
||||
boolean translateToXYZ, boolean applyFaceShading) {
|
||||
|
||||
if((blockAccess == null && !forceAllEdges) || face == null || texture == null) {
|
||||
@@ -333,11 +333,11 @@ public class RenderUtil {
|
||||
}
|
||||
|
||||
if(!forceAllEdges) {
|
||||
Block block = blockAccess.getBlock(x, y, z);
|
||||
if(block == null) {
|
||||
Block check = blockAccess.getBlock(x, y, z);
|
||||
if(check == null) {
|
||||
return;
|
||||
}
|
||||
if(!block.shouldSideBeRendered(blockAccess, x + face.offsetX, y + face.offsetY, z + face.offsetZ, face.ordinal())) {
|
||||
if(!check.shouldSideBeRendered(blockAccess, x + face.offsetX, y + face.offsetY, z + face.offsetZ, face.ordinal())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -365,6 +365,11 @@ public class RenderUtil {
|
||||
float xLen = 1 - Math.abs(edge.offsetX) * scaleFactor;
|
||||
float yLen = 1 - Math.abs(edge.offsetY) * scaleFactor;
|
||||
float zLen = 1 - Math.abs(edge.offsetZ) * scaleFactor;
|
||||
|
||||
xLen -= 2* (1 - block.getBlockBoundsMaxX()) - block.getBlockBoundsMinX();
|
||||
yLen -= 2* (1 - block.getBlockBoundsMaxY()) - block.getBlockBoundsMinY();
|
||||
zLen -= 2* (1 - block.getBlockBoundsMaxZ()) - block.getBlockBoundsMinZ();
|
||||
|
||||
BoundingBox bb = BoundingBox.UNIT_CUBE.scale(xLen, yLen, zLen);
|
||||
|
||||
List<Vector3f> corners = bb.getCornersForFace(face);
|
||||
|
||||
Reference in new issue
Block a user