Added Fusion Reactor

This commit is contained in:
Modmuss50 2015-11-16 21:10:39 +00:00
parent 473a981f51
commit a63128aa7e
6 changed files with 175 additions and 3 deletions

View file

@ -41,6 +41,15 @@ public class FusionReactorRecipe {
*/ */
int tickTime; int tickTime;
/**
*
* @param topInput This is the top slot stack
* @param bottomInput This is the bottom slot stack
* @param output This is the output stack
* @param startEU This is the inital EU amount
* @param euTick This is the eu that is transfured every tick
* @param tickTime This is the time the recipe takes to process
*/
public FusionReactorRecipe(ItemStack topInput, ItemStack bottomInput, ItemStack output, double startEU, double euTick, int tickTime) { public FusionReactorRecipe(ItemStack topInput, ItemStack bottomInput, ItemStack output, double startEU, double euTick, int tickTime) {
this.topInput = topInput; this.topInput = topInput;
this.bottomInput = bottomInput; this.bottomInput = bottomInput;

View file

@ -14,6 +14,9 @@ public class ContainerFusionReactor extends RebornContainer {
public int coilStatus; public int coilStatus;
public int energy; public int energy;
public int tickTime;
public int finalTickTime;
public int neededEU;
TileEntityFusionController fusionController; TileEntityFusionController fusionController;
@ -58,6 +61,15 @@ public class ContainerFusionReactor extends RebornContainer {
if (this.energy != (int) fusionController.getEnergy()) { if (this.energy != (int) fusionController.getEnergy()) {
icrafting.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy()); icrafting.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy());
} }
if (this.tickTime != fusionController.crafingTickTime) {
icrafting.sendProgressBarUpdate(this, 2, fusionController.crafingTickTime);
}
if (this.finalTickTime != fusionController.finalTickTime) {
icrafting.sendProgressBarUpdate(this, 3, fusionController.finalTickTime);
}
if (this.neededEU != fusionController.neededPower) {
icrafting.sendProgressBarUpdate(this, 4, fusionController.neededPower);
}
} }
} }
@ -66,6 +78,9 @@ public class ContainerFusionReactor extends RebornContainer {
super.addCraftingToCrafters(crafting); super.addCraftingToCrafters(crafting);
crafting.sendProgressBarUpdate(this, 0, fusionController.coilStatus); crafting.sendProgressBarUpdate(this, 0, fusionController.coilStatus);
crafting.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy()); crafting.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy());
crafting.sendProgressBarUpdate(this, 2, fusionController.crafingTickTime);
crafting.sendProgressBarUpdate(this, 3, fusionController.finalTickTime);
crafting.sendProgressBarUpdate(this, 4, fusionController.neededPower);
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@ -75,6 +90,16 @@ public class ContainerFusionReactor extends RebornContainer {
this.coilStatus = value; this.coilStatus = value;
} else if (id == 1) { } else if (id == 1) {
this.energy = value; this.energy = value;
} else if(id == 2){
this.tickTime = value;
} else if(id == 3){
this.finalTickTime = value;
} else if(id == 4){
this.neededEU = value;
} }
} }
public int getProgressScaled(){
return Math.max(0, Math.min(24, (this.tickTime > 0 ? 1 : 0) + this.tickTime * 24 / (this.finalTickTime < 1 ? 1 : this.finalTickTime)));
}
} }

View file

@ -28,6 +28,8 @@ public class GuiFusionReactor extends GuiContainer {
this.fontRendererObj.drawString("EU: " + containerFusionReactor.energy, 11, 8, 16448255); this.fontRendererObj.drawString("EU: " + containerFusionReactor.energy, 11, 8, 16448255);
this.fontRendererObj.drawString("Coils: " + (containerFusionReactor.coilStatus == 1 ? "Yes" : "No") , 11, 16, 16448255); this.fontRendererObj.drawString("Coils: " + (containerFusionReactor.coilStatus == 1 ? "Yes" : "No") , 11, 16, 16448255);
this.fontRendererObj.drawString("Start EU: " + containerFusionReactor.neededEU, 11, 24, 16448255);
} }
@Override @Override
@ -40,7 +42,7 @@ public class GuiFusionReactor extends GuiContainer {
drawTexturedModalRect(k + 88, l + 36, 176, 0, 14, 14); drawTexturedModalRect(k + 88, l + 36, 176, 0, 14, 14);
//progressBar //progressBar
drawTexturedModalRect(k + 111, l + 34, 176, 14, 24, 16); drawTexturedModalRect(k + 111, l + 34, 176, 14, containerFusionReactor.getProgressScaled(), 16);
} }
} }

