mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-20 12:09:51 +00:00
- Praecantatio Effect added
This commit is contained in:
1 parent
cc8c9e88ec
commit
2ffa945e5a
8 files changed
+157
-78
No files matched your search
@@ -75,6 +75,8 @@ public class CommonProxy implements IGuiHandler {
|
||||
FMLCommonHandler.instance().bus().register(worldEventHandler);
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandlerEntity());
|
||||
|
||||
RegisteredPotions.init();
|
||||
|
||||
AuraEffects.AER.getTickInterval(); //initalize AuraEffects
|
||||
|
||||
RegisteredRecipes.init();
|
||||
@@ -82,8 +84,6 @@ public class CommonProxy implements IGuiHandler {
|
||||
SyncDataHolder.initialize();
|
||||
ModSubstitutions.init();
|
||||
|
||||
RegisteredPotions.init();
|
||||
|
||||
RegisteredEntities.init();
|
||||
|
||||
DimensionManager.registerProviderType(ModConfig.dimOuterId, WorldProviderTCEldrich.class, true);
|
||||
|
||||
@@ -476,6 +476,7 @@ public class AuraEffects {
|
||||
}
|
||||
}
|
||||
}.register(Aspect.SOUL);
|
||||
public static final AuraEffect PRAECANTATIO = new PotionDistributionEffect(RegisteredPotions.VIS_DISCOUNT, 4, 6, ticksForMinutes(5), 1).register(Aspect.MAGIC);
|
||||
|
||||
public static class PotionDistributionEffect extends AuraEffect.EntityAuraEffect {
|
||||
|
||||
|
||||
@@ -54,69 +54,6 @@ public class EventHandlerEntity {
|
||||
}
|
||||
}*/
|
||||
|
||||
public static int getFortuneLevel(EntityLivingBase entity) {
|
||||
int fortuneLevel = getRealEnchantmentLevel(Enchantment.fortune.effectId, entity.getHeldItem());
|
||||
if(entity.isPotionActive(RegisteredPotions.POTION_LUCK)) {
|
||||
int lvl = entity.getActivePotionEffect(RegisteredPotions.POTION_LUCK).getAmplifier() + 1; //Amplifier 0-indexed
|
||||
fortuneLevel += lvl;
|
||||
}
|
||||
return fortuneLevel;
|
||||
}
|
||||
|
||||
public static int getLootingLevel(EntityLivingBase entity) {
|
||||
int lootingLevel = getRealEnchantmentLevel(Enchantment.looting.effectId, entity.getHeldItem());
|
||||
if(entity.isPotionActive(RegisteredPotions.POTION_LUCK)) {
|
||||
int lvl = entity.getActivePotionEffect(RegisteredPotions.POTION_LUCK).getAmplifier() + 1; //Amplifier 0-indexed
|
||||
lootingLevel += lvl;
|
||||
}
|
||||
return lootingLevel;
|
||||
}
|
||||
|
||||
public static int onGetEnchantmentLevel(int enchantmentId, ItemStack stack) {
|
||||
EntityPlayer possiblePlayer = null;
|
||||
if(stack != null) {
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
if(server != null) {
|
||||
for(EntityPlayer player : (List<EntityPlayer>)server.getConfigurationManager().playerEntityList) {
|
||||
if(player.getHeldItem() == stack) {
|
||||
possiblePlayer = player;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(possiblePlayer != null) {
|
||||
|
||||
if(enchantmentId == Enchantment.fortune.effectId) {
|
||||
return getFortuneLevel(possiblePlayer);
|
||||
} else if(enchantmentId == Enchantment.looting.effectId) {
|
||||
return getLootingLevel(possiblePlayer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return getRealEnchantmentLevel(enchantmentId, stack);
|
||||
}
|
||||
|
||||
private static int getRealEnchantmentLevel(int enchantmentId, ItemStack stack) {
|
||||
if (stack == null) {
|
||||
return 0;
|
||||
} else {
|
||||
NBTTagList nbttaglist = stack.getEnchantmentTagList();
|
||||
if (nbttaglist == null) {
|
||||
return 0;
|
||||
} else {
|
||||
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
|
||||
short id = nbttaglist.getCompoundTagAt(j).getShort("id");
|
||||
if (id == enchantmentId) {
|
||||
return nbttaglist.getCompoundTagAt(j).getShort("lvl");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void on(LivingSpawnEvent.CheckSpawn event) {
|
||||
if(event.entityLiving.isCreatureType(EnumCreatureType.monster, false)) {
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package makeo.gadomancy.common.events;
|
||||
|
||||
import makeo.gadomancy.common.registration.RegisteredPotions;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
* <p/>
|
||||
* Created by HellFirePvP @ 15.12.2015 14:57
|
||||
*/
|
||||
public class EventHandlerRedirect {
|
||||
|
||||
public static int getAdditionalVisDiscount(EntityPlayer player, Aspect aspect, int currentTotalDiscount) {
|
||||
if(player.isPotionActive(RegisteredPotions.VIS_DISCOUNT)) {
|
||||
currentTotalDiscount += (player.getActivePotionEffect(RegisteredPotions.VIS_DISCOUNT).getAmplifier() + 1) * 8;
|
||||
}
|
||||
return currentTotalDiscount;
|
||||
}
|
||||
|
||||
public static int getFortuneLevel(EntityLivingBase entity) {
|
||||
int fortuneLevel = getRealEnchantmentLevel(Enchantment.fortune.effectId, entity.getHeldItem());
|
||||
if(entity.isPotionActive(RegisteredPotions.POTION_LUCK)) {
|
||||
int lvl = entity.getActivePotionEffect(RegisteredPotions.POTION_LUCK).getAmplifier() + 1; //Amplifier 0-indexed
|
||||
fortuneLevel += lvl;
|
||||
}
|
||||
return fortuneLevel;
|
||||
}
|
||||
|
||||
public static int getLootingLevel(EntityLivingBase entity) {
|
||||
int lootingLevel = getRealEnchantmentLevel(Enchantment.looting.effectId, entity.getHeldItem());
|
||||
if(entity.isPotionActive(RegisteredPotions.POTION_LUCK)) {
|
||||
int lvl = entity.getActivePotionEffect(RegisteredPotions.POTION_LUCK).getAmplifier() + 1; //Amplifier 0-indexed
|
||||
lootingLevel += lvl;
|
||||
}
|
||||
return lootingLevel;
|
||||
}
|
||||
|
||||
public static int onGetEnchantmentLevel(int enchantmentId, ItemStack stack) {
|
||||
EntityPlayer possiblePlayer = null;
|
||||
if(stack != null) {
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
if(server != null) {
|
||||
for(EntityPlayer player : (List<EntityPlayer>) server.getConfigurationManager().playerEntityList) {
|
||||
if(player.getHeldItem() == stack) {
|
||||
possiblePlayer = player;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(possiblePlayer != null) {
|
||||
|
||||
if(enchantmentId == Enchantment.fortune.effectId) {
|
||||
return getFortuneLevel(possiblePlayer);
|
||||
} else if(enchantmentId == Enchantment.looting.effectId) {
|
||||
return getLootingLevel(possiblePlayer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return getRealEnchantmentLevel(enchantmentId, stack);
|
||||
}
|
||||
|
||||
private static int getRealEnchantmentLevel(int enchantmentId, ItemStack stack) {
|
||||
if (stack == null) {
|
||||
return 0;
|
||||
} else {
|
||||
NBTTagList nbttaglist = stack.getEnchantmentTagList();
|
||||
if (nbttaglist == null) {
|
||||
return 0;
|
||||
} else {
|
||||
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
|
||||
short id = nbttaglist.getCompoundTagAt(j).getShort("id");
|
||||
if (id == enchantmentId) {
|
||||
return nbttaglist.getCompoundTagAt(j).getShort("lvl");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package makeo.gadomancy.common.potions;
|
||||
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
* <p/>
|
||||
* Created by HellFirePvP @ 15.12.2015 19:06
|
||||
*/
|
||||
public class PotionVisAffinity extends PotionCustomTexture {
|
||||
|
||||
public PotionVisAffinity(int id) {
|
||||
super(id, false, Aspect.MAGIC.getColor(), Aspect.MAGIC.getImage());
|
||||
setPotionName("potion.visdiscount");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import makeo.gadomancy.common.potions.PotionAchromatic;
|
||||
import makeo.gadomancy.common.potions.PotionBuffGolem;
|
||||
import makeo.gadomancy.common.potions.PotionLetsGargamelItUp;
|
||||
import makeo.gadomancy.common.potions.PotionMiningLuck;
|
||||
import makeo.gadomancy.common.potions.PotionVisAffinity;
|
||||
import makeo.gadomancy.common.utils.Injector;
|
||||
import net.minecraft.potion.Potion;
|
||||
|
||||
@@ -21,12 +22,15 @@ public class RegisteredPotions {
|
||||
public static PotionBuffGolem BUFF_GOLEM;
|
||||
public static PotionAchromatic ACHROMATIC;
|
||||
public static PotionLetsGargamelItUp ELDRITCH;
|
||||
public static PotionVisAffinity VIS_DISCOUNT;
|
||||
|
||||
public static void init() {
|
||||
POTION_LUCK = registerPotion(PotionMiningLuck.class);
|
||||
BUFF_GOLEM = registerPotion(PotionBuffGolem.class);
|
||||
ACHROMATIC = registerPotion(PotionAchromatic.class);
|
||||
ELDRITCH = registerPotion(PotionLetsGargamelItUp.class);
|
||||
VIS_DISCOUNT = registerPotion(PotionVisAffinity.class);
|
||||
System.out.println(VIS_DISCOUNT);
|
||||
}
|
||||
|
||||
private static <T extends Potion> T registerPotion(Class<T> potionClass) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package makeo.gadomancy.coremod;
|
||||
|
||||
import cpw.mods.fml.common.asm.transformers.AccessTransformer;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
@@ -13,6 +13,7 @@ import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -25,22 +26,29 @@ import java.io.IOException;
|
||||
* Created by makeo @ 07.12.2015 21:48
|
||||
*/
|
||||
public class GadomancyTransformer extends AccessTransformer {
|
||||
public GadomancyTransformer() throws IOException {
|
||||
}
|
||||
|
||||
public static final String NAME_ENCHANTMENT_HELPER = "net.minecraft.enchantment.EnchantmentHelper";
|
||||
public static final String NAME_WANDMANAGER = "thaumcraft.common.items.wands.WandManager";
|
||||
|
||||
public GadomancyTransformer() throws IOException {}
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] bytes) {
|
||||
if(name.equalsIgnoreCase("net.minecraft.enchantment.EnchantmentHelper")) {
|
||||
ClassNode node = new ClassNode();
|
||||
ClassReader reader = new ClassReader(bytes);
|
||||
reader.accept(node, 0);
|
||||
boolean needsTransform = name.equalsIgnoreCase(NAME_ENCHANTMENT_HELPER) ||
|
||||
name.equalsIgnoreCase(NAME_WANDMANAGER);
|
||||
if(!needsTransform) return super.transform(name, transformedName, bytes);
|
||||
|
||||
ClassNode node = new ClassNode();
|
||||
ClassReader reader = new ClassReader(bytes);
|
||||
reader.accept(node, 0);
|
||||
|
||||
if(name.equalsIgnoreCase(NAME_ENCHANTMENT_HELPER)) {
|
||||
for (MethodNode mn : node.methods) {
|
||||
if(mn.name.equals("getFortuneModifier") || mn.name.equals("func_77517_e")) {
|
||||
mn.instructions = new InsnList();
|
||||
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "makeo/gadomancy/common/events/EventHandlerEntity",
|
||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "makeo/gadomancy/common/events/EventHandlerRedirect",
|
||||
"getFortuneLevel", "(Lnet/minecraft/entity/EntityLivingBase;)I", false));
|
||||
mn.instructions.add(new InsnNode(Opcodes.IRETURN));
|
||||
|
||||
@@ -49,16 +57,30 @@ public class GadomancyTransformer extends AccessTransformer {
|
||||
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ILOAD, 0));
|
||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
|
||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "makeo/gadomancy/common/events/EventHandlerEntity",
|
||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "makeo/gadomancy/common/events/EventHandlerRedirect",
|
||||
"onGetEnchantmentLevel", "(ILnet/minecraft/item/ItemStack;)I", false));
|
||||
mn.instructions.add(new InsnNode(Opcodes.IRETURN));
|
||||
}
|
||||
}
|
||||
} else if(name.equalsIgnoreCase(NAME_WANDMANAGER)) {
|
||||
for(MethodNode mn : node.methods) {
|
||||
if(mn.name.equals("getTotalVisDiscount")) {
|
||||
InsnList updateTotal = new InsnList();
|
||||
|
||||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
node.accept(writer);
|
||||
bytes = writer.toByteArray();
|
||||
updateTotal.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
updateTotal.add(new VarInsnNode(Opcodes.ALOAD, 1));
|
||||
updateTotal.add(new VarInsnNode(Opcodes.ILOAD, 2));
|
||||
updateTotal.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "makeo/gadomancy/common/events/EventHandlerRedirect",
|
||||
"getAdditionalVisDiscount", "(Lnet/minecraft/entity/player/EntityPlayer;Lthaumcraft/api/aspects/Aspect;I)I", false));
|
||||
|
||||
mn.instructions.insertBefore(mn.instructions.get(mn.instructions.size() - 5), updateTotal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
node.accept(writer);
|
||||
bytes = writer.toByteArray();
|
||||
return super.transform(name, transformedName, bytes);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user