Formatting

This commit is contained in:
oitsjustjose 2016-05-28 12:20:27 -05:00
commit 1c36086b87
7 changed files with 50 additions and 25 deletions

View file

@ -33,11 +33,11 @@ public class TinkersAddons
public void preInit(FMLPreInitializationEvent event)
{
CommonProxy.preInit();
modConfig = new Config(event.getSuggestedConfigurationFile());
modItems = new LibItems();
modModifiers = new LibModifiers();
MinecraftForge.EVENT_BUS.register(modConfig);
MinecraftForge.EVENT_BUS.register(new ModAutoRepair());
}

View file

@ -10,7 +10,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class Config
{
public Configuration config;
public boolean enableAutoRepair;
public boolean enableExtraModifierLvl1;
public boolean enableExtraModifierLvl2;
@ -29,11 +29,11 @@ public class Config
property = config.get(config.CATEGORY_GENERAL, "Enable Auto-Repair", true).setRequiresMcRestart(true);
property.comment = "Allows you to enable or disable the auto-repair trait";
enableAutoRepair = property.getBoolean();
property = config.get(config.CATEGORY_GENERAL, "Enable 1st bonus modifier mod for tools", true).setRequiresMcRestart(true);
property.comment = "Re-adds the diamond + gold block recipe to increase modifiers on a tool if enabled";
enableExtraModifierLvl1 = property.getBoolean();
property = config.get(config.CATEGORY_GENERAL, "Enable 2nd bonus modifier mod for tools", true).setRequiresMcRestart(true);
property.comment = "Re-adds the diamond block + gold apple recipe to increase modifiers on a tool if enabled";
enableExtraModifierLvl2 = property.getBoolean();
@ -41,11 +41,11 @@ public class Config
property = config.get(config.CATEGORY_GENERAL, "Enable 3rd bonus modifier mod for tools", true).setRequiresMcRestart(true);
property.comment = "Re-adds the nether star recipe to increase modifiers on a tool if enabled";
enableExtraModifierLvl3 = property.getBoolean();
if (config.hasChanged())
config.save();
}
@SubscribeEvent
public void onConfigurationChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event)
{

View file

@ -13,11 +13,11 @@ public class Lib
public static final String CLIENT_PROXY = "com.oitsjustjose.tinkers_addons.util.ClientProxy";
public static final String COMMON_PROXY = "com.oitsjustjose.tinkers_addons.util.CommonProxy";
public static final String GUI_FACTORY = "com.oitsjustjose.tinkers_addons.gui.ConfigGUI$GUIFactory";
public static final String TAG_AUTO_REPAIR = "Auto-Repair";
public static final String TAG_AUTO_REPAIR_COOLDOWN = "Last Auto-Repair";
public static final String TAG_REDSTONE_FLUX = "Redstone Flux";
private static final ArrayList<Item> allItems = new ArrayList<Item>();
private static final ArrayList<Block> allBlocks = new ArrayList<Block>();

View file

@ -7,6 +7,7 @@ import net.minecraft.item.Item;
public class LibItems
{
public Item materials;
public LibItems()
{
materials = new ItemModMaterial();

View file

@ -6,7 +6,7 @@ import org.apache.logging.log4j.Logger;
public class Log
{
private static Logger LOGGER = LogManager.getLogger(Lib.MODID);
public static void warn(String msg)
{
LOGGER.warn(msg);

View file

@ -2,28 +2,30 @@ package com.oitsjustjose.tinkers_addons.modifiers;
import java.util.ArrayList;
import com.oitsjustjose.tinkers_addons.TinkersAddons;
import com.oitsjustjose.tinkers_addons.lib.Lib;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.modifiers.Modifier;
import slimeknights.tconstruct.library.modifiers.ModifierAspect;
import slimeknights.tconstruct.library.tools.ToolCore;
import slimeknights.tconstruct.library.tools.ToolNBT;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.ToolHelper;
public class ModAutoRepair extends Modifier
{
//TODO: actually keep track of auto-repair level now!
public ModAutoRepair()
{
super("auto-repair");
addAspects(new ModifierAspect.LevelAspect(this, 5), new ModifierAspect.DataAspect(this, 0x2CA401), ModifierAspect.freeModifier);
this.addAspects(new ModifierAspect.LevelAspect(this, 5), new ModifierAspect.DataAspect(this, 0x2CA401), ModifierAspect.freeModifier);
this.addItem(new ItemStack(TinkersAddons.modItems.materials, 1, 0), 1, 1);
}
@Override
@ -35,10 +37,7 @@ public class ModAutoRepair extends Modifier
@Override
public void applyEffect(NBTTagCompound rootCompound, NBTTagCompound modifierTag)
{
ToolNBT toolData = TagUtil.getOriginalToolStats(rootCompound);
NBTTagCompound tag = TagUtil.getToolTag(rootCompound);
int autoRepairLevel = toolData.get().getInteger(Lib.TAG_AUTO_REPAIR) + 1;
tag.setInteger(Lib.TAG_AUTO_REPAIR, autoRepairLevel);
// Nothing special to do here
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
@ -49,6 +48,7 @@ public class ModAutoRepair extends Modifier
EntityPlayer player = event.entityPlayer;
ArrayList<ItemStack> tinkersTools = new ArrayList<ItemStack>();
int autoRepairLevel = 0;
for (ItemStack iterStack : player.inventory.mainInventory)
if (iterStack != null && iterStack.getItem() instanceof ToolCore)
tinkersTools.add(iterStack);
@ -56,14 +56,38 @@ public class ModAutoRepair extends Modifier
for (ItemStack iterStack : tinkersTools)
{
NBTTagCompound tag = TagUtil.getToolTag(iterStack.getTagCompound());
int autoRepairLevel = tag.getInteger(Lib.TAG_AUTO_REPAIR);
NBTTagList tagList = TagUtil.getModifiersTagList(iterStack);
for (int i = 0; i < tagList.tagCount(); i++)
{
if (tagList.get(i) instanceof NBTTagCompound)
{
NBTTagCompound currTag = (NBTTagCompound) tagList.get(i);
if (currTag.getString("identifier").contains("auto-repair"))
{
autoRepairLevel = currTag.getInteger("level");
}
}
}
long lastRepairTime = tag.getLong(Lib.TAG_AUTO_REPAIR_COOLDOWN);
// Calculates that the last repair time stored minus the current time is less than or equal to 30 seconds divided by auto-repair level
if ((System.currentTimeMillis() - lastRepairTime) >= (15000))
if ((System.currentTimeMillis() - lastRepairTime) >= (getRepairCooldown(player)) && autoRepairLevel > 0)
{
ToolHelper.healTool(iterStack, autoRepairLevel, event.entityPlayer);
tag.setLong(Lib.TAG_AUTO_REPAIR_COOLDOWN, System.currentTimeMillis());
}
}
}
int getRepairCooldown(EntityPlayer player)
{
World world = player.getEntityWorld();
int rand = world.rand.nextInt(999);
if (player.dimension == -1)
return 10000 + rand;
if (world.canSeeSky(player.getPosition()) && !world.isRaining())
return 12500 + rand;
else
return 15000 + rand;
}
}

View file

@ -14,10 +14,10 @@ public class ModExtraModifier extends Modifier
public ModExtraModifier(int level)
{
super("bonus-modifier_" + level);
this.addAspects(new ModifierAspect.SingleAspect(this), new ModifierAspect.DataAspect(this, 0x8cf4e2));
this.addItem(new ItemStack(TinkersAddons.modItems.materials, 1, level), 1, 1);
this.addAspects(new ModifierAspect.SingleAspect(this), new ModifierAspect.DataAspect(this, 0x8cf4e2));
this.addItem(new ItemStack(TinkersAddons.modItems.materials, 1, level), 1, 1);
}
@Override
public boolean isHidden()
{
@ -27,9 +27,9 @@ public class ModExtraModifier extends Modifier
@Override
public void applyEffect(NBTTagCompound rootCompound, NBTTagCompound modifierTag)
{
ToolNBT data = TagUtil.getToolStats(rootCompound);
data.modifiers++;
ToolNBT data = TagUtil.getToolStats(rootCompound);
data.modifiers++;
TagUtil.setToolTag(rootCompound, data.get());
TagUtil.setToolTag(rootCompound, data.get());
}
}