mirror of
https://github.com/GTNewHorizons/IguanaTweaksTConstruct.git
synced 2026-11-26 06:43:05 +00:00
Redstone Modifier now keeps XP-% the same when modifying
This commit is contained in:
1 parent
6d7828788c
commit
ea2fe16779
4 files changed
+125
-14
No files matched your search
@@ -26,7 +26,12 @@ import net.minecraft.item.Item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mod(modid= Reference.MOD_ID, name= Reference.MOD_NAME, version="1.6.X-1p",
|
||||
// inofficial todo list:
|
||||
// todo: find a solution to stone-head-tools not having xp even when head is replaced (maybe like old iguana, disallow stone tools?)
|
||||
// todo: PR a ToolModifyEvent in ModifyBuilder to Tinkers to update XP when a modifier that modifies XP needed is applied.
|
||||
// todo: refactor adding modifiers on levelup from that long chaotic function + normal modifiers ;o
|
||||
|
||||
@Mod(modid= Reference.MOD_ID, name= Reference.MOD_NAME, version="1.7.X-1p",
|
||||
dependencies = "required-after:" + Reference.TCON_MOD_ID + ";after:*")
|
||||
public class IguanaTweaksTConstruct {
|
||||
|
||||
|
||||
@@ -5,19 +5,30 @@ import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import iguanaman.iguanatweakstconstruct.leveling.handlers.LevelingEventHandler;
|
||||
import iguanaman.iguanatweakstconstruct.leveling.handlers.ToolTipHandler;
|
||||
import iguanaman.iguanatweakstconstruct.leveling.modifiers.ModMiningLevelBoost;
|
||||
import iguanaman.iguanatweakstconstruct.leveling.modifiers.ModXpAwareRedstone;
|
||||
import iguanaman.iguanatweakstconstruct.reference.Reference;
|
||||
import iguanaman.iguanatweakstconstruct.util.HarvestLevels;
|
||||
import iguanaman.iguanatweakstconstruct.util.Log;
|
||||
import mantle.pulsar.pulse.Handler;
|
||||
import mantle.pulsar.pulse.Pulse;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import tconstruct.library.TConstructRegistry;
|
||||
import tconstruct.library.client.TConstructClientRegistry;
|
||||
import tconstruct.library.crafting.ModifyBuilder;
|
||||
import tconstruct.library.modifier.ItemModifier;
|
||||
import tconstruct.library.tools.ToolCore;
|
||||
import tconstruct.modifiers.tools.ModAttack;
|
||||
import tconstruct.modifiers.tools.ModRedstone;
|
||||
import tconstruct.tools.TinkerTools;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
/**
|
||||
* The Leveling Pulse. If Leveling were a separate mod instead of pulse-model, this'd be a @Mod
|
||||
* This pulse contains all the stuff that has to do with tool leveling.
|
||||
@@ -36,7 +47,43 @@ public class IguanaToolLeveling {
|
||||
{
|
||||
TConstructRegistry.registerActiveToolMod(new LevelingActiveToolMod());
|
||||
|
||||
// substitute modifiers that need an xp-aware implementation
|
||||
takeOverModifiers();
|
||||
|
||||
|
||||
// mobhead modifiers for mining boost
|
||||
registerBoostModifiers();
|
||||
}
|
||||
|
||||
private ItemStack[] getMobHead(int meta)
|
||||
{
|
||||
return new ItemStack[]{new ItemStack(Items.skull, 1, meta)};
|
||||
}
|
||||
|
||||
@Handler
|
||||
public void postInit(FMLPostInitializationEvent event)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(new LevelingEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new ToolTipHandler());
|
||||
}
|
||||
|
||||
// replace modifiers with our own, adjusted, modifiers
|
||||
private void takeOverModifiers()
|
||||
{
|
||||
List<ItemModifier> mods = ModifyBuilder.instance.itemModifiers;
|
||||
for(ListIterator<ItemModifier> iter = mods.listIterator(); iter.hasNext();)
|
||||
{
|
||||
ItemModifier mod = iter.next();
|
||||
// redstone
|
||||
if(mod instanceof ModRedstone) {
|
||||
iter.set(new ModXpAwareRedstone((ModRedstone) mod));
|
||||
Log.trace("Replaced Redstone Modifier");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void registerBoostModifiers()
|
||||
{
|
||||
ModifyBuilder.registerModifier(new ModMiningLevelBoost(getMobHead(HEAD_Zombie), 20, HarvestLevels._2_copper));
|
||||
ModifyBuilder.registerModifier(new ModMiningLevelBoost(getMobHead(HEAD_Skeleton), 21, HarvestLevels._3_iron));
|
||||
ModifyBuilder.registerModifier(new ModMiningLevelBoost(getMobHead(HEAD_Creeper), 22, HarvestLevels._4_bronze));
|
||||
@@ -54,16 +101,4 @@ public class IguanaToolLeveling {
|
||||
for (int index = 0; index < modifierIds.length; ++index)
|
||||
TConstructClientRegistry.addEffectRenderMapping(tool, modifierIds[index], Reference.RESOURCE, renderNames[index], true);
|
||||
}
|
||||
|
||||
private ItemStack[] getMobHead(int meta)
|
||||
{
|
||||
return new ItemStack[]{new ItemStack(Items.skull, 1, meta)};
|
||||
}
|
||||
|
||||
@Handler
|
||||
public void postInit(FMLPostInitializationEvent event)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(new LevelingEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new ToolTipHandler());
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package iguanaman.iguanatweakstconstruct.leveling;
|
||||
package iguanaman.iguanatweakstconstruct.leveling.modifiers;
|
||||
|
||||
import iguanaman.iguanatweakstconstruct.leveling.LevelingLogic;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package iguanaman.iguanatweakstconstruct.leveling.modifiers;
|
||||
|
||||
import iguanaman.iguanatweakstconstruct.leveling.LevelingLogic;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import tconstruct.modifiers.tools.ModRedstone;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The same as the redstone modifier, but translates current XP on modifying.
|
||||
* Basically: You get XP when applying it, because the required XP for the next level also increases. XP% stays the same.
|
||||
*/
|
||||
public class ModXpAwareRedstone extends ModRedstone {
|
||||
|
||||
public ModXpAwareRedstone(int effect, ItemStack[] items, int[] values) {
|
||||
super(effect, items, values);
|
||||
}
|
||||
|
||||
public ModXpAwareRedstone(ModRedstone modifier) {
|
||||
super(modifier.effectIndex, ListStackToStackArray(modifier.stacks), ListIntToIntArray(modifier.increase));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modify(ItemStack[] input, ItemStack tool) {
|
||||
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
|
||||
// get max xp before modifying
|
||||
long oldXP = LevelingLogic.getRequiredXp(tool, tags);
|
||||
long oldBoostXP = LevelingLogic.getRequiredBoostXp(tool);
|
||||
// modify
|
||||
super.modify(input, tool);
|
||||
|
||||
// update regular xp
|
||||
if(LevelingLogic.hasXp(tags)) {
|
||||
long newXP = LevelingLogic.getRequiredXp(tool, tags);
|
||||
float xp = LevelingLogic.getXp(tags);
|
||||
xp *= (float) newXP / (float) oldXP;
|
||||
tags.setLong(LevelingLogic.TAG_EXP, Math.round(xp));
|
||||
}
|
||||
|
||||
// update boost xp
|
||||
if(LevelingLogic.hasBoostXp(tags))
|
||||
{
|
||||
long newBoostXP = LevelingLogic.getRequiredBoostXp(tool);
|
||||
float xp = LevelingLogic.getBoostXp(tags);
|
||||
xp *= (float) newBoostXP / (float) oldBoostXP;
|
||||
tags.setLong(LevelingLogic.TAG_BOOST_EXP, Math.round(xp));
|
||||
}
|
||||
}
|
||||
|
||||
// we need this because the constructor expects an int[] array, although it uses Integer internally, and Integer[] can't be casted to int[]...
|
||||
static int[] ListIntToIntArray(List<Integer> list)
|
||||
{
|
||||
int[] arr = new int[list.size()];
|
||||
for(int i = 0; i < list.size(); i++)
|
||||
arr[i] = list.get(i);
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
static ItemStack[] ListStackToStackArray(List<ItemStack> list)
|
||||
{
|
||||
ItemStack[] arr = new ItemStack[list.size()];
|
||||
for(int i = 0; i < list.size(); i++)
|
||||
arr[i] = list.get(i);
|
||||
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user