Large improvement to power system, fixes #204
This commit is contained in:
parent
3f47e89f85
commit
cf34fe1f1f
10 changed files with 128 additions and 97 deletions
|
@ -6,7 +6,12 @@ import net.minecraft.block.BlockContainer;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import techreborn.api.IListInfoProvider;
|
||||
import techreborn.api.power.IEnergyInterfaceItem;
|
||||
import techreborn.cofhLib.util.helpers.MathHelper;
|
||||
import techreborn.lib.ChatColor;
|
||||
import techreborn.util.Color;
|
||||
|
||||
public class StackToolTipEvent {
|
||||
|
||||
|
@ -14,7 +19,23 @@ public class StackToolTipEvent {
|
|||
public void handleItemTooltipEvent(ItemTooltipEvent event) {
|
||||
if(event.itemStack.getItem() instanceof IListInfoProvider){
|
||||
((IListInfoProvider) event.itemStack.getItem()).addInfo(event.toolTip, false);
|
||||
} else{
|
||||
} else if (event.itemStack.getItem() instanceof IEnergyInterfaceItem){
|
||||
int percentage = percentage((int)((IEnergyInterfaceItem) event.itemStack.getItem()).getMaxPower(event.itemStack), (int)((IEnergyInterfaceItem) event.itemStack.getItem()).getEnergy(event.itemStack));
|
||||
ChatColor color;
|
||||
if(percentage<= 10){
|
||||
color = ChatColor.RED;
|
||||
} else if(percentage >= 75){
|
||||
color = ChatColor.GREEN;
|
||||
} else {
|
||||
color = ChatColor.YELLOW;
|
||||
}
|
||||
event.toolTip.add(color + "" + (int)((IEnergyInterfaceItem) event.itemStack.getItem()).getEnergy(event.itemStack) + ChatColor.LIGHT_PURPLE + " stored eu");
|
||||
event.toolTip.add(Color.GREEN + "" + (int)((IEnergyInterfaceItem) event.itemStack.getItem()).getMaxPower(event.itemStack) + ChatColor.LIGHT_PURPLE + " max eu");
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)){
|
||||
event.toolTip.add(ChatColor.GREEN +"" + percentage + "%" + ChatColor.LIGHT_PURPLE +" charged");
|
||||
event.toolTip.add(Color.GREEN + "" + (int)((IEnergyInterfaceItem) event.itemStack.getItem()).getMaxTransfer(event.itemStack) + ChatColor.LIGHT_PURPLE + " eu/tick in/out");
|
||||
}
|
||||
} else {
|
||||
Block block = Block.getBlockFromItem(event.itemStack.getItem());
|
||||
if(block != null && block instanceof BlockContainer && block.getClass().getCanonicalName().startsWith("techreborn.")){
|
||||
TileEntity tile = block.createTileEntity(Minecraft.getMinecraft().theWorld, event.itemStack.getItemDamage());
|
||||
|
@ -25,4 +46,10 @@ public class StackToolTipEvent {
|
|||
}
|
||||
}
|
||||
|
||||
public int percentage(int MaxValue, int CurrentValue) {
|
||||
if (CurrentValue == 0)
|
||||
return 0;
|
||||
return (int) ((CurrentValue * 100.0f) / MaxValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,23 +41,6 @@ public class ItemLithiumBatpack extends PoweredArmor {
|
|||
return "techreborn:" + "textures/models/lithiumbatpack.png";
|
||||
}
|
||||
|
||||
@SuppressWarnings(
|
||||
{"rawtypes", "unchecked"})
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
|
||||
ItemStack itemStack = new ItemStack(this, 1);
|
||||
if (getChargedItem(itemStack) == this && ElectricItem.manager != null) {
|
||||
ItemStack charged = new ItemStack(this, 1);
|
||||
ElectricItem.manager.charge(charged, 2147483647, 2147483647, true,
|
||||
false);
|
||||
itemList.add(charged);
|
||||
}
|
||||
if (getEmptyItem(itemStack) == this) {
|
||||
itemList.add(new ItemStack(this, 1, getMaxDamage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getMaxPower(ItemStack stack) {
|
||||
return maxCharge;
|
||||
|
|
|
@ -72,26 +72,6 @@ public class ItemCloakingDevice extends PoweredItem {
|
|||
return Teir;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
|
||||
ItemStack itemStack = new ItemStack(this, 1);
|
||||
if (getChargedItem(itemStack) == this) {
|
||||
ItemStack charged = new ItemStack(this, 1);
|
||||
setEnergy(MaxCharge, charged);
|
||||
itemList.add(charged);
|
||||
}
|
||||
if (getEmptyItem(itemStack) == this) {
|
||||
itemList.add(new ItemStack(this, 1, getMaxDamage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDurabilityForDisplay(ItemStack stack) {
|
||||
double charge = (getEnergy(stack) / getMaxCharge(stack));
|
||||
return 1 - charge;
|
||||
|
||||
}
|
||||
|
||||
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
|
||||
ItemStack itemstack1 = player.getCurrentArmor(3);
|
||||
|
||||
|
|
|
@ -42,22 +42,6 @@ public class ItemOmniTool extends PoweredPickaxe{
|
|||
this.itemIcon = iconRegister.registerIcon("techreborn:" + "tool/omnitool");
|
||||
}
|
||||
|
||||
@SuppressWarnings(
|
||||
{"rawtypes", "unchecked"})
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
|
||||
ItemStack itemStack = new ItemStack(this, 1);
|
||||
|
||||
if (getChargedItem(itemStack) == this) {
|
||||
ItemStack charged = new ItemStack(this, 1);
|
||||
setEnergy(maxCharge, charged);
|
||||
itemList.add(charged);
|
||||
}
|
||||
if (getEmptyItem(itemStack) == this) {
|
||||
itemList.add(new ItemStack(this, 1, getMaxDamage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockDestroyed(ItemStack stack, World world, Block block,
|
||||
int par4, int par5, int par6, EntityLivingBase entityLiving) {
|
||||
|
|
|
@ -51,22 +51,6 @@ public class ItemRockCutter extends PoweredPickaxe {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings(
|
||||
{"rawtypes", "unchecked"})
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
|
||||
ItemStack itemStack = new ItemStack(this, 1);
|
||||
if (getChargedItem(itemStack) == this) {
|
||||
ItemStack charged = new ItemStack(this, 1);
|
||||
setEnergy(maxCharge, charged);
|
||||
itemList.add(charged);
|
||||
}
|
||||
|
||||
if (getEmptyItem(itemStack) == this) {
|
||||
itemList.add(new ItemStack(this, 1, getMaxDamage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHarvestBlock(Block block, ItemStack stack) {
|
||||
if(Items.diamond_pickaxe.canHarvestBlock(block, stack)) {
|
||||
|
|
64
src/main/java/techreborn/lib/ChatColor.java
Normal file
64
src/main/java/techreborn/lib/ChatColor.java
Normal file
|
@ -0,0 +1,64 @@
|
|||
package techreborn.lib;
|
||||
|
||||
|
||||
public enum ChatColor {
|
||||
|
||||
BLACK('0'),
|
||||
|
||||
DARK_BLUE('1'),
|
||||
|
||||
DARK_GREEN('2'),
|
||||
|
||||
DARK_AQUA('3'),
|
||||
|
||||
DARK_RED('4'),
|
||||
|
||||
DARK_PURPLE('5'),
|
||||
|
||||
GOLD('6'),
|
||||
|
||||
GRAY('7'),
|
||||
|
||||
DARK_GRAY('8'),
|
||||
|
||||
BLUE('9'),
|
||||
|
||||
GREEN('a'),
|
||||
|
||||
AQUA('b'),
|
||||
|
||||
RED('c'),
|
||||
|
||||
LIGHT_PURPLE('d'),
|
||||
|
||||
YELLOW('e'),
|
||||
|
||||
WHITE('f'),
|
||||
|
||||
MAGIC('k'),
|
||||
|
||||
BOLD('l'),
|
||||
|
||||
STRIKETHROUGH('m'),
|
||||
|
||||
UNDERLINE('n'),
|
||||
|
||||
ITALIC('o'),
|
||||
|
||||
RESET('r');
|
||||
|
||||
public static final char COLOR_CHAR = '\u00A7';
|
||||
|
||||
private final String toString;
|
||||
|
||||
ChatColor(char code) {
|
||||
this.toString = new String(new char[] {COLOR_CHAR, code});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -26,15 +26,18 @@ public abstract class PoweredArmor extends ItemArmor implements IEnergyInterface
|
|||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
|
||||
ItemStack itemStack = new ItemStack(this, 1);
|
||||
itemList.add(itemStack);
|
||||
|
||||
ItemStack charged = new ItemStack(this, 1);
|
||||
setEnergy(getMaxPower(charged), charged);
|
||||
itemList.add(charged);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDurabilityForDisplay(ItemStack stack) {
|
||||
double charge = (getEnergy(stack) / getMaxPower(stack));
|
||||
return 1 - charge;
|
||||
|
||||
if (getChargedItem(itemStack) == this) {
|
||||
ItemStack charged = new ItemStack(this, 1);
|
||||
setEnergy(getMaxCharge(charged), charged);
|
||||
itemList.add(charged);
|
||||
}
|
||||
if (getEmptyItem(itemStack) == this) {
|
||||
itemList.add(new ItemStack(this, 1, getMaxDamage()));
|
||||
}
|
||||
}
|
||||
|
||||
//TechReborn
|
||||
|
|
|
@ -25,15 +25,18 @@ public abstract class PoweredItem extends Item implements IEnergyInterfaceItem,
|
|||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
|
||||
ItemStack itemStack = new ItemStack(this, 1);
|
||||
itemList.add(itemStack);
|
||||
|
||||
ItemStack charged = new ItemStack(this, 1);
|
||||
setEnergy(getMaxPower(charged), charged);
|
||||
itemList.add(charged);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDurabilityForDisplay(ItemStack stack) {
|
||||
double charge = (getEnergy(stack) / getMaxPower(stack));
|
||||
return 1 - charge;
|
||||
|
||||
if (getChargedItem(itemStack) == this) {
|
||||
ItemStack charged = new ItemStack(this, 1);
|
||||
setEnergy(getMaxCharge(charged), charged);
|
||||
itemList.add(charged);
|
||||
}
|
||||
if (getEmptyItem(itemStack) == this) {
|
||||
itemList.add(new ItemStack(this, 1, getMaxDamage()));
|
||||
}
|
||||
}
|
||||
|
||||
//TechReborn
|
||||
|
|
|
@ -27,16 +27,18 @@ public abstract class PoweredPickaxe extends ItemPickaxe implements IEnergyInter
|
|||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
|
||||
ItemStack itemStack = new ItemStack(this, 1);
|
||||
itemList.add(itemStack);
|
||||
|
||||
if (getChargedItem(itemStack) == this) {
|
||||
ItemStack charged = new ItemStack(this, 1);
|
||||
setEnergy(getMaxCharge(charged), charged);
|
||||
itemList.add(charged);
|
||||
}
|
||||
if (getEmptyItem(itemStack) == this) {
|
||||
itemList.add(new ItemStack(this, 1, getMaxDamage()));
|
||||
ItemStack charged = new ItemStack(this, 1);
|
||||
setEnergy(getMaxPower(charged), charged);
|
||||
itemList.add(charged);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDurabilityForDisplay(ItemStack stack) {
|
||||
double charge = (getEnergy(stack) / getMaxPower(stack));
|
||||
return 1 - charge;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//TechReborn
|
||||
|
|
|
@ -19,6 +19,7 @@ import techreborn.api.IListInfoProvider;
|
|||
import techreborn.api.power.IEnergyInterfaceTile;
|
||||
import techreborn.asm.Strippable;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.lib.ChatColor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -289,9 +290,9 @@ public abstract class TilePowerAcceptor extends RFProviderTile implements
|
|||
|
||||
@Override
|
||||
public void addInfo(List<String> info, boolean isRealTile) {
|
||||
info.add("Energy buffer Size " + getEUString(getMaxPower()));
|
||||
info.add("Max Input " + getEUString(getMaxInput()));
|
||||
info.add("Max Output " + getEUString(getMaxOutput()));
|
||||
info.add(ChatColor.LIGHT_PURPLE + "Energy buffer Size " + ChatColor.GREEN + getEUString(getMaxPower()));
|
||||
info.add(ChatColor.LIGHT_PURPLE +"Max Input " + ChatColor.GREEN + getEUString(getMaxInput()));
|
||||
info.add(ChatColor.LIGHT_PURPLE +"Max Output " + ChatColor.GREEN + getEUString(getMaxOutput()));
|
||||
}
|
||||
|
||||
private String getEUString(double euValue) {
|
||||
|
|
Loading…
Add table
Reference in a new issue