Skip to content

Commit

Permalink
Improve tier handling & recipe generation (#19)
Browse files Browse the repository at this point in the history
* initial work

* optimize

* last improvements

* don't go throw each recipe if gtnh is loaded

* spotlessApply

* add separated configs & adjust upgrade generation

* dark steel is also explosion safe

* add missing upgrades

* another two missing upgrades

* use explosion indicator & remove netherite ugprades expect obsidian

* use resistance number

* make upgrades configurable

* prevent crystal/obsidian to darksteel upgrade beeing added if darksteel is disbaled
  • Loading branch information
Pilzinsel64 authored Mar 12, 2024
1 parent b1e9640 commit 394d2e7
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 125 deletions.
15 changes: 6 additions & 9 deletions src/main/java/cpw/mods/ironchest/BlockIronChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
******************************************************************************/
package cpw.mods.ironchest;

import static cpw.mods.ironchest.IronChest.ENABLE_STEEL_CHESTS;
import static net.minecraftforge.common.util.ForgeDirection.DOWN;
import static net.minecraftforge.common.util.ForgeDirection.UP;

Expand Down Expand Up @@ -220,26 +219,24 @@ public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List
}
switch (type) {
case STEEL -> {
if (ENABLE_STEEL_CHESTS) {
if (IronChestType.STEEL.isEnabled()) {
par3List.add(new ItemStack(this, 1, type.ordinal()));
}
}
case SILVER -> {
if (ENABLE_STEEL_CHESTS) {
continue;
if (IronChestType.SILVER.isEnabled()) {
par3List.add(new ItemStack(this, 1, type.ordinal()));
}
par3List.add(new ItemStack(this, 1, type.ordinal()));
}
case DARKSTEEL -> {
if (IronChest.ENABLE_DARK_STEEL_CHESTS) {
if (IronChestType.DARKSTEEL.isEnabled()) {
par3List.add(new ItemStack(this, 1, type.ordinal()));
}
}
case NETHERITE -> {
if (IronChest.ENABLE_DARK_STEEL_CHESTS) {
continue;
if (IronChestType.NETHERITE.isEnabled()) {
par3List.add(new ItemStack(this, 1, type.ordinal()));
}
par3List.add(new ItemStack(this, 1, type.ordinal()));
}
default -> par3List.add(new ItemStack(this, 1, type.ordinal()));
}
Expand Down
56 changes: 33 additions & 23 deletions src/main/java/cpw/mods/ironchest/ChestChangerType.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
******************************************************************************/
package cpw.mods.ironchest;

import static cpw.mods.ironchest.IronChest.ENABLE_STEEL_CHESTS;
import static cpw.mods.ironchest.IronChestType.*;

import net.minecraft.init.Blocks;
Expand All @@ -33,7 +32,13 @@ public enum ChestChangerType {
OBSIDIANNETHERITE(OBSIDIAN, NETHERITE, "obsidianNetheriteUpgrade", "Obsidian to Netherite Chest Upgrade", "OOO",
"msm", "OOO"),
DIAMONDDARKSTEEL(DIAMOND, DARKSTEEL, "diamondDarkSteelUpgrade", "Diamond to Dark Steel Chest Upgrade", "OOO", "msm",
"OOO");
"OOO"),
CRYSTALDARKSTEEL(CRYSTAL, DARKSTEEL, "crystalDarkSteelUpgrade", "Crystal to Dark Steel Chest Upgrade", "OOO", "msm",
"OOO"),
OBSIDIANDARKSTEEL(OBSIDIAN, DARKSTEEL, "obsidianDarkSteelUpgrade", "Obsidian to Dark Steel Chest Upgrade", "OOO",
"msm", "OOO"),
IRONSTEEL(IRON, STEEL, "ironSteelUpgrade", "Iron to Steel Chest Upgrade", "mGm", "GsG", "mGm"),
IRONSILVER(IRON, SILVER, "ironSilverUpgrade", "Iron to Silver Chest Upgrade", "mGm", "GsG", "mGm");

private final IronChestType source;
private final IronChestType target;
Expand All @@ -59,6 +64,10 @@ public int getTarget() {
return this.target.ordinal();
}

public boolean isAllowed() {
return target.allowUpgradeFrom(source);
}

public ItemChestChanger buildItem(Configuration cfg) {
item = new ItemChestChanger(this);
GameRegistry.registerItem(item, itemName);
Expand All @@ -81,32 +90,31 @@ public void addRecipes() {

public static void buildItems(Configuration cfg) {
for (ChestChangerType type : values()) {
switch (type) {
case STEELGOLD, COPPERSTEEL -> {
if (ENABLE_STEEL_CHESTS) {
type.buildItem(cfg);
if (type.isAllowed()) {
switch (type) {
case STEELGOLD, COPPERSTEEL -> {
if (IronChestType.STEEL.isEnabled()) {
type.buildItem(cfg);
}
}
}
case SILVERGOLD, COPPERSILVER -> {
if (ENABLE_STEEL_CHESTS) {
continue;
case SILVERGOLD, COPPERSILVER -> {
if (IronChestType.SILVER.isEnabled()) {
type.buildItem(cfg);
}
}
type.buildItem(cfg);
}
case DIAMONDDARKSTEEL -> {
if (IronChest.ENABLE_DARK_STEEL_CHESTS) {
type.buildItem(cfg);
case DIAMONDDARKSTEEL, CRYSTALDARKSTEEL, OBSIDIANDARKSTEEL -> {
if (IronChestType.DARKSTEEL.isEnabled()) {
type.buildItem(cfg);
}
}
}
case OBSIDIANNETHERITE -> {
if (IronChest.ENABLE_DARK_STEEL_CHESTS) {
continue;
case OBSIDIANNETHERITE -> {
if (IronChestType.NETHERITE.isEnabled()) {
type.buildItem(cfg);
}
}
type.buildItem(cfg);
default -> type.buildItem(cfg);
}
default -> type.buildItem(cfg);
}

}
}

Expand All @@ -115,7 +123,9 @@ public static void generateRecipes() {
return;
}
for (ChestChangerType item : values()) {
item.addRecipes();
if (item.isAllowed()) {
item.addRecipes();
}
}
}
}
49 changes: 25 additions & 24 deletions src/main/java/cpw/mods/ironchest/IronChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public class IronChest {
public static boolean TRANSPARENT_RENDER_INSIDE = true;
public static double TRANSPARENT_RENDER_DISTANCE = 128D;
public static boolean ENABLE_STEEL_CHESTS = true;
public static boolean ENABLE_SILVER_CHESTS = false;
public static boolean ENABLE_DARK_STEEL_CHESTS = false;
public static boolean ENABLE_NETHERITE_CHESTS = true;
public static String[] blocklistUpgrades = new String[] {};
public static boolean isGTNHLoaded;

@EventHandler
Expand All @@ -60,16 +63,28 @@ public void preInit(FMLPreInitializationEvent event) {
.getBoolean(true);
TRANSPARENT_RENDER_DISTANCE = cfg.get(Configuration.CATEGORY_GENERAL, "transparentRenderDistance", 128D)
.getDouble(128D);
ENABLE_STEEL_CHESTS = cfg.get(
Configuration.CATEGORY_GENERAL,
"enableSteelChests",
true,
"Enables the steel chest instead of the silver chest.").getBoolean(true);
ENABLE_STEEL_CHESTS = cfg
.get(Configuration.CATEGORY_GENERAL, "enableSteelChests", true, "Enables the steel chest.")
.getBoolean(true);
ENABLE_SILVER_CHESTS = cfg
.get(Configuration.CATEGORY_GENERAL, "enableSilverChests", false, "Enables the silver chest.")
.getBoolean(false);
ENABLE_DARK_STEEL_CHESTS = cfg.get(
Configuration.CATEGORY_GENERAL,
"enableDarkSteelChests",
isGTNHLoaded,
"Enables the dark steel chest instead the netherit chest.").getBoolean(isGTNHLoaded);
"Enables the dark steel.").getBoolean(isGTNHLoaded);
ENABLE_NETHERITE_CHESTS = cfg.get(
Configuration.CATEGORY_GENERAL,
"enableNetheriteChests",
!isGTNHLoaded,
"Enables the netherite chest.").getBoolean(!isGTNHLoaded);
blocklistUpgrades = cfg.getStringList(
"blocklistUpgrades",
Configuration.CATEGORY_GENERAL,
new String[] {},
"Disallowed upgrades. All upgrades listed here will not be registred and no recipes will be generated for it."
+ "\nExample: IRON:GOLD");
ChestChangerType.buildItems(cfg);
} catch (Exception e) {
FMLLog.log(Level.ERROR, e, "IronChest has a problem loading its configuration");
Expand All @@ -84,21 +99,7 @@ public void preInit(FMLPreInitializationEvent event) {
@EventHandler
public void load(FMLInitializationEvent evt) {
for (IronChestType typ : IronChestType.values()) {
if (typ.name().equals("STEEL") && ENABLE_STEEL_CHESTS) {
GameRegistry.registerTileEntityWithAlternatives(
typ.clazz,
"IronChest." + typ.name(),
typ.name(),
"SILVER",
"IronChest.SILVER");
} else if (typ.name().equals("SILVER")) {
if (ENABLE_STEEL_CHESTS) {
continue;
}
GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest." + typ.name(), typ.name());
} else {
GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest." + typ.name(), typ.name());
}
GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest." + typ.name(), typ.name());
proxy.registerTileEntitySpecialRenderer(typ);
}
OreDictionary.registerOre("chestWood", Blocks.chest);
Expand All @@ -120,7 +121,7 @@ public void modsLoaded(FMLPostInitializationEvent evt) {}
@Mod.EventHandler
public void missingMapping(FMLMissingMappingsEvent event) {
for (FMLMissingMappingsEvent.MissingMapping mapping : event.getAll()) {
if (ENABLE_STEEL_CHESTS) {
if (IronChestType.STEEL.isEnabled()) {
if (mapping.type == GameRegistry.Type.BLOCK) {
switch (mapping.name) {
case "IronChest:copperSilverUpgrade":
Expand All @@ -143,15 +144,15 @@ public void missingMapping(FMLMissingMappingsEvent event) {
}
}
}
if (ENABLE_DARK_STEEL_CHESTS) {
if (IronChestType.DARKSTEEL.isEnabled()) {
if (mapping.name.equals("IronChest:obsidianNetheriteUpgrade")) {
if (mapping.type == GameRegistry.Type.BLOCK) {
mapping.remap(GameRegistry.findBlock("IronChest", "diamondDarkSteelUpgrade"));
} else {
mapping.remap(GameRegistry.findItem("IronChest", "diamondDarkSteelUpgrade"));
}
}
} else {
} else if (IronChestType.NETHERITE.isEnabled()) {
if (mapping.name.equals("IronChest:diamondDarkSteelUpgrade")) {
if (mapping.type == GameRegistry.Type.BLOCK) {
mapping.remap(GameRegistry.findBlock("IronChest", "obsidianNetheriteUpgrade"));
Expand Down
Loading

0 comments on commit 394d2e7

Please sign in to comment.