Prevent duplicate creation of the AutoRepair modifier
This commit is contained in:
parent
cc5f2fd5ee
commit
b37984d25e
2 changed files with 68 additions and 67 deletions
|
|
@ -16,7 +16,7 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
|||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
|
||||
@Mod(modid = Lib.MODID, name = Lib.NAME, version = Lib.VERSION, guiFactory = Lib.GUI_FACTORY, dependencies = "required-after:tconstruct@[1.12-2.7.2.19,);" + "required-after:mantle@[1.12-1.3.1.18,)")
|
||||
@Mod(modid = Lib.MODID, name = Lib.NAME, version = Lib.VERSION, guiFactory = Lib.GUI_FACTORY, dependencies = "required-after:tconstruct@[1.12-2.7.3.30,);" + "required-after:mantle@[1.12-1.3.1.21,)")
|
||||
public class TinkersAddons
|
||||
{
|
||||
@Instance(Lib.MODID)
|
||||
|
|
@ -36,7 +36,6 @@ public class TinkersAddons
|
|||
MinecraftForge.EVENT_BUS.register(clientRegistry);
|
||||
modItems = new LibItems();
|
||||
modModifiers = new LibModifiers();
|
||||
MinecraftForge.EVENT_BUS.register(new ModAutoRepair());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
|
@ -21,79 +22,80 @@ import slimeknights.tconstruct.library.utils.ToolHelper;
|
|||
|
||||
public class ModAutoRepair extends Modifier
|
||||
{
|
||||
public ModAutoRepair()
|
||||
{
|
||||
super("auto-repair");
|
||||
this.addAspects(new ModifierAspect.LevelAspect(this, 5), new ModifierAspect.DataAspect(this, 0x2CA401), ModifierAspect.freeModifier);
|
||||
this.addItem(new ItemStack(TinkersAddons.modItems.MODIFIERS, 1, 0), 1, 1);
|
||||
}
|
||||
public ModAutoRepair()
|
||||
{
|
||||
super("auto-repair");
|
||||
this.addAspects(new ModifierAspect.LevelAspect(this, 5), new ModifierAspect.DataAspect(this, 0x2CA401), ModifierAspect.freeModifier);
|
||||
this.addItem(new ItemStack(TinkersAddons.modItems.MODIFIERS, 1, 0), 1, 1);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip(NBTTagCompound modifierTag, boolean detailed)
|
||||
{
|
||||
return super.getTooltip(modifierTag, detailed);
|
||||
}
|
||||
@Override
|
||||
public String getTooltip(NBTTagCompound modifierTag, boolean detailed)
|
||||
{
|
||||
return super.getTooltip(modifierTag, detailed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyEffect(NBTTagCompound rootCompound, NBTTagCompound modifierTag)
|
||||
{
|
||||
// Nothing special to do here
|
||||
}
|
||||
@Override
|
||||
public void applyEffect(NBTTagCompound rootCompound, NBTTagCompound modifierTag)
|
||||
{
|
||||
// Nothing special to do here
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onUpdate(PlayerEvent event)
|
||||
{
|
||||
if (event.getEntityPlayer() == null)
|
||||
return;
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onUpdate(PlayerEvent event)
|
||||
{
|
||||
if (event.getEntityPlayer() == null)
|
||||
return;
|
||||
|
||||
EntityPlayer player = event.getEntityPlayer();
|
||||
ArrayList<ItemStack> tinkersTools = new ArrayList<ItemStack>();
|
||||
int autoRepairLevel;
|
||||
for (ItemStack iterStack : player.inventory.mainInventory)
|
||||
if (iterStack != null && iterStack.getItem() instanceof ToolCore)
|
||||
tinkersTools.add(iterStack);
|
||||
EntityPlayer player = event.getEntityPlayer();
|
||||
ArrayList<ItemStack> tinkersTools = new ArrayList<ItemStack>();
|
||||
int autoRepairLevel;
|
||||
for (ItemStack iterStack : player.inventory.mainInventory)
|
||||
if (iterStack != null && iterStack.getItem() instanceof ToolCore)
|
||||
tinkersTools.add(iterStack);
|
||||
|
||||
// Works to include items held in the second hand
|
||||
if (player.getHeldItemOffhand() != null && player.getHeldItemOffhand().getItem() instanceof ToolCore)
|
||||
tinkersTools.add(player.getHeldItemOffhand());
|
||||
// Works to include items held in the second hand
|
||||
if (player.getHeldItemOffhand() != null && player.getHeldItemOffhand().getItem() instanceof ToolCore)
|
||||
tinkersTools.add(player.getHeldItemOffhand());
|
||||
|
||||
for (ItemStack iterStack : tinkersTools)
|
||||
{
|
||||
autoRepairLevel = 0;
|
||||
NBTTagCompound tag = TagUtil.getToolTag(iterStack.getTagCompound());
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ItemStack iterStack : tinkersTools)
|
||||
{
|
||||
autoRepairLevel = 0;
|
||||
NBTTagCompound tag = TagUtil.getToolTag(iterStack.getTagCompound());
|
||||
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);
|
||||
long lastRepairTime = tag.getLong(Lib.TAG_AUTO_REPAIR_COOLDOWN);
|
||||
|
||||
if (autoRepairLevel > 0 && (System.currentTimeMillis() - lastRepairTime) >= (getRepairCooldown(player)) && !player.isSwingInProgress)
|
||||
{
|
||||
ToolHelper.healTool(iterStack, autoRepairLevel, player);
|
||||
tag.setLong(Lib.TAG_AUTO_REPAIR_COOLDOWN, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (autoRepairLevel > 0 && (System.currentTimeMillis() - lastRepairTime) >= (getRepairCooldown(player)) && !player.isSwingInProgress)
|
||||
{
|
||||
ToolHelper.healTool(iterStack, autoRepairLevel, player);
|
||||
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())
|
||||
if (world.getWorldTime() >= 0 && world.getWorldTime() <= 13000)
|
||||
return 12500 + rand;
|
||||
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())
|
||||
if (world.getWorldTime() >= 0 && world.getWorldTime() <= 13000)
|
||||
return 12500 + rand;
|
||||
|
||||
return 15000 + rand;
|
||||
}
|
||||
return 15000 + rand;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue