From 8a444fce61af45e5d14df3c2bd5921343ee5d6f9 Mon Sep 17 00:00:00 2001 From: Jared Date: Tue, 15 May 2018 14:06:34 +0200 Subject: [PATCH] Added a way to remove Thaumcraft aspects, close #638 --- build.gradle | 2 +- .../handlers/aspects/CTAspectStack.java | 4 +- .../handlers/expand/IItemAspectExpansion.java | 46 +++++++++++++------ 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 4cd3ab7..f6d5443 100644 --- a/build.gradle +++ b/build.gradle @@ -66,7 +66,7 @@ repositories { } dependencies { - deobfCompile "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.5.+" + deobfCompile "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.8.470" deobfCompile "mezz.jei:jei_1.12.2:4.8.6.162" deobfCompile "com.blamejared:MTLib:3.0.2.4" deobfCompile "com.azanor.baubles:Baubles:1.12-1.5.2" diff --git a/src/main/java/com/blamejared/compat/thaumcraft/handlers/aspects/CTAspectStack.java b/src/main/java/com/blamejared/compat/thaumcraft/handlers/aspects/CTAspectStack.java index 71bd4a0..d1cb9c4 100644 --- a/src/main/java/com/blamejared/compat/thaumcraft/handlers/aspects/CTAspectStack.java +++ b/src/main/java/com/blamejared/compat/thaumcraft/handlers/aspects/CTAspectStack.java @@ -8,8 +8,8 @@ import stanhebben.zenscript.annotations.*; @ZenClass("thaumcraft.aspect.CTAspectStack") public class CTAspectStack { - private CTAspect internal; - private int amount; + private final CTAspect internal; + private final int amount; public CTAspectStack(CTAspect internal, int amount) { this.internal = internal; diff --git a/src/main/java/com/blamejared/compat/thaumcraft/handlers/expand/IItemAspectExpansion.java b/src/main/java/com/blamejared/compat/thaumcraft/handlers/expand/IItemAspectExpansion.java index 2087d9a..b2ab8f6 100644 --- a/src/main/java/com/blamejared/compat/thaumcraft/handlers/expand/IItemAspectExpansion.java +++ b/src/main/java/com/blamejared/compat/thaumcraft/handlers/expand/IItemAspectExpansion.java @@ -1,14 +1,14 @@ package com.blamejared.compat.thaumcraft.handlers.expand; import com.blamejared.ModTweaker; -import com.blamejared.compat.thaumcraft.handlers.aspects.*; +import com.blamejared.compat.thaumcraft.handlers.aspects.CTAspectStack; import com.blamejared.mtlib.helpers.*; import com.blamejared.mtlib.utils.BaseAction; import crafttweaker.annotations.*; import crafttweaker.api.item.IItemStack; import stanhebben.zenscript.annotations.*; import thaumcraft.api.ThaumcraftApi; -import thaumcraft.api.aspects.*; +import thaumcraft.api.aspects.AspectList; import java.util.*; @@ -18,6 +18,7 @@ import java.util.*; public class IItemAspectExpansion { private static Map backupAspects = new HashMap<>(); + @ZenMethod public static void setAspects(IItemStack stack, CTAspectStack... aspects) { ModTweaker.LATE_ADDITIONS.add(new BaseAction("Aspects") { @@ -47,18 +48,33 @@ public class IItemAspectExpansion { } - @ZenMethod - public static CTAspectStack[] getAspects(IItemStack stack) { - if(backupAspects.containsKey(stack)){ - return backupAspects.get(stack); - } - AspectList list = new AspectList(InputHelper.toStack(stack)); - CTAspectStack[] arr = new CTAspectStack[list.size()]; - int count = 0; - for(Map.Entry entry : list.aspects.entrySet()) { - arr[count++] = new CTAspectStack(new CTAspect(entry.getKey()), entry.getValue()); - } - return arr; - } + @ZenMethod + public static void removeAspects(IItemStack stack, CTAspectStack... aspects) { + ModTweaker.LATE_REMOVALS.add(new BaseAction("Aspects") { + + @Override + public void apply() { + AspectList list = new AspectList(InputHelper.toStack(stack)); + for(CTAspectStack aspect : aspects) { + list.remove(aspect.getInternal().getInternal()); + } + ThaumcraftApi.registerObjectTag(InputHelper.toStack(stack), list); + } + + @Override + public String describe() { + return "Removing aspects on item: " + LogHelper.getStackDescription(stack) + "," + getAspects(); + } + + private String getAspects() { + StringBuilder builder = new StringBuilder(); + for(CTAspectStack aspect : aspects) { + builder.append(aspect.getInternal().getInternal().getName()).append(", "); + } + return builder.reverse().deleteCharAt(0).deleteCharAt(0).reverse().toString(); + } + }); + + } }