diff options
author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2023-06-22 23:48:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-22 23:48:40 +0200 |
commit | 705dec10c37a7f878f11aad11ea4615a7c08ec00 (patch) | |
tree | 96d8f4eaa486eed2cb9bb3b469007354a48743b2 /src/main/java/kubatech/config | |
parent | 4f7ebceca5992e3d81f86b264460f38db27eb28b (diff) | |
download | GT5-Unofficial-705dec10c37a7f878f11aad11ea4615a7c08ec00.tar.gz GT5-Unofficial-705dec10c37a7f878f11aad11ea4615a7c08ec00.tar.bz2 GT5-Unofficial-705dec10c37a7f878f11aad11ea4615a7c08ec00.zip |
Remove Mobs Info NEI page from KubaTech (#82)
* Add Mobs Info
* Use MobsInfo
* Update dependencies.gradle
* Update repositories.gradle
* Update GT_MetaTileEntity_ExtremeExterminationChamber.java
* Update dependencies.gradle
Diffstat (limited to 'src/main/java/kubatech/config')
-rw-r--r-- | src/main/java/kubatech/config/Config.java | 49 | ||||
-rw-r--r-- | src/main/java/kubatech/config/OverridesConfig.java | 246 |
2 files changed, 0 insertions, 295 deletions
diff --git a/src/main/java/kubatech/config/Config.java b/src/main/java/kubatech/config/Config.java index 6508063faf..1976e76949 100644 --- a/src/main/java/kubatech/config/Config.java +++ b/src/main/java/kubatech/config/Config.java @@ -51,59 +51,10 @@ public class Config { public static class MobHandler { - public static boolean mobHandlerEnabled = true; - - public enum _CacheRegenerationTrigger { - - Never, - ModAdditionRemoval, - ModAdditionRemovalChange, - Always; - - public static _CacheRegenerationTrigger get(int oridinal) { - return values()[oridinal]; - } - } - - public static _CacheRegenerationTrigger regenerationTrigger = _CacheRegenerationTrigger.ModAdditionRemovalChange; - public static boolean includeEmptyMobs = true; - public static String[] mobBlacklist; public static double playerOnlyDropsModifier = .1d; private static void load(Configuration configuration) { Category category = Category.MOB_HANDLER; - mobHandlerEnabled = configuration - .get(category.get(), "Enabled", true, "Enable \"Mob Drops\" NEI page and Extreme Extermination Chamber") - .getBoolean(); - StringBuilder c = new StringBuilder("When will cache regeneration trigger? "); - for (_CacheRegenerationTrigger value : _CacheRegenerationTrigger.values()) c.append(value.ordinal()) - .append(" - ") - .append(value.name()) - .append(", "); - regenerationTrigger = _CacheRegenerationTrigger.get( - configuration - .get( - category.get(), - "CacheRegenerationTrigger", - _CacheRegenerationTrigger.ModAdditionRemovalChange.ordinal(), - c.toString()) - .getInt()); - includeEmptyMobs = configuration - .get(category.get(), "IncludeEmptyMobs", true, "Include mobs that have no drops in NEI") - .getBoolean(); - mobBlacklist = configuration - .get( - category.get(), - "MobBlacklist", - new String[] { "Giant", "Thaumcraft.TravelingTrunk", "chisel.snowman", "OpenBlocks.Luggage", - "OpenBlocks.MiniMe", "SpecialMobs.SpecialCreeper", "SpecialMobs.SpecialZombie", - "SpecialMobs.SpecialPigZombie", "SpecialMobs.SpecialSlime", "SpecialMobs.SpecialSkeleton", - "SpecialMobs.SpecialEnderman", "SpecialMobs.SpecialCaveSpider", "SpecialMobs.SpecialGhast", - "SpecialMobs.SpecialWitch", "SpecialMobs.SpecialSpider", "TwilightForest.HydraHead", - "TwilightForest.RovingCube", "TwilightForest.Harbinger Cube", "TwilightForest.Adherent", - "SpecialMobs.SpecialSilverfish", }, - "These mobs will be skipped when generating recipe map") - .getStringList(); playerOnlyDropsModifier = configuration .get( category.get(), diff --git a/src/main/java/kubatech/config/OverridesConfig.java b/src/main/java/kubatech/config/OverridesConfig.java deleted file mode 100644 index 6547854557..0000000000 --- a/src/main/java/kubatech/config/OverridesConfig.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * spotless:off - * KubaTech - Gregtech Addon - * Copyright (C) 2022 - 2023 kuba6000 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see <https://www.gnu.org/licenses/>. - * spotless:on - */ - -package kubatech.config; - -import java.io.File; -import java.io.Reader; -import java.io.Writer; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import net.minecraft.entity.EntityList; -import net.minecraft.entity.EntityLiving; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.JsonToNBT; -import net.minecraft.nbt.NBTTagCompound; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.dreammaster.main.MainRegistry; -import com.dreammaster.modcustomdrops.CustomDrops; -import com.google.common.io.Files; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; - -import cpw.mods.fml.common.registry.GameRegistry; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import kubatech.Tags; -import kubatech.api.ConstructableItemStack; -import kubatech.api.LoaderReference; -import kubatech.api.helpers.ReflectionHelper; -import kubatech.api.mobhandler.MobDrop; -import kubatech.api.utils.GSONUtils; - -public class OverridesConfig { - - private static final Logger LOG = LogManager.getLogger(Tags.MODID + "[Config-Overrides]"); - - public static class MobDropSimplified { - - @GSONUtils.SkipGSON - ItemStack stack; - - ConstructableItemStack reconstructableStack; - MobDrop.DropType type; - - private MobDropSimplified() {} - - public MobDropSimplified(ItemStack stack, MobDrop.DropType type) { - reconstructableStack = new ConstructableItemStack(stack); - this.type = type; - } - - public void reconstructStack() { - stack = reconstructableStack.construct(); - } - - public boolean isMatching(MobDrop drop) { - return reconstructableStack.isSame(drop.reconstructableStack, true); - } - - private static final ByteBuf BufHelper = Unpooled.buffer(); - - public void writeToByteBuf(ByteBuf byteBuf) { - BufHelper.clear(); - reconstructableStack.writeToByteBuf(BufHelper); - BufHelper.writeInt(type.ordinal()); - byteBuf.writeInt(BufHelper.readableBytes()); - byteBuf.writeBytes(BufHelper); - } - - public static MobDropSimplified readFromByteBuf(ByteBuf byteBuf) { - MobDropSimplified mobDropSimplified = new MobDropSimplified(); - int size = byteBuf.readInt(); - mobDropSimplified.reconstructableStack = ConstructableItemStack.readFromByteBuf(byteBuf); - mobDropSimplified.type = MobDrop.DropType.get(byteBuf.readInt()); - mobDropSimplified.reconstructStack(); - return mobDropSimplified; - } - } - - public static class MobOverride { - - public boolean removeAll = false; - public final List<MobDrop> additions = new ArrayList<>(); - public final List<MobDropSimplified> removals = new ArrayList<>(); - - private static final ByteBuf BufHelper = Unpooled.buffer(); - - public void writeToByteBuf(ByteBuf byteBuf) { - BufHelper.clear(); - BufHelper.writeBoolean(removeAll); - BufHelper.writeInt(additions.size()); - additions.forEach(drop -> drop.writeToByteBuf(BufHelper)); - BufHelper.writeInt(removals.size()); - removals.forEach(drop -> drop.writeToByteBuf(BufHelper)); - byteBuf.writeInt(BufHelper.readableBytes()); - byteBuf.writeBytes(BufHelper); - } - - public static MobOverride readFromByteBuf(ByteBuf byteBuf) { - int size = byteBuf.readInt(); - MobOverride mobOverride = new MobOverride(); - mobOverride.removeAll = byteBuf.readBoolean(); - int additionssize = byteBuf.readInt(); - for (int i = 0; i < additionssize; i++) mobOverride.additions.add(MobDrop.readFromByteBuf(byteBuf)); - int removalssize = byteBuf.readInt(); - for (int i = 0; i < removalssize; i++) mobOverride.removals.add(MobDropSimplified.readFromByteBuf(byteBuf)); - return mobOverride; - } - } - - public static Map<String, MobOverride> overrides = new HashMap<>(); - private static File overrideFile = null; - - private static final Gson gson = GSONUtils.GSON_BUILDER_PRETTY.create(); - - @SuppressWarnings("UnstableApiUsage") - public static void LoadConfig() { - LOG.info("Loading Config"); - if (overrideFile == null) overrideFile = Config.getConfigFile("MobOverrides.json"); - if (!overrideFile.exists()) writeExampleFile(); - Reader reader = null; - try { - reader = Files.newReader(overrideFile, StandardCharsets.UTF_8); - overrides = gson.fromJson(reader, new TypeToken<Map<String, MobOverride>>() {}.getType()); - overrides.remove("ExampleMob"); - overrides.values() - .forEach(o -> o.additions.forEach(MobDrop::reconstructStack)); - if (LoaderReference.GTNHCoreMod) { - LOG.info("Detected GTNH Core Mod, parsing custom drops from there."); - CustomDrops coredrops = ReflectionHelper - .getField(MainRegistry.Module_CustomDrops, "_mCustomDrops", null); - if (coredrops != null) { - @SuppressWarnings("unchecked") - ArrayList<CustomDrops.CustomDrop> customdrops = (ArrayList<CustomDrops.CustomDrop>) ((ArrayList<CustomDrops.CustomDrop>) coredrops - .getCustomDrops()).clone(); - for (CustomDrops.CustomDrop customdrop : customdrops) { - try { - Class<?> eclass = Class.forName(customdrop.getEntityName()); - if (!EntityLiving.class.isAssignableFrom(eclass)) continue; - String ename = (String) EntityList.classToStringMapping.get(eclass); - if (ename == null) continue; - MobOverride override = overrides.computeIfAbsent(ename, k -> new MobOverride()); - for (CustomDrops.CustomDrop.Drop drop : customdrop.getDrops()) { - String[] parts = drop.getItemName() - .split(":"); - ItemStack stack = GameRegistry.findItemStack(parts[0], parts[1], 1); - if (stack == null) continue; - if (parts.length > 2) stack.setItemDamage(Integer.parseInt(parts[2])); - String pNBT = ReflectionHelper.getField(drop, "mTag", null); - if (pNBT != null && !pNBT.isEmpty()) { - try { - stack.stackTagCompound = (NBTTagCompound) JsonToNBT.func_150315_a(pNBT); - } catch (Exception ignored) {} - } - int chance = drop.getChance() * 100; - int amount = drop.getAmount(); - if (drop.getIsRandomAmount()) { - // average chance formula - // chance *= ((((amount * (amount + 1d)) / 2d)) + 1d) / (amount + 1d); - chance *= (2d + (amount * amount) + amount) / (2d * (amount + 1d)); - amount = 1; - if (chance > 10000) { - int div = (int) Math.ceil(chance / 10000d); - amount *= div; - chance /= div; - } - } - stack.stackSize = amount; - // Drops from coremod are player only - override.additions - .add(new MobDrop(stack, MobDrop.DropType.Normal, chance, null, null, false, true)); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - if (reader != null) try { - reader.close(); - } catch (Exception ignored) {} - } - } - - @SuppressWarnings("UnstableApiUsage") - private static void writeExampleFile() { - LOG.info("No config has been detected, writing an example one"); - Writer writer = null; - try { - writer = Files.newWriter(overrideFile, StandardCharsets.UTF_8); - Map<String, MobOverride> example = new HashMap<>(1); - MobOverride ex1 = new MobOverride(); - ex1.removals.add(new MobDropSimplified(new ItemStack(Items.rotten_flesh, 1), MobDrop.DropType.Normal)); - HashMap<Integer, Integer> exdamages = new HashMap<>(3); - exdamages.put(1, 1); - exdamages.put(2, 5); - exdamages.put(3, 10); - ex1.additions.add( - new MobDrop( - new ItemStack(Items.diamond_sword), - MobDrop.DropType.Rare, - 500, - 20, - exdamages, - true, - false)); - example.put("ExampleMob", ex1); - gson.toJson(example, writer); - writer.flush(); - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - if (writer != null) try { - writer.close(); - } catch (Exception ignored) {} - } - } -} |