Fix a typo in EnergyValueRegistry, more work on some extra commands, and fix a mistake in calculating a stacks energy value in the tooltip handler
This commit is contained in:
parent
4b4abb84f1
commit
56c1a56d26
|
@ -39,7 +39,7 @@ public class ItemTooltipEventHandler
|
|||
if (stack.getStackSize() > 1)
|
||||
{
|
||||
event.toolTip.add(String.format("Exchange Energy (Item): %s", energyValueDecimalFormat.format(energyValue.getEnergyValue())));
|
||||
event.toolTip.add(String.format("Exchange Energy (Stack of %s): %s", event.itemStack.stackSize, energyValueDecimalFormat.format(energyValue.getEnergyValue())));
|
||||
event.toolTip.add(String.format("Exchange Energy (Stack of %s): %s", event.itemStack.stackSize, energyValueDecimalFormat.format(stack.getStackSize() * energyValue.getEnergyValue())));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.knowledge.TransmutationKnowledgeRegistry;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandPlayerForgetCurrentItem extends CommandBase
|
||||
{
|
||||
|
@ -28,6 +35,43 @@ public class CommandPlayerForgetCurrentItem extends CommandBase
|
|||
@Override
|
||||
public void processCommand(ICommandSender commandSender, String[] args)
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException(Messages.Commands.PLAYER_FORGET_CURRENT_ITEM_USAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityPlayer entityPlayer = getPlayer(commandSender, args[1]);
|
||||
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
ItemStack itemStack = ((EntityPlayer) commandSender).getCurrentEquippedItem();
|
||||
if (itemStack != null)
|
||||
{
|
||||
TransmutationKnowledgeRegistry.getInstance().makePlayerForget(entityPlayer, itemStack);
|
||||
func_152373_a(commandSender, this, Messages.Commands.PLAYER_FORGET_CURRENT_ITEM_SUCCESS, new Object[]{commandSender.getCommandSenderName(), entityPlayer.getCommandSenderName(), itemStack.func_151000_E()});
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException(Messages.Commands.NO_ITEM);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException(Messages.Commands.PLAYER_NOT_FOUND_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender commandSender, String[] args)
|
||||
{
|
||||
if (args.length == 2)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, FMLCommonHandler.instance().getMinecraftServerInstance().getAllUsernames());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.knowledge.AbilityRegistry;
|
||||
import com.pahimar.ee3.knowledge.TransmutationKnowledgeRegistry;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandPlayerLearnCurrentItem extends CommandBase
|
||||
{
|
||||
|
@ -28,6 +36,46 @@ public class CommandPlayerLearnCurrentItem extends CommandBase
|
|||
@Override
|
||||
public void processCommand(ICommandSender commandSender, String[] args)
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
throw new WrongUsageException(Messages.Commands.PLAYER_LEARN_CURRENT_ITEM_USAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityPlayer entityPlayer = getPlayer(commandSender, args[1]);
|
||||
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
ItemStack itemStack = ((EntityPlayer) commandSender).getCurrentEquippedItem();
|
||||
|
||||
if (itemStack != null)
|
||||
{
|
||||
if (AbilityRegistry.getInstance().isLearnable(itemStack))
|
||||
{
|
||||
TransmutationKnowledgeRegistry.getInstance().teachPlayer(entityPlayer, itemStack);
|
||||
func_152373_a(commandSender, this, Messages.Commands.PLAYER_LEARN_CURRENT_ITEM_SUCCESS, new Object[]{commandSender.getCommandSenderName(), entityPlayer.getCommandSenderName(), itemStack.func_151000_E()});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException(Messages.Commands.NO_ITEM);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException(Messages.Commands.PLAYER_NOT_FOUND_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender commandSender, String[] args)
|
||||
{
|
||||
if (args.length == 2)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, FMLCommonHandler.instance().getMinecraftServerInstance().getAllUsernames());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,7 @@ import com.pahimar.ee3.network.message.MessageSetEnergyValue;
|
|||
import com.pahimar.ee3.reference.Files;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import com.pahimar.ee3.reference.Reference;
|
||||
import com.pahimar.ee3.util.SerializationHelper;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
|
@ -20,7 +18,6 @@ import net.minecraft.nbt.JsonToNBT;
|
|||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -96,7 +93,6 @@ public class CommandSetEnergyValue extends CommandBase
|
|||
|
||||
if (wrappedStack != null && newEnergyValue != null && Float.compare(newEnergyValue.getEnergyValue(), 0) > 0)
|
||||
{
|
||||
File energyValuesDataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + Reference.LOWERCASE_MOD_ID + File.separator + "energyvalues");
|
||||
if (args[1].equalsIgnoreCase("pre"))
|
||||
{
|
||||
Map<WrappedStack, EnergyValue> preAssignedValues = SerializationHelper.readEnergyValueStackMapFromJsonFile(Files.PRE_ASSIGNED_ENERGY_VALUES);
|
||||
|
|
|
@ -1,9 +1,22 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.api.EnergyValue;
|
||||
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||
import com.pahimar.ee3.exchange.WrappedStack;
|
||||
import com.pahimar.ee3.network.PacketHandler;
|
||||
import com.pahimar.ee3.network.message.MessageSetEnergyValue;
|
||||
import com.pahimar.ee3.reference.Files;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import com.pahimar.ee3.util.SerializationHelper;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandSetEnergyValueCurrentItem extends CommandBase
|
||||
{
|
||||
|
@ -28,6 +41,70 @@ public class CommandSetEnergyValueCurrentItem extends CommandBase
|
|||
@Override
|
||||
public void processCommand(ICommandSender commandSender, String[] args)
|
||||
{
|
||||
if (args.length < 3)
|
||||
{
|
||||
throw new WrongUsageException(Messages.Commands.SET_ENERGY_VALUE_CURRENT_ITEM_USAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
double energyValue = 0;
|
||||
|
||||
if (args.length >= 3)
|
||||
{
|
||||
energyValue = parseDoubleWithMin(commandSender, args[2], 0);
|
||||
}
|
||||
|
||||
ItemStack itemStack = ((EntityPlayer) commandSender).getCurrentEquippedItem();
|
||||
|
||||
if (itemStack != null)
|
||||
{
|
||||
WrappedStack wrappedStack = new WrappedStack(itemStack);
|
||||
EnergyValue newEnergyValue = new EnergyValue(energyValue);
|
||||
|
||||
if (wrappedStack != null && newEnergyValue != null && Float.compare(newEnergyValue.getEnergyValue(), 0) > 0)
|
||||
{
|
||||
if (args[1].equalsIgnoreCase("pre"))
|
||||
{
|
||||
Map<WrappedStack, EnergyValue> preAssignedValues = SerializationHelper.readEnergyValueStackMapFromJsonFile(Files.PRE_ASSIGNED_ENERGY_VALUES);
|
||||
preAssignedValues.put(wrappedStack, newEnergyValue);
|
||||
|
||||
SerializationHelper.writeEnergyValueStackMapToJsonFile(Files.PRE_ASSIGNED_ENERGY_VALUES, preAssignedValues);
|
||||
EnergyValueRegistry.getInstance().setShouldRegenNextRestart(true);
|
||||
}
|
||||
else if (args[1].equalsIgnoreCase("post"))
|
||||
{
|
||||
EnergyValueRegistry.getInstance().setEnergyValue(wrappedStack, newEnergyValue);
|
||||
|
||||
Map<WrappedStack, EnergyValue> postAssignedValues = SerializationHelper.readEnergyValueStackMapFromJsonFile(Files.POST_ASSIGNED_ENERGY_VALUES);
|
||||
postAssignedValues.put(wrappedStack, newEnergyValue);
|
||||
|
||||
SerializationHelper.writeEnergyValueStackMapToJsonFile(Files.POST_ASSIGNED_ENERGY_VALUES, postAssignedValues);
|
||||
PacketHandler.INSTANCE.sendToAll(new MessageSetEnergyValue(wrappedStack, newEnergyValue));
|
||||
}
|
||||
|
||||
// Notify admins and log the value change
|
||||
func_152373_a(commandSender, this, Messages.Commands.SET_ENERGY_VALUE_CURRENT_ITEM_SUCCESS, new Object[]{commandSender.getCommandSenderName(), args[1], itemStack.func_151000_E(), newEnergyValue.getChatComponent()});
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException(Messages.Commands.SET_ENERGY_VALUE_CURRENT_ITEM_USAGE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException(Messages.Commands.NO_ITEM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender commandSender, String[] args)
|
||||
{
|
||||
if (args.length == 2)
|
||||
{
|
||||
return getListOfStringsMatchingLastWord(args, "pre", "post");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -438,7 +438,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
|
|||
}
|
||||
}
|
||||
}
|
||||
LogHelper.info(String.format("Pass %s: Computed %s values for obejcts in %s ms", passNumber, computedValueCount, System.currentTimeMillis() - passStartTime));
|
||||
LogHelper.info(String.format("Pass %s: Computed %s values for objects in %s ms", passNumber, computedValueCount, System.currentTimeMillis() - passStartTime));
|
||||
}
|
||||
LogHelper.info(String.format("Finished dynamic value computation (computed %s values for objects in %s ms)", totalComputedValueCount, System.currentTimeMillis() - computationStartTime));
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ public final class Messages
|
|||
|
||||
public static final String PLAYER_NOT_FOUND_ERROR = COMMAND_PREFIX + "player-not-found.error";
|
||||
public static final String INVALID_NBT_TAG_ERROR = COMMAND_PREFIX + "invalid-nbt-tag.error";
|
||||
public static final String NO_ITEM = COMMAND_PREFIX + "no-item.error";
|
||||
|
||||
public static final String SET_ENERGY_VALUE_USAGE = COMMAND_PREFIX + Names.Commands.SET_ENERGY_VALUE + ".usage";
|
||||
public static final String SET_ENERGY_VALUE_SUCCESS = COMMAND_PREFIX + Names.Commands.SET_ENERGY_VALUE + ".success";
|
||||
|
|
|
@ -105,6 +105,7 @@ gui.nei.ee3:aludel=Aludel
|
|||
commands.ee3.usage=/ee3
|
||||
commands.ee3.player-not-found.error=Player with name %s was not found on the server
|
||||
commands.ee3.invalid-nbt-tag.error=Data tag parsing failed: %s
|
||||
commands.ee3.no-item.error=No current item
|
||||
commands.ee3.set-energy-value.usage=/ee3 set-energy-value <pre> <item> <value> [data] [dataTag] OR /ee3 set-energy-value <post> <item> <value> [data] [dataTag]
|
||||
commands.ee3.set-energy-value.success=%s set a %s EnergyValue of %s to %s
|
||||
commands.ee3.set-energy-value-current-item.usage=/ee3 set-energy-value-current-item <pre> <value> OR /ee3 set-energy-value-current-item <post> <value>
|
||||
|
|
Loading…
Reference in a new issue