Added wireless charger.

This commit is contained in:
CrazyPants committed 2014-07-04 00:01:23 +08:00
1 parent 1bfe73ded2
commit 98ae9db25e
16 files changed
+779 -53

No files matched your search

@@ -157,6 +157,9 @@ public class ClientProxy extends CommonProxy {
BlockFarmStation.renderId = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(new FarmingStationRenderer());
// BlockWirelessCharger.renderId = RenderingRegistry.getNextAvailableRenderId();
// RenderingRegistry.registerBlockHandler(new WirelessChargerRenderer());
if(Config.useCombustionGenModel) {
CombustionGeneratorModelRenderer cgmr = new CombustionGeneratorModelRenderer();
@@ -87,6 +87,7 @@ import crazypants.enderio.machine.still.BlockVat;
import crazypants.enderio.machine.still.VatRecipeManager;
import crazypants.enderio.machine.tank.BlockTank;
import crazypants.enderio.machine.vacuum.BlockVacuumChest;
import crazypants.enderio.machine.wireless.BlockWirelessCharger;
import crazypants.enderio.material.Alloy;
import crazypants.enderio.material.BlockDarkIronBars;
import crazypants.enderio.material.BlockFusedQuartz;
@@ -169,6 +170,7 @@ public class EnderIO {
public static BlockReservoir blockReservoir;
public static BlockAlloySmelter blockAlloySmelter;
public static BlockCapacitorBank blockCapacitorBank;
public static BlockWirelessCharger blockWirelessCharger;
public static BlockCrusher blockCrusher;
public static BlockHyperCube blockHyperCube;
public static BlockPowerMonitor blockPowerMonitor;
@@ -245,6 +247,7 @@ public class EnderIO {
blockPowerMonitor = BlockPowerMonitor.create();
blockFarmStation = BlockFarmStation.create();
blockCapacitorBank = BlockCapacitorBank.create();
blockWirelessCharger = BlockWirelessCharger.create();
blockPainter = BlockPainter.create();
blockPaintedFence = BlockPaintedFence.create();
@@ -39,7 +39,8 @@ public class GuiHandler implements IGuiHandler {
public static final int GUI_ID_CRAFTER = 87;
public static final int GUI_ID_ZOMBIE_GEN = 71;
public static final int GUI_ID_POWERED_SPAWNER = 88;
public static final int GUI_ID_VACUUM_CHEST = 89;
public static final int GUI_ID_VACUUM_CHEST = 89;
public static final int GUI_ID_WIRELESS_CHARGER = 90;
protected final Map<Integer, IGuiHandler> guiHandlers = new HashMap<Integer, IGuiHandler>();
@@ -47,6 +47,8 @@ public enum ModObject {
blockFarmStation,
blockTank,
blockCrafter,
blockVacuumChest,
blockWirelessCharger,
blockPoweredSpawner,
itemBrokenSpawner,
@@ -74,7 +76,8 @@ public enum ModObject {
blockTravelAnchor,
itemTravelStaff,
itemMagnet, itemGliderWing, blockVacuumChest;
itemMagnet,
itemGliderWing;
public final String unlocalisedName;
@@ -81,7 +81,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
private List<Receptor> localReceptors;
private boolean receptorsDirty = true;
private final ItemStack[] inventory;
private final ItemStack[] inventory;
private List<GaugeBounds> gaugeBounds;
@@ -99,6 +99,8 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
float lastRenderStoredRatio;
// private boolean registered = false;
public TileCapacitorBank() {
inventory = new ItemStack[4];
storedEnergy = 0;
@@ -109,6 +111,15 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
maxInput = maxIO;
maxOutput = maxIO;
updatePowerHandler();
}
@Override
public void invalidate() {
super.invalidate();
// if(registered) {
// WirelessChargerController.instance.deregisterCharger(this);
// registered = false;
// }
}
@Override
@@ -133,8 +144,6 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
return IoMode.PULL;
}
@Override
public boolean supportsMode(ForgeDirection faceHit, IoMode mode) {
IPowerInterface rec = getReceptorForFace(faceHit);
@@ -191,18 +200,16 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
return null;
}
@Override
public void updateEntity() {
if(worldObj == null) { // sanity check
return;
}
if(blockMetadata == -1) {
isCreative = getBlockMetadata() == 1;
}
if(worldObj.isRemote) {
if(render) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
@@ -217,17 +224,24 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
}
if(!isContoller()) {
if(notifyNeighbours) {
// if(registered) {
// WirelessChargerController.instance.deregisterCharger(this);
// registered = false;
// }
if(notifyNeighbours) {
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
notifyNeighbours = false;
}
return;
}
// if(!registered) {
// WirelessChargerController.instance.registerCharger(this);
// registered = true;
// }
chargeItems();
boolean hasSignal = isRecievingRedstoneSignal();
boolean hasSignal = isRecievingRedstoneSignal();
if(inputControlMode == RedstoneControlMode.IGNORE) {
inputEnabled = true;
} else if(inputControlMode == RedstoneControlMode.NEVER) {
@@ -253,15 +267,15 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
powerHandler.setEnergy(0);
}
if(isCreative) {
storedEnergy = getMaxEnergyStored()/2;
storedEnergy = getMaxEnergyStored() / 2;
}
if(lastSyncPowerStored != storedEnergy && worldObj.getTotalWorldTime() % 10 == 0) {
lastSyncPowerStored = storedEnergy;
PacketHandler.sendToAllAround(new PacketPowerStorage(this), this, 64);
PacketHandler.sendToAllAround(new PacketPowerStorage(this), this, 64);
}
if(notifyNeighbours) {
if(notifyNeighbours) {
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
notifyNeighbours = false;
}
@@ -275,10 +289,10 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
return gaugeBounds;
}
private void chargeItems() {
public boolean chargeItems(ItemStack[] items) {
boolean chargedItem = false;
float available = Math.min(maxIO, storedEnergy);
for (ItemStack item : inventory) {
for (ItemStack item : items) {
if(item != null && available > 0) {
float used = 0;
if(item.getItem() instanceof IEnergyContainerItem) {
@@ -294,7 +308,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
used = (chargable.getEnergyStored(item) - cur) / 10;
}
}
}
if(used > 0) {
storedEnergy = storedEnergy - used;
chargedItem = true;
@@ -302,9 +316,14 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
}
}
}
return chargedItem;
}
private void chargeItems() {
boolean chargedItem = chargeItems(inventory);
if(chargedItem) {
markDirty();
}
}
}
public boolean isOutputEnabled() {
@@ -357,7 +376,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
} else {
used = 0;
}
} else {
} else {
used = powerInterface.recieveEnergy(receptor.fromDir.getOpposite(), canTransmit);
}
@@ -728,6 +747,10 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
}
public void onBreakBlock() {
// if(registered) {
// WirelessChargerController.instance.deregisterCharger(this);
// registered = false;
// }
TileCapacitorBank controller = getController();
controller.clearCurrentMultiblock();
}
@@ -748,39 +771,43 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
}
private void formMultiblock() {
if(isCreative) {
return;
}
List<TileCapacitorBank> blocks = new ArrayList<TileCapacitorBank>();
blocks.add(this);
findNighbouringBanks(this, blocks);
// try {
if(isCreative) {
return;
}
List<TileCapacitorBank> blocks = new ArrayList<TileCapacitorBank>();
blocks.add(this);
findNighbouringBanks(this, blocks);
if(blocks.size() < 2) {
return;
}
for (TileCapacitorBank cb : blocks) {
cb.clearCurrentMultiblock();
}
if(blocks.size() < 2) {
return;
}
for (TileCapacitorBank cb : blocks) {
cb.clearCurrentMultiblock();
}
BlockCoord[] mb = new BlockCoord[blocks.size()];
for (int i = 0; i < blocks.size(); i++) {
mb[i] = new BlockCoord(blocks.get(i));
}
BlockCoord[] mb = new BlockCoord[blocks.size()];
for (int i = 0; i < blocks.size(); i++) {
mb[i] = new BlockCoord(blocks.get(i));
}
TileCapacitorBank secondary = blocks.get(1);
maxInput = maxOutput = -1;
TileCapacitorBank secondary = blocks.get(1);
maxInput = maxOutput = -1;
if (secondary.maxInput != secondary.maxIO) {
maxInput = secondary.maxInput;
}
if(secondary.maxInput != secondary.maxIO) {
maxInput = secondary.maxInput;
}
if (secondary.maxOutput != secondary.maxIO) {
maxOutput = secondary.maxOutput;
}
if(secondary.maxOutput != secondary.maxIO) {
maxOutput = secondary.maxOutput;
}
for (TileCapacitorBank cb : blocks) {
cb.setMultiblock(mb);
}
for (TileCapacitorBank cb : blocks) {
cb.setMultiblock(mb);
}
// } finally {
// WirelessChargerController.instance.registerCharger(getController());
// }
}
private void findNighbouringBanks(TileCapacitorBank tileCapacitorBank, List<TileCapacitorBank> blocks) {
@@ -800,6 +827,9 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
private void setMultiblock(BlockCoord[] mb) {
if(multiblock != null && isMaster()) {
//WirelessChargerController.instance.deregisterCharger(this);
// split up current multiblock and reconfigure all the internal capacitors
float powerPerBlock = storedEnergy / multiblock.length;
for (BlockCoord bc : multiblock) {
@@ -819,6 +849,8 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
multiblock = mb;
if(isMaster()) {
//WirelessChargerController.instance.registerCharger(this);
List<ItemStack> invItems = new ArrayList<ItemStack>();
float totalStored = 0;
@@ -841,7 +873,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
storedEnergy = totalStored;
maxStoredEnergy = totalCap;
maxIO = totalIO;
maxInput = maxInput < 0 ? maxIO : Math.min(maxInput, maxIO);
maxInput = maxInput < 0 ? maxIO : Math.min(maxInput, maxIO);
maxOutput = maxOutput < 0 ? maxIO : Math.min(maxOutput, maxIO);
for (BlockCoord bc : multiblock) {
TileCapacitorBank cb = getCapBank(bc);
@@ -1153,7 +1185,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
@Override
public boolean hasCustomInventoryName() {
return false;
}
@@ -1161,7 +1193,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
this.isCreative = true;
maxIO = maxIO * 1000;
maxInput = maxIO;
maxOutput = maxIO;
maxOutput = maxIO;
updatePowerHandler();
}
@@ -47,7 +47,7 @@ public class BlockVacuumChest extends BlockEio implements IGuiHandler {
if(entityPlayer.isSneaking() && entityPlayer.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
IToolWrench wrench = (IToolWrench) entityPlayer.getCurrentEquippedItem().getItem();
if(wrench.canWrench(entityPlayer, x, y, z)) {
removedByPlayer(world, entityPlayer, x, y, z);
removedByPlayer(world, entityPlayer, x, y, z, false);
if(entityPlayer.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
((IToolWrench) entityPlayer.getCurrentEquippedItem().getItem()).wrenchUsed(entityPlayer, x, y, z);
}
@@ -0,0 +1,144 @@
package crazypants.enderio.machine.wireless;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import buildcraft.api.tools.IToolWrench;
import cpw.mods.fml.common.network.IGuiHandler;
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.conduit.ConduitUtil;
import crazypants.enderio.machine.power.PacketPowerStorage;
import crazypants.enderio.machine.vacuum.BlockVacuumChest;
import crazypants.enderio.machine.vacuum.ContainerVacuumChest;
import crazypants.enderio.machine.vacuum.GuiVacuumChest;
import crazypants.enderio.machine.vacuum.TileVacuumChest;
import crazypants.enderio.network.PacketHandler;
public class BlockWirelessCharger extends BlockEio /*implements IGuiHandler*/ {
public static BlockWirelessCharger create() {
PacketHandler.INSTANCE.registerMessage(PacketStoredEnergy.class, PacketStoredEnergy.class, PacketHandler.nextID(), Side.CLIENT);
BlockWirelessCharger res = new BlockWirelessCharger();
res.init();
return res;
}
public static int renderId = 0;
private IIcon centerOn;
private IIcon centerOff;
protected BlockWirelessCharger() {
super(ModObject.blockWirelessCharger.unlocalisedName, TileWirelessCharger.class);
setLightOpacity(1);
}
// @Override
// protected void init() {
// super.init();
// EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_WIRELESS_CHARGER, this);
// }
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) {
if(ConduitUtil.isToolEquipped(entityPlayer)) {
if(entityPlayer.isSneaking() && entityPlayer.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
IToolWrench wrench = (IToolWrench) entityPlayer.getCurrentEquippedItem().getItem();
if(wrench.canWrench(entityPlayer, x, y, z)) {
removedByPlayer(world, entityPlayer, x, y, z, false);
if(entityPlayer.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
((IToolWrench) entityPlayer.getCurrentEquippedItem().getItem()).wrenchUsed(entityPlayer, x, y, z);
}
return true;
}
}
}
// if(entityPlayer.isSneaking()) {
// return false;
// }
// entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_WIRELESS_CHARGER, world, x, y, z);
// return true;
return false;
}
@Override
public void registerBlockIcons(IIconRegister iIconRegister) {
centerOn = iIconRegister.registerIcon("enderio:blockWirelessChargerOn");
centerOff = iIconRegister.registerIcon("enderio:blockWirelessChargerOff");
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int p_149673_5_) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileWirelessCharger) {
TileWirelessCharger twc = (TileWirelessCharger)te;
if(twc.storedEnergy > 0) {
return centerOn;
}
}
return centerOff;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int p_149691_1_, int p_149691_2_) {
return centerOff;
}
public IIcon getCenterOn() {
return centerOn;
}
public IIcon getCenterOff() {
return centerOff;
}
@Override
public int getRenderType() {
return renderId;
}
@Override
public boolean isOpaqueCube() {
return false;
}
// @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 TileWire) {
// return new ContainerVacuumChest(player, player.inventory, (TileVacuumChest) te);
// }
// 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 TileVacuumChest) {
// return new GuiVacuumChest(player, player.inventory, (TileVacuumChest) te);
// }
// return null;
// }
public void breakBlock(World world, int x, int y, int z, Block block, int p_149749_6_) {
super.breakBlock(world, x, y, z, block, p_149749_6_);
world.removeTileEntity(x, y, z);
}
}
@@ -0,0 +1,15 @@
package crazypants.enderio.machine.wireless;
import crazypants.util.BlockCoord;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public interface IWirelessCharger {
World getWorld();
BlockCoord getLocation();
boolean chargeItems(ItemStack[] armorInventory);
}
@@ -0,0 +1,67 @@
package crazypants.enderio.machine.wireless;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import crazypants.enderio.EnderIO;
import crazypants.enderio.machine.power.PacketPowerStorage;
import crazypants.enderio.machine.power.TileCapacitorBank;
import crazypants.util.BlockCoord;
public class PacketStoredEnergy implements IMessage, IMessageHandler<PacketStoredEnergy, IMessage> {
private int x;
private int y;
private int z;
private double storedEnergy;
public PacketStoredEnergy() {
}
public PacketStoredEnergy(TileWirelessCharger ent) {
x = ent.xCoord;
y = ent.yCoord;
z = ent.zCoord;
storedEnergy = ent.storedEnergy;
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
buf.writeDouble(storedEnergy);
}
@Override
public void fromBytes(ByteBuf buf) {
x = buf.readInt();
y = buf.readInt();
z = buf.readInt();
storedEnergy = buf.readDouble();
}
@Override
public IMessage onMessage(PacketStoredEnergy message, MessageContext ctx) {
EntityPlayer player = EnderIO.proxy.getClientPlayer();
TileEntity te = player.worldObj.getTileEntity(message.x, message.y, message.z);
if(te instanceof TileWirelessCharger) {
TileWirelessCharger me = (TileWirelessCharger) te;
boolean doRender = (me.storedEnergy <= 0 && message.storedEnergy > 0) ||
(me.storedEnergy > 0 && message.storedEnergy <= 0);
me.storedEnergy = message.storedEnergy;
if(doRender) {
System.out.println("PacketStoredEnergy.onMessage: ");
player.worldObj.markBlockRangeForRenderUpdate(message.x, message.y, message.z, message.x, message.y, message.z);
//player.worldObj.markBlockForUpdate(message.x, message.y, message.z);
}
}
return null;
}
}
@@ -0,0 +1,168 @@
package crazypants.enderio.machine.wireless;
import cofh.api.energy.IEnergyContainerItem;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import crazypants.enderio.EnderIO;
import crazypants.enderio.TileEntityEio;
import crazypants.enderio.power.IInternalPowerReceptor;
import crazypants.enderio.power.PowerHandlerUtil;
import crazypants.util.BlockCoord;
public class TileWirelessCharger extends TileEntityEio implements IInternalPowerReceptor, IWirelessCharger {
public static final int MAX_ENERGY_STORED_MJ = 100000;
public static final int MAX_ENERGY_IN = 1000;
public static final int MAX_ENERGY_OUT = 1000;
double storedEnergy;
private PowerHandler powerHandler;
private double lastPowerUpdate = -1;
private boolean registered = false;
public TileWirelessCharger() {
powerHandler = new PowerHandler(this, Type.STORAGE);
powerHandler.configure(0, MAX_ENERGY_IN, 0, MAX_ENERGY_IN);
}
@Override
public void invalidate() {
super.invalidate();
WirelessChargerController.instance.deregisterCharger(this);
registered = false;
}
@Override
public void updateEntity() {
if(worldObj == null || worldObj.isRemote) {
return;
}
if(!registered) {
WirelessChargerController.instance.registerCharger(this);
registered = true;
}
double stored = powerHandler.getEnergyStored();
if(stored > 0) {
storedEnergy += stored;
storedEnergy = Math.min(storedEnergy, MAX_ENERGY_STORED_MJ);
if(stored == MAX_ENERGY_STORED_MJ) {
powerHandler.configure(0, 0, 0, 0);
} else {
powerHandler.configure(0, MAX_ENERGY_IN, 0, MAX_ENERGY_IN);
}
powerHandler.setEnergy(0);
}
if( (lastPowerUpdate == -1) ||
(lastPowerUpdate == 0 && storedEnergy > 0) ||
(lastPowerUpdate > 0 && storedEnergy == 0) ||
(lastPowerUpdate != storedEnergy && worldObj.getTotalWorldTime() % 20 == 0)
) {
lastPowerUpdate = storedEnergy;
EnderIO.packetPipeline.sendToAllAround(new PacketStoredEnergy(this), this);
}
}
public boolean chargeItems(ItemStack[] items) {
boolean chargedItem = false;
double available = Math.min(MAX_ENERGY_OUT, storedEnergy);
for (ItemStack item : items) {
if(item != null && available > 0) {
float used = 0;
if(item.getItem() instanceof IEnergyContainerItem) {
IEnergyContainerItem chargable = (IEnergyContainerItem) item.getItem();
float max = chargable.getMaxEnergyStored(item);
float cur = chargable.getEnergyStored(item);
double canUse = Math.min(available * 10, max - cur);
if(cur < max) {
used = chargable.receiveEnergy(item, (int) canUse, false) / 10;
// TODO: I should be able to use 'used' but it is always returning 0
// ATM.
used = (chargable.getEnergyStored(item) - cur) / 10;
}
}
if(used > 0) {
storedEnergy = storedEnergy - used;
chargedItem = true;
available -= used;
}
}
}
return chargedItem;
}
@Override
protected void writeCustomNBT(NBTTagCompound root) {
root.setDouble("storedEnergy", storedEnergy);
}
@Override
protected void readCustomNBT(NBTTagCompound root) {
storedEnergy = root.getDouble("storedEnergy");
}
@Override
public void doWork(PowerHandler arg0) {
}
@Override
public PowerReceiver getPowerReceiver(ForgeDirection arg0) {
return powerHandler.getPowerReceiver();
}
@Override
public World getWorld() {
return getWorldObj();
}
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
double maxMj = Math.min(maxReceive / 10, MAX_ENERGY_IN);
double canRecieve = Math.min(MAX_ENERGY_STORED_MJ - storedEnergy, maxMj);
int canRecieveRF = (int)(canRecieve * 10);
if(!simulate) {
storedEnergy += (canRecieveRF / 10);
}
return canRecieveRF;
}
@Override
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
return 0;
}
@Override
public int getEnergyStored(ForgeDirection from) {
return (int)(storedEnergy * 10);
}
@Override
public int getMaxEnergyStored(ForgeDirection from) {
return MAX_ENERGY_STORED_MJ * 10;
}
@Override
public boolean canConnectEnergy(ForgeDirection from) {
return true;
}
@Override
public BlockCoord getLocation() {
return new BlockCoord(this);
}
}
@@ -0,0 +1,192 @@
package crazypants.enderio.machine.wireless;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import scala.Array;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.relauncher.Side;
import crazypants.enderio.item.darksteel.DarkSteelController;
import crazypants.enderio.item.darksteel.DarkSteelRecipeManager;
import crazypants.util.BlockCoord;
public class WirelessChargerController {
public static WirelessChargerController instance = new WirelessChargerController();
public static final int RANGE = 24;
public static final int RANGE_SQ = RANGE * RANGE;
static {
FMLCommonHandler.instance().bus().register(WirelessChargerController.instance);
MinecraftForge.EVENT_BUS.register(WirelessChargerController.instance);
}
private Map<Integer, Map<BlockCoord, IWirelessCharger>> perWorldChargers = new HashMap<Integer, Map<BlockCoord, IWirelessCharger>>();
private WirelessChargerController() {
}
public void registerCharger(IWirelessCharger capBank) {
if(capBank == null) {
return;
}
Map<BlockCoord, IWirelessCharger> chargers = getChargersForWorld(capBank.getWorld());
chargers.put(capBank.getLocation(), capBank);
}
public void deregisterCharger(IWirelessCharger capBank) {
if(capBank == null) {
return;
}
Map<BlockCoord, IWirelessCharger> chargers = getChargersForWorld(capBank.getWorld());
chargers.remove(capBank.getLocation());
}
@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
if(event.side == Side.CLIENT || event.phase != TickEvent.Phase.END) {
return;
}
Map<BlockCoord, IWirelessCharger> chargers = getChargersForWorld(event.player.worldObj);
if(chargers.isEmpty()) {
return;
}
BlockCoord bc = new BlockCoord((int) event.player.posX, (int) event.player.posY, (int) event.player.posZ);
for (IWirelessCharger capBank : chargers.values()) {
if(capBank.getLocation().distanceSquared(bc) <= RANGE_SQ) {
boolean done = chargeFromCapBank(event.player, capBank);
if(done) {
return;
}
}
}
}
private boolean chargeFromCapBank(EntityPlayer player, IWirelessCharger capBank) {
boolean res = capBank.chargeItems(player.inventory.armorInventory);
res |= capBank.chargeItems(player.inventory.mainInventory);
if(res) {
player.inventory.markDirty();
}
return res;
}
private Map<BlockCoord, IWirelessCharger> getChargersForWorld(World world) {
Map<BlockCoord, IWirelessCharger> res = perWorldChargers.get(world.provider.dimensionId);
if(res == null) {
res = new HashMap<BlockCoord, IWirelessCharger>();
perWorldChargers.put(world.provider.dimensionId, res);
}
return res;
}
// public static final int CHUNK_RANGE = (RANGE/16 + (RANGE%16 == 0 ? 0 : 1));
//
// private Map<Integer, Map<ChunkCoordIntPair, List<TileCapacitorBank>>> perWorldChargers = new HashMap<Integer, Map<ChunkCoordIntPair,List<TileCapacitorBank>>>();
//
// private WirelessChargerController() {
// }
//
// public void registerCharger(TileCapacitorBank capBank) {
// if(capBank == null) {
// return;
// }
// Map<ChunkCoordIntPair, List<TileCapacitorBank>> chargers = getChargersForWorld(capBank.getWorld());
// List<ChunkCoordIntPair> coords = getChunksInRange(capBank.getLocation());
// for(ChunkCoordIntPair cc : coords) {
// addCharger(chargers, cc, capBank);
// }
//
// }
//
// public void dereigsterCharger(TileCapacitorBank capBank) {
// if(capBank == null) {
// return;
// }
// Map<ChunkCoordIntPair, List<TileCapacitorBank>> chargers = getChargersForWorld(capBank.getWorld());
// List<ChunkCoordIntPair> coords = getChunksInRange(capBank.getLocation());
// for(ChunkCoordIntPair cc : coords) {
// removeCharger(chargers, cc, capBank);
// }
// }
//
//
// @SubscribeEvent
// public void onPlayerTick(TickEvent.PlayerTickEvent event) {
// if(event.side == Side.CLIENT || event.phase != TickEvent.Phase.END) {
// return;
// }
//
// List<TileCapacitorBank> charges = getChargersInRange(event.player);
//
//
// }
//
// private List<TileCapacitorBank> getChargersInRange(EntityPlayer player) {
// Map<ChunkCoordIntPair, List<TileCapacitorBank>> worldCharges = getChargersForWorld(player.worldObj);
// if(worldCharges.isEmpty()) {
// return null;
// }
// BlockCoord bc = new BlockCoord((int)player.posX, 0, (int)player.posZ);
// List<ChunkCoordIntPair> chunks = getChunksInRange(bc);
//
// List<TileCapacitorBank> result = new ArrayList<TileCapacitorBank>();
//
// }
//
//
// private void removeCharger(Map<ChunkCoordIntPair, List<TileCapacitorBank>> chunkChargers, ChunkCoordIntPair cc, TileCapacitorBank capBank) {
// List<TileCapacitorBank> chargers = chunkChargers.get(cc);
// if(chargers == null) {
// return;
// }
// chargers.remove(capBank);
// if(chargers.size() == 0) {
// chunkChargers.remove(cc);
// }
// }
//
// private void addCharger(Map<ChunkCoordIntPair, List<TileCapacitorBank>> chunkChargers, ChunkCoordIntPair cc, TileCapacitorBank capBank) {
// List<TileCapacitorBank> chargers = chunkChargers.get(cc);
// if(chargers == null) {
// chargers = new ArrayList<TileCapacitorBank>();
// chunkChargers.put(cc, chargers);
// }
// chargers.add(capBank);
// }
//
// private List<ChunkCoordIntPair> getChunksInRange(BlockCoord coord) {
// int chunkX = coord.x >> 4;
// int chunkY = coord.y >> 4;
//
// List<ChunkCoordIntPair> res = new ArrayList<ChunkCoordIntPair>();
// for(int xOffset=-CHUNK_RANGE; xOffset <= CHUNK_RANGE; xOffset++) {
// for(int yOffset=-CHUNK_RANGE; yOffset <= CHUNK_RANGE; yOffset++) {
// res.add(new ChunkCoordIntPair(chunkX + xOffset, chunkY + yOffset));
// }
// }
// return res;
// }
//
// private Map<ChunkCoordIntPair, List<TileCapacitorBank>> getChargersForWorld(World world) {
// int id = world.provider.dimensionId;
// Map<ChunkCoordIntPair, List<TileCapacitorBank>> res = perWorldChargers.get(id);
// if(res == null) {
// res = new HashMap<ChunkCoordIntPair, List<TileCapacitorBank>>();
// perWorldChargers.put(id, res);
// }
// return res;
// }
}
@@ -0,0 +1,96 @@
package crazypants.enderio.machine.wireless;
import org.lwjgl.opengl.GL11;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import crazypants.enderio.EnderIO;
import crazypants.render.BoundingBox;
import crazypants.render.CubeRenderer;
import crazypants.render.IconUtil;
import crazypants.render.VertexRotation;
import crazypants.render.VertexTransform;
import crazypants.render.VertexTransformComposite;
import crazypants.render.VertexTranslation;
import crazypants.vecmath.Vector3d;
import crazypants.vecmath.Vector3f;
import crazypants.vecmath.Vertex;
public class WirelessChargerRenderer implements ISimpleBlockRenderingHandler {
@Override
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
// GL11.glPushMatrix();
// GL11.glTranslatef(0, 0, 0.5f);
// GL11.glRotatef(45, 0, 1, 0);
// GL11.glTranslatef(0, 0, -0.5f);
//GL11.glTranslatef(0.5f, 0, 0);
Tessellator.instance.startDrawingQuads();
renderWorldBlock(null, 0, 0, 0, null, 0, renderer);
Tessellator.instance.draw();
// GL11.glPopMatrix();
}
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
Tessellator tes = Tessellator.instance;
IIcon baseIcon = EnderIO.blockWirelessCharger.getIcon(0, 0);
tes.addTranslation(x, y, z);
VertexTransform rot = new VertexRotation(Math.toRadians(45), new Vector3d(0,1,0), new Vector3d(0.5,0.5,0.5));
VertexTransform trans = new VertexTranslation(0, -0.5 + 0.025, 0);
VertexTransformComposite xform = new VertexTransformComposite(rot, trans);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(0.7, 0.05, 0.7), baseIcon, xform, true);
trans = new VertexTranslation(0, 0.5 - 0.025, 0);
xform = new VertexTransformComposite(rot, trans);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(0.7, 0.05, 0.7), baseIcon, xform, true);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(0.2, 0.91, 0.2), EnderIO.blockWirelessCharger.getCenterOn(), true);
trans = new VertexTranslation(0, 0, 0.5 - 0.01);
xform = new VertexTransformComposite(trans);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(0.25, 0.25, 0.01), baseIcon, xform, true);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(0.01, 1, 0.01), baseIcon, xform, true);
rot = new VertexRotation(Math.toRadians(90), new Vector3d(0,1,0), new Vector3d(0.5,0.5,0.5));
xform = new VertexTransformComposite(trans, rot);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(0.25, 0.25, 0.01), baseIcon, xform, true);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(0.01, 1, 0.01), baseIcon, xform, true);
rot = new VertexRotation(Math.toRadians(180), new Vector3d(0,1,0), new Vector3d(0.5,0.5,0.5));
xform = new VertexTransformComposite(trans, rot);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(0.25, 0.25, 0.01), baseIcon, xform, true);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(0.01, 1, 0.01), baseIcon, xform, true);
rot = new VertexRotation(Math.toRadians(270), new Vector3d(0,1,0), new Vector3d(0.5,0.5,0.5));
xform = new VertexTransformComposite(trans, rot);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(0.25, 0.25, 0.01), baseIcon, xform, true);
CubeRenderer.render(BoundingBox.UNIT_CUBE.scale(0.01, 1, 0.01), baseIcon, xform, true);
tes.addTranslation(-x, -y, -z);
return false;
}
@Override
public boolean shouldRender3DInInventory(int modelId) {
return true;
}
@Override
public int getRenderId() {
return BlockWirelessCharger.renderId;
}
}