View file

@ -23,6 +23,8 @@ import reborncore.common.util.CraftingHelper;
import reborncore.common.util.OreUtil; import reborncore.common.util.OreUtil;
import reborncore.common.util.RecipeRemover; import reborncore.common.util.RecipeRemover;
import techreborn.Core; import techreborn.Core;
import techreborn.api.reactor.FusionReactorRecipe;
import techreborn.api.reactor.FusionReactorRecipeHelper;
import techreborn.api.recipe.RecipeHandler; import techreborn.api.recipe.RecipeHandler;
import techreborn.api.recipe.machines.*; import techreborn.api.recipe.machines.*;
import techreborn.compat.ICompatModule; import techreborn.compat.ICompatModule;
@ -51,6 +53,8 @@ public class RecipesIC2 implements ICompatModule {
addTRThermalCentrifugeRecipes(); addTRThermalCentrifugeRecipes();
addMetalFormerRecipes(); addMetalFormerRecipes();
addTRRecipes(); addTRRecipes();
FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("wolframium"), ItemCells.getCellByName("lithium"), IC2Items.getItem("iridiumOre"), 90000000, -2048, 1024));
} }
@Override @Override

View file

@ -12,6 +12,8 @@ import reborncore.common.util.CraftingHelper;
import reborncore.common.util.OreUtil; import reborncore.common.util.OreUtil;
import techreborn.Core; import techreborn.Core;
import techreborn.api.TechRebornAPI; import techreborn.api.TechRebornAPI;
import techreborn.api.reactor.FusionReactorRecipe;
import techreborn.api.reactor.FusionReactorRecipeHelper;
import techreborn.api.recipe.RecipeHandler; import techreborn.api.recipe.RecipeHandler;
import techreborn.api.recipe.machines.*; import techreborn.api.recipe.machines.*;
import techreborn.blocks.BlockOre; import techreborn.blocks.BlockOre;
@ -45,6 +47,14 @@ public class
addBlastFurnaceRecipes(); addBlastFurnaceRecipes();
addIndustrialGrinderRecipes(); addIndustrialGrinderRecipes();
addImplosionCompressorRecipes(); addImplosionCompressorRecipes();
addReactorRecipes();
}
static void addReactorRecipes(){
FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("tritium"), ItemCells.getCellByName("deuterium"), ItemCells.getCellByName("helium"), 40000000, 32768, 1024));
FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("tritium"), ItemCells.getCellByName("deuterium"), ItemCells.getCellByName("helium3"), 60000000, 32768, 2048));
FusionReactorRecipeHelper.registerRecipe(new FusionReactorRecipe(ItemCells.getCellByName("wolframium"), ItemCells.getCellByName("Berylium"), ItemDusts.getDustByName("platinum"), 80000000, -2048, 1024));
} }
static void addGeneralShapedRecipes() { static void addGeneralShapedRecipes() {
@ -245,8 +255,6 @@ public class
'P', "plateCopper" 'P', "plateCopper"
); );
GameRegistry.addShapelessRecipe(ItemCells.getCellByName("heliumPlasma"), ItemCells.getCellByName("tritium"), ItemCells.getCellByName("deuterium"));
Core.logHelper.info("Shapped Recipes Added"); Core.logHelper.info("Shapped Recipes Added");
} }

View file

