mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 06:53:24 +00:00
Stubs in place
This commit is contained in:
1 parent
30b9af9647
commit
91370e20e7
16 files changed
+1287
-1
No files matched your search
@@ -64,6 +64,8 @@ import crazypants.enderio.machine.AbstractMachineRenderer;
|
||||
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.enchanter.EnchanterModelRenderer;
|
||||
import crazypants.enderio.machine.enchanter.TileEnchanter;
|
||||
import crazypants.enderio.machine.farm.BlockFarmStation;
|
||||
@@ -273,6 +275,13 @@ public class ClientProxy extends CommonProxy {
|
||||
BlockElectricLight.renderId = RenderingRegistry.getNextAvailableRenderId();
|
||||
RenderingRegistry.registerBlockHandler(new ElectricLightRenderer());
|
||||
|
||||
if(EnderIO.blockCapBank != null) {
|
||||
BlockCapBank.renderId = RenderingRegistry.getNextAvailableRenderId();
|
||||
CapBankRenderer newCbr = new CapBankRenderer();
|
||||
RenderingRegistry.registerBlockHandler(newCbr);
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockCapBank), newCbr);
|
||||
}
|
||||
|
||||
CapacitorBankRenderer capr = new CapacitorBankRenderer();
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockCapacitorBank), capr);
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ import crazypants.enderio.machine.PacketRedstoneMode;
|
||||
import crazypants.enderio.machine.alloy.AlloyRecipeManager;
|
||||
import crazypants.enderio.machine.alloy.BlockAlloySmelter;
|
||||
import crazypants.enderio.machine.attractor.BlockAttractor;
|
||||
import crazypants.enderio.machine.capbank.BlockCapBank;
|
||||
import crazypants.enderio.machine.crafter.BlockCrafter;
|
||||
import crazypants.enderio.machine.crusher.BlockCrusher;
|
||||
import crazypants.enderio.machine.crusher.CrusherRecipeManager;
|
||||
@@ -219,6 +220,7 @@ public class EnderIO {
|
||||
public static BlockReservoir blockReservoir;
|
||||
public static BlockAlloySmelter blockAlloySmelter;
|
||||
public static BlockCapacitorBank blockCapacitorBank;
|
||||
public static BlockCapBank blockCapBank;
|
||||
public static BlockWirelessCharger blockWirelessCharger;
|
||||
public static BlockCrusher blockCrusher;
|
||||
public static BlockHyperCube blockHyperCube;
|
||||
@@ -306,6 +308,7 @@ public class EnderIO {
|
||||
blockCrusher = BlockCrusher.create();
|
||||
blockAlloySmelter = BlockAlloySmelter.create();
|
||||
blockCapacitorBank = BlockCapacitorBank.create();
|
||||
blockCapBank = BlockCapBank.create();
|
||||
|
||||
blockPainter = BlockPainter.create();
|
||||
blockPaintedFence = BlockPaintedFence.create();
|
||||
|
||||
@@ -51,6 +51,8 @@ public class GuiHandler implements IGuiHandler {
|
||||
public static final int GUI_ID_XP_OBELISK = 98;
|
||||
public static final int GUI_ID_ANVIL = 99;
|
||||
|
||||
public static final int GUI_ID_CAP_BANK = 100;
|
||||
|
||||
protected final Map<Integer, IGuiHandler> guiHandlers = new HashMap<Integer, IGuiHandler>();
|
||||
|
||||
public void registerGuiHandler(int id, IGuiHandler handler) {
|
||||
|
||||
@@ -42,6 +42,7 @@ public enum ModObject {
|
||||
blockAlloySmelter,
|
||||
blockSolarPanel,
|
||||
blockCapacitorBank,
|
||||
blockCapBank,
|
||||
blockSagMill,
|
||||
blockHyperCube,
|
||||
blockPowerMonitor,
|
||||
@@ -102,7 +103,7 @@ public enum ModObject {
|
||||
public final String unlocalisedName;
|
||||
|
||||
private ModObject() {
|
||||
this.unlocalisedName = name();
|
||||
unlocalisedName = name();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,437 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
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.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.BlockEio;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.gui.IAdvancedTooltipProvider;
|
||||
import crazypants.enderio.gui.TooltipAddera;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
import crazypants.enderio.tool.ToolUtil;
|
||||
import crazypants.enderio.waila.IWailaInfoProvider;
|
||||
|
||||
public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTooltipProvider, IWailaInfoProvider {
|
||||
|
||||
public static int renderId = -1;
|
||||
|
||||
public static BlockCapBank create() {
|
||||
|
||||
BlockCapBank res = new BlockCapBank();
|
||||
res.init();
|
||||
return res;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
IIcon overlayIcon;
|
||||
@SideOnly(Side.CLIENT)
|
||||
IIcon fillBarIcon;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[] blockIcons;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[] borderIcons;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[] inputIcons;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[] outputIcons;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[] lockedIcons;
|
||||
|
||||
protected BlockCapBank() {
|
||||
super(ModObject.blockCapBank.unlocalisedName, TileCapBank.class);
|
||||
setHardness(2.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
GameRegistry.registerBlock(this, BlockItemCapBank.class, name);
|
||||
if(teClass != null) {
|
||||
GameRegistry.registerTileEntity(teClass, name + "TileEntity");
|
||||
}
|
||||
|
||||
EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_CAP_BANK, this);
|
||||
setLightOpacity(255);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List list) {
|
||||
int meta = 0;
|
||||
for (CapBankType type : CapBankType.types()) {
|
||||
if(type.isCreative()) {
|
||||
list.add(BlockItemCapBank.createItemStackWithPower(meta, type.getMaxEnergyStored() / 2));
|
||||
} else {
|
||||
list.add(BlockItemCapBank.createItemStackWithPower(meta, 0));
|
||||
list.add(BlockItemCapBank.createItemStackWithPower(meta, type.getMaxEnergyStored()));
|
||||
}
|
||||
meta++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(int par1) {
|
||||
return par1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addCommonEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addBasicEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
list.add(PowerDisplayUtil.formatStoredPower(PowerHandlerUtil.getStoredEnergyForItem(itemstack), CapBankType.getTypeFromMeta(itemstack.getItemDamage())
|
||||
.getMaxEnergyStored()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addDetailedEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
TooltipAddera.addDetailedTooltipFromResources(list, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) {
|
||||
|
||||
if(ToolUtil.breakBlockWithTool(this, world, x, y, z, entityPlayer)) {
|
||||
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);
|
||||
if(world.isRemote) {
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
} else {
|
||||
world.notifyBlocksOfNeighborChange(x, y, z, EnderIO.blockCapBank);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!world.isRemote) {
|
||||
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_CAP_BANK, world, x, y, z);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if(te instanceof TileCapBank) {
|
||||
// return new ContainerCapBank(player, player.inventory, ((TileCapBank) te).getController());
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if(te instanceof TileCapBank) {
|
||||
// return new GuiCapBank(player, player.inventory, ((TileCapBank) te).getController());
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister IIconRegister) {
|
||||
blockIcon = IIconRegister.registerIcon("enderio:capacitorBank");
|
||||
overlayIcon = IIconRegister.registerIcon("enderio:capacitorBankOverlays");
|
||||
fillBarIcon = IIconRegister.registerIcon("enderio:capacitorBankFillBar");
|
||||
|
||||
blockIcons = new IIcon[CapBankType.types().size()];
|
||||
borderIcons = new IIcon[CapBankType.types().size()];
|
||||
inputIcons = new IIcon[CapBankType.types().size()];
|
||||
outputIcons = new IIcon[CapBankType.types().size()];
|
||||
lockedIcons = new IIcon[CapBankType.types().size()];
|
||||
int index = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return renderId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) {
|
||||
Block i1 = par1IBlockAccess.getBlock(par2, par3, par4);
|
||||
return i1 == this ? false : super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(int side, int meta) {
|
||||
meta = MathHelper.clamp_int(meta, 0, blockIcons.length - 1);
|
||||
return blockIcons[meta];
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getBorderIcon(int side, int meta) {
|
||||
meta = MathHelper.clamp_int(meta, 0, blockIcons.length - 1);
|
||||
return borderIcons[meta];
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(IBlockAccess ba, int x, int y, int z, int side) {
|
||||
TileEntity te = ba.getTileEntity(x, y, z);
|
||||
if(!(te instanceof TileCapBank)) {
|
||||
return blockIcons[0];
|
||||
}
|
||||
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) {
|
||||
return blockIcons[meta];
|
||||
}
|
||||
if(mode == IoMode.PULL) {
|
||||
return inputIcons[meta];
|
||||
}
|
||||
if(mode == IoMode.PUSH) {
|
||||
return outputIcons[meta];
|
||||
}
|
||||
return lockedIcons[meta];
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onBlockAdded(World world, int x, int y, int z) {
|
||||
// if(world.isRemote) {
|
||||
// return;
|
||||
// }
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if(te instanceof TileCapacitorBank) {
|
||||
// TileCapacitorBank tr = (TileCapacitorBank) te;
|
||||
// int meta = world.getBlockMetadata(x, y, z);
|
||||
// if(meta == 1) {
|
||||
// tr.setCreativeMode();
|
||||
// }
|
||||
// tr.onBlockAdded();
|
||||
// }
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public void onNeighborBlockChange(World world, int x, int y, int z, Block blockId) {
|
||||
// if(world.isRemote) {
|
||||
// return;
|
||||
// }
|
||||
// TileEntity tile = world.getTileEntity(x, y, z);
|
||||
// if(tile instanceof TileCapBank) {
|
||||
// TileCapBank te = (TileCapBank) tile;
|
||||
// te.onNeighborBlockChange(blockId);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
|
||||
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
// if(!world.isRemote) {
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if(te instanceof TileCapBank) {
|
||||
// TileCapBank cb = (TileCapBank) te;
|
||||
// cb.onBreakBlock();
|
||||
//
|
||||
// ItemStack itemStack =
|
||||
// BlockItemCapacitorBank.createItemStackWithPower(cb.doGetEnergyStored());
|
||||
// ret.add(itemStack);
|
||||
// }
|
||||
// }
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) {
|
||||
if(!world.isRemote) {
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if(te instanceof TileCapBank) {
|
||||
// TileCapBank cb = (TileCapBank) te;
|
||||
// cb.onBreakBlock();
|
||||
//
|
||||
// // If we are not in Creative or blockCapBankAllwaysDrop is set to true, allow the item drop.
|
||||
// // This option allows creative players to pick up broken capacitor banks
|
||||
//
|
||||
// if(!player.capabilities.isCreativeMode || "true".equalsIgnoreCase(System.getProperty("blockCapBankAllwaysDrop"))) {
|
||||
// ItemStack itemStack =
|
||||
// BlockItemCapacitorBank.createItemStackWithPower(cb.doGetEnergyStored());
|
||||
// if(cb.isCreative()) {
|
||||
// itemStack.setItemDamage(1);
|
||||
// }
|
||||
// float f = 0.7F;
|
||||
// double d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
// double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
// double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
// EntityItem entityitem = new EntityItem(world, x + d0, y + d1, z + d2, itemStack);
|
||||
// entityitem.delayBeforeCanPickup = 10;
|
||||
// world.spawnEntityInWorld(entityitem);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
return super.removedByPlayer(world, player, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
|
||||
if(world.isRemote) {
|
||||
return;
|
||||
}
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if(te instanceof TileCapacitorBank) {
|
||||
// TileCapacitorBank cb = (TileCapacitorBank) te;
|
||||
// cb.addEnergy(PowerHandlerUtil.getStoredEnergyForItem(stack));
|
||||
// if(player instanceof EntityPlayer) {
|
||||
// for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
// BlockCoord bc = new BlockCoord(x, y, z);
|
||||
// bc = bc.getLocation(dir);
|
||||
// te = world.getTileEntity(bc.x, bc.y, bc.z);
|
||||
// if(te instanceof TileCapacitorBank) {
|
||||
// if(((TileCapacitorBank)te).isMaxSize()) {
|
||||
// ((EntityPlayer)player).addChatComponentMessage(new ChatComponentText("Capacitor bank is at maximum size"));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int quantityDropped(Random r) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
|
||||
if(!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if(!(te instanceof TileCapacitorBank)) {
|
||||
// super.breakBlock(world, x, y, z, par5, par6);
|
||||
// return;
|
||||
// }
|
||||
// TileCapacitorBank cb = (TileCapacitorBank) te;
|
||||
// Util.dropItems(world, cb, x, y, z, true);
|
||||
}
|
||||
world.removeTileEntity(x, y, z);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// @SideOnly(Side.CLIENT)
|
||||
// public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) {
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if(!(te instanceof TileCapacitorBank)) {
|
||||
// return super.getSelectedBoundingBoxFromPool(world, x, y, z);
|
||||
// }
|
||||
// TileCapacitorBank tr = (TileCapacitorBank) te;
|
||||
// if(!tr.isMultiblock()) {
|
||||
// return super.getSelectedBoundingBoxFromPool(world, x, y, z);
|
||||
// }
|
||||
//
|
||||
// Vector3d min = new Vector3d(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
|
||||
// Vector3d max = new Vector3d(-Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE);
|
||||
// for (BlockCoord bc : tr.multiblock) {
|
||||
// min.x = Math.min(min.x, bc.x);
|
||||
// max.x = Math.max(max.x, bc.x + 1);
|
||||
// min.y = Math.min(min.y, bc.y);
|
||||
// max.y = Math.max(max.y, bc.y + 1);
|
||||
// min.z = Math.min(min.z, bc.z);
|
||||
// max.z = Math.max(max.z, bc.z + 1);
|
||||
// }
|
||||
// return AxisAlignedBB.getBoundingBox(min.x, min.y, min.z, max.x, max.y, max.z);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorInputOverride() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(World w, int x, int y, int z, int side) {
|
||||
TileEntity te = w.getTileEntity(x, y, z);
|
||||
if(te instanceof TileCapBank) {
|
||||
return ((TileCapBank) te).getComparatorOutput();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getWailaInfo(List<String> tooltip, EntityPlayer player, World world, int x, int y, int z) {
|
||||
// TileEntity te = world.getTileEntity(x, y, z);
|
||||
// if (te instanceof TileCapBank) {
|
||||
// TileCapBank cap = (TileCapBank) te;
|
||||
// String format = Util.TAB + Util.ALIGNRIGHT + EnumChatFormatting.WHITE;
|
||||
//
|
||||
// tooltip.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxIO"), format, fmt.format(cap.getMaxIO()), Util.TAB + Util.ALIGNRIGHT));
|
||||
// tooltip.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxIn"), format, fmt.format(cap.getMaxInput()), Util.TAB + Util.ALIGNRIGHT));
|
||||
// tooltip.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxOut"), format, fmt.format(cap.getMaxOutput()), Util.TAB + Util.ALIGNRIGHT));
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultDisplayMask(World world, int x, int y, int z) {
|
||||
return IWailaInfoProvider.BIT_DETAILED;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
|
||||
public class BlockItemCapBank extends ItemBlock implements IEnergyContainerItem {
|
||||
|
||||
public static ItemStack createItemStackWithPower(int meta, int storedEnergy) {
|
||||
ItemStack res = new ItemStack(EnderIO.blockCapBank, 1, meta);
|
||||
PowerHandlerUtil.setStoredEnergyForItem(res, storedEnergy);
|
||||
return res;
|
||||
}
|
||||
|
||||
public BlockItemCapBank() {
|
||||
super(EnderIO.blockCapBank);
|
||||
setHasSubtypes(true);
|
||||
}
|
||||
|
||||
public BlockItemCapBank(Block block) {
|
||||
super(block);
|
||||
setHasSubtypes(true);
|
||||
setCreativeTab(EnderIOTab.tabEnderIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int par1) {
|
||||
return par1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack par1ItemStack) {
|
||||
return CapBankType.getTypeFromMeta(par1ItemStack.getItemDamage()).getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showDurabilityBar(ItemStack itemStack) {
|
||||
return !CapBankType.getTypeFromMeta(itemStack.getItemDamage()).isCreative();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDurabilityForDisplay(ItemStack itemStack) {
|
||||
int maxStored = CapBankType.getTypeFromMeta(itemStack.getItemDamage()).getMaxEnergyStored();
|
||||
double stored = maxStored - getEnergyStored(itemStack) + 1;
|
||||
double max = maxStored + 1;
|
||||
return stored / max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
|
||||
CapBankType type = CapBankType.getTypeFromMeta(container.getItemDamage());
|
||||
int energy = getEnergyStored(container);
|
||||
int maxInput = type.getMaxIO();
|
||||
int energyReceived = Math.min(type.getMaxEnergyStored() - energy, Math.min(maxReceive, maxInput));
|
||||
|
||||
if(!simulate && !type.isCreative()) {
|
||||
energy += energyReceived;
|
||||
PowerHandlerUtil.setStoredEnergyForItem(container, energy);
|
||||
}
|
||||
return energyReceived;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
|
||||
CapBankType type = CapBankType.getTypeFromMeta(container.getItemDamage());
|
||||
int energy = getEnergyStored(container);
|
||||
int maxOutput = type.getMaxIO();
|
||||
int energyExtracted = Math.min(energy, Math.min(maxExtract, maxOutput));
|
||||
|
||||
if(!simulate && !type.isCreative()) {
|
||||
energy -= energyExtracted;
|
||||
PowerHandlerUtil.setStoredEnergyForItem(container, energy);
|
||||
}
|
||||
return energyExtracted;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ItemStack container) {
|
||||
return PowerHandlerUtil.getStoredEnergyForItem(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ItemStack container) {
|
||||
return CapBankType.getTypeFromMeta(container.getItemDamage()).getMaxEnergyStored();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CapBankNetwork {
|
||||
|
||||
protected final List<TileCapBank> capBanks = new ArrayList<TileCapBank>();
|
||||
|
||||
private int ioCap;
|
||||
|
||||
private long timeAtLastApply;
|
||||
|
||||
public void init(TileCapBank cap, Collection<TileCapBank> neighbours, World world) {
|
||||
if(world.isRemote) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
for (TileCapBank con : neighbours) {
|
||||
CapBankNetwork network = con.getNetwork();
|
||||
if(network != null) {
|
||||
network.destroyNetwork();
|
||||
}
|
||||
}
|
||||
setNetwork(world, cap);
|
||||
notifyNetworkOfUpdate();
|
||||
}
|
||||
|
||||
protected void setNetwork(World world, TileCapBank cap) {
|
||||
if(cap != null && cap.setNetwork(this)) {
|
||||
addCapBank(cap);
|
||||
Collection<TileCapBank> neighbours = NetworkManager.getNeigbours(cap);
|
||||
for (TileCapBank neighbour : neighbours) {
|
||||
if(neighbour.getNetwork() == null) {
|
||||
setNetwork(world, neighbour);
|
||||
} else if(neighbour.getNetwork() != this) {
|
||||
neighbour.getNetwork().destroyNetwork();
|
||||
setNetwork(world, neighbour);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void destroyNetwork() {
|
||||
for (TileCapBank cb : capBanks) {
|
||||
cb.setNetwork(null);
|
||||
}
|
||||
capBanks.clear();
|
||||
}
|
||||
|
||||
public void addCapBank(TileCapBank cap) {
|
||||
if(!capBanks.contains(cap)) {
|
||||
capBanks.add(cap);
|
||||
ioCap += cap.getType().getMaxIO();
|
||||
}
|
||||
}
|
||||
|
||||
public int getMaxEnergyRecieved() {
|
||||
return ioCap;
|
||||
}
|
||||
|
||||
public void onUpdateEntity(TileCapBank tileCapBank) {
|
||||
World world = tileCapBank.getWorldObj();
|
||||
if(world == null) {
|
||||
return;
|
||||
}
|
||||
if(world.isRemote) {
|
||||
return;
|
||||
}
|
||||
long curTime = world.getTotalWorldTime();
|
||||
if(curTime != timeAtLastApply) {
|
||||
timeAtLastApply = curTime;
|
||||
powerManager.applyRecievedPower();
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyNetworkOfUpdate() {
|
||||
for (TileCapBank cb : capBanks) {
|
||||
cb.getWorldObj().markBlockForUpdate(cb.xCoord, cb.yCoord, cb.zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.util.MathHelper;
|
||||
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");
|
||||
private static final CapBankType BASIC = new CapBankType("BASIC", "tile.blockCapBank.basic", Config.capacitorBankMaxIoRF, Config.capacitorBankMaxStorageRF,
|
||||
true,
|
||||
false, "enderio:capacitorBank", "enderio:blankMachinePanel", "enderio:capacitorBankInput", "enderio:capacitorBankOutput", "enderio:capacitorBankLocked");
|
||||
private static final CapBankType VIBRANT = new CapBankType("VIBRANT", "tile.blockCapBank.vibrant", Config.capacitorBankMaxIoRF * 4,
|
||||
Config.capacitorBankMaxStorageRF * 8,
|
||||
true, false, "enderio:capacitorBank", "enderio:capacitorBankVibrantBorder", "enderio:capacitorBankInput", "enderio:capacitorBankOutput",
|
||||
"enderio:capacitorBankLocked");
|
||||
|
||||
private static final List<CapBankType> TYPES = new ArrayList<CapBankType>();
|
||||
|
||||
static {
|
||||
TYPES.add(CREATIVE);
|
||||
TYPES.add(BASIC);
|
||||
TYPES.add(VIBRANT);
|
||||
}
|
||||
|
||||
public static List<CapBankType> types() {
|
||||
return TYPES;
|
||||
}
|
||||
|
||||
public static CapBankType getTypeFromMeta(int meta) {
|
||||
meta = MathHelper.clamp_int(meta, 0, TYPES.size() - 1);
|
||||
return types().get(meta);
|
||||
}
|
||||
|
||||
public static CapBankType getTypeFromUID(String uid) {
|
||||
for (CapBankType type : TYPES) {
|
||||
if(type.uid.equals(uid)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return BASIC;
|
||||
}
|
||||
|
||||
private final String uid;
|
||||
private final String unlocalizedName;
|
||||
private final int maxIO;
|
||||
private final int maxStored;
|
||||
private final boolean isMultiblock;
|
||||
private final boolean isCreative;
|
||||
private final String icon;
|
||||
private final String borderIcon;
|
||||
private final String inputIcon;
|
||||
private final String outputIcon;
|
||||
private final String lockedIcon;
|
||||
|
||||
public CapBankType(String uid, String unlocalizedName, int maxIO, int maxStored, boolean isMultiblock, boolean isCreative, String icon, String borderIcon,
|
||||
String inputIcon, String outputIcon, String lockedIcon) {
|
||||
this.uid = uid;
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
this.maxIO = maxIO;
|
||||
this.maxStored = maxStored;
|
||||
this.isMultiblock = isMultiblock;
|
||||
this.isCreative = isCreative;
|
||||
this.icon = icon;
|
||||
this.borderIcon = borderIcon;
|
||||
this.inputIcon = inputIcon;
|
||||
this.outputIcon = outputIcon;
|
||||
this.lockedIcon = lockedIcon;
|
||||
}
|
||||
|
||||
public int getMaxIO() {
|
||||
return maxIO;
|
||||
}
|
||||
|
||||
public int getMaxEnergyStored() {
|
||||
return maxStored;
|
||||
}
|
||||
|
||||
public boolean isMultiblock() {
|
||||
return isMultiblock;
|
||||
}
|
||||
|
||||
public boolean isCreative() {
|
||||
return isCreative;
|
||||
}
|
||||
|
||||
public String getUnlocalizedName() {
|
||||
return unlocalizedName;
|
||||
}
|
||||
|
||||
public String getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public String getBorderIcon() {
|
||||
return borderIcon;
|
||||
}
|
||||
|
||||
public String getInputIcon() {
|
||||
return inputIcon;
|
||||
}
|
||||
|
||||
public String getOutputIcon() {
|
||||
return outputIcon;
|
||||
}
|
||||
|
||||
public String getLockedIcon() {
|
||||
return lockedIcon;
|
||||
}
|
||||
|
||||
public String getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
public class ContainerCapBank {
|
||||
|
||||
public ContainerCapBank(EntityPlayer player, InventoryPlayer inventory, CapBankNetwork controller) {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
public class GuiCapBank {
|
||||
|
||||
public GuiCapBank(EntityPlayer player, InventoryPlayer inventory, CapBankNetwork controller) {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class NetworkManager {
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static void ensureValidNetwork(TileCapBank cap) {
|
||||
World world = cap.getWorldObj();
|
||||
Collection<TileCapBank> neighbours = getNeigbours(cap);
|
||||
if(reuseNetwork(cap, neighbours, world)) {
|
||||
return;
|
||||
}
|
||||
CapBankNetwork network = new CapBankNetwork();
|
||||
network.init(cap, neighbours, world);
|
||||
return;
|
||||
}
|
||||
|
||||
public static Collection<TileCapBank> getNeigbours(TileCapBank cap) {
|
||||
if(!cap.getType().isMultiblock()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<TileCapBank> res = new ArrayList<TileCapBank>();
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
BlockCoord bc = cap.getLocation().getLocation(dir);
|
||||
TileEntity te = cap.getWorldObj().getTileEntity(bc.x, bc.y, bc.z);
|
||||
if(te instanceof TileCapBank) {
|
||||
TileCapBank neighbour = (TileCapBank) te;
|
||||
if(neighbour.canConnectTo(cap)) {
|
||||
res.add(neighbour);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private static boolean reuseNetwork(TileCapBank cap, Collection<TileCapBank> neighbours, World world) {
|
||||
CapBankNetwork network = null;
|
||||
for (TileCapBank conduit : neighbours) {
|
||||
if(network == null) {
|
||||
network = conduit.getNetwork();
|
||||
} else if(network != conduit.getNetwork()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(network == null) {
|
||||
return false;
|
||||
}
|
||||
if(cap.setNetwork(network)) {
|
||||
network.addCapBank(cap);
|
||||
network.notifyNetworkOfUpdate();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
package crazypants.enderio.machine.capbank;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.TileEntityEio;
|
||||
import crazypants.enderio.conduit.IConduitBundle;
|
||||
import crazypants.enderio.machine.IIoConfigurable;
|
||||
import crazypants.enderio.machine.IoMode;
|
||||
import crazypants.enderio.power.IInternalPowerReceptor;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor, IInventory, IIoConfigurable {
|
||||
|
||||
private Map<ForgeDirection, IoMode> faceModes;
|
||||
|
||||
private CapBankType type;
|
||||
|
||||
private int energyStored;
|
||||
|
||||
private CapBankNetwork network;
|
||||
|
||||
@Override
|
||||
public BlockCoord getLocation() {
|
||||
return new BlockCoord(this);
|
||||
}
|
||||
|
||||
public CapBankType getType() {
|
||||
if(type == null) {
|
||||
type = CapBankType.getTypeFromMeta(getBlockMetadata());
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
//---------- Multiblock
|
||||
|
||||
public CapBankNetwork getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public boolean setNetwork(CapBankNetwork network) {
|
||||
this.network = network;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canConnectTo(TileCapBank cap) {
|
||||
CapBankType t = getType();
|
||||
return t.isMultiblock() && t.getUid().equals(cap.getType().getUid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
CapBankNetwork network = getNetwork();
|
||||
if(network != null) {
|
||||
network.destroyNetwork();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if(worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
updateNetwork(worldObj);
|
||||
}
|
||||
|
||||
|
||||
private void updateNetwork(World world) {
|
||||
if(getNetwork() == null) {
|
||||
NetworkManager.ensureValidNetwork(this);
|
||||
if(getNetwork() != null && !world.isRemote) {
|
||||
// world.notifyBlocksOfNeighborChange(bundle.getEntity().xCoord, bundle.getEntity().yCoord, bundle.getEntity().zCoord,
|
||||
// bundle.getEntity().getBlockType());
|
||||
}
|
||||
}
|
||||
if(getNetwork() != null) {
|
||||
getNetwork().onUpdateEntity(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//---------- IO
|
||||
|
||||
|
||||
@Override
|
||||
public IoMode toggleIoModeForFace(ForgeDirection faceHit) {
|
||||
IPowerInterface rec = getReceptorForFace(faceHit);
|
||||
IoMode curMode = getIoMode(faceHit);
|
||||
if(curMode == IoMode.PULL) {
|
||||
setIoMode(faceHit, IoMode.PUSH, true);
|
||||
return IoMode.PUSH;
|
||||
}
|
||||
if(curMode == IoMode.PUSH) {
|
||||
setIoMode(faceHit, IoMode.DISABLED, true);
|
||||
return IoMode.DISABLED;
|
||||
}
|
||||
if(curMode == IoMode.DISABLED) {
|
||||
if(rec == null || rec.getDelegate() instanceof IConduitBundle) {
|
||||
setIoMode(faceHit, IoMode.NONE, true);
|
||||
return IoMode.NONE;
|
||||
}
|
||||
}
|
||||
setIoMode(faceHit, IoMode.PULL, true);
|
||||
return IoMode.PULL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsMode(ForgeDirection faceHit, IoMode mode) {
|
||||
IPowerInterface rec = getReceptorForFace(faceHit);
|
||||
if(mode == IoMode.NONE) {
|
||||
return rec == null || rec.getDelegate() instanceof IConduitBundle;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIoMode(ForgeDirection faceHit, IoMode mode) {
|
||||
setIoMode(faceHit, mode, true);
|
||||
}
|
||||
|
||||
public void setIoMode(ForgeDirection faceHit, IoMode mode, boolean updateReceptors) {
|
||||
if(mode == IoMode.NONE && faceModes == null) {
|
||||
return;
|
||||
}
|
||||
if(faceModes == null) {
|
||||
faceModes = new EnumMap<ForgeDirection, IoMode>(ForgeDirection.class);
|
||||
}
|
||||
faceModes.put(faceHit, mode);
|
||||
|
||||
//TODO
|
||||
// if(updateReceptors) {
|
||||
// receptorsDirty = true;
|
||||
// getController().masterReceptorsDirty = true;
|
||||
// notifyNeighbours = true;
|
||||
// }
|
||||
// render = true;
|
||||
// updateBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IoMode getIoMode(ForgeDirection face) {
|
||||
if(faceModes == null) {
|
||||
return IoMode.NONE;
|
||||
}
|
||||
IoMode res = faceModes.get(face);
|
||||
if(res == null) {
|
||||
return IoMode.NONE;
|
||||
}
|
||||
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);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
//----------- Power
|
||||
|
||||
@Override
|
||||
public void setEnergyStored(int stored) {
|
||||
energyStored = MathHelper.clamp_int(stored, 0, getMaxEnergyStored());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
return energyStored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from) {
|
||||
return getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyRecieved(ForgeDirection dir) {
|
||||
CapBankNetwork con = getNetwork();
|
||||
if(con == null) {
|
||||
getType().getMaxEnergyStored();
|
||||
}
|
||||
return con.getMaxEnergyRecieved();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return getType().getMaxEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
return PowerHandlerUtil.recieveInternal(this, maxReceive, from, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from) {
|
||||
return getType().getMaxEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from) {
|
||||
return getIoMode(from) != IoMode.DISABLED;
|
||||
}
|
||||
|
||||
public int getComparatorOutput() {
|
||||
return (int) (((double) getEnergyStored() / (double) getMaxEnergyStored()) * 15);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean displayPower() {
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------- Inventory
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int p_70301_1_) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
//---------------- NBT
|
||||
|
||||
@Override
|
||||
protected void writeCustomNBT(NBTTagCompound nbtRoot) {
|
||||
|
||||
nbtRoot.setString("type", getType().getUid());
|
||||
|
||||
//face modes
|
||||
if(faceModes != null) {
|
||||
nbtRoot.setByte("hasFaces", (byte) 1);
|
||||
for (Entry<ForgeDirection, IoMode> e : faceModes.entrySet()) {
|
||||
nbtRoot.setShort("face" + e.getKey().ordinal(), (short) e.getValue().ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readCustomNBT(NBTTagCompound nbtRoot) {
|
||||
|
||||
type = CapBankType.getTypeFromUID(nbtRoot.getString("type"));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user