With my previous post in mind, here is my ItemCoaxiumRod.java file, there is one problem: The item itself isn't available in the Creative inventory. When I add the ModItems.ITEMS.add(this), I get a NullPointerException (crash log below). I am declaring my Item in my ModItems class, in init package like this:
package com.sm.FirstMod.items;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Queue;
import com.sm.FirstMod.Main;
import com.sm.FirstMod.init.ModItems;
import ic2.api.reactor.IReactor;
import ic2.api.reactor.IReactorComponent;
import ic2.core.IC2Potion;
import ic2.core.item.armor.ItemArmorHazmat;
import ic2.core.item.reactor.ItemReactorUranium;
//VV getting method not visible error...
//import ic2.core.item.reactor.ItemReactorUranium.ItemStackCoord;
//do I just copy the method from ItemReactorUranium?
import ic2.core.ref.ItemName;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemCoaxiumRod extends Item implements IReactorComponent
{
public final int numberOfCells;
public ItemCoaxiumRod(String name, int cells)
{
super();
numberOfCells = cells;
//when added, causes NullPointerException
//ModItems.ITEMS.add(getContainerItem());
}
@Override
public boolean canBePlacedIn(ItemStack paramItemStack, IReactor paramIReactor) {
return true;
}
@Override
public void processChamber(ItemStack stack, IReactor reactor, int x, int y, boolean heatRun)
{
if (!reactor.produceEnergy()) { return; }
int basePulses = 1 + numberOfCells / 2;
for (int iteration = 0; iteration < numberOfCells; iteration++)
{
int pulses = basePulses;
if (!heatRun)
{
for (int i = 0; i < pulses; i++)
{
acceptUraniumPulse(stack, reactor, stack, x, y, x, y, heatRun);
}
pulses = pulses + (checkPulseable(reactor, x - 1, y, stack, x, y, heatRun) + checkPulseable(reactor, x + 1, y, stack, x, y, heatRun) + checkPulseable(reactor, x, y - 1, stack, x, y, heatRun) + checkPulseable(reactor, x, y + 1, stack, x, y, heatRun));
}
else
{
pulses = pulses + (checkPulseable(reactor, x - 1, y, stack, x, y, heatRun) + checkPulseable(reactor, x + 1, y, stack, x, y, heatRun) + checkPulseable(reactor, x, y - 1, stack, x, y, heatRun) + checkPulseable(reactor, x, y + 1, stack, x, y, heatRun));
int heat = triangularNumber(pulses) * 4;
heat = getFinalHeat(stack, reactor, x, y, heat);
Queue<ItemStackCoord> heatAcceptors = new ArrayDeque();
checkHeatAcceptor(reactor, x - 1, y, heatAcceptors);
checkHeatAcceptor(reactor, x + 1, y, heatAcceptors);
checkHeatAcceptor(reactor, x, y - 1, heatAcceptors);
checkHeatAcceptor(reactor, x, y + 1, heatAcceptors);
while ((!heatAcceptors.isEmpty()) && (heat > 0))
{
int dheat = heat / heatAcceptors.size();
heat -= dheat;
ItemStackCoord acceptor = (ItemStackCoord)heatAcceptors.remove();
//func_77973_b() is getItem()??
IReactorComponent acceptorComp = (IReactorComponent)stack.getItem();
dheat = acceptorComp.alterHeat(stack, reactor, x, y, dheat);
heat += dheat;
}
if (heat > 0) { reactor.addHeat(heat);}
}
}
}
@Override
public boolean acceptUraniumPulse(ItemStack stack, IReactor reactor, ItemStack pulsingStack, int youX, int youY, int pulseX, int pulseY, boolean heatrun)
{
if (!heatrun) {
reactor.addOutput(1.0F);
}
return true;
}
@Override
public boolean canStoreHeat(ItemStack paramItemStack, IReactor paramIReactor, int paramInt1, int paramInt2) {
// TODO Auto-generated method stub
return false;
}
@Override
public int getMaxHeat(ItemStack paramItemStack, IReactor paramIReactor, int paramInt1, int paramInt2) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getCurrentHeat(ItemStack paramItemStack, IReactor paramIReactor, int paramInt1, int paramInt2) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int alterHeat(ItemStack paramItemStack, IReactor paramIReactor, int paramInt1, int paramInt2,
int paramInt3) {
// TODO Auto-generated method stub
return 0;
}
@Override
public float influenceExplosion(ItemStack paramItemStack, IReactor paramIReactor) {
// TODO Auto-generated method stub
return 0;
}
public static int triangularNumber(int x)
{
return (x * x + x) / 2;
}
public static int checkPulseable(IReactor reactor, int x, int y, ItemStack stack, int mex, int mey, boolean heatrun)
{
ItemStack other = reactor.getItemAt(x, y);
if ((other != null) && ((other.getItem() instanceof IReactorComponent)) &&
(((IReactorComponent)other.getItem()).acceptUraniumPulse(other, reactor, stack, x, y, mex, mey, heatrun))) {
return 1;
}
return 0;
}
//what is happening??
private static class ItemStackCoord { public final ItemStack stack;
public final int x;
public final int y;
public ItemStackCoord(ItemStack stack, int x, int y) { this.stack = stack;
this.x = x;
this.y = y;
}
}
//its a simple getter :P
//protected or public? Copy from ItemUranium? Keep the 'protected'?
public int getFinalHeat(ItemStack stack, IReactor reactor, int x, int y, int heat) { return heat; }
//func_77973_b() is getItem(), right?
protected void checkHeatAcceptor(IReactor reactor, int x, int y, Collection<ItemStackCoord> heatAcceptors)
{
ItemStack stack = reactor.getItemAt(x, y);
if ((stack != null) && ((stack.getItem() instanceof IReactorComponent)) &&
(((IReactorComponent)stack.getItem()).canStoreHeat(stack, reactor, x, y)))
heatAcceptors.add(new ItemStackCoord(stack, x, y));
}
}
Display More