Skip to content

Commit

Permalink
Fusion display (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
ALongStringOfNumbers authored Jul 5, 2021
1 parent a2c4bcd commit b9eda2a
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

public class FusionRecipeBuilder extends RecipeBuilder<FusionRecipeBuilder> {

private int EUToStart;
private long EUToStart;

public FusionRecipeBuilder() {
}

public FusionRecipeBuilder(Recipe recipe, RecipeMap<FusionRecipeBuilder> recipeMap) {
super(recipe, recipeMap);
this.EUToStart = recipe.getRecipePropertyStorage().getRecipePropertyValue(FusionEUToStartProperty.getInstance(), 0);
this.EUToStart = recipe.getRecipePropertyStorage().getRecipePropertyValue(FusionEUToStartProperty.getInstance(), 0L);
}

public FusionRecipeBuilder(RecipeBuilder<FusionRecipeBuilder> recipeBuilder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package gregtech.api.recipes.recipeproperties;

import gregtech.api.util.TextFormattingUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
import org.apache.commons.lang3.Validate;

public class FusionEUToStartProperty extends RecipeProperty<Integer>{
import java.util.Map;
import java.util.TreeMap;

public class FusionEUToStartProperty extends RecipeProperty<Long>{

private static final String KEY = "eu_to_start";

private static final TreeMap<Long, String> registeredFusionTiers = new TreeMap<>();

private static FusionEUToStartProperty INSTANCE;

private FusionEUToStartProperty() {
super(KEY, Integer.class);
protected FusionEUToStartProperty() {
super(KEY, Long.class);
}

public static FusionEUToStartProperty getInstance() {
Expand All @@ -25,6 +31,24 @@ public static FusionEUToStartProperty getInstance() {
@Override
public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) {
minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.eu_to_start",
value), x, y, color);
TextFormattingUtil.formatLongToCompactString(castValue(value))) + getFusionTier(castValue(value)), x, y, color);
}

private String getFusionTier(Long eu) {

Map.Entry<Long, String> mapEntry = registeredFusionTiers.ceilingEntry(eu);

if(mapEntry == null) {
throw new IllegalArgumentException("Value is above registered maximum EU values");
}

return String.format(" %s", mapEntry.getValue());
}

public static void registerFusionTier(int tier, String shortName) {
Validate.notNull(shortName);
long maxEU = 16 * 10000000L * (long) Math.pow(2, tier - 6);
registeredFusionTiers.put(maxEU, shortName);

}
}
6 changes: 6 additions & 0 deletions src/main/java/gregtech/common/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gregtech.api.items.metaitem.MetaItem;
import gregtech.api.recipes.crafttweaker.MetaItemBracketHandler;
import gregtech.api.recipes.recipeproperties.BlastTemperatureProperty;
import gregtech.api.recipes.recipeproperties.FusionEUToStartProperty;
import gregtech.api.unification.material.type.DustMaterial;
import gregtech.api.unification.material.type.Material;
import gregtech.api.unification.ore.OrePrefix;
Expand Down Expand Up @@ -156,6 +157,11 @@ public static void registerRecipes(RegistryEvent.Register<IRecipe> event) {
"tile.wire_coil." + values.getName() + ".name");
}

//Registers Fusion tiers for the FusionEUToStartProperty
FusionEUToStartProperty.registerFusionTier(6, "(MK1)");
FusionEUToStartProperty.registerFusionTier(7, "(MK2)");
FusionEUToStartProperty.registerFusionTier(8, "(MK3)");

GTLog.logger.info("Registering ore dictionary...");

MetaItems.registerOreDict();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import gregtech.api.multiblock.PatternMatchContext;
import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.RecipeMaps;
import gregtech.api.recipes.recipeproperties.FusionEUToStartProperty;
import gregtech.api.render.ICubeRenderer;
import gregtech.api.render.Textures;
import gregtech.common.blocks.BlockFusionCoil;
Expand All @@ -38,7 +39,7 @@ public class MetaTileEntityFusionReactor extends RecipeMapMultiblockController {

private final int tier;
private EnergyContainerList inputEnergyContainers;
private int heat = 0; // defined in TileEntityFusionReactor but serialized in FusionRecipeLogic
private long heat = 0; // defined in TileEntityFusionReactor but serialized in FusionRecipeLogic

public MetaTileEntityFusionReactor(ResourceLocation metaTileEntityId, int tier) {
super(metaTileEntityId, RecipeMaps.FUSION_RECIPES);
Expand Down Expand Up @@ -215,12 +216,13 @@ public void updateWorkable() {
@Override
protected Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs, IMultipleTankHandler fluidInputs) {
Recipe recipe = super.findRecipe(maxVoltage, inputs, fluidInputs);
return (recipe != null && recipe.getIntegerProperty("eu_to_start") <= energyContainer.getEnergyCapacity()) ? recipe : null;
return (recipe != null && recipe.getRecipePropertyStorage().getRecipePropertyValue(FusionEUToStartProperty.getInstance(), 0L)
<= energyContainer.getEnergyCapacity()) ? recipe : null;
}

@Override
protected boolean setupAndConsumeRecipeInputs(Recipe recipe) {
int heatDiff = recipe.getIntegerProperty("eu_to_start") - heat;
long heatDiff = recipe.getRecipePropertyStorage().getRecipePropertyValue(FusionEUToStartProperty.getInstance(), 0L) - heat;
if (heatDiff <= 0) {
return super.setupAndConsumeRecipeInputs(recipe);
}
Expand All @@ -235,14 +237,14 @@ protected boolean setupAndConsumeRecipeInputs(Recipe recipe) {
@Override
public NBTTagCompound serializeNBT() {
NBTTagCompound tag = super.serializeNBT();
tag.setInteger("Heat", heat);
tag.setLong("Heat", heat);
return tag;
}

@Override
public void deserializeNBT(NBTTagCompound compound) {
super.deserializeNBT(compound);
heat = compound.getInteger("Heat");
heat = compound.getLong("Heat");
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -3720,7 +3720,7 @@ gregtech.recipe.not_consumed=§bDoes not get consumed in the process
gregtech.recipe.chance=Chance: %s%% +%s%%/tier
gregtech.recipe.blast_furnace_temperature=Temperature: %,dK (%s)
gregtech.recipe.explosive=Explosive: %s
gregtech.recipe.eu_to_start=Energy To Start: %,dEU
gregtech.recipe.eu_to_start=Energy To Start: %sEU

gregtech.fluid.click_to_fill=§7Click with a empty fluid container to fill it from tank.
gregtech.fluid.click_to_fill.shift=§7(Shift-clicking will fill all containers in your hand)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/gregtech/lang/ru_ru.lang
Original file line number Diff line number Diff line change
Expand Up @@ -2820,7 +2820,7 @@ gregtech.recipe.amperage=Сила тока: %d
gregtech.recipe.not_consumed=Не расходуется
gregtech.recipe.chance=Шанс: %s%% +%s%%/уровень
gregtech.recipe.blast_furnace_temperature=Температура: %dK (%s)
gregtech.recipe.eu_to_start=Энергия для запуска: %dEU
gregtech.recipe.eu_to_start=Энергия для запуска: %sEU

gregtech.fluid.click_to_fill=§7Нажмите с пустым контейнером для жидкости, чтобы заполнить его из бака.
gregtech.fluid.click_to_fill.shift=§7(Shift-нажатие заполнит все контейнеры в вашей руке)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/gregtech/lang/zh_cn.lang
Original file line number Diff line number Diff line change
Expand Up @@ -2799,7 +2799,7 @@ gregtech.recipe.amperage=电流: %d
gregtech.recipe.not_consumed=不在加工时消耗
gregtech.recipe.chance=出产概率: %s%% +%s%%/tier
gregtech.recipe.blast_furnace_temperature=温度: %d K (%s)
gregtech.recipe.eu_to_start=启动耗电: %d EU
gregtech.recipe.eu_to_start=启动耗电: %sEU

gregtech.fluid.click_to_fill=§7手持空的流体容器点击储罐以取走流体.
gregtech.fluid.click_to_fill.shift=§7(Shift+单击将装满所有手持容器)
Expand Down

0 comments on commit b9eda2a

Please sign in to comment.