First Test for Thaumcraft Entity Aspects.
This commit is contained in:
parent
03d73b82fb
commit
5c3a12cb92
|
@ -2,9 +2,11 @@ package modtweaker.mods.thaumcraft;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import modtweaker.helpers.ReflectionHelper;
|
||||
import thaumcraft.api.ThaumcraftApi;
|
||||
import thaumcraft.api.ThaumcraftApi.EntityTags;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
import thaumcraft.api.research.ResearchCategories;
|
||||
|
@ -60,4 +62,23 @@ public class ThaumcraftHelper {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static AspectList getEntityAspects(String name) {
|
||||
for(EntityTags tag : ThaumcraftApi.scanEntities)
|
||||
{
|
||||
if(tag.entityName==name && tag.nbts.length==0)
|
||||
return tag.aspects;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void removeEntityAspects(String name) {
|
||||
List<EntityTags> tags = ThaumcraftApi.scanEntities;
|
||||
for(EntityTags tag : tags)
|
||||
{
|
||||
if(tag.entityName==name && tag.nbts.length==0)
|
||||
ThaumcraftApi.scanEntities.remove(tag);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import minetweaker.api.item.IItemStack;
|
|||
import modtweaker.mods.thaumcraft.ThaumcraftHelper;
|
||||
import modtweaker.util.BaseDescriptionAddition;
|
||||
import modtweaker.util.BaseDescriptionRemoval;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
@ -108,4 +109,114 @@ public class Aspects {
|
|||
return stack.getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
/** Add/Remove/Set Aspects for entities **/
|
||||
@ZenMethod
|
||||
public static void addForEntity(String entityName, String aspects) {
|
||||
if(!EntityList.stringToClassMapping.containsKey(entityName))
|
||||
{
|
||||
MineTweakerAPI.getLogger().logError("No such entity "+entityName);
|
||||
return;
|
||||
}
|
||||
MineTweakerAPI.apply(new AddForEntity(entityName, aspects, false));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void setForEntity(String entityName, String aspects) {
|
||||
if(!EntityList.stringToClassMapping.containsKey(entityName))
|
||||
{
|
||||
MineTweakerAPI.getLogger().logError("No such entity "+entityName);
|
||||
return;
|
||||
}
|
||||
MineTweakerAPI.apply(new AddForEntity(entityName, aspects, true));
|
||||
}
|
||||
|
||||
//Adds or sets Aspects
|
||||
private static class AddForEntity extends BaseDescriptionAddition {
|
||||
private final String entityName;
|
||||
private final String aspects;
|
||||
private final boolean replace;
|
||||
private AspectList oldList;
|
||||
private AspectList newList;
|
||||
|
||||
public AddForEntity(String entityName, String aspects, boolean replace) {
|
||||
super("Aspects");
|
||||
this.entityName = entityName;
|
||||
this.aspects = aspects;
|
||||
this.replace = replace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
oldList = ThaumcraftHelper.getEntityAspects(entityName);
|
||||
if (!replace) newList = ThaumcraftHelper.parseAspects(oldList, aspects);
|
||||
else newList = ThaumcraftHelper.parseAspects(aspects);
|
||||
ThaumcraftHelper.removeEntityAspects(entityName);
|
||||
ThaumcraftApi.registerEntityTag(entityName, newList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
ThaumcraftHelper.removeEntityAspects(entityName);
|
||||
if (oldList != null)
|
||||
ThaumcraftApi.registerEntityTag(entityName, oldList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return entityName;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeForEntity(String entityName, String aspects) {
|
||||
if(!EntityList.stringToClassMapping.containsKey(entityName))
|
||||
{
|
||||
MineTweakerAPI.getLogger().logError("No such entity "+entityName);
|
||||
return;
|
||||
}
|
||||
MineTweakerAPI.apply(new RemoveForEntity(entityName, aspects));
|
||||
}
|
||||
|
||||
private static class RemoveForEntity extends BaseDescriptionRemoval {
|
||||
private final String entityName;
|
||||
private final String aspects;
|
||||
private AspectList oldList;
|
||||
private AspectList newList;
|
||||
|
||||
public RemoveForEntity(String entityName, String aspects) {
|
||||
super("Aspects");
|
||||
this.entityName = entityName;
|
||||
this.aspects = aspects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
oldList = ThaumcraftHelper.getEntityAspects(entityName);
|
||||
if (oldList != null) {
|
||||
newList = ThaumcraftHelper.removeAspects(oldList, aspects);
|
||||
ThaumcraftHelper.removeEntityAspects(entityName);
|
||||
ThaumcraftApi.registerEntityTag(entityName, newList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return oldList != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
ThaumcraftHelper.removeEntityAspects(entityName);
|
||||
ThaumcraftApi.registerEntityTag(entityName, oldList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return entityName;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue