Made the power bar on items colorful too \o/

This commit is contained in:
Ellpeck 2016-11-27 21:53:16 +01:00
parent 72c1c276cf
commit 56898a95db
6 changed files with 37 additions and 26 deletions

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.items; package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.data.PlayerData;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
@ -29,8 +30,6 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemWingsOfTheBats extends ItemBase{ public class ItemWingsOfTheBats extends ItemBase{
@ -64,29 +63,29 @@ public class ItemWingsOfTheBats extends ItemBase{
} }
@Override @Override
@SideOnly(Side.CLIENT)
public double getDurabilityForDisplay(ItemStack stack){ public double getDurabilityForDisplay(ItemStack stack){
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(Minecraft.getMinecraft().player); EntityPlayer player = ActuallyAdditions.proxy.getCurrentPlayer();
if(data != null){ if(player != null){
double diff = MAX_FLY_TIME-data.batWingsFlyTime; PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
return 1-(diff/MAX_FLY_TIME); if(data != null){
} double diff = MAX_FLY_TIME-data.batWingsFlyTime;
else{ return 1-(diff/MAX_FLY_TIME);
return super.getDurabilityForDisplay(stack); }
} }
return super.getDurabilityForDisplay(stack);
} }
@Override @Override
@SideOnly(Side.CLIENT)
public int getRGBDurabilityForDisplay(ItemStack stack){ public int getRGBDurabilityForDisplay(ItemStack stack){
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(Minecraft.getMinecraft().player); EntityPlayer player = ActuallyAdditions.proxy.getCurrentPlayer();
if(data != null){ if(player != null){
int curr = data.batWingsFlyTime; PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
return MathHelper.hsvToRGB(Math.max(0.0F, 1-(float)curr/MAX_FLY_TIME)/3.0F, 1.0F, 1.0F); if(data != null){
} int curr = data.batWingsFlyTime;
else{ return MathHelper.hsvToRGB(Math.max(0.0F, 1-(float)curr/MAX_FLY_TIME)/3.0F, 1.0F, 1.0F);
return super.getRGBDurabilityForDisplay(stack); }
} }
return super.getRGBDurabilityForDisplay(stack);
} }
@SubscribeEvent @SubscribeEvent

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.items.base;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.tile.CustomEnergyStorage; import de.ellpeck.actuallyadditions.mod.tile.CustomEnergyStorage;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaForgeUnitsWrapper; import de.ellpeck.actuallyadditions.mod.util.compat.TeslaForgeUnitsWrapper;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil; import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
@ -106,13 +107,10 @@ public abstract class ItemEnergy extends ItemBase{
@Override @Override
public int getRGBDurabilityForDisplay(ItemStack stack){ public int getRGBDurabilityForDisplay(ItemStack stack){
if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){ EntityPlayer player = ActuallyAdditions.proxy.getCurrentPlayer();
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null); if(player != null && player.world != null){
if(storage != null){ float[] color = AssetUtil.getWheelColor(player.world.getTotalWorldTime()%256);
int currEnergy = storage.getEnergyStored(); return MathHelper.rgb(color[0]/255F, color[1]/255F, color[2]/255F);
int maxEnergy = storage.getMaxEnergyStored();
return MathHelper.hsvToRGB(Math.max(0.0F, (float)currEnergy/maxEnergy)/3.0F, 1.0F, 1.0F);
}
} }
return super.getRGBDurabilityForDisplay(stack); return super.getRGBDurabilityForDisplay(stack);
} }

View file

@ -24,6 +24,7 @@ import net.minecraft.block.Block;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -117,4 +118,9 @@ public class ClientProxy implements IProxy{
public void addColoredItem(Item item){ public void addColoredItem(Item item){
COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING.add(item); COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING.add(item);
} }
@Override
public EntityPlayer getCurrentPlayer(){
return Minecraft.getMinecraft().player;
}
} }

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.proxy; package de.ellpeck.actuallyadditions.mod.proxy;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -28,4 +29,6 @@ public interface IProxy{
void addRenderRegister(ItemStack stack, ResourceLocation location, String variant); void addRenderRegister(ItemStack stack, ResourceLocation location, String variant);
void addColoredItem(Item item); void addColoredItem(Item item);
EntityPlayer getCurrentPlayer();
} }

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.proxy; package de.ellpeck.actuallyadditions.mod.proxy;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -44,4 +45,9 @@ public class ServerProxy implements IProxy{
public void addColoredItem(Item item){ public void addColoredItem(Item item){
} }
@Override
public EntityPlayer getCurrentPlayer(){
return null;
}
} }

View file

@ -320,7 +320,6 @@ public final class AssetUtil{
GlStateManager.enableFog(); GlStateManager.enableFog();
} }
@SideOnly(Side.CLIENT)
public static float[] getWheelColor(float pos){ public static float[] getWheelColor(float pos){
if(pos < 85.0f){ if(pos < 85.0f){
return new float[]{pos*3.0F, 255.0f-pos*3.0f, 0.0f}; return new float[]{pos*3.0F, 255.0f-pos*3.0f, 0.0f};