Fixed enchant system
Now you can allow any enchants to be set to exact GT tool in Others config
This commit is contained in:
parent
784a2ac9a4
commit
ab3d6f87dc
3 changed files with 46 additions and 20 deletions
|
@ -10,7 +10,6 @@ import gregtechmod.api.enums.Materials;
|
|||
import gregtechmod.api.enums.OrePrefixes;
|
||||
import gregtechmod.api.interfaces.IGT_Mod;
|
||||
import gregtechmod.api.interfaces.IMetaTileEntity;
|
||||
import gregtechmod.api.items.GT_Tool_Item;
|
||||
import gregtechmod.api.metatileentity.BaseMetaPipeEntity;
|
||||
import gregtechmod.api.metatileentity.BaseMetaTileEntity;
|
||||
import gregtechmod.api.metatileentity.MetaPipeEntity;
|
||||
|
@ -99,7 +98,6 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
@ -271,6 +269,8 @@ public class GT_Mod implements IGT_Mod {
|
|||
GregTech_API.sSpecialFile = new GT_Config(new Configuration(new File(gtDir, "Other.cfg")));
|
||||
GregTech_API.sIDFile = new GT_Config(GT_Config.sConfigFileIDs = new Configuration(new File(gtDir, "IDs.cfg")));
|
||||
|
||||
GregTech_API.sSpecialFile.mConfig.getCategory("enchants").setComment("There you can set allowed enchant IDs to specific GT tools\nIt will let you apply choosen enchant in anvil to GT tool");
|
||||
|
||||
mDoNotInit = (!tFile.getAbsolutePath().toLowerCase().contains("voltz")) && (tFile.getAbsolutePath().toLowerCase().contains(".technic") || tFile.getAbsolutePath().toLowerCase().contains("tekkit"));
|
||||
if (mDoNotInit) {
|
||||
GT_Log.log.warn("Detected Technic Launcher.");
|
||||
|
@ -294,10 +294,6 @@ public class GT_Mod implements IGT_Mod {
|
|||
return;
|
||||
}
|
||||
|
||||
GT_Tool_Item.allowedEnchantIDs.addAll( // TODO make per different tool type
|
||||
Arrays.stream(tConfig1.get("general", "allowedEnchantmnetsIDs", new int[0], "List of enchantment IDs allowed to use any GT tools in anvil (No enchantment table :P)").getIntList())
|
||||
.boxed().collect(Collectors.toList()));
|
||||
|
||||
GT_Log.mOreDictLogFile = new File(aEvent.getModConfigurationDirectory().getParentFile(), "logs/GT_OreDict.log");
|
||||
if(!GT_Log.mOreDictLogFile.exists()) {
|
||||
try {
|
||||
|
|
|
@ -6,6 +6,7 @@ import gregtechmod.api.util.GT_OreDictUnificator;
|
|||
import gregtechmod.api.util.GT_Utility;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -29,6 +30,7 @@ import net.minecraft.world.World;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
@ -37,8 +39,8 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
* This is just a basic Tool, which has normal durability and could break Blocks.
|
||||
*/
|
||||
public class GT_Tool_Item extends GT_Generic_Item {
|
||||
|
||||
public static final List<Integer> allowedEnchantIDs = new ArrayList<>();
|
||||
|
||||
private static final Multimap<String, Integer> toolEnchants = MultimapBuilder.hashKeys().hashSetValues().build();
|
||||
|
||||
public final List<String> mEffectiveAgainstList = new ArrayList<String>();
|
||||
public final List<Block> mEffectiveBlocksList = new ArrayList<Block>();
|
||||
|
@ -77,6 +79,17 @@ public class GT_Tool_Item extends GT_Generic_Item {
|
|||
GT_ModHandler.registerBoxableItemToToolBox(this);
|
||||
}
|
||||
|
||||
// Registry for enhantability config
|
||||
public final static void registerTool(GT_Tool_Item item) {
|
||||
if (item.delegate == null || GT_Utility.isStringInvalid(item.delegate.name()))
|
||||
throw new IllegalArgumentException("Wrong item was supplied! May be it still not registered in GameRegistry");
|
||||
String regName = item.delegate.name();
|
||||
int[] enchantIDs = GregTech_API.sSpecialFile.mConfig.get("enchants", regName, new int[0]).getIntList();
|
||||
for (int i : enchantIDs) {
|
||||
toolEnchants.put(regName, Integer.valueOf(i));
|
||||
}
|
||||
}
|
||||
|
||||
public final GT_Tool_Item addToEffectiveList(String aEntityClassName) {
|
||||
mEffectiveAgainstList.add(aEntityClassName.substring(aEntityClassName.lastIndexOf(".")+1));
|
||||
return this;
|
||||
|
@ -201,12 +214,15 @@ public class GT_Tool_Item extends GT_Generic_Item {
|
|||
|
||||
public void checkEnchantmentEffects(ItemStack aStack) {
|
||||
if (aStack != null) {
|
||||
Collection<Integer> allowedEnchantIDs = toolEnchants.get(delegate.name());
|
||||
|
||||
if (aStack.isItemEnchanted()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Integer, Integer> enchs = EnchantmentHelper.getEnchantments(aStack);
|
||||
enchs = Maps.filterEntries(enchs, e -> allowedEnchantIDs.contains(e.getKey()));
|
||||
enchs = Maps.filterEntries(enchs, e -> allowedEnchantIDs != null && allowedEnchantIDs.contains(e.getKey()));
|
||||
EnchantmentHelper.setEnchantments(enchs, aStack);
|
||||
}
|
||||
|
||||
if (!GT_ModHandler.isElectricItem(aStack) || GT_ModHandler.canUseElectricItem(aStack, mEUperBrokenBlock < 0 ? getDamagePerBlockBreak() * 1000 : mEUperBrokenBlock)) {
|
||||
if (mSilklevel > 0) aStack.addEnchantment(Enchantment.silkTouch , mSilklevel);
|
||||
if (mFortunelevel > 0) aStack.addEnchantment(Enchantment.fortune , mFortunelevel);
|
||||
|
@ -217,10 +233,14 @@ public class GT_Tool_Item extends GT_Generic_Item {
|
|||
|
||||
/**
|
||||
* Will called through hook in ContainerRepair
|
||||
* TODO: add configurable mappings, remove class check
|
||||
*/
|
||||
public boolean checkEnchant(Enchantment ench, ItemStack stack) {
|
||||
return allowedEnchantIDs.contains(ench.effectId) && stack.getItem() instanceof GT_Saw_Item;
|
||||
Collection<Integer> IDs;
|
||||
if (this == stack.getItem() && (IDs = toolEnchants.get(delegate.name())) != null) {
|
||||
return IDs.contains(ench.effectId);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -272,13 +292,12 @@ public class GT_Tool_Item extends GT_Generic_Item {
|
|||
|
||||
@Override
|
||||
public boolean isBookEnchantable(ItemStack aStack, ItemStack aBook) {
|
||||
if (aBook.hasEffect(0)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Integer, Integer> enchs = EnchantmentHelper.getEnchantments(aBook);
|
||||
Entry<Integer, Integer> enchant = enchs.entrySet().parallelStream().findAny().get();
|
||||
if (enchant != null) {
|
||||
return allowedEnchantIDs.contains(enchant.getKey());
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Integer, Integer> enchs = EnchantmentHelper.getEnchantments(aBook);
|
||||
Entry<Integer, Integer> enchant = enchs.entrySet().parallelStream().findAny().get();
|
||||
Collection<Integer> IDs;
|
||||
if (enchant != null && (IDs = toolEnchants.get(delegate.name())) != null) {
|
||||
return IDs.contains(enchant.getKey());
|
||||
}
|
||||
|
||||
|
||||
|
@ -316,7 +335,7 @@ public class GT_Tool_Item extends GT_Generic_Item {
|
|||
// checkEnchantmentEffects(aStack); // Seriosly? pinging every render tick poor item?
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<Integer> enchsIds = EnchantmentHelper.getEnchantments(aStack).keySet();
|
||||
enchsIds.retainAll(allowedEnchantIDs);
|
||||
enchsIds.retainAll(toolEnchants.get(delegate.name()));
|
||||
return enchsIds.size() > 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import gregtechmod.api.items.GT_Spray_Hardener_Item;
|
|||
import gregtechmod.api.items.GT_Spray_Hydration_Item;
|
||||
import gregtechmod.api.items.GT_Spray_Ice_Item;
|
||||
import gregtechmod.api.items.GT_Spray_Pepper_Item;
|
||||
import gregtechmod.api.items.GT_Tool_Item;
|
||||
import gregtechmod.api.util.GT_FoodStat;
|
||||
import gregtechmod.api.util.GT_Log;
|
||||
import gregtechmod.api.util.GT_ModHandler;
|
||||
|
@ -52,6 +53,7 @@ import gregtechmod.common.items.GT_Vanilla_Sword;
|
|||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.Potion;
|
||||
|
||||
|
@ -513,7 +515,7 @@ public class GT_ItemLoader implements Runnable {
|
|||
GameRegistry.registerItem(GregTech_API.sItemList[118], "tungstensteel_saw");
|
||||
GameRegistry.registerItem(GregTech_API.sItemList[119], "electric_saw");
|
||||
GameRegistry.registerItem(GregTech_API.sItemList[120], "advanced_saw");
|
||||
GameRegistry.registerItem(GregTech_API.sItemList[121], "empty_electric_Saw");
|
||||
GameRegistry.registerItem(GregTech_API.sItemList[121], "empty_electric_saw");
|
||||
GameRegistry.registerItem(GregTech_API.sItemList[122], "empty_advanced_saw");
|
||||
GameRegistry.registerItem(GregTech_API.sItemList[123], "advanced_drill");
|
||||
GameRegistry.registerItem(GregTech_API.sItemList[124], "flint_sword");
|
||||
|
@ -536,6 +538,15 @@ public class GT_ItemLoader implements Runnable {
|
|||
GameRegistry.registerItem(GregTech_API.sItemList[141], "empty_electric_screwdriver");
|
||||
GameRegistry.registerItem(GregTech_API.sItemList[142], "plastic_mallet");
|
||||
|
||||
GT_Log.log.info("Loading tools");
|
||||
for (Item item : GregTech_API.sItemList) {
|
||||
if (item instanceof GT_Tool_Item) {
|
||||
GT_Tool_Item.registerTool((GT_Tool_Item)item);
|
||||
}
|
||||
}
|
||||
|
||||
GregTech_API.sSpecialFile.mConfig.save();
|
||||
|
||||
GT_Log.log.info("Loading item related stuff");
|
||||
GT_OreDictUnificator.addToBlacklist(GT_Items.Circuit_Integrated.getWildcard(1));
|
||||
|
||||
|
|
Loading…
Reference in a new issue