here it goes again

adds OC compat to the new fusion reactor and the particle accelerator
This commit is contained in:
Voxelstice 2025-11-27 18:17:51 +03:00
parent 3bdd7b4c94
commit 9ab73e382f
10 changed files with 977 additions and 190 deletions

View File

@ -2,6 +2,7 @@ package com.hbm.tileentity.machine.albion;
import java.util.List; import java.util.List;
import com.hbm.handler.CompatHandler;
import com.hbm.inventory.container.ContainerPADetector; import com.hbm.inventory.container.ContainerPADetector;
import com.hbm.inventory.gui.GUIPADetector; import com.hbm.inventory.gui.GUIPADetector;
import com.hbm.inventory.recipes.ParticleAcceleratorRecipes; import com.hbm.inventory.recipes.ParticleAcceleratorRecipes;
@ -15,8 +16,13 @@ import com.hbm.tileentity.machine.albion.TileEntityPASource.Particle;
import com.hbm.util.fauxpointtwelve.BlockPos; import com.hbm.util.fauxpointtwelve.BlockPos;
import com.hbm.util.fauxpointtwelve.DirPos; import com.hbm.util.fauxpointtwelve.DirPos;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.SimpleComponent;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -24,7 +30,8 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityPADetector extends TileEntityCooledBase implements IGUIProvider, IParticleUser { @Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityPADetector extends TileEntityCooledBase implements IGUIProvider, IParticleUser, SimpleComponent, CompatHandler.OCComponent {
public static final long usage = 100_000; public static final long usage = 100_000;
@ -122,7 +129,7 @@ public class TileEntityPADetector extends TileEntityCooledBase implements IGUIPr
for(ParticleAcceleratorRecipe recipe : ParticleAcceleratorRecipes.recipes) { for(ParticleAcceleratorRecipe recipe : ParticleAcceleratorRecipes.recipes) {
if(!recipe.matchesRecipe(particle.input1, particle.input2)) continue; // another W for continue if(!recipe.matchesRecipe(particle.input1, particle.input2)) continue; // another W for continue
if(particle.momentum < recipe.momentum) { if(particle.momentum < recipe.momentum) {
particle.crash(PAState.CRASH_UNDERSPEED); particle.crash(PAState.CRASH_UNDERSPEED);
return; return;
@ -146,12 +153,12 @@ public class TileEntityPADetector extends TileEntityCooledBase implements IGUIPr
} }
} }
} }
if((recipe.output1 != null && recipe.output1.getItem() == ModItems.particle_digamma) || (recipe.output2 != null && recipe.output2.getItem() == ModItems.particle_digamma)) { if((recipe.output1 != null && recipe.output1.getItem() == ModItems.particle_digamma) || (recipe.output2 != null && recipe.output2.getItem() == ModItems.particle_digamma)) {
List<EntityPlayer> players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5).expand(100, 50, 100)); List<EntityPlayer> players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5).expand(100, 50, 100));
for(EntityPlayer player : players) player.triggerAchievement(MainRegistry.achOmega12); for(EntityPlayer player : players) player.triggerAchievement(MainRegistry.achOmega12);
} }
particle.crash(PAState.SUCCESS); particle.crash(PAState.SUCCESS);
return; return;
} }
@ -183,4 +190,85 @@ public class TileEntityPADetector extends TileEntityCooledBase implements IGUIPr
public BlockPos getExitPos(Particle particle) { public BlockPos getExitPos(Particle particle) {
return null; return null;
} }
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "ntm_pa_detector";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getEnergyInfo(Context context, Arguments args) {
return new Object[] {getPower(), getMaxPower()};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getCoolant(Context context, Arguments args) {
return new Object[] {
coolantTanks[0].getFill(), coolantTanks[0].getMaxFill(),
coolantTanks[1].getFill(), coolantTanks[1].getMaxFill(),
};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getCrafting(Context context, Arguments args) {
Object[] items = new Object[] {"", 0, "", 0, "", 0, "", 0};
for (int i = 0; i < 4; i++) {
ItemStack slot = slots[i+1];
if (slot != null) {
items[i*2] = slot.getUnlocalizedName();
items[(i*2)+1] = slot.stackSize;
}
}
return items;
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
Object[] items = new Object[] {"", 0, "", 0, "", 0, "", 0};
for (int i = 0; i < 4; i++) {
ItemStack slot = slots[i+1];
if (slot != null) {
items[i*2] = slot.getUnlocalizedName();
items[(i*2)+1] = slot.stackSize;
}
}
return new Object[] {
getPower(), getMaxPower(),
coolantTanks[0].getFill(), coolantTanks[0].getMaxFill(),
coolantTanks[1].getFill(), coolantTanks[1].getMaxFill(),
items[0], items[1], items[2], items[3],
items[4], items[5], items[6], items[7]
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public String[] methods() {
return new String[] {
"getEnergyInfo",
"getCoolant",
"getCrafting",
"getInfo"
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
switch (method) {
case "getEnergyInfo": return getEnergyInfo(context, args);
case "getCoolant": return getCoolant(context, args);
case "getCrafting": return getCrafting(context, args);
case "getInfo": return getInfo(context, args);
}
throw new NoSuchMethodException();
}
} }

View File

@ -266,6 +266,21 @@ public class TileEntityPADipole extends TileEntityCooledBase implements IGUIProv
return "ntm_pa_dipole"; return "ntm_pa_dipole";
} }
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getEnergyInfo(Context context, Arguments args) {
return new Object[] {getPower(), getMaxPower()};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getCoolant(Context context, Arguments args) {
return new Object[] {
coolantTanks[0].getFill(), coolantTanks[0].getMaxFill(),
coolantTanks[1].getFill(), coolantTanks[1].getMaxFill(),
};
}
@Callback(direct = true) @Callback(direct = true)
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] getDirLower(Context context, Arguments args) { public Object[] getDirLower(Context context, Arguments args) {
@ -321,10 +336,25 @@ public class TileEntityPADipole extends TileEntityCooledBase implements IGUIProv
return new Object[] {}; return new Object[] {};
} }
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
return new Object[] {
getPower(), getMaxPower(),
coolantTanks[0].getFill(), coolantTanks[0].getMaxFill(),
coolantTanks[1].getFill(), coolantTanks[1].getMaxFill(),
dirToName(dirLower), dirToName(dirUpper), dirToName(dirRedstone), threshold
};
}
@Override @Override
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public String[] methods() { public String[] methods() {
return new String[] { return new String[] {
"getEnergyInfo",
"getCoolant",
"getDirLower", "getDirLower",
"setDirLower", "setDirLower",
"getDirUpper", "getDirUpper",
@ -333,6 +363,7 @@ public class TileEntityPADipole extends TileEntityCooledBase implements IGUIProv
"setDirRedstone", "setDirRedstone",
"getThreshold", "getThreshold",
"setThreshold", "setThreshold",
"getInfo",
}; };
} }
@ -340,6 +371,9 @@ public class TileEntityPADipole extends TileEntityCooledBase implements IGUIProv
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] invoke(String method, Context context, Arguments args) throws Exception { public Object[] invoke(String method, Context context, Arguments args) throws Exception {
switch (method) { switch (method) {
case "getEnergyInfo": return getEnergyInfo(context, args);
case "getCoolant": return getCoolant(context, args);
case "getDirLower": return getDirLower(context, args); case "getDirLower": return getDirLower(context, args);
case "setDirLower": return setDirLower(context, args); case "setDirLower": return setDirLower(context, args);
case "getDirUpper": return getDirUpper(context, args); case "getDirUpper": return getDirUpper(context, args);
@ -348,6 +382,8 @@ public class TileEntityPADipole extends TileEntityCooledBase implements IGUIProv
case "setDirRedstone": return setDirRedstone(context, args); case "setDirRedstone": return setDirRedstone(context, args);
case "getThreshold": return getThreshold(context, args); case "getThreshold": return getThreshold(context, args);
case "setThreshold": return setThreshold(context, args); case "setThreshold": return setThreshold(context, args);
case "getInfo": return getInfo(context, args);
} }
throw new NoSuchMethodException(); throw new NoSuchMethodException();
} }
@ -361,7 +397,7 @@ public class TileEntityPADipole extends TileEntityCooledBase implements IGUIProv
@Override @Override
public String runRORFunction(String name, String[] params) { public String runRORFunction(String name, String[] params) {
if((PREFIX_FUNCTION + "setthreshold").equals(name) && params.length > 0) { if((PREFIX_FUNCTION + "setthreshold").equals(name) && params.length > 0) {
this.threshold = IRORInteractive.parseInt(params[0], 0, 999_999_999); this.threshold = IRORInteractive.parseInt(params[0], 0, 999_999_999);
this.markChanged(); this.markChanged();

View File

@ -1,5 +1,6 @@
package com.hbm.tileentity.machine.albion; package com.hbm.tileentity.machine.albion;
import com.hbm.handler.CompatHandler;
import com.hbm.inventory.container.ContainerPAQuadrupole; import com.hbm.inventory.container.ContainerPAQuadrupole;
import com.hbm.inventory.gui.GUIPAQuadrupole; import com.hbm.inventory.gui.GUIPAQuadrupole;
import com.hbm.items.ModItems; import com.hbm.items.ModItems;
@ -12,19 +13,25 @@ import com.hbm.util.EnumUtil;
import com.hbm.util.fauxpointtwelve.BlockPos; import com.hbm.util.fauxpointtwelve.BlockPos;
import com.hbm.util.fauxpointtwelve.DirPos; import com.hbm.util.fauxpointtwelve.DirPos;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.SimpleComponent;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityPAQuadrupole extends TileEntityCooledBase implements IGUIProvider, IParticleUser { @Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityPAQuadrupole extends TileEntityCooledBase implements IGUIProvider, IParticleUser, SimpleComponent, CompatHandler.OCComponent {
public static final long usage = 100_000; public static final long usage = 100_000;
public static final int focusGain = 100; public static final int focusGain = 100;
public TileEntityPAQuadrupole() { public TileEntityPAQuadrupole() {
super(2); super(2);
} }
@ -49,7 +56,7 @@ public class TileEntityPAQuadrupole extends TileEntityCooledBase implements IGUI
@Override @Override
public void onEnter(Particle particle, ForgeDirection dir) { public void onEnter(Particle particle, ForgeDirection dir) {
EnumCoilType type = null; EnumCoilType type = null;
int mult = 1; int mult = 1;
if(slots[1] != null && slots[1].getItem() == ModItems.pa_coil) { if(slots[1] != null && slots[1].getItem() == ModItems.pa_coil) {
type = EnumUtil.grabEnumSafely(EnumCoilType.class, slots[1].getItemDamage()); type = EnumUtil.grabEnumSafely(EnumCoilType.class, slots[1].getItemDamage());
@ -60,7 +67,7 @@ public class TileEntityPAQuadrupole extends TileEntityCooledBase implements IGUI
if(this.power < this.usage * mult) particle.crash(PAState.CRASH_NOPOWER); if(this.power < this.usage * mult) particle.crash(PAState.CRASH_NOPOWER);
if(type == null) particle.crash(PAState.CRASH_NOCOIL); if(type == null) particle.crash(PAState.CRASH_NOCOIL);
if(type != null && type.quadMax < particle.momentum) particle.crash(PAState.CRASH_OVERSPEED); if(type != null && type.quadMax < particle.momentum) particle.crash(PAState.CRASH_OVERSPEED);
if(particle.invalid) return; if(particle.invalid) return;
particle.addDistance(3); particle.addDistance(3);
@ -76,19 +83,19 @@ public class TileEntityPAQuadrupole extends TileEntityCooledBase implements IGUI
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.power = Library.chargeTEFromItems(slots, 0, power, this.getMaxPower()); this.power = Library.chargeTEFromItems(slots, 0, power, this.getMaxPower());
} }
super.updateEntity(); super.updateEntity();
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 1, xCoord - 1,
@ -99,10 +106,10 @@ public class TileEntityPAQuadrupole extends TileEntityCooledBase implements IGUI
zCoord + 2 zCoord + 2
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -129,4 +136,57 @@ public class TileEntityPAQuadrupole extends TileEntityCooledBase implements IGUI
public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUIPAQuadrupole(player.inventory, this); return new GUIPAQuadrupole(player.inventory, this);
} }
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "ntm_pa_quad";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getEnergyInfo(Context context, Arguments args) {
return new Object[] {getPower(), getMaxPower()};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getCoolant(Context context, Arguments args) {
return new Object[] {
coolantTanks[0].getFill(), coolantTanks[0].getMaxFill(),
coolantTanks[1].getFill(), coolantTanks[1].getMaxFill(),
};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
return new Object[] {
getPower(), getMaxPower(),
coolantTanks[0].getFill(), coolantTanks[0].getMaxFill(),
coolantTanks[1].getFill(), coolantTanks[1].getMaxFill(),
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public String[] methods() {
return new String[] {
"getEnergyInfo",
"getCoolant",
"getInfo"
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
switch (method) {
case "getEnergyInfo": return getEnergyInfo(context, args);
case "getCoolant": return getCoolant(context, args);
case "getInfo": return getInfo(context, args);
}
throw new NoSuchMethodException();
}
} }

View File

@ -1,5 +1,6 @@
package com.hbm.tileentity.machine.albion; package com.hbm.tileentity.machine.albion;
import com.hbm.handler.CompatHandler;
import com.hbm.inventory.container.ContainerPARFC; import com.hbm.inventory.container.ContainerPARFC;
import com.hbm.inventory.gui.GUIPARFC; import com.hbm.inventory.gui.GUIPARFC;
import com.hbm.lib.Library; import com.hbm.lib.Library;
@ -9,20 +10,26 @@ import com.hbm.tileentity.machine.albion.TileEntityPASource.Particle;
import com.hbm.util.fauxpointtwelve.BlockPos; import com.hbm.util.fauxpointtwelve.BlockPos;
import com.hbm.util.fauxpointtwelve.DirPos; import com.hbm.util.fauxpointtwelve.DirPos;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.SimpleComponent;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityPARFC extends TileEntityCooledBase implements IGUIProvider, IParticleUser { @Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityPARFC extends TileEntityCooledBase implements IGUIProvider, IParticleUser, SimpleComponent, CompatHandler.OCComponent {
public static final long usage = 250_000; public static final long usage = 250_000;
public static final int momentumGain = 100; public static final int momentumGain = 100;
public static final int defocusGain = 100; public static final int defocusGain = 100;
public TileEntityPARFC() { public TileEntityPARFC() {
super(1); super(1);
} }
@ -49,7 +56,7 @@ public class TileEntityPARFC extends TileEntityCooledBase implements IGUIProvide
if(!isCool()) particle.crash(PAState.CRASH_NOCOOL); if(!isCool()) particle.crash(PAState.CRASH_NOCOOL);
if(this.power < this.usage) particle.crash(PAState.CRASH_NOPOWER); if(this.power < this.usage) particle.crash(PAState.CRASH_NOPOWER);
if(particle.invalid) return; if(particle.invalid) return;
particle.addDistance(9); particle.addDistance(9);
@ -66,19 +73,19 @@ public class TileEntityPARFC extends TileEntityCooledBase implements IGUIProvide
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.power = Library.chargeTEFromItems(slots, 0, power, this.getMaxPower()); this.power = Library.chargeTEFromItems(slots, 0, power, this.getMaxPower());
} }
super.updateEntity(); super.updateEntity();
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 4, xCoord - 4,
@ -89,10 +96,10 @@ public class TileEntityPARFC extends TileEntityCooledBase implements IGUIProvide
zCoord + 5 zCoord + 5
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -121,4 +128,57 @@ public class TileEntityPARFC extends TileEntityCooledBase implements IGUIProvide
public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUIPARFC(player.inventory, this); return new GUIPARFC(player.inventory, this);
} }
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "ntm_pa_rfc";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getEnergyInfo(Context context, Arguments args) {
return new Object[] {getPower(), getMaxPower()};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getCoolant(Context context, Arguments args) {
return new Object[] {
coolantTanks[0].getFill(), coolantTanks[0].getMaxFill(),
coolantTanks[1].getFill(), coolantTanks[1].getMaxFill(),
};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
return new Object[] {
getPower(), getMaxPower(),
coolantTanks[0].getFill(), coolantTanks[0].getMaxFill(),
coolantTanks[1].getFill(), coolantTanks[1].getMaxFill(),
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public String[] methods() {
return new String[] {
"getEnergyInfo",
"getCoolant",
"getInfo"
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
switch (method) {
case "getEnergyInfo": return getEnergyInfo(context, args);
case "getCoolant": return getCoolant(context, args);
case "getInfo": return getInfo(context, args);
}
throw new NoSuchMethodException();
}
} }

View File

@ -1,6 +1,7 @@
package com.hbm.tileentity.machine.albion; package com.hbm.tileentity.machine.albion;
import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.BlockDummyable;
import com.hbm.handler.CompatHandler;
import com.hbm.interfaces.IControlReceiver; import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.container.ContainerPASource; import com.hbm.inventory.container.ContainerPASource;
import com.hbm.inventory.gui.GUIPASource; import com.hbm.inventory.gui.GUIPASource;
@ -11,9 +12,14 @@ import com.hbm.util.EnumUtil;
import com.hbm.util.fauxpointtwelve.BlockPos; import com.hbm.util.fauxpointtwelve.BlockPos;
import com.hbm.util.fauxpointtwelve.DirPos; import com.hbm.util.fauxpointtwelve.DirPos;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.SimpleComponent;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
@ -24,7 +30,8 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityPASource extends TileEntityCooledBase implements IGUIProvider, IConditionalInvAccess, IControlReceiver { @Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityPASource extends TileEntityCooledBase implements IGUIProvider, IConditionalInvAccess, IControlReceiver, SimpleComponent, CompatHandler.OCComponent {
public static final long usage = 100_000; public static final long usage = 100_000;
public Particle particle; public Particle particle;
@ -237,7 +244,7 @@ public class TileEntityPASource extends TileEntityCooledBase implements IGUIProv
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
if(particle != null) { if(particle != null) {
NBTTagCompound particleTag = new NBTTagCompound(); NBTTagCompound particleTag = new NBTTagCompound();
particleTag.setInteger("x", particle.x); particleTag.setInteger("x", particle.x);
@ -247,12 +254,12 @@ public class TileEntityPASource extends TileEntityCooledBase implements IGUIProv
particleTag.setInteger("momentum", particle.momentum); particleTag.setInteger("momentum", particle.momentum);
particleTag.setInteger("defocus", particle.defocus); particleTag.setInteger("defocus", particle.defocus);
particleTag.setInteger("dist", particle.distanceTraveled); particleTag.setInteger("dist", particle.distanceTraveled);
NBTTagCompound inputTag1 = new NBTTagCompound(); NBTTagCompound inputTag1 = new NBTTagCompound();
NBTTagCompound inputTag2 = new NBTTagCompound(); NBTTagCompound inputTag2 = new NBTTagCompound();
particle.input1.writeToNBT(inputTag1); particle.input1.writeToNBT(inputTag1);
particle.input2.writeToNBT(inputTag2); particle.input2.writeToNBT(inputTag2);
particleTag.setTag("input1", inputTag1); particleTag.setTag("input1", inputTag1);
particleTag.setTag("input2", inputTag2); particleTag.setTag("input2", inputTag2);
nbt.setTag("particle", particleTag); nbt.setTag("particle", particleTag);
@ -278,6 +285,114 @@ public class TileEntityPASource extends TileEntityCooledBase implements IGUIProv
this.particle.distanceTraveled = particleTag.getInteger("dist"); this.particle.distanceTraveled = particleTag.getInteger("dist");
} }
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "ntm_pa_source";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getEnergyInfo(Context context, Arguments args) {
return new Object[] {getPower(), getMaxPower()};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getCoolant(Context context, Arguments args) {
return new Object[] {
coolantTanks[0].getFill(), coolantTanks[0].getMaxFill(),
coolantTanks[1].getFill(), coolantTanks[1].getMaxFill(),
};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getMomentum(Context context, Arguments args) {
return new Object[] {lastSpeed};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getState(Context context, Arguments args) {
return new Object[] {state.name()};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getCrafting(Context context, Arguments args) {
Object[] items = new Object[] {"", 0, "", 0, "", 0, "", 0};
for (int i = 0; i < 4; i++) {
ItemStack slot = slots[i+1];
if (slot != null) {
items[i*2] = slot.getUnlocalizedName();
items[(i*2)+1] = slot.stackSize;
}
}
return items;
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] cancelOperation(Context context, Arguments args) {
particle = null;
state = PAState.IDLE;
return new Object[] {};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
Object[] items = new Object[] {"", 0, "", 0, "", 0, "", 0};
for (int i = 0; i < 4; i++) {
ItemStack slot = slots[i+1];
if (slot != null) {
items[i*2] = slot.getUnlocalizedName();
items[(i*2)+1] = slot.stackSize;
}
}
return new Object[] {
getPower(), getMaxPower(),
coolantTanks[0].getFill(), coolantTanks[0].getMaxFill(),
coolantTanks[1].getFill(), coolantTanks[1].getMaxFill(),
items[0], items[1], items[2], items[3],
items[4], items[5], items[6], items[7],
lastSpeed, state.name()
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public String[] methods() {
return new String[] {
"getEnergyInfo",
"getCoolant",
"getMomentum",
"getState",
"getCrafting",
"cancelOperation",
"getInfo"
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
switch (method) {
case "getEnergyInfo": return getEnergyInfo(context, args);
case "getCoolant": return getCoolant(context, args);
case "getMomentum": return getMomentum(context, args);
case "getState": return getState(context, args);
case "getCrafting": return getCrafting(context, args);
case "cancelOperation": return cancelOperation(context, args);
case "getInfo": return getInfo(context, args);
}
throw new NoSuchMethodException();
}
public static class Particle { public static class Particle {
private TileEntityPASource source; private TileEntityPASource source;

View File

@ -1,5 +1,6 @@
package com.hbm.tileentity.machine.fusion; package com.hbm.tileentity.machine.fusion;
import com.hbm.handler.CompatHandler;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
import com.hbm.inventory.fluid.trait.FT_Heatable; import com.hbm.inventory.fluid.trait.FT_Heatable;
@ -11,35 +12,41 @@ import com.hbm.util.fauxpointtwelve.BlockPos;
import com.hbm.util.fauxpointtwelve.DirPos; import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.fluidmk2.IFluidStandardTransceiverMK2; import api.hbm.fluidmk2.IFluidStandardTransceiverMK2;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.SimpleComponent;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityFusionBoiler extends TileEntityLoadedBase implements IFluidStandardTransceiverMK2, IFusionPowerReceiver { @Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityFusionBoiler extends TileEntityLoadedBase implements IFluidStandardTransceiverMK2, IFusionPowerReceiver, SimpleComponent, CompatHandler.OCComponent {
protected GenNode plasmaNode; protected GenNode plasmaNode;
public long plasmaEnergy; public long plasmaEnergy;
public long plasmaEnergySync; public long plasmaEnergySync;
public FluidTank[] tanks; public FluidTank[] tanks;
public TileEntityFusionBoiler() { public TileEntityFusionBoiler() {
this.tanks = new FluidTank[2]; this.tanks = new FluidTank[2];
this.tanks[0] = new FluidTank(Fluids.WATER, 32_000); this.tanks[0] = new FluidTank(Fluids.WATER, 32_000);
this.tanks[1] = new FluidTank(Fluids.SUPERHOTSTEAM, 32_000); this.tanks[1] = new FluidTank(Fluids.SUPERHOTSTEAM, 32_000);
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.plasmaEnergySync = this.plasmaEnergy; this.plasmaEnergySync = this.plasmaEnergy;
this.plasmaEnergy = 0; this.plasmaEnergy = 0;
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
if(tanks[0].getTankType() != Fluids.NONE) this.trySubscribe(tanks[0].getTankType(), worldObj, pos); if(tanks[0].getTankType() != Fluids.NONE) this.trySubscribe(tanks[0].getTankType(), worldObj, pos);
if(tanks[1].getFill() > 0) this.tryProvide(tanks[1], worldObj, pos); if(tanks[1].getFill() > 0) this.tryProvide(tanks[1], worldObj, pos);
@ -48,26 +55,26 @@ public class TileEntityFusionBoiler extends TileEntityLoadedBase implements IFlu
if(plasmaNode == null || plasmaNode.expired) { if(plasmaNode == null || plasmaNode.expired) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getOpposite();
plasmaNode = UniNodespace.getNode(worldObj, xCoord + dir.offsetX * 4, yCoord + 2, zCoord + dir.offsetZ * 4, PlasmaNetworkProvider.THE_PROVIDER); plasmaNode = UniNodespace.getNode(worldObj, xCoord + dir.offsetX * 4, yCoord + 2, zCoord + dir.offsetZ * 4, PlasmaNetworkProvider.THE_PROVIDER);
if(plasmaNode == null) { if(plasmaNode == null) {
plasmaNode = new GenNode(PlasmaNetworkProvider.THE_PROVIDER, plasmaNode = new GenNode(PlasmaNetworkProvider.THE_PROVIDER,
new BlockPos(xCoord + dir.offsetX * 4, yCoord + 2, zCoord + dir.offsetZ * 4)) new BlockPos(xCoord + dir.offsetX * 4, yCoord + 2, zCoord + dir.offsetZ * 4))
.setConnections(new DirPos(xCoord + dir.offsetX * 5, yCoord + 2, zCoord + dir.offsetZ * 5, dir)); .setConnections(new DirPos(xCoord + dir.offsetX * 5, yCoord + 2, zCoord + dir.offsetZ * 5, dir));
UniNodespace.createNode(worldObj, plasmaNode); UniNodespace.createNode(worldObj, plasmaNode);
} }
} }
if(plasmaNode != null && plasmaNode.hasValidNet()) plasmaNode.net.addReceiver(this); if(plasmaNode != null && plasmaNode.hasValidNet()) plasmaNode.net.addReceiver(this);
this.networkPackNT(50); this.networkPackNT(50);
} }
} }
public DirPos[] getConPos() { public DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
return new DirPos[] { return new DirPos[] {
//new DirPos(xCoord + dir.offsetX * 5, yCoord + 2, zCoord + dir.offsetZ * 5, dir), //new DirPos(xCoord + dir.offsetX * 5, yCoord + 2, zCoord + dir.offsetZ * 5, dir),
new DirPos(xCoord - dir.offsetX * 1 + rot.offsetX * 2, yCoord, zCoord - dir.offsetZ * 1 + rot.offsetZ * 2, rot), new DirPos(xCoord - dir.offsetX * 1 + rot.offsetX * 2, yCoord, zCoord - dir.offsetZ * 1 + rot.offsetZ * 2, rot),
@ -82,17 +89,17 @@ public class TileEntityFusionBoiler extends TileEntityLoadedBase implements IFlu
@Override @Override
public void receiveFusionPower(long fusionPower, double neutronPower) { public void receiveFusionPower(long fusionPower, double neutronPower) {
this.plasmaEnergy = fusionPower; this.plasmaEnergy = fusionPower;
int waterCycles = Math.min(tanks[0].getFill(), tanks[1].getMaxFill() - tanks[1].getFill()); int waterCycles = Math.min(tanks[0].getFill(), tanks[1].getMaxFill() - tanks[1].getFill());
int steamCycles = (int) (Math.min(fusionPower / tanks[0].getTankType().getTrait(FT_Heatable.class).getFirstStep().heatReq, waterCycles)); int steamCycles = (int) (Math.min(fusionPower / tanks[0].getTankType().getTrait(FT_Heatable.class).getFirstStep().heatReq, waterCycles));
// the Math.min call was mushed into the steam cycles call instead of doing it afterwards as usual // the Math.min call was mushed into the steam cycles call instead of doing it afterwards as usual
// in order to prevent issues when casting, should the fusion reactor output truly absurd amounts of power // in order to prevent issues when casting, should the fusion reactor output truly absurd amounts of power
// due to the water cycles being effectively capped via the buffer size // due to the water cycles being effectively capped via the buffer size
if(steamCycles > 0) { if(steamCycles > 0) {
tanks[0].setFill(tanks[0].getFill() - steamCycles); tanks[0].setFill(tanks[0].getFill() - steamCycles);
tanks[1].setFill(tanks[1].getFill() + steamCycles); tanks[1].setFill(tanks[1].getFill() + steamCycles);
if(worldObj.rand.nextInt(200) == 0) { if(worldObj.rand.nextInt(200) == 0) {
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 2, zCoord + 0.5, "hbm:block.boilerGroan", 2.5F, 1.0F); worldObj.playSoundEffect(xCoord + 0.5, yCoord + 2, zCoord + 0.5, "hbm:block.boilerGroan", 2.5F, 1.0F);
} }
@ -103,7 +110,7 @@ public class TileEntityFusionBoiler extends TileEntityLoadedBase implements IFlu
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
buf.writeLong(plasmaEnergySync); buf.writeLong(plasmaEnergySync);
this.tanks[0].serialize(buf); this.tanks[0].serialize(buf);
this.tanks[1].serialize(buf); this.tanks[1].serialize(buf);
} }
@ -112,7 +119,7 @@ public class TileEntityFusionBoiler extends TileEntityLoadedBase implements IFlu
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
this.plasmaEnergy = buf.readLong(); this.plasmaEnergy = buf.readLong();
this.tanks[0].deserialize(buf); this.tanks[0].deserialize(buf);
this.tanks[1].deserialize(buf); this.tanks[1].deserialize(buf);
} }
@ -170,4 +177,57 @@ public class TileEntityFusionBoiler extends TileEntityLoadedBase implements IFlu
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
return 65536.0D; return 65536.0D;
} }
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "ntm_fusion_boiler";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getPlasmaEnergy(Context context, Arguments args) {
return new Object[] {plasmaEnergySync};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getFluid(Context context, Arguments args) {
return new Object[] {
tanks[0].getFill(), tanks[0].getMaxFill(),
tanks[1].getFill(), tanks[1].getMaxFill()
};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
return new Object[] {
plasmaEnergySync,
tanks[0].getFill(), tanks[0].getMaxFill(),
tanks[1].getFill(), tanks[1].getMaxFill(),
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public String[] methods() {
return new String[] {
"getPlasmaEnergy",
"getFluid",
"getInfo"
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
switch (method) {
case "getPlasmaEnergy": return getPlasmaEnergy(context, args);
case "getFluid": return getFluid(context, args);
case "getInfo": return getInfo(context, args);
}
throw new NoSuchMethodException();
}
} }

View File

@ -1,5 +1,6 @@
package com.hbm.tileentity.machine.fusion; package com.hbm.tileentity.machine.fusion;
import com.hbm.handler.CompatHandler;
import com.hbm.inventory.FluidStack; import com.hbm.inventory.FluidStack;
import com.hbm.inventory.container.ContainerFusionBreeder; import com.hbm.inventory.container.ContainerFusionBreeder;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
@ -18,9 +19,14 @@ import com.hbm.util.fauxpointtwelve.BlockPos;
import com.hbm.util.fauxpointtwelve.DirPos; import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.fluidmk2.IFluidStandardTransceiverMK2; import api.hbm.fluidmk2.IFluidStandardTransceiverMK2;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.SimpleComponent;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -29,10 +35,11 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityFusionBreeder extends TileEntityMachineBase implements IFluidStandardTransceiverMK2, IFusionPowerReceiver, IGUIProvider { @Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityFusionBreeder extends TileEntityMachineBase implements IFluidStandardTransceiverMK2, IFusionPowerReceiver, IGUIProvider, SimpleComponent, CompatHandler.OCComponent {
protected GenNode plasmaNode; protected GenNode plasmaNode;
public FluidTank[] tanks; public FluidTank[] tanks;
public double neutronEnergy; public double neutronEnergy;
@ -42,7 +49,7 @@ public class TileEntityFusionBreeder extends TileEntityMachineBase implements IF
public TileEntityFusionBreeder() { public TileEntityFusionBreeder() {
super(3); super(3);
tanks = new FluidTank[2]; tanks = new FluidTank[2];
tanks[0] = new FluidTank(Fluids.NONE, 16_000); tanks[0] = new FluidTank(Fluids.NONE, 16_000);
tanks[1] = new FluidTank(Fluids.NONE, 16_000); tanks[1] = new FluidTank(Fluids.NONE, 16_000);
@ -52,44 +59,44 @@ public class TileEntityFusionBreeder extends TileEntityMachineBase implements IF
public String getName() { public String getName() {
return "container.fusionBreeder"; return "container.fusionBreeder";
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
tanks[0].setType(0, slots); tanks[0].setType(0, slots);
if(!canProcessSolid() && !canProcessLiquid()) { if(!canProcessSolid() && !canProcessLiquid()) {
this.progress = 0; this.progress = 0;
} }
// because tile updates may happen in any order and the value that needs // because tile updates may happen in any order and the value that needs
// to be synced needs to persist until the next tick due to the batched packets // to be synced needs to persist until the next tick due to the batched packets
this.neutronEnergySync = this.neutronEnergy; this.neutronEnergySync = this.neutronEnergy;
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
if(tanks[0].getTankType() != Fluids.NONE) this.trySubscribe(tanks[0].getTankType(), worldObj, pos); if(tanks[0].getTankType() != Fluids.NONE) this.trySubscribe(tanks[0].getTankType(), worldObj, pos);
if(tanks[1].getFill() > 0) this.tryProvide(tanks[1], worldObj, pos); if(tanks[1].getFill() > 0) this.tryProvide(tanks[1], worldObj, pos);
} }
if(plasmaNode == null || plasmaNode.expired) { if(plasmaNode == null || plasmaNode.expired) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getOpposite();
plasmaNode = UniNodespace.getNode(worldObj, xCoord + dir.offsetX * 2, yCoord + 2, zCoord + dir.offsetZ * 2, PlasmaNetworkProvider.THE_PROVIDER); plasmaNode = UniNodespace.getNode(worldObj, xCoord + dir.offsetX * 2, yCoord + 2, zCoord + dir.offsetZ * 2, PlasmaNetworkProvider.THE_PROVIDER);
if(plasmaNode == null) { if(plasmaNode == null) {
plasmaNode = new GenNode(PlasmaNetworkProvider.THE_PROVIDER, plasmaNode = new GenNode(PlasmaNetworkProvider.THE_PROVIDER,
new BlockPos(xCoord + dir.offsetX * 2, yCoord + 2, zCoord + dir.offsetZ * 2)) new BlockPos(xCoord + dir.offsetX * 2, yCoord + 2, zCoord + dir.offsetZ * 2))
.setConnections(new DirPos(xCoord + dir.offsetX * 3, yCoord + 2, zCoord + dir.offsetZ * 3, dir)); .setConnections(new DirPos(xCoord + dir.offsetX * 3, yCoord + 2, zCoord + dir.offsetZ * 3, dir));
UniNodespace.createNode(worldObj, plasmaNode); UniNodespace.createNode(worldObj, plasmaNode);
} }
} }
if(plasmaNode != null && plasmaNode.hasValidNet()) plasmaNode.net.addReceiver(this); if(plasmaNode != null && plasmaNode.hasValidNet()) plasmaNode.net.addReceiver(this);
this.networkPackNT(25); this.networkPackNT(25);
this.neutronEnergy = 0; this.neutronEnergy = 0;
} }
} }
@ -115,17 +122,17 @@ public class TileEntityFusionBreeder extends TileEntityMachineBase implements IF
} }
public boolean canProcessLiquid() { public boolean canProcessLiquid() {
Pair<Integer, FluidStack> output = FluidBreederRecipes.getOutput(tanks[0].getTankType()); Pair<Integer, FluidStack> output = FluidBreederRecipes.getOutput(tanks[0].getTankType());
if(output == null) return false; if(output == null) return false;
if(tanks[0].getFill() < output.getKey()) return false; if(tanks[0].getFill() < output.getKey()) return false;
FluidStack fluid = output.getValue(); FluidStack fluid = output.getValue();
if(tanks[1].getTankType() != fluid.type && tanks[1].getFill() > 0) return false; if(tanks[1].getTankType() != fluid.type && tanks[1].getFill() > 0) return false;
tanks[1].setTankType(fluid.type); tanks[1].setTankType(fluid.type);
if(tanks[1].getFill() + fluid.fill > tanks[1].getMaxFill()) return false; if(tanks[1].getFill() + fluid.fill > tanks[1].getMaxFill()) return false;
return true; return true;
} }
@ -156,7 +163,7 @@ public class TileEntityFusionBreeder extends TileEntityMachineBase implements IF
tanks[0].setFill(tanks[0].getFill() - output.getKey()); tanks[0].setFill(tanks[0].getFill() - output.getKey());
tanks[1].setFill(tanks[1].getFill() + output.getValue().fill); tanks[1].setFill(tanks[1].getFill() + output.getValue().fill);
} }
public void doProgress() { public void doProgress() {
if(canProcessSolid()) { if(canProcessSolid()) {
@ -187,11 +194,11 @@ public class TileEntityFusionBreeder extends TileEntityMachineBase implements IF
@Override public boolean canExtractItem(int slot, ItemStack itemStack, int side) { return slot == 2; } @Override public boolean canExtractItem(int slot, ItemStack itemStack, int side) { return slot == 2; }
@Override public int[] getAccessibleSlotsFromSide(int side) { return new int[] {1, 2}; } @Override public int[] getAccessibleSlotsFromSide(int side) { return new int[] {1, 2}; }
public DirPos[] getConPos() { public DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + dir.offsetX * 3, yCoord + 2, zCoord + dir.offsetZ * 3, dir), new DirPos(xCoord + dir.offsetX * 3, yCoord + 2, zCoord + dir.offsetZ * 3, dir),
new DirPos(xCoord + rot.offsetX * 2, yCoord, zCoord + rot.offsetZ * 2, rot), new DirPos(xCoord + rot.offsetX * 2, yCoord, zCoord + rot.offsetZ * 2, rot),
@ -215,7 +222,7 @@ public class TileEntityFusionBreeder extends TileEntityMachineBase implements IF
super.serialize(buf); super.serialize(buf);
buf.writeDouble(neutronEnergySync); buf.writeDouble(neutronEnergySync);
buf.writeDouble(progress); buf.writeDouble(progress);
this.tanks[0].serialize(buf); this.tanks[0].serialize(buf);
this.tanks[1].serialize(buf); this.tanks[1].serialize(buf);
} }
@ -225,7 +232,7 @@ public class TileEntityFusionBreeder extends TileEntityMachineBase implements IF
super.deserialize(buf); super.deserialize(buf);
this.neutronEnergy = buf.readDouble(); this.neutronEnergy = buf.readDouble();
this.progress = buf.readDouble(); this.progress = buf.readDouble();
this.tanks[0].deserialize(buf); this.tanks[0].deserialize(buf);
this.tanks[1].deserialize(buf); this.tanks[1].deserialize(buf);
} }
@ -289,4 +296,111 @@ public class TileEntityFusionBreeder extends TileEntityMachineBase implements IF
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
return 65536.0D; return 65536.0D;
} }
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "ntm_fusion_breeder";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getNeutronEnergy(Context context, Arguments args) {
return new Object[] {neutronEnergySync};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getProgress(Context context, Arguments args) {
return new Object[] {progress / capacity};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getFluid(Context context, Arguments args) {
return new Object[] {
tanks[0].getFill(), tanks[0].getMaxFill(), tanks[0].getTankType().getUnlocalizedName(),
tanks[1].getFill(), tanks[1].getMaxFill(), tanks[1].getTankType().getUnlocalizedName()
};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getCrafting(Context context, Arguments args) {
ItemStack input = slots[1];
String inputName = "";
int inputSize = 0;
if (input != null) {
inputName = input.getUnlocalizedName();
inputSize = input.stackSize;
}
ItemStack output = slots[2];
String outputName = "";
int outputSize = 0;
if (output != null) {
outputName = output.getUnlocalizedName();
outputSize = output.stackSize;
}
return new Object[] {
inputName, inputSize,
outputName, outputSize
};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
ItemStack input = slots[1];
String inputName = "";
int inputSize = 0;
if (input != null) {
inputName = input.getUnlocalizedName();
inputSize = input.stackSize;
}
ItemStack output = slots[2];
String outputName = "";
int outputSize = 0;
if (output != null) {
outputName = output.getUnlocalizedName();
outputSize = output.stackSize;
}
return new Object[] {
neutronEnergySync, progress / capacity,
tanks[0].getFill(), tanks[0].getMaxFill(), tanks[0].getTankType().getUnlocalizedName(),
tanks[1].getFill(), tanks[1].getMaxFill(), tanks[1].getTankType().getUnlocalizedName(),
inputName, inputSize,
outputName, outputSize
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public String[] methods() {
return new String[] {
"getNeutronEnergy",
"getProgress",
"getFluid",
"getCrafting",
"getInfo"
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
switch (method) {
case "getNeutronEnergy": return getNeutronEnergy(context, args);
case "getProgress": return getProgress(context, args);
case "getFluid": return getFluid(context, args);
case "getCrafting": return getCrafting(context, args);
case "getInfo": return getInfo(context, args);
}
throw new NoSuchMethodException();
}
} }

View File

@ -2,6 +2,7 @@ package com.hbm.tileentity.machine.fusion;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.hbm.handler.CompatHandler;
import com.hbm.interfaces.IControlReceiver; import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.container.ContainerFusionKlystron; import com.hbm.inventory.container.ContainerFusionKlystron;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
@ -21,9 +22,14 @@ import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.energymk2.IEnergyReceiverMK2; import api.hbm.energymk2.IEnergyReceiverMK2;
import api.hbm.fluidmk2.IFluidStandardReceiverMK2; import api.hbm.fluidmk2.IFluidStandardReceiverMK2;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.SimpleComponent;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -33,7 +39,8 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityFusionKlystron extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardReceiverMK2, IControlReceiver, IGUIProvider { @Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityFusionKlystron extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardReceiverMK2, IControlReceiver, IGUIProvider, SimpleComponent, CompatHandler.OCComponent {
protected GenNode klystronNode; protected GenNode klystronNode;
public static final long MAX_OUTPUT = 1_000_000; public static final long MAX_OUTPUT = 1_000_000;
@ -42,19 +49,19 @@ public class TileEntityFusionKlystron extends TileEntityMachineBase implements I
public long output; public long output;
public long power; public long power;
public long maxPower; public long maxPower;
public float fan; public float fan;
public float prevFan; public float prevFan;
public float fanSpeed; public float fanSpeed;
public static final float FAN_ACCELERATION = 0.125F; public static final float FAN_ACCELERATION = 0.125F;
public FluidTank compair; public FluidTank compair;
private AudioWrapper audio; private AudioWrapper audio;
public TileEntityFusionKlystron() { public TileEntityFusionKlystron() {
super(1); super(1);
compair = new FluidTank(Fluids.AIR, AIR_CONSUMPTION * 60); compair = new FluidTank(Fluids.AIR, AIR_CONSUMPTION * 60);
} }
@ -62,62 +69,62 @@ public class TileEntityFusionKlystron extends TileEntityMachineBase implements I
public String getName() { public String getName() {
return "container.fusionKlystron"; return "container.fusionKlystron";
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.maxPower = Math.max(1_000_000L, this.outputTarget * 100L); this.maxPower = Math.max(1_000_000L, this.outputTarget * 100L);
this.power = Library.chargeTEFromItems(slots, 0, power, maxPower); this.power = Library.chargeTEFromItems(slots, 0, power, maxPower);
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos); this.trySubscribe(worldObj, pos);
this.trySubscribe(compair.getTankType(), worldObj, pos); this.trySubscribe(compair.getTankType(), worldObj, pos);
} }
this.output = 0; this.output = 0;
double powerFactor = TileEntityFusionTorus.getSpeedScaled(maxPower, power); double powerFactor = TileEntityFusionTorus.getSpeedScaled(maxPower, power);
double airFactor = TileEntityFusionTorus.getSpeedScaled(compair.getMaxFill(), compair.getFill()); double airFactor = TileEntityFusionTorus.getSpeedScaled(compair.getMaxFill(), compair.getFill());
double factor = Math.min(powerFactor, airFactor); double factor = Math.min(powerFactor, airFactor);
long powerReq = (long) Math.ceil(outputTarget * factor); long powerReq = (long) Math.ceil(outputTarget * factor);
int airReq = (int) Math.ceil(AIR_CONSUMPTION * factor); int airReq = (int) Math.ceil(AIR_CONSUMPTION * factor);
if(outputTarget > 0 && power >= powerReq && compair.getFill() >= airReq) { if(outputTarget > 0 && power >= powerReq && compair.getFill() >= airReq) {
this.output = powerReq; this.output = powerReq;
this.power -= powerReq; this.power -= powerReq;
this.compair.setFill(this.compair.getFill() - airReq); this.compair.setFill(this.compair.getFill() - airReq);
} }
if(output < outputTarget / 50) output = 0; if(output < outputTarget / 50) output = 0;
if(klystronNode == null || klystronNode.expired) { if(klystronNode == null || klystronNode.expired) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getOpposite();
klystronNode = UniNodespace.getNode(worldObj, xCoord + dir.offsetX * 4, yCoord + 2, zCoord + dir.offsetZ * 4, KlystronNetworkProvider.THE_PROVIDER); klystronNode = UniNodespace.getNode(worldObj, xCoord + dir.offsetX * 4, yCoord + 2, zCoord + dir.offsetZ * 4, KlystronNetworkProvider.THE_PROVIDER);
if(klystronNode == null) { if(klystronNode == null) {
klystronNode = new GenNode(KlystronNetworkProvider.THE_PROVIDER, klystronNode = new GenNode(KlystronNetworkProvider.THE_PROVIDER,
new BlockPos(xCoord + dir.offsetX * 4, yCoord + 2, zCoord + dir.offsetZ * 4)) new BlockPos(xCoord + dir.offsetX * 4, yCoord + 2, zCoord + dir.offsetZ * 4))
.setConnections(new DirPos(xCoord + dir.offsetX * 5, yCoord + 2, zCoord + dir.offsetZ * 5, dir)); .setConnections(new DirPos(xCoord + dir.offsetX * 5, yCoord + 2, zCoord + dir.offsetZ * 5, dir));
UniNodespace.createNode(worldObj, klystronNode); UniNodespace.createNode(worldObj, klystronNode);
} }
} }
if(klystronNode.net != null) klystronNode.net.addProvider(this); if(klystronNode.net != null) klystronNode.net.addProvider(this);
if(klystronNode != null && klystronNode.net != null) { if(klystronNode != null && klystronNode.net != null) {
KlystronNetwork net = (KlystronNetwork) klystronNode.net; KlystronNetwork net = (KlystronNetwork) klystronNode.net;
for(Object o : net.receiverEntries.entrySet()) { for(Object o : net.receiverEntries.entrySet()) {
Entry e = (Entry) o; Entry e = (Entry) o;
if(e.getKey() instanceof TileEntityFusionTorus) { // replace this with an interface should we ever get more acceptors if(e.getKey() instanceof TileEntityFusionTorus) { // replace this with an interface should we ever get more acceptors
TileEntityFusionTorus torus = (TileEntityFusionTorus) e.getKey(); TileEntityFusionTorus torus = (TileEntityFusionTorus) e.getKey();
if(torus.isLoaded() && !torus.isInvalid()) { // check against zombie network members if(torus.isLoaded() && !torus.isInvalid()) { // check against zombie network members
torus.klystronEnergy += this.output; torus.klystronEnergy += this.output;
break; // we only do one anyway break; // we only do one anyway
@ -125,29 +132,29 @@ public class TileEntityFusionKlystron extends TileEntityMachineBase implements I
} }
} }
} }
this.networkPackNT(100); this.networkPackNT(100);
} else { } else {
double mult = TileEntityFusionTorus.getSpeedScaled(outputTarget, output); double mult = TileEntityFusionTorus.getSpeedScaled(outputTarget, output);
if(this.output > 0) this.fanSpeed += FAN_ACCELERATION * mult; if(this.output > 0) this.fanSpeed += FAN_ACCELERATION * mult;
else this.fanSpeed -= FAN_ACCELERATION; else this.fanSpeed -= FAN_ACCELERATION;
this.fanSpeed = MathHelper.clamp_float(this.fanSpeed, 0F, 5F * (float) mult); this.fanSpeed = MathHelper.clamp_float(this.fanSpeed, 0F, 5F * (float) mult);
this.prevFan = this.fan; this.prevFan = this.fan;
this.fan += this.fanSpeed; this.fan += this.fanSpeed;
if(this.fan >= 360F) { if(this.fan >= 360F) {
this.fan -= 360F; this.fan -= 360F;
this.prevFan -= 360F; this.prevFan -= 360F;
} }
if(this.fanSpeed > 0 && MainRegistry.proxy.me().getDistanceSq(xCoord + 0.5, yCoord + 2.5, zCoord + 0.5) < 30 * 30) { if(this.fanSpeed > 0 && MainRegistry.proxy.me().getDistanceSq(xCoord + 0.5, yCoord + 2.5, zCoord + 0.5) < 30 * 30) {
float speed = this.fanSpeed / 5F; float speed = this.fanSpeed / 5F;
if(audio == null) { if(audio == null) {
audio = MainRegistry.proxy.getLoopedSound("hbm:block.fel", xCoord + 0.5F, yCoord + 2.5F, zCoord + 0.5F, getVolume(speed), 15F, speed, 20); audio = MainRegistry.proxy.getLoopedSound("hbm:block.fel", xCoord + 0.5F, yCoord + 2.5F, zCoord + 0.5F, getVolume(speed), 15F, speed, 20);
audio.startSound(); audio.startSound();
@ -156,9 +163,9 @@ public class TileEntityFusionKlystron extends TileEntityMachineBase implements I
audio.updatePitch(speed); audio.updatePitch(speed);
audio.keepAlive(); audio.keepAlive();
} }
} else { } else {
if(audio != null) { if(audio != null) {
if(audio.isPlaying()) audio.stopSound(); if(audio.isPlaying()) audio.stopSound();
audio = null; audio = null;
@ -166,11 +173,11 @@ public class TileEntityFusionKlystron extends TileEntityMachineBase implements I
} }
} }
} }
public DirPos[] getConPos() { public DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + dir.offsetX * 4, yCoord + 2, zCoord + dir.offsetZ * 4, dir), new DirPos(xCoord + dir.offsetX * 4, yCoord + 2, zCoord + dir.offsetZ * 4, dir),
new DirPos(xCoord + rot.offsetX * 3, yCoord, zCoord + rot.offsetZ * 3, rot), new DirPos(xCoord + rot.offsetX * 3, yCoord, zCoord + rot.offsetZ * 3, rot),
@ -221,7 +228,7 @@ public class TileEntityFusionKlystron extends TileEntityMachineBase implements I
this.output = buf.readLong(); this.output = buf.readLong();
this.compair.deserialize(buf); this.compair.deserialize(buf);
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@ -229,18 +236,18 @@ public class TileEntityFusionKlystron extends TileEntityMachineBase implements I
this.power = nbt.getLong("power"); this.power = nbt.getLong("power");
this.maxPower = nbt.getLong("maxPower"); this.maxPower = nbt.getLong("maxPower");
this.outputTarget = nbt.getLong("outputTarget"); this.outputTarget = nbt.getLong("outputTarget");
this.compair.readFromNBT(nbt, "t"); this.compair.readFromNBT(nbt, "t");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setLong("power", power); nbt.setLong("power", power);
nbt.setLong("maxPower", maxPower); nbt.setLong("maxPower", maxPower);
nbt.setLong("outputTarget", outputTarget); nbt.setLong("outputTarget", outputTarget);
this.compair.writeToNBT(nbt, "t"); this.compair.writeToNBT(nbt, "t");
} }
@ -299,11 +306,77 @@ public class TileEntityFusionKlystron extends TileEntityMachineBase implements I
@Override @Override
public void receiveControl(NBTTagCompound data) { public void receiveControl(NBTTagCompound data) {
if(data.hasKey("amount")) { if(data.hasKey("amount")) {
this.outputTarget = data.getLong("amount"); this.outputTarget = data.getLong("amount");
if(this.outputTarget < 0) this.outputTarget = 0; if(this.outputTarget < 0) this.outputTarget = 0;
if(this.outputTarget > MAX_OUTPUT) this.outputTarget = MAX_OUTPUT; if(this.outputTarget > MAX_OUTPUT) this.outputTarget = MAX_OUTPUT;
} }
} }
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "ntm_fusion_klystron";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getEnergyInfo(Context context, Arguments args) {
return new Object[] {getPower(), getMaxPower()};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getAir(Context context, Arguments args) {
return new Object[] {compair.getFill(), compair.getMaxFill()};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getOutput(Context context, Arguments args) {
return new Object[] {output, outputTarget};
}
@Callback(direct = true, limit = 4)
@Optional.Method(modid = "OpenComputers")
public Object[] setOutput(Context context, Arguments args) {
outputTarget = (long) MathHelper.clamp_double(args.checkDouble(0), 0.0, MAX_OUTPUT);
return new Object[] {};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
return new Object[] {
getPower(), getMaxPower(),
compair.getFill(), compair.getMaxFill(),
output, outputTarget
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public String[] methods() {
return new String[] {
"getEnergyInfo",
"getAir",
"getOutput",
"setOutput",
"getInfo"
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
switch (method) {
case "getEnergyInfo": return getEnergyInfo(context, args);
case "getAir": return getAir(context, args);
case "getOutput": return getOutput(context, args);
case "setOutput": return setOutput(context, args);
case "getInfo": return getInfo(context, args);
}
throw new NoSuchMethodException();
}
} }

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.stream.JsonWriter; import com.google.gson.stream.JsonWriter;
import com.hbm.handler.CompatHandler;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
import com.hbm.main.MainRegistry; import com.hbm.main.MainRegistry;
@ -18,105 +19,111 @@ import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.energymk2.IEnergyProviderMK2; import api.hbm.energymk2.IEnergyProviderMK2;
import api.hbm.fluidmk2.IFluidStandardTransceiverMK2; import api.hbm.fluidmk2.IFluidStandardTransceiverMK2;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.SimpleComponent;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityFusionMHDT extends TileEntityLoadedBase implements IEnergyProviderMK2, IFluidStandardTransceiverMK2, IFusionPowerReceiver, IConfigurableMachine { @Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityFusionMHDT extends TileEntityLoadedBase implements IEnergyProviderMK2, IFluidStandardTransceiverMK2, IFusionPowerReceiver, IConfigurableMachine, SimpleComponent, CompatHandler.OCComponent {
protected GenNode plasmaNode; protected GenNode plasmaNode;
public long plasmaEnergy; public long plasmaEnergy;
public long plasmaEnergySync; public long plasmaEnergySync;
public long power; public long power;
public float rotor; public float rotor;
public float prevRotor; public float prevRotor;
public float rotorSpeed; public float rotorSpeed;
public static final float ROTOR_ACCELERATION = 0.125F; public static final float ROTOR_ACCELERATION = 0.125F;
public static final double PLASMA_EFFICIENCY = 1.35D; public static final double PLASMA_EFFICIENCY = 1.35D;
public static final int COOLANT_USE = 50; public static final int COOLANT_USE = 50;
public static long MINIMUM_PLASMA = 5_000_000L; public static long MINIMUM_PLASMA = 5_000_000L;
public FluidTank[] tanks; public FluidTank[] tanks;
private AudioWrapper audio; private AudioWrapper audio;
@Override public String getConfigName() { return "mhd-turbine"; } @Override public String getConfigName() { return "mhd-turbine"; }
@Override public void readIfPresent(JsonObject obj) { MINIMUM_PLASMA = IConfigurableMachine.grab(obj, "L:minimumPlasma", MINIMUM_PLASMA); } @Override public void readIfPresent(JsonObject obj) { MINIMUM_PLASMA = IConfigurableMachine.grab(obj, "L:minimumPlasma", MINIMUM_PLASMA); }
@Override public void writeConfig(JsonWriter writer) throws IOException { writer.name("L:minimumPlasma").value(MINIMUM_PLASMA); } @Override public void writeConfig(JsonWriter writer) throws IOException { writer.name("L:minimumPlasma").value(MINIMUM_PLASMA); }
public TileEntityFusionMHDT() { public TileEntityFusionMHDT() {
this.tanks = new FluidTank[2]; this.tanks = new FluidTank[2];
this.tanks[0] = new FluidTank(Fluids.PERFLUOROMETHYL_COLD, 4_000); this.tanks[0] = new FluidTank(Fluids.PERFLUOROMETHYL_COLD, 4_000);
this.tanks[1] = new FluidTank(Fluids.PERFLUOROMETHYL, 4_000); this.tanks[1] = new FluidTank(Fluids.PERFLUOROMETHYL, 4_000);
} }
public boolean hasMinimumPlasma() { public boolean hasMinimumPlasma() {
return this.plasmaEnergy >= MINIMUM_PLASMA; return this.plasmaEnergy >= MINIMUM_PLASMA;
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.plasmaEnergySync = this.plasmaEnergy; this.plasmaEnergySync = this.plasmaEnergy;
if(isCool()) { if(isCool()) {
this.power = (long) Math.floor(this.plasmaEnergy * PLASMA_EFFICIENCY); this.power = (long) Math.floor(this.plasmaEnergy * PLASMA_EFFICIENCY);
if(!this.hasMinimumPlasma()) this.power /= 2; if(!this.hasMinimumPlasma()) this.power /= 2;
tanks[0].setFill(tanks[0].getFill() - COOLANT_USE); tanks[0].setFill(tanks[0].getFill() - COOLANT_USE);
tanks[1].setFill(tanks[1].getFill() + COOLANT_USE); tanks[1].setFill(tanks[1].getFill() + COOLANT_USE);
} }
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.tryProvide(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.tryProvide(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
if(tanks[0].getTankType() != Fluids.NONE) this.trySubscribe(tanks[0].getTankType(), worldObj, pos); if(tanks[0].getTankType() != Fluids.NONE) this.trySubscribe(tanks[0].getTankType(), worldObj, pos);
if(tanks[1].getFill() > 0) this.tryProvide(tanks[1], worldObj, pos); if(tanks[1].getFill() > 0) this.tryProvide(tanks[1], worldObj, pos);
} }
if(plasmaNode == null || plasmaNode.expired) { if(plasmaNode == null || plasmaNode.expired) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getOpposite();
plasmaNode = UniNodespace.getNode(worldObj, xCoord + dir.offsetX * 6, yCoord + 2, zCoord + dir.offsetZ * 6, PlasmaNetworkProvider.THE_PROVIDER); plasmaNode = UniNodespace.getNode(worldObj, xCoord + dir.offsetX * 6, yCoord + 2, zCoord + dir.offsetZ * 6, PlasmaNetworkProvider.THE_PROVIDER);
if(plasmaNode == null) { if(plasmaNode == null) {
plasmaNode = new GenNode(PlasmaNetworkProvider.THE_PROVIDER, plasmaNode = new GenNode(PlasmaNetworkProvider.THE_PROVIDER,
new BlockPos(xCoord + dir.offsetX * 6, yCoord + 2, zCoord + dir.offsetZ * 6)) new BlockPos(xCoord + dir.offsetX * 6, yCoord + 2, zCoord + dir.offsetZ * 6))
.setConnections(new DirPos(xCoord + dir.offsetX * 7, yCoord + 2, zCoord + dir.offsetZ * 7, dir)); .setConnections(new DirPos(xCoord + dir.offsetX * 7, yCoord + 2, zCoord + dir.offsetZ * 7, dir));
UniNodespace.createNode(worldObj, plasmaNode); UniNodespace.createNode(worldObj, plasmaNode);
} }
} }
if(plasmaNode != null && plasmaNode.hasValidNet()) plasmaNode.net.addReceiver(this); if(plasmaNode != null && plasmaNode.hasValidNet()) plasmaNode.net.addReceiver(this);
this.networkPackNT(150); this.networkPackNT(150);
this.plasmaEnergy = 0; this.plasmaEnergy = 0;
} else { } else {
if(this.plasmaEnergy > 0 && isCool()) this.rotorSpeed += ROTOR_ACCELERATION; if(this.plasmaEnergy > 0 && isCool()) this.rotorSpeed += ROTOR_ACCELERATION;
else this.rotorSpeed -= ROTOR_ACCELERATION; else this.rotorSpeed -= ROTOR_ACCELERATION;
this.rotorSpeed = MathHelper.clamp_float(this.rotorSpeed, 0F, hasMinimumPlasma() ? 15F : 10F); this.rotorSpeed = MathHelper.clamp_float(this.rotorSpeed, 0F, hasMinimumPlasma() ? 15F : 10F);
this.prevRotor = this.rotor; this.prevRotor = this.rotor;
this.rotor += this.rotorSpeed; this.rotor += this.rotorSpeed;
if(this.rotor >= 360F) { if(this.rotor >= 360F) {
this.rotor -= 360F; this.rotor -= 360F;
this.prevRotor -= 360F; this.prevRotor -= 360F;
} }
if(this.rotorSpeed > 0 && MainRegistry.proxy.me().getDistanceSq(xCoord + 0.5, yCoord + 2.5, zCoord + 0.5) < 30 * 30) { if(this.rotorSpeed > 0 && MainRegistry.proxy.me().getDistanceSq(xCoord + 0.5, yCoord + 2.5, zCoord + 0.5) < 30 * 30) {
float speed = this.rotorSpeed / 15F; float speed = this.rotorSpeed / 15F;
if(audio == null) { if(audio == null) {
audio = MainRegistry.proxy.getLoopedSound("hbm:block.largeTurbineRunning", xCoord + 0.5F, yCoord + 1.5F, zCoord + 0.5F, getVolume(speed), 20F, speed, 20); audio = MainRegistry.proxy.getLoopedSound("hbm:block.largeTurbineRunning", xCoord + 0.5F, yCoord + 1.5F, zCoord + 0.5F, getVolume(speed), 20F, speed, 20);
audio.startSound(); audio.startSound();
@ -125,9 +132,9 @@ public class TileEntityFusionMHDT extends TileEntityLoadedBase implements IEnerg
audio.updatePitch(speed); audio.updatePitch(speed);
audio.keepAlive(); audio.keepAlive();
} }
} else { } else {
if(audio != null) { if(audio != null) {
if(audio.isPlaying()) audio.stopSound(); if(audio.isPlaying()) audio.stopSound();
audio = null; audio = null;
@ -135,15 +142,15 @@ public class TileEntityFusionMHDT extends TileEntityLoadedBase implements IEnerg
} }
} }
} }
public boolean isCool() { public boolean isCool() {
return tanks[0].getFill() >= COOLANT_USE && tanks[1].getFill() + COOLANT_USE <= tanks[1].getMaxFill(); return tanks[0].getFill() >= COOLANT_USE && tanks[1].getFill() + COOLANT_USE <= tanks[1].getMaxFill();
} }
public DirPos[] getConPos() { public DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + dir.offsetX * 4 + rot.offsetX * 4, yCoord, zCoord + dir.offsetZ * 4 + rot.offsetZ * 4, rot), new DirPos(xCoord + dir.offsetX * 4 + rot.offsetX * 4, yCoord, zCoord + dir.offsetZ * 4 + rot.offsetZ * 4, rot),
new DirPos(xCoord + dir.offsetX * 4 - rot.offsetX * 4, yCoord, zCoord + dir.offsetZ * 4 - rot.offsetZ * 4, rot.getOpposite()), new DirPos(xCoord + dir.offsetX * 4 - rot.offsetX * 4, yCoord, zCoord + dir.offsetZ * 4 - rot.offsetZ * 4, rot.getOpposite()),
@ -158,7 +165,7 @@ public class TileEntityFusionMHDT extends TileEntityLoadedBase implements IEnerg
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
buf.writeLong(plasmaEnergySync); buf.writeLong(plasmaEnergySync);
this.tanks[0].serialize(buf); this.tanks[0].serialize(buf);
this.tanks[1].serialize(buf); this.tanks[1].serialize(buf);
} }
@ -167,7 +174,7 @@ public class TileEntityFusionMHDT extends TileEntityLoadedBase implements IEnerg
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
this.plasmaEnergy = buf.readLong(); this.plasmaEnergy = buf.readLong();
this.tanks[0].deserialize(buf); this.tanks[0].deserialize(buf);
this.tanks[1].deserialize(buf); this.tanks[1].deserialize(buf);
} }
@ -244,4 +251,65 @@ public class TileEntityFusionMHDT extends TileEntityLoadedBase implements IEnerg
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
return 65536.0D; return 65536.0D;
} }
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "ntm_fusion_mhdt";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getEnergyInfo(Context context, Arguments args) {
return new Object[] {power};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getPlasmaEnergy(Context context, Arguments args) {
return new Object[] {plasmaEnergySync};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getCoolant(Context context, Arguments args) {
return new Object[] {
tanks[0].getFill(), tanks[0].getMaxFill(),
tanks[1].getFill(), tanks[1].getMaxFill()
};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
return new Object[] {
power, plasmaEnergySync,
tanks[0].getFill(), tanks[0].getMaxFill(),
tanks[1].getFill(), tanks[1].getMaxFill(),
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public String[] methods() {
return new String[] {
"getEnergyInfo",
"getPlasmaEnergy",
"getCoolant",
"getInfo"
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
switch (method) {
case "getEnergyInfo": return getEnergyInfo(context, args);
case "getPlasmaEnergy": return getPlasmaEnergy(context, args);
case "getCoolant": return getCoolant(context, args);
case "getInfo": return getInfo(context, args);
}
throw new NoSuchMethodException();
}
} }

View File

@ -2,6 +2,7 @@ package com.hbm.tileentity.machine.fusion;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.hbm.handler.CompatHandler;
import com.hbm.interfaces.IControlReceiver; import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.container.ContainerFusionTorus; import com.hbm.inventory.container.ContainerFusionTorus;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
@ -25,9 +26,14 @@ import com.hbm.util.BobMathUtil;
import com.hbm.util.fauxpointtwelve.BlockPos; import com.hbm.util.fauxpointtwelve.BlockPos;
import com.hbm.util.fauxpointtwelve.DirPos; import com.hbm.util.fauxpointtwelve.DirPos;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.SimpleComponent;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -37,10 +43,11 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIProvider, IControlReceiver { @Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIProvider, IControlReceiver, SimpleComponent, CompatHandler.OCComponent {
public boolean didProcess = false; public boolean didProcess = false;
public FluidTank[] tanks; public FluidTank[] tanks;
public ModuleMachineFusion fusionModule; public ModuleMachineFusion fusionModule;
@ -51,7 +58,7 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
public long klystronEnergy; public long klystronEnergy;
public long plasmaEnergy; public long plasmaEnergy;
public double fuelConsumption; public double fuelConsumption;
public float magnet; public float magnet;
public float prevMagnet; public float prevMagnet;
public float magnetSpeed; public float magnetSpeed;
@ -59,21 +66,21 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
private AudioWrapper audio; private AudioWrapper audio;
public int timeOffset = -1; public int timeOffset = -1;
public TileEntityFusionTorus() { public TileEntityFusionTorus() {
super(3); super(3);
klystronNodes = new GenNode[4]; klystronNodes = new GenNode[4];
plasmaNodes = new GenNode[4]; plasmaNodes = new GenNode[4];
connections = new boolean[4]; connections = new boolean[4];
this.tanks = new FluidTank[4]; this.tanks = new FluidTank[4];
this.tanks[0] = new FluidTank(Fluids.NONE, 4_000); this.tanks[0] = new FluidTank(Fluids.NONE, 4_000);
this.tanks[1] = new FluidTank(Fluids.NONE, 4_000); this.tanks[1] = new FluidTank(Fluids.NONE, 4_000);
this.tanks[2] = new FluidTank(Fluids.NONE, 4_000); this.tanks[2] = new FluidTank(Fluids.NONE, 4_000);
this.tanks[3] = new FluidTank(Fluids.NONE, 4_000); this.tanks[3] = new FluidTank(Fluids.NONE, 4_000);
this.fusionModule = new ModuleMachineFusion(0, this, slots) this.fusionModule = new ModuleMachineFusion(0, this, slots)
.fluidInput(tanks[0], tanks[1], tanks[2]) .fluidInput(tanks[0], tanks[1], tanks[2])
.fluidOutput(tanks[3]) .fluidOutput(tanks[3])
@ -87,7 +94,7 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
for(int i = 0; i < 4; i++) { for(int i = 0; i < 4; i++) {
@ -97,10 +104,10 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
if(klystronNodes[i].net != null) klystronNodes[i].net.addReceiver(this); if(klystronNodes[i].net != null) klystronNodes[i].net.addReceiver(this);
if(plasmaNodes[i].net != null) plasmaNodes[i].net.addProvider(this); if(plasmaNodes[i].net != null) plasmaNodes[i].net.addProvider(this);
} }
this.temperature += this.temp_passive_heating; this.temperature += this.temp_passive_heating;
if(this.temperature > KELVIN + 20) this.temperature = KELVIN + 20; if(this.temperature > KELVIN + 20) this.temperature = KELVIN + 20;
if(this.temperature > this.temperature_target) { if(this.temperature > this.temperature_target) {
int cyclesTemp = (int) Math.ceil((Math.min(this.temperature - temperature_target, temp_change_max)) / temp_change_per_mb); int cyclesTemp = (int) Math.ceil((Math.min(this.temperature - temperature_target, temp_change_max)) / temp_change_per_mb);
int cyclesCool = coolantTanks[0].getFill(); int cyclesCool = coolantTanks[0].getFill();
@ -111,9 +118,9 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
coolantTanks[1].setFill(coolantTanks[1].getFill() + cycles); coolantTanks[1].setFill(coolantTanks[1].getFill() + cycles);
this.temperature -= this.temp_change_per_mb * cycles; this.temperature -= this.temp_change_per_mb * cycles;
} }
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
if(worldObj.getTotalWorldTime() % 20 == 0) { if(worldObj.getTotalWorldTime() % 20 == 0) {
this.trySubscribe(worldObj, pos); this.trySubscribe(worldObj, pos);
this.trySubscribe(coolantTanks[0].getTankType(), worldObj, pos); this.trySubscribe(coolantTanks[0].getTankType(), worldObj, pos);
@ -127,19 +134,19 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
} }
this.power = Library.chargeTEFromItems(slots, 0, power, this.getMaxPower()); this.power = Library.chargeTEFromItems(slots, 0, power, this.getMaxPower());
// keeping track of PLASMA receivers because those need to share the combined output // keeping track of PLASMA receivers because those need to share the combined output
int receiverCount = 0; int receiverCount = 0;
// collectors for determining the speed of the bonus bar // collectors for determining the speed of the bonus bar
int collectors = 0; int collectors = 0;
for(int i = 0; i < 4; i++) { for(int i = 0; i < 4; i++) {
connections[i] = false; connections[i] = false;
if(klystronNodes[i] != null && klystronNodes[i].hasValidNet() && !klystronNodes[i].net.providerEntries.isEmpty()) connections[i] = true; if(klystronNodes[i] != null && klystronNodes[i].hasValidNet() && !klystronNodes[i].net.providerEntries.isEmpty()) connections[i] = true;
if(!connections[i] && plasmaNodes[i] != null && plasmaNodes[i].hasValidNet() && !plasmaNodes[i].net.receiverEntries.isEmpty()) connections[i] = true; if(!connections[i] && plasmaNodes[i] != null && plasmaNodes[i].hasValidNet() && !plasmaNodes[i].net.receiverEntries.isEmpty()) connections[i] = true;
if(plasmaNodes[i] != null && plasmaNodes[i].hasValidNet() && !plasmaNodes[i].net.receiverEntries.isEmpty()) { if(plasmaNodes[i] != null && plasmaNodes[i].hasValidNet() && !plasmaNodes[i].net.receiverEntries.isEmpty()) {
for(Object o : plasmaNodes[i].net.receiverEntries.entrySet()) { for(Object o : plasmaNodes[i].net.receiverEntries.entrySet()) {
Entry<Object, Long> entry = (Entry<Object, Long>) o; Entry<Object, Long> entry = (Entry<Object, Long>) o;
Object thing = entry.getKey(); Object thing = entry.getKey();
@ -150,18 +157,18 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
} }
} }
} }
FusionRecipe recipe = (FusionRecipe) this.fusionModule.getRecipe(); FusionRecipe recipe = (FusionRecipe) this.fusionModule.getRecipe();
double powerFactor = TileEntityFusionTorus.getSpeedScaled(this.getMaxPower(), power); double powerFactor = TileEntityFusionTorus.getSpeedScaled(this.getMaxPower(), power);
double fuel0Factor = recipe != null && recipe.inputFluid.length > 0 ? getSpeedScaled(tanks[0].getMaxFill(), tanks[0].getFill()) : 1D; double fuel0Factor = recipe != null && recipe.inputFluid.length > 0 ? getSpeedScaled(tanks[0].getMaxFill(), tanks[0].getFill()) : 1D;
double fuel1Factor = recipe != null && recipe.inputFluid.length > 1 ? getSpeedScaled(tanks[1].getMaxFill(), tanks[1].getFill()) : 1D; double fuel1Factor = recipe != null && recipe.inputFluid.length > 1 ? getSpeedScaled(tanks[1].getMaxFill(), tanks[1].getFill()) : 1D;
double fuel2Factor = recipe != null && recipe.inputFluid.length > 2 ? getSpeedScaled(tanks[2].getMaxFill(), tanks[2].getFill()) : 1D; double fuel2Factor = recipe != null && recipe.inputFluid.length > 2 ? getSpeedScaled(tanks[2].getMaxFill(), tanks[2].getFill()) : 1D;
double factor = BobMathUtil.min(powerFactor, fuel0Factor, fuel1Factor, fuel2Factor); double factor = BobMathUtil.min(powerFactor, fuel0Factor, fuel1Factor, fuel2Factor);
boolean ignition = recipe != null ? recipe.ignitionTemp <= this.klystronEnergy : true; boolean ignition = recipe != null ? recipe.ignitionTemp <= this.klystronEnergy : true;
this.plasmaEnergy = 0; this.plasmaEnergy = 0;
this.fuelConsumption = 0; this.fuelConsumption = 0;
this.fusionModule.preUpdate(factor, collectors * 0.5D); this.fusionModule.preUpdate(factor, collectors * 0.5D);
@ -172,17 +179,17 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
this.plasmaEnergy = (long) Math.ceil(recipe.outputTemp * factor); this.plasmaEnergy = (long) Math.ceil(recipe.outputTemp * factor);
this.fuelConsumption = factor; this.fuelConsumption = factor;
} }
double outputIntensity = this.getOuputIntensity(receiverCount); double outputIntensity = this.getOuputIntensity(receiverCount);
double outputFlux = recipe != null ? recipe.neutronFlux * factor : 0D; double outputFlux = recipe != null ? recipe.neutronFlux * factor : 0D;
if(this.plasmaEnergy > 0) for(int i = 0; i < 4; i++) { if(this.plasmaEnergy > 0) for(int i = 0; i < 4; i++) {
if(plasmaNodes[i] != null && plasmaNodes[i].hasValidNet() && !plasmaNodes[i].net.receiverEntries.isEmpty()) { if(plasmaNodes[i] != null && plasmaNodes[i].hasValidNet() && !plasmaNodes[i].net.receiverEntries.isEmpty()) {
for(Object o : plasmaNodes[i].net.receiverEntries.entrySet()) { for(Object o : plasmaNodes[i].net.receiverEntries.entrySet()) {
Entry<Object, Long> entry = (Entry<Object, Long>) o; Entry<Object, Long> entry = (Entry<Object, Long>) o;
if(entry.getKey() instanceof IFusionPowerReceiver) { if(entry.getKey() instanceof IFusionPowerReceiver) {
long powerReceived = (long) Math.ceil(this.plasmaEnergy * outputIntensity); long powerReceived = (long) Math.ceil(this.plasmaEnergy * outputIntensity);
((IFusionPowerReceiver) entry.getKey()).receiveFusionPower(powerReceived, outputFlux); ((IFusionPowerReceiver) entry.getKey()).receiveFusionPower(powerReceived, outputFlux);
@ -190,33 +197,33 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
} }
} }
} }
this.networkPackNT(150); this.networkPackNT(150);
this.klystronEnergy = 0; this.klystronEnergy = 0;
} else { } else {
if(timeOffset == -1) this.timeOffset = worldObj.rand.nextInt(30_000); if(timeOffset == -1) this.timeOffset = worldObj.rand.nextInt(30_000);
double powerFactor = TileEntityFusionTorus.getSpeedScaled(this.getMaxPower(), power); double powerFactor = TileEntityFusionTorus.getSpeedScaled(this.getMaxPower(), power);
if(this.didProcess) this.magnetSpeed += MAGNET_ACCELERATION; if(this.didProcess) this.magnetSpeed += MAGNET_ACCELERATION;
else this.magnetSpeed -= MAGNET_ACCELERATION; else this.magnetSpeed -= MAGNET_ACCELERATION;
this.magnetSpeed = MathHelper.clamp_float(this.magnetSpeed, 0F, 30F * (float) powerFactor); this.magnetSpeed = MathHelper.clamp_float(this.magnetSpeed, 0F, 30F * (float) powerFactor);
this.prevMagnet = this.magnet; this.prevMagnet = this.magnet;
this.magnet += this.magnetSpeed; this.magnet += this.magnetSpeed;
if(this.magnet >= 360F) { if(this.magnet >= 360F) {
this.magnet -= 360F; this.magnet -= 360F;
this.prevMagnet -= 360F; this.prevMagnet -= 360F;
} }
if(this.magnetSpeed > 0 && MainRegistry.proxy.me().getDistanceSq(xCoord + 0.5, yCoord + 2.5, zCoord + 0.5) < 50 * 50) { if(this.magnetSpeed > 0 && MainRegistry.proxy.me().getDistanceSq(xCoord + 0.5, yCoord + 2.5, zCoord + 0.5) < 50 * 50) {
float speed = this.magnetSpeed / 30F; float speed = this.magnetSpeed / 30F;
if(audio == null) { if(audio == null) {
audio = MainRegistry.proxy.getLoopedSound("hbm:block.fusionReactorRunning", xCoord + 0.5F, yCoord + 2.5F, zCoord + 0.5F, getVolume(speed), 30F, speed, 20); audio = MainRegistry.proxy.getLoopedSound("hbm:block.fusionReactorRunning", xCoord + 0.5F, yCoord + 2.5F, zCoord + 0.5F, getVolume(speed), 30F, speed, 20);
audio.startSound(); audio.startSound();
@ -225,9 +232,9 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
audio.updatePitch(speed); audio.updatePitch(speed);
audio.keepAlive(); audio.keepAlive();
} }
} else { } else {
if(audio != null) { if(audio != null) {
if(audio.isPlaying()) audio.stopSound(); if(audio.isPlaying()) audio.stopSound();
audio = null; audio = null;
@ -235,24 +242,24 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
} }
} }
} }
public static double getOuputIntensity(int receiverCount) { public static double getOuputIntensity(int receiverCount) {
if(receiverCount == 1) return 1D; // 100% if(receiverCount == 1) return 1D; // 100%
if(receiverCount == 2) return 0.625D; // 125% if(receiverCount == 2) return 0.625D; // 125%
if(receiverCount == 3) return 0.5D; // 150% if(receiverCount == 3) return 0.5D; // 150%
return 0.4375D; // 175% return 0.4375D; // 175%
} }
public GenNode createNode(INetworkProvider provider, ForgeDirection dir) { public GenNode createNode(INetworkProvider provider, ForgeDirection dir) {
GenNode node = UniNodespace.getNode(worldObj, xCoord + dir.offsetX * 7, yCoord + 2, zCoord + dir.offsetZ * 7, provider); GenNode node = UniNodespace.getNode(worldObj, xCoord + dir.offsetX * 7, yCoord + 2, zCoord + dir.offsetZ * 7, provider);
if(node != null) return node; if(node != null) return node;
node = new GenNode(provider, node = new GenNode(provider,
new BlockPos(xCoord + dir.offsetX * 7, yCoord + 2, zCoord + dir.offsetZ * 7)) new BlockPos(xCoord + dir.offsetX * 7, yCoord + 2, zCoord + dir.offsetZ * 7))
.setConnections(new DirPos(xCoord + dir.offsetX * 8, yCoord + 2, zCoord + dir.offsetZ * 8, dir)); .setConnections(new DirPos(xCoord + dir.offsetX * 8, yCoord + 2, zCoord + dir.offsetZ * 8, dir));
UniNodespace.createNode(worldObj, node); UniNodespace.createNode(worldObj, node);
return node; return node;
} }
@ -288,7 +295,7 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
buf.writeLong(this.klystronEnergy); buf.writeLong(this.klystronEnergy);
buf.writeLong(this.plasmaEnergy); buf.writeLong(this.plasmaEnergy);
buf.writeDouble(this.fuelConsumption); buf.writeDouble(this.fuelConsumption);
this.fusionModule.serialize(buf); this.fusionModule.serialize(buf);
for(int i = 0; i < 4; i++) this.tanks[i].serialize(buf); for(int i = 0; i < 4; i++) this.tanks[i].serialize(buf);
for(int i = 0; i < 4; i++) buf.writeBoolean(connections[i]); for(int i = 0; i < 4; i++) buf.writeBoolean(connections[i]);
@ -301,26 +308,26 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
this.klystronEnergy = buf.readLong(); this.klystronEnergy = buf.readLong();
this.plasmaEnergy = buf.readLong(); this.plasmaEnergy = buf.readLong();
this.fuelConsumption = buf.readDouble(); this.fuelConsumption = buf.readDouble();
this.fusionModule.deserialize(buf); this.fusionModule.deserialize(buf);
for(int i = 0; i < 4; i++) this.tanks[i].deserialize(buf); for(int i = 0; i < 4; i++) this.tanks[i].deserialize(buf);
for(int i = 0; i < 4; i++) connections[i] = buf.readBoolean(); for(int i = 0; i < 4; i++) connections[i] = buf.readBoolean();
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
for(int i = 0; i < 4; i++) this.tanks[i].readFromNBT(nbt, "ft" + i); for(int i = 0; i < 4; i++) this.tanks[i].readFromNBT(nbt, "ft" + i);
this.power = nbt.getLong("power"); this.power = nbt.getLong("power");
this.fusionModule.readFromNBT(nbt); this.fusionModule.readFromNBT(nbt);
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
for(int i = 0; i < 4; i++) this.tanks[i].writeToNBT(nbt, "ft" + i); for(int i = 0; i < 4; i++) this.tanks[i].writeToNBT(nbt, "ft" + i);
nbt.setLong("power", power); nbt.setLong("power", power);
@ -335,7 +342,7 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
@Override public FluidTank[] getSendingTanks() { return new FluidTank[] {coolantTanks[1], tanks[3]}; } @Override public FluidTank[] getSendingTanks() { return new FluidTank[] {coolantTanks[1], tanks[3]}; }
@Override public FluidTank[] getReceivingTanks() { return new FluidTank[] {coolantTanks[0], tanks[0], tanks[1], tanks[2]}; } @Override public FluidTank[] getReceivingTanks() { return new FluidTank[] {coolantTanks[0], tanks[0], tanks[1], tanks[2]}; }
@Override public FluidTank[] getAllTanks() { return new FluidTank[] {coolantTanks[0], coolantTanks[1], tanks[0], tanks[1], tanks[2], tanks[3]}; } @Override public FluidTank[] getAllTanks() { return new FluidTank[] {coolantTanks[0], coolantTanks[1], tanks[0], tanks[1], tanks[2], tanks[3]}; }
/** Linearly scales up from 0% to 100% from 0 to 0.5, then stays at 100% */ /** Linearly scales up from 0% to 100% from 0 to 0.5, then stays at 100% */
public static double getSpeedScaled(double max, double level) { public static double getSpeedScaled(double max, double level) {
if(max == 0) return 0D; if(max == 0) return 0D;
@ -453,4 +460,110 @@ public class TileEntityFusionTorus extends TileEntityCooledBase implements IGUIP
} }
} }
} }
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "ntm_fusion_torus";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getEnergyInfo(Context context, Arguments args) {
return new Object[] {getPower(), getMaxPower()};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getFluid(Context context, Arguments args) {
return new Object[] {
tanks[0].getFill(), tanks[0].getMaxFill(), tanks[0].getTankType().getUnlocalizedName(),
tanks[1].getFill(), tanks[1].getMaxFill(), tanks[1].getTankType().getUnlocalizedName(),
tanks[2].getFill(), tanks[2].getMaxFill(), tanks[2].getTankType().getUnlocalizedName(),
tanks[3].getFill(), tanks[3].getMaxFill(), tanks[3].getTankType().getUnlocalizedName(),
};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getCoolant(Context context, Arguments args) {
return new Object[] {
coolantTanks[0].getFill(), coolantTanks[0].getMaxFill(),
coolantTanks[1].getFill(), coolantTanks[1].getMaxFill(),
};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getKlystronEnergy(Context context, Arguments args) {
return new Object[] {klystronEnergy};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getPlasmaEnergy(Context context, Arguments args) {
return new Object[] {plasmaEnergy};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getFuelConsumption(Context context, Arguments args) {
return new Object[] {fuelConsumption};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getRecipeProgress(Context context, Arguments args) {
return new Object[] {fusionModule.progress, fusionModule.bonus};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
return new Object[] {
getPower(), getMaxPower(),
tanks[0].getFill(), tanks[0].getMaxFill(), tanks[0].getTankType().getUnlocalizedName(),
tanks[1].getFill(), tanks[1].getMaxFill(), tanks[1].getTankType().getUnlocalizedName(),
tanks[2].getFill(), tanks[2].getMaxFill(), tanks[2].getTankType().getUnlocalizedName(),
tanks[3].getFill(), tanks[3].getMaxFill(), tanks[3].getTankType().getUnlocalizedName(),
coolantTanks[0].getFill(), coolantTanks[0].getMaxFill(),
coolantTanks[1].getFill(), coolantTanks[1].getMaxFill(),
klystronEnergy, plasmaEnergy, fuelConsumption,
fusionModule.progress, fusionModule.bonus
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public String[] methods() {
return new String[] {
"getEnergyInfo",
"getFluid",
"getCoolant",
"getKlystronEnergy",
"getPlasmaEnergy",
"getFuelConsumption",
"getRecipeProgress",
"getInfo"
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
switch (method) {
case "getEnergyInfo": return getEnergyInfo(context, args);
case "getFluid": return getFluid(context, args);
case "getCoolant": return getCoolant(context, args);
case "getKlystronEnergy": return getKlystronEnergy(context, args);
case "getPlasmaEnergy": return getPlasmaEnergy(context, args);
case "getFuelConsumption": return getFuelConsumption(context, args);
case "getRecipeProgress": return getRecipeProgress(context, args);
case "getInfo": return getInfo(context, args);
}
throw new NoSuchMethodException();
}
} }