Browse Source

more config options, optimizations

master
Adrian Siekierka 1 year ago
parent
commit
b8438caf6c

+ 1
- 1
build.gradle View File

@@ -13,7 +13,7 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'net.minecrell.licenser'
version = "0.1.0"
version = "0.1.1"
group = "pl.asie.tinkeredhegemony"
archivesBaseName = "TinkeredHegemony"

+ 17
- 0
src/main/java/pl/asie/tinkeredhegemony/DisabledItemClass.java View File

@@ -27,6 +27,8 @@ import slimeknights.tconstruct.library.tools.IToolPart;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;

public class DisabledItemClass {
@@ -35,6 +37,7 @@ public class DisabledItemClass {
private final Item tconItem;
private final Class<? extends Item> tconItemClass;
private final Collection<IToolPart> partsMaterialMatch;
private final Set<Item> itemSet;

public DisabledItemClass(String name, Predicate<Item> itemPredicate, Item tconItem, Class<? extends Item> tconItemClass, IToolPart... partsMaterialMatch) {
this.name = name;
@@ -42,6 +45,20 @@ public class DisabledItemClass {
this.tconItem = tconItem;
this.tconItemClass = tconItemClass;
this.partsMaterialMatch = ImmutableSet.copyOf(partsMaterialMatch);
this.itemSet = new HashSet<>();
}

public Set<Item> getItemSet() {
return itemSet;
}

protected void updateItemSet(Set<Item> set) {
itemSet.clear();
for (Item i : set) {
if (getItemPredicate().test(i)) {
itemSet.add(i);
}
}
}

public Collection<IToolPart> getPartsMaterialMatch() {

+ 4
- 1
src/main/java/pl/asie/tinkeredhegemony/IngredientTinkerTool.java View File

@@ -72,9 +72,12 @@ public class IngredientTinkerTool extends Ingredient {
Material m = materials.get(i);
PartMaterialType c = components.get(i);
for (IToolPart part : c.getPossibleParts()) {
partsSeen.add(part);
if (rp.remove(Pair.of(m, part))) {
partsFound.add(part);
} else {
// we only use the sets for the .removeIf below,
// and partsFound.contains() is sufficient
partsSeen.add(part);
}
}
}

+ 6
- 3
src/main/java/pl/asie/tinkeredhegemony/MaterialMatcher.java View File

@@ -19,6 +19,7 @@

package pl.asie.tinkeredhegemony;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
@@ -103,17 +104,19 @@ public class MaterialMatcher {
.toArray(ItemStack[]::new);

// let's try to heuristically determine!
List<Material> mats = new ArrayList<>();
ImmutableList.Builder<Material> mats = new ImmutableList.Builder<>();
boolean empty = true;

for (Material m : TinkerMaterials.materials) {
Optional<RecipeMatch.Match> match = m.matches(ingredients);
if (match.isPresent()) {
mats.add(m);
empty = false;
}
}

if (!mats.isEmpty()) {
return mats;
if (!empty) {
return mats.build();
}

TinkeredHegemony.logger.warn("Could not find material for item " + i.getRegistryName() + "!");

+ 5
- 7
src/main/java/pl/asie/tinkeredhegemony/RecipeTAPatchwork.java View File

@@ -90,13 +90,11 @@ public class RecipeTAPatchwork extends IForgeRegistryEntry.Impl<IRecipe> impleme
Item replItem = null;

if (validMaterials.size() > 0) {
for (Item replacementItem : TinkeredHegemony.itemSet) {
if (c.getItemPredicate().test(replacementItem)) {
Collection<Material> ms = MaterialMatcher.get(replacementItem);
if (ms != null && ms.containsAll(validMaterials)) {
replItem = replacementItem;
break;
}
for (Item replacementItem : c.getItemSet()) {
Collection<Material> ms = MaterialMatcher.get(replacementItem);
if (ms != null && ms.containsAll(validMaterials)) {
replItem = replacementItem;
break;
}
}
}

+ 35
- 16
src/main/java/pl/asie/tinkeredhegemony/TinkeredHegemony.java View File

@@ -58,7 +58,7 @@ public class TinkeredHegemony {
protected static final Set<DisabledItemClass> classMap = new HashSet<>();
protected static final Set<Item> itemSet = new HashSet<>();

private boolean performRecipeReplacement;
private boolean performRecipeReplacement, performRecipePatchwork, performItemDisabling, performItemNeutralizing;

private void addIfConfigured(DisabledItemClass disabledItemClass, boolean def) {
if (config.getBoolean("disable", disabledItemClass.getName(), def, "")) {
@@ -71,12 +71,23 @@ public class TinkeredHegemony {
logger = event.getModLog();
config = new Configuration(event.getSuggestedConfigurationFile());

performItemDisabling = config.getBoolean("performItemDisabling", "general", true, "Should vanilla item recipes be removed?");
performItemNeutralizing = config.getBoolean("performItemNeutralizing", "general", true, "Should vanilla tool items be effectively nullified (maximum damage set to 1)?");
performRecipePatchwork = config.getBoolean("performRecipePatchwork", "general", true, "Should Tinkers' Construct items be capable of replacing vanilla equivalents in recipes?");
performRecipeReplacement = config.getBoolean("performRecipeReplacement", "general", true, "Should ingredients be replaced in compatible recipes? This will primarily affect recipe guides.");

if (config.hasChanged()) {
config.save();
}

MinecraftForge.EVENT_BUS.register(this);
}

@SubscribeEvent(priority = EventPriority.LOWEST)
public void onRegisterRecipe(RegistryEvent.Register<IRecipe> event) {
event.getRegistry().register(new RecipeTAPatchwork().setRegistryName("tinkeredhegemony:replacement"));
if (performRecipePatchwork) {
event.getRegistry().register(new RecipeTAPatchwork().setRegistryName("tinkeredhegemony:replacement"));
}
}

@Mod.EventHandler
@@ -90,8 +101,6 @@ public class TinkeredHegemony {

MaterialMatcher.init(config);

performRecipeReplacement = config.getBoolean("performRecipeReplacement", "general", true, "Should ingredients be replaced in compatible IRecipes? This will primarily affect recipe guides.");

if (config.hasChanged()) {
config.save();
}
@@ -106,8 +115,10 @@ public class TinkeredHegemony {
if (optc.isPresent()) {
if (config.getBoolean(i.getRegistryName().toString(), "disabledItems", true, "")) {
DisabledItemClass c = optc.get();
originalDurabilities.put(i, i.getMaxDamage(new ItemStack(i)));
i.setMaxDamage(1);
if (performItemNeutralizing) {
originalDurabilities.put(i, i.getMaxDamage(new ItemStack(i)));
i.setMaxDamage(1);
}
itemSet.add(i);
}
}
@@ -115,19 +126,27 @@ public class TinkeredHegemony {

Set<Item> itemsNotified = Sets.newHashSet(itemSet);

Iterator<IRecipe> iterator = CraftingManager.REGISTRY.iterator();
while (iterator.hasNext()) {
IRecipe recipe = iterator.next();
ItemStack output = recipe.getRecipeOutput();
if (!output.isEmpty() && itemSet.contains(output.getItem())) {
ForgeRegistries.RECIPES.register(new RecipeDummy(recipe.getGroup()).setRegistryName(recipe.getRegistryName()));
logger.info("Disabled " + Item.REGISTRY.getNameForObject(output.getItem()).toString() + " (removed recipe)");
itemsNotified.remove(output.getItem());
if (performItemDisabling) {
Iterator<IRecipe> iterator = CraftingManager.REGISTRY.iterator();
while (iterator.hasNext()) {
IRecipe recipe = iterator.next();
ItemStack output = recipe.getRecipeOutput();
if (!output.isEmpty() && itemSet.contains(output.getItem())) {
ForgeRegistries.RECIPES.register(new RecipeDummy(recipe.getGroup()).setRegistryName(recipe.getRegistryName()));
logger.info("Disabled " + Item.REGISTRY.getNameForObject(output.getItem()).toString() + " (removed recipe)");
itemsNotified.remove(output.getItem());
}
}
}

for (Item i : itemsNotified) {
logger.info("Disabled " + Item.REGISTRY.getNameForObject(i).toString());
if (performItemNeutralizing || performItemDisabling) {
for (Item i : itemsNotified) {
logger.info("Disabled " + Item.REGISTRY.getNameForObject(i).toString());
}
}
c
for (DisabledItemClass c : classMap) {
c.updateItemSet(itemSet);
}

if (performRecipeReplacement) {

Loading…
Cancel
Save