Move all the tool-levelup-stuff into a separate Puslar Module and MAKE IT WORK >:D

This commit is contained in:
Bernhard Bonigl committed 2014-07-14 23:22:35 +02:00
1 parent 87945655cc
commit 655d6c6ff7
9 files changed
+354 -18

No files matched your search

@@ -1,18 +1,20 @@
package iguanaman.iguanatweakstconstruct;
import iguanaman.iguanatweakstconstruct.commands.IguanaCommandLevelUpTool;
import iguanaman.iguanatweakstconstruct.commands.IguanaCommandToolXP;
import iguanaman.iguanatweakstconstruct.leveling.commands.IguanaCommandLevelUpTool;
import iguanaman.iguanatweakstconstruct.leveling.commands.IguanaCommandToolXP;
import iguanaman.iguanatweakstconstruct.leveling.Leveling;
import iguanaman.iguanatweakstconstruct.proxy.CommonProxy;
import iguanaman.iguanatweakstconstruct.reference.IguanaConfig;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
import iguanaman.iguanatweakstconstruct.reference.IguanaReference;
import iguanaman.iguanatweakstconstruct.util.IguanaLog;
import mantle.pulsar.config.ForgeCFG;
import mantle.pulsar.control.PulseManager;
import mantle.pulsar.pulse.Handler;
import mantle.pulsar.pulse.PulseMeta;
import net.minecraft.command.ICommandManager;
import net.minecraft.command.ServerCommandManager;
import net.minecraft.item.Item;
@@ -43,7 +45,8 @@ public class IguanaTweaksTConstruct {
// TODO: decide wether or not the same cfg as tcon should be used
// use the PulseManager. This allows us to separate the different parts into independend modules and have stuff together. yay.
private PulseManager pulsar = new PulseManager(IguanaReference.MOD_ID, new ForgeCFG("TinkersModules", "Modules added by Iguana Tweaks for Tinkers Construct"));
private ForgeCFG pulseCFG = new ForgeCFG("TinkersModules", "Addon: Iguana Tweaks for Tinkers Construct");
private PulseManager pulsar = new PulseManager(IguanaReference.MOD_ID, pulseCFG);
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
@@ -65,6 +68,7 @@ public class IguanaTweaksTConstruct {
//IguanaBlocks.init();
//IguanaItems.init();
pulsar.registerPulse(new Leveling());
pulsar.preInit(event);
}
@@ -94,12 +98,13 @@ public class IguanaTweaksTConstruct {
@EventHandler
public void serverStarting(FMLServerStartingEvent event)
{
if (IguanaConfig.toolLeveling)
PulseMeta meta = new PulseMeta(IguanaReference.PULSE_LEVELING, "", false, false);
if (pulseCFG.isModuleEnabled(meta))
{
ICommandManager commandManager = FMLCommonHandler.instance().getMinecraftServerInstance().getCommandManager();
ServerCommandManager serverCommandManager = (ServerCommandManager) commandManager;
serverCommandManager.registerCommand(new IguanaCommandLevelUpTool());
serverCommandManager.registerCommand(new IguanaCommandToolXP());
IguanaLog.debug("Adding command: leveluptool");
event.registerServerCommand(new IguanaCommandLevelUpTool());
IguanaLog.debug("Adding command: toolxp");
event.registerServerCommand(new IguanaCommandToolXP());
}
}
@@ -0,0 +1,36 @@
package iguanaman.iguanatweakstconstruct.leveling;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import iguanaman.iguanatweakstconstruct.leveling.commands.IguanaCommandLevelUpTool;
import iguanaman.iguanatweakstconstruct.leveling.commands.IguanaCommandToolXP;
import iguanaman.iguanatweakstconstruct.reference.IguanaReference;
import iguanaman.iguanatweakstconstruct.util.IguanaLog;
import mantle.pulsar.pulse.Handler;
import mantle.pulsar.pulse.Pulse;
import net.minecraftforge.common.MinecraftForge;
import tconstruct.library.TConstructRegistry;
/**
* 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.
*/
@Pulse(id = IguanaReference.PULSE_LEVELING, description = "The Iguana Tweaks Leveling System for Tinker's Tools")
public class Leveling {
@Handler
public void init(FMLInitializationEvent event)
{
TConstructRegistry.registerActiveToolMod(new LevelingToolMod());
}
@Handler
public void postInit(FMLPostInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(new LevelingEventHandler());
}
}
@@ -0,0 +1,192 @@
package iguanaman.iguanatweakstconstruct.leveling;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import iguanaman.iguanatweakstconstruct.IguanaLevelingLogic;
import iguanaman.iguanatweakstconstruct.IguanaTweaksTConstruct;
import iguanaman.iguanatweakstconstruct.reference.IguanaConfig;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import tconstruct.items.tools.Hammer;
import tconstruct.items.tools.Pickaxe;
import tconstruct.items.tools.Shortbow;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.event.ToolCraftEvent;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.tools.Weapon;
import tconstruct.tools.TinkerTools;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class LevelingEventHandler {
@SubscribeEvent
public void onHurt (LivingHurtEvent event)
{
if (event.source.damageType.equals("player") || event.source.damageType.equals("arrow"))
if (event.source.getEntity() instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) event.source.getEntity();
ItemStack stack = player.getCurrentEquippedItem();
if (stack != null && stack.hasTagCompound())
if (stack.getItem() instanceof Weapon || stack.getItem() instanceof Shortbow && event.source.damageType.equals("arrow"))
{
long xp = Math.round(event.ammount);
if (event.entityLiving instanceof EntityAnimal) xp = Math.round(event.ammount / 4f);
if (xp > 0) IguanaLevelingLogic.addXP(stack, player, xp);
}
}
}
@SubscribeEvent
public void onUseHoe(UseHoeEvent event) {
EntityPlayer player = event.entityPlayer;
ItemStack stack = event.current;
if (stack != null && stack.hasTagCompound() && stack.getItem() instanceof ToolCore)
IguanaLevelingLogic.addXP(stack, player, 1L);
}
@SubscribeEvent
public void onCraftTool (ToolCraftEvent.NormalTool event) {
// arrows don't get levels
if(event.tool == TinkerTools.arrow)
return;
NBTTagCompound toolTag = event.toolTag.getCompoundTag("InfiTool");
int head = toolTag.getInteger("Head");
int handle = toolTag.getInteger("Handle");
int accessory = toolTag.getInteger("Accessory");
int extra = toolTag.hasKey("Extra") ? toolTag.getInteger("Extra") : -1;
// CREATE TOOLTIP LISTS
List<String> tips = new ArrayList<String>();
List<String> modifierTips = new ArrayList<String>();
// MINING LEVEL TOOLTIP
if (event.tool instanceof Pickaxe || event.tool instanceof Hammer)
{
String mLevel = IguanaTweaksTConstruct.getHarvestLevelName(toolTag.getInteger("HarvestLevel"));
tips.add("Mining Level: " + mLevel);
modifierTips.add("");
}
// TOOL LEVELING DATA + TOOLTIP
if (IguanaConfig.toolLeveling)
{
tips.add(IguanaLevelingLogic.getLevelTooltip(1));
modifierTips.add("");
toolTag.setInteger("ToolLevel", 1);
toolTag.setLong("ToolEXP", 0);
if (IguanaConfig.showTooltipXP)
{
tips.add(IguanaLevelingLogic.getXpString(new ItemStack(event.tool), false, toolTag));
modifierTips.add("");
}
if (IguanaConfig.levelingPickaxeBoost && (event.tool instanceof Pickaxe || event.tool instanceof Hammer))
{
toolTag.setLong("HeadEXP", 0);
int hLevel = toolTag.hasKey("HarvestLevel") ? hLevel = toolTag.getInteger("HarvestLevel") : -1;
if (hLevel >= TConstructRegistry.getMaterial("Copper").harvestLevel() && hLevel < TConstructRegistry.getMaterial("Manyullyn").harvestLevel())
{
if (IguanaConfig.showTooltipXP)
{
tips.add(IguanaLevelingLogic.getXpString(new ItemStack(event.tool), false, toolTag, true));
modifierTips.add("");
}
tips.add("\u00A76Requires boost");
modifierTips.add("");
}
}
}
// STORE + REMOVE EXISTING TOOLTIPS
int tipNum = 0;
while (true)
{
String tip = "Tooltip" + ++tipNum;
if (toolTag.hasKey(tip))
{
tips.add(toolTag.getString(tip));
modifierTips.add(toolTag.getString("ModifierTip" + tipNum));
toolTag.removeTag(tip);
toolTag.removeTag("ModifierTip" + tipNum);
}
else break;
}
// WRITE TOOLTIPS
for (int i = 1; i <= tips.size(); ++i)
if (tips.get(i - 1) != null)
{
toolTag.setString("Tooltip" + i, tips.get(i - 1));
if (modifierTips.get(i - 1) != null)
toolTag.setString("ModifierTip" + i, modifierTips.get(i - 1));
else
toolTag.setString("ModifierTip" + i, "");
}
if (IguanaConfig.toolLeveling && IguanaConfig.toolLevelingExtraModifiers)
toolTag.setInteger("Modifiers", Math.max(toolTag.getInteger("Modifiers") - 3, 0));
if (event.tool == TinkerTools.hammer || event.tool == TinkerTools.excavator || event.tool == TinkerTools.lumberaxe)
{
List<String> replaceTags = new ArrayList<String>(Arrays.asList(
"MiningSpeed", "MiningSpeed2", "MiningSpeedHandle", "MiningSpeedExtra"
));
for (String replaceTag : replaceTags)
if (toolTag.hasKey(replaceTag)) toolTag.setInteger(replaceTag, Math.round(toolTag.getInteger(replaceTag) / 2f));
}
}
// Display XP of held tool in debug (F3) if config is set
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onRenderGameOverlay(RenderGameOverlayEvent.Text event) {
if (IguanaConfig.toolLeveling && IguanaConfig.showDebugXP)
{
Minecraft mc = Minecraft.getMinecraft();
EntityPlayer player = mc.thePlayer;
if (!player.isDead && mc.gameSettings.showDebugInfo) {
ItemStack equipped = player.getCurrentEquippedItem();
if (equipped != null && equipped.getItem() != null && equipped.getItem() instanceof ToolCore)
{
NBTTagCompound tags = equipped.getTagCompound().getCompoundTag("InfiTool");
int level = tags.getInteger("ToolLevel");
int hLevel = tags.hasKey("HarvestLevel") ? hLevel = tags.getInteger("HarvestLevel") : -1;
event.left.add("");
if (IguanaConfig.showTooltipXP)
{
if (level <= 5)
event.left.add(IguanaLevelingLogic.getXpString(equipped, true));
if (IguanaConfig.levelingPickaxeBoost)
if (hLevel >= TConstructRegistry.getMaterial("Copper").harvestLevel() && hLevel < TConstructRegistry.getMaterial("Manyullyn").harvestLevel()
&& !tags.hasKey("HarvestLevelModified")
&& (equipped.getItem() instanceof Pickaxe || equipped.getItem() instanceof Hammer))
event.left.add(IguanaLevelingLogic.getXpString(equipped, true, true));
}
}
}
}
}
}
@@ -0,0 +1,97 @@
package iguanaman.iguanatweakstconstruct.leveling;
import cpw.mods.fml.common.FMLLog;
import iguanaman.iguanatweakstconstruct.IguanaLevelingLogic;
import iguanaman.iguanatweakstconstruct.util.IguanaLog;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.ActiveToolMod;
import tconstruct.library.tools.HarvestTool;
import tconstruct.library.tools.ToolCore;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
public class LevelingToolMod extends ActiveToolMod {
private static Method ToolStrength;
private static Method EffectiveMaterials;
static {
try {
ToolStrength = HarvestTool.class.getDeclaredMethod("calculateStrength", NBTTagCompound.class, Block.class, int.class);
ToolStrength.setAccessible(true);
EffectiveMaterials = HarvestTool.class.getDeclaredMethod("getEffectiveMaterials");
EffectiveMaterials.setAccessible(true);
} catch (NoSuchMethodException e) {
IguanaLog.error(e);
e.printStackTrace();
}
}
// TODO: make this customizable?
static List<Material> materialBlacklist = Arrays.asList(
Material.leaves, Material.vine, Material.circuits,
Material.glass, Material.piston, Material.snow
);
@Override
public boolean beforeBlockBreak(ToolCore tool, ItemStack stack, int x, int y, int z, EntityLivingBase entity) {
if (!(entity instanceof EntityPlayer)) return false;
// why are you breaking this block with that tool! It's not a harvest tool derp!
if(!(tool instanceof HarvestTool)) return false;
Block block = entity.worldObj.getBlock(x, y, z);
int meta = entity.worldObj.getBlockMetadata(x, y, z);
if (block == null || materialBlacklist.contains(block.blockMaterial)) return false;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
HarvestTool harvestTool = (HarvestTool) tool;
boolean harvestable = false,
effective = false,
strong = false;
try {
harvestable = harvestTool.canHarvestBlock(block, stack);
Float strength = (Float)ToolStrength.invoke(harvestTool, tags, block, meta);
strong = strength >= 1.0f;
Material[] materials = (Material[])EffectiveMaterials.invoke(harvestTool);
for(Material m : materials)
if(m == block.getMaterial())
effective = true;
} catch (IllegalAccessException e) {
IguanaLog.error(e);
e.printStackTrace();
} catch (InvocationTargetException e) {
IguanaLog.error(e);
e.printStackTrace();
}
IguanaLog.trace("Tool is [harvestable: '" + harvestable + "', effective: '" + effective + "', strong: '" + strong + "']");
// only give xp if the use makes sense
if(harvestable && effective && strong)
// TODO: maybe give xp depending on WHAT block was mined? (xp determined by hardness, if it was an ore, etc.)
IguanaLevelingLogic.addXP(stack, (EntityPlayer) entity, 1);
// TODO: Find replacement for canHarvestBlock and getStrVsBlock
//if (tool.canHarvestBlock(block) && tool.getStrVsBlock(stack, block, meta) > 1f)
//IguanaLog.log("xp added");
// TODO: Find replacement for canHarvestBlock and getStrVsBlock
//IguanaLevelingLogic.addXP(stack, (EntityPlayer)entity, 1L);
return false;
}
@Override
public boolean afterBlockBreak() {
IguanaLog.debug("afterBlockBreak is implemented. Somebody tell me that so I can update xp giving.");
return super.afterBlockBreak();
}
}
@@ -1,4 +1,4 @@
package iguanaman.iguanatweakstconstruct.commands;
package iguanaman.iguanatweakstconstruct.leveling.commands;
import iguanaman.iguanatweakstconstruct.IguanaLevelingLogic;
import net.minecraft.command.CommandBase;
@@ -1,4 +1,4 @@
package iguanaman.iguanatweakstconstruct.commands;
package iguanaman.iguanatweakstconstruct.leveling.commands;
import iguanaman.iguanatweakstconstruct.IguanaLevelingLogic;
import net.minecraft.command.CommandBase;
@@ -7,6 +7,8 @@ import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.rcon.RConConsoleSource;
import net.minecraft.util.ChatComponentText;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.ToolCore;
@@ -51,6 +53,7 @@ public class IguanaCommandToolXP extends CommandBase {
if (entityplayermp != icommandsender)
{
// TODO: find replacement for notifyAdmins
// possibly RConConsoleSource?
//notifyAdmins(icommandsender, 1, "Added " + xp + " to %s's tool", new Object[]{entityplayermp.getEntityName()});
}
else
@@ -5,6 +5,8 @@ public class IguanaReference {
public static final String MOD_NAME = "Iguana Tweaks for Tinker's Construct";
public static final String TCON_MOD_ID = "TConstruct";
public static final String PULSE_LEVELING = "ToolLeveling";
public static final String PROXY_CLIENT_CLASS = "iguanaman.iguanatweakstconstruct.proxy.ClientProxy";
public static final String PROXY_SERVER_CLASS = "iguanaman.iguanatweakstconstruct.proxy.CommonProxy";
}
@@ -129,7 +129,7 @@ public class ModifierTweaks
if (IguanaConfig.toolLeveling)
{
IguanaLog.info("Adding leveling active modifier");
TConstructRegistry.activeModifiers.add(0, new IguanaActiveToolMod());
//TConstructRegistry.activeModifiers.add(0, new IguanaActiveToolMod());
}
}
@@ -71,7 +71,7 @@ public class IguanaEventHandler {
event.setResult(Event.Result.DENY);
}
}
/*
@SubscribeEvent
public void onHurt (LivingHurtEvent event)
{
@@ -97,7 +97,7 @@ public class IguanaEventHandler {
ItemStack stack = event.current;
if (stack != null && stack.hasTagCompound() && stack.getItem() instanceof ToolCore)
IguanaLevelingLogic.addXP(stack, player, 1L);
}
}*/
void addDrops(LivingDropsEvent event, ItemStack dropStack)
{
@@ -286,7 +286,8 @@ public class IguanaEventHandler {
}
}
// Leveling
/*
if (event.tool != TinkerTools.arrow)
{
// CREATE TOOLTIP LISTS
@@ -374,7 +375,7 @@ public class IguanaEventHandler {
if (toolTag.hasKey(replaceTag)) toolTag.setInteger(replaceTag, Math.round(toolTag.getInteger(replaceTag) / 2f));
}
}
*/
}
/* Crafting */
@@ -425,7 +426,7 @@ public class IguanaEventHandler {
if (addGravel) event.drops.add(new ItemStack(Blocks.gravel));
}
}
/*
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onRenderGameOverlay(RenderGameOverlayEvent.Text event) {
@@ -459,7 +460,7 @@ public class IguanaEventHandler {
}
}
}
}
}*/
}