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;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
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.LivingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemWingsOfTheBats extends ItemBase{
@ -64,29 +63,29 @@ public class ItemWingsOfTheBats extends ItemBase{
}
@Override
@SideOnly(Side.CLIENT)
public double getDurabilityForDisplay(ItemStack stack){
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(Minecraft.getMinecraft().player);
if(data != null){
double diff = MAX_FLY_TIME-data.batWingsFlyTime;
return 1-(diff/MAX_FLY_TIME);
}
else{
return super.getDurabilityForDisplay(stack);
EntityPlayer player = ActuallyAdditions.proxy.getCurrentPlayer();
if(player != null){
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
if(data != null){
double diff = MAX_FLY_TIME-data.batWingsFlyTime;
return 1-(diff/MAX_FLY_TIME);
}
}
return super.getDurabilityForDisplay(stack);
}
@Override
@SideOnly(Side.CLIENT)
public int getRGBDurabilityForDisplay(ItemStack stack){
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(Minecraft.getMinecraft().player);
if(data != null){
int curr = data.batWingsFlyTime;
return MathHelper.hsvToRGB(Math.max(0.0F, 1-(float)curr/MAX_FLY_TIME)/3.0F, 1.0F, 1.0F);
}
else{
return super.getRGBDurabilityForDisplay(stack);
EntityPlayer player = ActuallyAdditions.proxy.getCurrentPlayer();
if(player != null){
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
if(data != null){
int curr = data.batWingsFlyTime;
return MathHelper.hsvToRGB(Math.max(0.0F, 1-(float)curr/MAX_FLY_TIME)/3.0F, 1.0F, 1.0F);
}
}
return super.getRGBDurabilityForDisplay(stack);
}
@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.tile.CustomEnergyStorage;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaForgeUnitsWrapper;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.minecraft.creativetab.CreativeTabs;
@ -106,13 +107,10 @@ public abstract class ItemEnergy extends ItemBase{
@Override
public int getRGBDurabilityForDisplay(ItemStack stack){
if(stack.hasCapability(CapabilityEnergy.ENERGY, null)){
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
if(storage != null){
int currEnergy = storage.getEnergyStored();
int maxEnergy = storage.getMaxEnergyStored();
return MathHelper.hsvToRGB(Math.max(0.0F, (float)currEnergy/maxEnergy)/3.0F, 1.0F, 1.0F);
}
EntityPlayer player = ActuallyAdditions.proxy.getCurrentPlayer();
if(player != null && player.world != null){
float[] color = AssetUtil.getWheelColor(player.world.getTotalWorldTime()%256);
return MathHelper.rgb(color[0]/255F, color[1]/255F, color[2]/255F);
}
return super.getRGBDurabilityForDisplay(stack);
}

View file

@ -24,6 +24,7 @@ import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
@ -117,4 +118,9 @@ public class ClientProxy implements IProxy{
public void addColoredItem(Item 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;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
@ -28,4 +29,6 @@ public interface IProxy{
void addRenderRegister(ItemStack stack, ResourceLocation location, String variant);
void addColoredItem(Item item);
EntityPlayer getCurrentPlayer();
}

View file

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

View file

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