@ -6,6 +6,9 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import reborncore.common.util.Inventory; import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
import techreborn.api.reactor.FusionReactorRecipe;
import techreborn.api.reactor.FusionReactorRecipeHelper;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
import techreborn.powerSystem.TilePowerAcceptor; import techreborn.powerSystem.TilePowerAcceptor;
@ -17,6 +20,17 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
//0= no coils, 1 = coils //0= no coils, 1 = coils
public int coilStatus = 0; public int coilStatus = 0;
int topStackSlot = 0;
int bottomStackSlot = 1;
int outputStackSlot = 2;
public int crafingTickTime = 0;
public int finalTickTime = 0;
public int neededPower = 0;
FusionReactorRecipe currentRecipe = null;
boolean hasStartedCrafting = false;
public TileEntityFusionController() { public TileEntityFusionController() {
super(4); super(4);
} }
@ -164,5 +178,115 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
if(worldObj.getTotalWorldTime() % 20 == 0){ if(worldObj.getTotalWorldTime() % 20 == 0){
checkCoils(); checkCoils();
} }
if(!worldObj.isRemote){
if(coilStatus == 1){
if(currentRecipe == null){
if(inventory.hasChanged){
for(FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes){
System.out.println(getStackInSlot(topStackSlot) + "@" + reactorRecipe.getTopInput());
if(ItemUtils.isItemEqual(getStackInSlot(topStackSlot), reactorRecipe.getTopInput(), true, true, true)){
if(reactorRecipe.getBottomInput() != null){
if(ItemUtils.isItemEqual(getStackInSlot(bottomStackSlot), reactorRecipe.getBottomInput(), true, true, true) == false){
break;
}
}
if(canFitStack(reactorRecipe.getOutput(), outputStackSlot, true)){
currentRecipe = reactorRecipe;
hasStartedCrafting = false;
crafingTickTime = 0;
finalTickTime = currentRecipe.getTickTime();
neededPower = (int) currentRecipe.getStartEU();
break;
}
}
}
}
} else {
if(inventory.hasChanged){
if(!validateRecipe()){
resetCrafter();
}
}
if(!hasStartedCrafting){
if(canUseEnergy(currentRecipe.getStartEU())){
setEnergy(getEnergy() - currentRecipe.getStartEU());
hasStartedCrafting = true;
}
} else {
if(crafingTickTime < currentRecipe.getTickTime()){
if(currentRecipe.getEuTick() > 0){ //Power gen
addEnergy(currentRecipe.getEuTick()); //Waste power if it has no where to go
crafingTickTime++;
} else { //Power user
if(canUseEnergy(currentRecipe.getEuTick() * -1)){
setEnergy(getEnergy() - (currentRecipe.getEuTick() * -1));
crafingTickTime++;
}
}
} else {
if(canFitStack(currentRecipe.getOutput(), outputStackSlot, true)){
if(getStackInSlot(outputStackSlot) == null){
setInventorySlotContents(outputStackSlot, currentRecipe.getOutput().copy());
} else {
decrStackSize(outputStackSlot, -currentRecipe.getOutput().stackSize);
}
decrStackSize(topStackSlot, currentRecipe.getTopInput().stackSize);
if(currentRecipe.getBottomInput() != null){
decrStackSize(bottomStackSlot, currentRecipe.getBottomInput().stackSize);
}
resetCrafter();
}
}
}
}
} else {
if(currentRecipe != null){
resetCrafter();
}
}
}
if (inventory.hasChanged) {
inventory.hasChanged = false;
}
}
private boolean validateRecipe(){
if(ItemUtils.isItemEqual(getStackInSlot(topStackSlot), currentRecipe.getTopInput(), true, true, true)){
if(currentRecipe.getBottomInput() != null){
if(ItemUtils.isItemEqual(getStackInSlot(bottomStackSlot), currentRecipe.getBottomInput(), true, true, true) == false){
return false;
}
}
if(canFitStack(currentRecipe.getOutput(), outputStackSlot, true)){
return true;
}
}
return false;
}
private void resetCrafter(){
currentRecipe = null;
crafingTickTime = 0;
finalTickTime = 0;
neededPower = 0;
hasStartedCrafting = false;
}
public boolean canFitStack(ItemStack stack, int slot, boolean oreDic) {//Checks to see if it can fit the stack
if (stack == null) {
return true;
}
if (inventory.getStackInSlot(slot) == null) {
return true;
}
if (ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true, oreDic)) {
if (stack.stackSize + inventory.getStackInSlot(slot).stackSize <= stack.getMaxStackSize()) {
return true;
}
}
return false;
} }
} }