aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/item/general
diff options
context:
space:
mode:
author‭huajijam <strhuaji@gmail.com>2019-02-05 12:26:34 +0800
committer‭huajijam <strhuaji@gmail.com>2019-02-05 12:26:34 +0800
commit40d7e5da9f5b84213e2c3e4596fdc69b94bd523e (patch)
tree900ad3e45065d8ab8229d0f01823054d3b99583f /src/Java/gtPlusPlus/core/item/general
parent8e8a95f5a047a192a64d1e85fb297debac3decbc (diff)
parent3187b70de7bd7bb6eee323dd0f7f9e191fd8e7cf (diff)
downloadGT5-Unofficial-40d7e5da9f5b84213e2c3e4596fdc69b94bd523e.tar.gz
GT5-Unofficial-40d7e5da9f5b84213e2c3e4596fdc69b94bd523e.tar.bz2
GT5-Unofficial-40d7e5da9f5b84213e2c3e4596fdc69b94bd523e.zip
Automatic synchronization
Diffstat (limited to 'src/Java/gtPlusPlus/core/item/general')
-rw-r--r--src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java4
-rw-r--r--src/Java/gtPlusPlus/core/item/general/ItemHealingDevice.java265
2 files changed, 237 insertions, 32 deletions
diff --git a/src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java b/src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java
index c651fb38d9..4abb84a33c 100644
--- a/src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java
+++ b/src/Java/gtPlusPlus/core/item/general/ItemGiantEgg.java
@@ -136,7 +136,9 @@ public class ItemGiantEgg extends BaseItemBurnable {
if (player && NBTUtils.getTagCompound(aStack, "GT.CraftingComponents") == null) {
if (mCorrectStemCells == null) {
if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && Utils.getGregtechSubVersion() > 28) {
- ItemList xl = ItemList.valueOf("Circuit_Chip_Stemcell");
+
+
+ ItemList xl = Utils.getValueOfItemList("Circuit_Chip_Stemcell", ItemList.Circuit_Elite);
if (xl != null && xl.hasBeenSet()) {
mCorrectStemCells = xl.get(1);
}
diff --git a/src/Java/gtPlusPlus/core/item/general/ItemHealingDevice.java b/src/Java/gtPlusPlus/core/item/general/ItemHealingDevice.java
index f458bce139..c8acdc2152 100644
--- a/src/Java/gtPlusPlus/core/item/general/ItemHealingDevice.java
+++ b/src/Java/gtPlusPlus/core/item/general/ItemHealingDevice.java
@@ -8,9 +8,13 @@ import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import baubles.api.BaubleType;
@@ -18,9 +22,12 @@ import baubles.api.IBauble;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.creative.AddToCreativeTab;
import gtPlusPlus.core.lib.CORE;
+import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.math.MathUtils;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.minecraft.PlayerUtils;
+import gtPlusPlus.core.util.sys.KeyboardUtils;
+import gtPlusPlus.xmod.gregtech.common.helpers.ChargingHelper;
import ic2.api.item.ElectricItem;
import ic2.api.item.IElectricItem;
import ic2.api.item.IElectricItemManager;
@@ -47,29 +54,12 @@ public class ItemHealingDevice extends Item implements IElectricItem, IElectricI
if (worldObj.isRemote) {
return;
}
-
- if (player instanceof EntityPlayer){
- for (final ItemStack is : ((EntityPlayer) player).inventory.mainInventory) {
- if (is == itemStack) {
- continue;
- }
- if (is != null) {
- if (is.getItem() instanceof IElectricItem) {
- final IElectricItem electricItem = (IElectricItem) is.getItem();
- this.chargeEU = ElectricItem.manager.getCharge(is);
- }
-
- }
- }
- }
-
-
super.onUpdate(itemStack, worldObj, player, p_77663_4_, p_77663_5_);
}
@Override
public boolean canProvideEnergy(final ItemStack itemStack) {
- return true;
+ return false;
}
@Override
@@ -127,16 +117,43 @@ public class ItemHealingDevice extends Item implements IElectricItem, IElectricI
return (int) r;
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) {
+
+ String aString1 = StatCollector.translateToLocal("GTPP.nanohealer.tooltip.1");
+ String aString2 = StatCollector.translateToLocal("GTPP.nanohealer.tooltip.2");
+ String aString3 = StatCollector.translateToLocal("GTPP.nanohealer.tooltip.3");
+ String aString4 = StatCollector.translateToLocal("GTPP.nanohealer.tooltip.4");
+ String aString5 = StatCollector.translateToLocal("GTPP.nanohealer.tooltip.5");
+ String aStringTooltip = StatCollector.translateToLocal("GTPP.nanohealer.hidden");
+ String aEuInfo = StatCollector.translateToLocal("GTPP.info.euInfo");
+ String aTier = StatCollector.translateToLocal("GTPP.machines.tier");
+ String aInputLimit = StatCollector.translateToLocal("GTPP.info.inputLimit");
+ String aCurrentPower = StatCollector.translateToLocal("GTPP.info.currentPower");
+ String aEU = StatCollector.translateToLocal("GTPP.info.eu");
+ String aEUT = aEU+"/t";
+ boolean isShowing = getShowMessages(stack);
+
+ list.add("");
+
+ list.add(EnumChatFormatting.GREEN + aString1 + EnumChatFormatting.GRAY);
+ list.add(EnumChatFormatting.GREEN + aString2 + EnumChatFormatting.GRAY);
+ list.add(EnumChatFormatting.GREEN + aString3 + EnumChatFormatting.GRAY);
+ list.add(EnumChatFormatting.RED + aString4 + EnumChatFormatting.GRAY);
+
list.add("");
- list.add(EnumChatFormatting.GREEN+"Worn as a Necklace within Baubles."+EnumChatFormatting.GRAY);
- list.add(EnumChatFormatting.GREEN+"Drains 1638400eu to restore hunger."+EnumChatFormatting.GRAY);
- list.add("");
- list.add(EnumChatFormatting.GOLD+"IC2/EU Information"+EnumChatFormatting.GRAY);
- list.add(EnumChatFormatting.GRAY+"Tier: ["+EnumChatFormatting.YELLOW+this.getTier(this.thisStack)+EnumChatFormatting.GRAY+"] Transfer Limit: ["+EnumChatFormatting.YELLOW+this.getTransferLimit(this.thisStack)+EnumChatFormatting.GRAY +"Eu/t]");
- list.add(EnumChatFormatting.GRAY+"Current Power: ["+EnumChatFormatting.YELLOW+(long) this.getCharge(stack)+EnumChatFormatting.GRAY+"Eu] ["+EnumChatFormatting.YELLOW+MathUtils.findPercentage(this.getCharge(stack), this.getMaxCharge(stack))+EnumChatFormatting.GRAY +"%]");
- list.add(EnumChatFormatting.GRAY+"Uses Remaining: ["+EnumChatFormatting.YELLOW+this.secondsLeft(stack)+ EnumChatFormatting.GRAY +"]");
+
+ list.add(EnumChatFormatting.GOLD + aEuInfo + EnumChatFormatting.GRAY);
+ list.add(EnumChatFormatting.GRAY + aTier+": [" + EnumChatFormatting.YELLOW + this.getTier(stack)
+ + EnumChatFormatting.GRAY + "] "+aInputLimit+": [" + EnumChatFormatting.YELLOW
+ + this.getTransferLimit(stack) + EnumChatFormatting.GRAY + aEUT);
+ list.add(EnumChatFormatting.GRAY + aCurrentPower +": [" + EnumChatFormatting.YELLOW + (long) this.getCharge(stack)
+ + EnumChatFormatting.GRAY + aEU +"] [" + EnumChatFormatting.YELLOW
+ + MathUtils.findPercentage(this.getCharge(stack), this.getMaxCharge(stack)) + EnumChatFormatting.GRAY
+ + "%]");
+ list.add(EnumChatFormatting.GOLD + aString5 + EnumChatFormatting.GRAY);
+ list.add(EnumChatFormatting.GOLD + aStringTooltip + " " + (!isShowing ? EnumChatFormatting.DARK_GREEN : EnumChatFormatting.DARK_RED) + !isShowing + EnumChatFormatting.GRAY);
super.addInformation(stack, aPlayer, list, bool);
}
@@ -214,19 +231,205 @@ public class ItemHealingDevice extends Item implements IElectricItem, IElectricI
}
@Override //TODO
- public void onWornTick(final ItemStack arg0, final EntityLivingBase arg1) {
+ public void onWornTick(final ItemStack aBaubleStack, final EntityLivingBase arg1) {
if (!arg1.worldObj.isRemote){
- if (this.getCharge(arg0) >= (1638400/4)){
+
+ //Try Charge First
+
+ //Inv Slots
+ for (final ItemStack aInvStack : ((EntityPlayer) arg1).inventory.mainInventory) {
+ if (aInvStack == aBaubleStack) {
+ continue;
+ }
+
+ if (this.getCharge(aBaubleStack) == this.getMaxCharge(aBaubleStack)) {
+ break;
+ }
+
+ if (aInvStack != null) {
+ if (ChargingHelper.isItemValid(aInvStack)) {
+
+
+ double aTransferRate;
+ double aCurrentChargeForThisBauble;
+ int mTier;
+ final IElectricItem electricItem = (IElectricItem) aInvStack.getItem();
+
+ if (electricItem != null) {
+
+ aTransferRate = electricItem.getTransferLimit(aInvStack);
+ mTier = electricItem.getTier(aInvStack);
+ aCurrentChargeForThisBauble = ElectricItem.manager.getCharge(aBaubleStack);
+
+ if (aCurrentChargeForThisBauble < maxValueEU) {
+ if ((ElectricItem.manager.getCharge(aInvStack) >= aTransferRate)) {
+ if (electricItem.canProvideEnergy(aInvStack)) {
+ double d = ElectricItem.manager.discharge(aInvStack, aTransferRate, mTier, false, true, false);
+ //Logger.INFO("Charging from "+aInvStack.getDisplayName() +" | "+d);
+ ElectricItem.manager.charge(aBaubleStack, d, mTier, true, false);
+ }
+ }
+ }
+ }
+ }
+ }
+ if (this.getCharge(aBaubleStack) <= (this.getMaxCharge(aBaubleStack) - getTransferLimit(aBaubleStack))) {
+ continue;
+ }
+ else {
+ break;
+ }
+ }
+
+
+ //Try Heal
+ if (this.getCharge(aBaubleStack) > 0){
+
+ //health Check
+ float hp = 0;
if (arg1.getHealth() < arg1.getMaxHealth()){
final float rx = arg1.getMaxHealth()-arg1.getHealth();
Logger.INFO("rx:"+rx);
- arg1.heal(rx*2);
- this.discharge(arg0, (1638400/4)*rx, 6, true, true, false);
- PlayerUtils.messagePlayer((EntityPlayer) arg1, "Your NanoBooster Whirs! Leaving you feeling stronger. It Healed "+rx+" hp.");
- PlayerUtils.messagePlayer((EntityPlayer) arg1, "You check it's remaining uses, it has "+this.secondsLeft(arg0)+".");
+ arg1.heal(rx*2);
+ hp = rx;
+ this.discharge(aBaubleStack, (1638400)*rx, 6, true, true, false);
+ }
+
+ //Hunger Check
+ int hunger = 0;
+ if (arg1 instanceof EntityPlayerMP) {
+ EntityPlayerMP g = (EntityPlayerMP) arg1;
+ if (g != null) {
+ hunger = 20 - g.getFoodStats().getFoodLevel();
+ g.getFoodStats().setFoodLevel(g.getFoodStats().getFoodLevel() + hunger);
+ this.discharge(aBaubleStack, (1638400) * hunger, 6, true, true, false);
+ }
+ }
+
+ //Saturation Check
+ float saturation = 0;
+ if (arg1 instanceof EntityPlayerMP) {
+ EntityPlayerMP g = (EntityPlayerMP) arg1;
+ if (g != null) {
+ saturation = 5f - g.getFoodStats().getSaturationLevel();
+ g.getFoodStats().setFoodSaturationLevel(g.getFoodStats().getSaturationLevel() + saturation);
+ this.discharge(aBaubleStack, (1638400) * saturation, 6, true, true, false);
+ }
}
+
+
+ saturation = (int) saturation;
+
+ //Only show Messages if they're enabled.
+ if (getShowMessages(aBaubleStack)) {
+ if (hp > 0 || hunger > 0 || saturation > 0)
+ PlayerUtils.messagePlayer((EntityPlayer) arg1,
+ "Your NanoBooster Whirs! Leaving you feeling stronger.");
+
+ if (hp > 0)
+ PlayerUtils.messagePlayer((EntityPlayer) arg1, "Healed " + hp + " hp.");
+
+ if (hunger > 0)
+ PlayerUtils.messagePlayer((EntityPlayer) arg1, "Healed " + hunger + " hunger.");
+
+ if (saturation > 0)
+ PlayerUtils.messagePlayer((EntityPlayer) arg1, "Satured Hunger by " + saturation + ".");
+
+ if (hp > 0 || hunger > 0 || saturation > 0)
+ PlayerUtils.messagePlayer((EntityPlayer) arg1,
+ "You check it's remaining uses, it has " + (int) this.secondsLeft(aBaubleStack) + ".");
+
+ }
+
+
+
+
+ }
+ }
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ private static boolean createNBT(ItemStack rStack){
+ final NBTTagCompound tagMain = new NBTTagCompound();
+ tagMain.setBoolean("ShowMSG", false);
+ rStack.setTagCompound(tagMain);
+ return true;
+ }
+
+ public static final boolean getShowMessages(final ItemStack aStack) {
+ NBTTagCompound aNBT = aStack.getTagCompound();
+ if (aNBT == null) {
+ if (!createNBT(aStack)) {
+ return false;
+ }
+ else {
+ aNBT = aStack.getTagCompound();
+ }
+ }
+ return aNBT.getBoolean("ShowMSG");
+
+ }
+
+ public static final boolean setShowMessages(final ItemStack aStack, final boolean aShow) {
+ NBTTagCompound aNBT = aStack.getTagCompound();
+ if (aNBT == null) {
+ if (!createNBT(aStack)) {
+ return false;
+ } else {
+ aNBT = aStack.getTagCompound();
}
}
+ aNBT.setBoolean("ShowMSG", aShow);
+ return true;
+ }
+
+ @Override
+ public boolean onItemUse(ItemStack p_77648_1_, EntityPlayer p_77648_2_, World p_77648_3_, int p_77648_4_,
+ int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) {
+ // TODO Auto-generated method stub
+ return super.onItemUse(p_77648_1_, p_77648_2_, p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_8_,
+ p_77648_9_, p_77648_10_);
+ }
+
+ @Override
+ public ItemStack onItemRightClick(ItemStack aStack, World aWorld, EntityPlayer aPlayer) {
+ ItemStack superStack = super.onItemRightClick(aStack, aWorld, aPlayer);
+ boolean isShiftHeld = KeyboardUtils.isShiftKeyDown();
+ if (isShiftHeld) {
+ boolean oldState = getShowMessages(superStack);
+ boolean newState = Utils.invertBoolean(oldState);
+ ItemHealingDevice.setShowMessages(superStack, newState);
+ PlayerUtils.messagePlayer(aPlayer, (!oldState ? "Showing info messages" : "Hiding info messages"));
+ }
+ return superStack;
+ }
+
+ @Override
+ public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player) {
+ return true;
}
+
+
+
}