Skip to content

Commit

Permalink
fix: shift infinite rainbow based on real time
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus8448 committed Oct 8, 2024
1 parent d241854 commit 6ed5986
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 22 deletions.
5 changes: 0 additions & 5 deletions src/main/java/dev/galacticraft/mod/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import net.minecraft.network.chat.TextColor;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -706,10 +705,6 @@ static int getStorageLevelColor(double scale) {
static Style getStorageLevelStyle(double scale) {
return Style.EMPTY.withColor(TextColor.fromRgb(getStorageLevelColor(scale)));
}

static Style getRainbow(int ticks) {
return Style.EMPTY.withColor(TextColor.fromRgb(Mth.hsvToRgb(ticks / 1000.0f, 1, 1)));
}
}
}

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/dev/galacticraft/mod/client/util/ColorUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2019-2024 Team Galacticraft
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package dev.galacticraft.mod.client.util;

import net.minecraft.util.Mth;

public class ColorUtil {
public static int getRainbow(long interval) {
return Mth.hsvToRgb((float)(System.currentTimeMillis() % interval) / (float)interval, 1.0F, 1.0F);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class BatteryItem extends Item implements SimpleEnergyItem {
private final long transfer;

public BatteryItem(Properties settings, long capacity, long transfer) {
super(settings.stacksTo(1));
super(settings);
this.capacity = capacity;
this.transfer = transfer;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/galacticraft/mod/content/item/GCItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ public class GCItems {
// this.additionsSlotDescription = component5;

// BATTERIES
public static final Item BATTERY = new BatteryItem(new Item.Properties(), 15000, 500);
public static final Item INFINITE_BATTERY = new InfiniteBatteryItem(new Item.Properties().rarity(Rarity.EPIC));
public static final Item BATTERY = new BatteryItem(new Item.Properties().stacksTo(1), 15000, 500);
public static final Item INFINITE_BATTERY = new InfiniteBatteryItem(new Item.Properties().stacksTo(1).rarity(Rarity.EPIC));

//FLUID BUCKETS
public static final Item CRUDE_OIL_BUCKET = new BucketItem(GCFluids.CRUDE_OIL, new Item.Properties().craftRemainder(Items.BUCKET).stacksTo(1));
Expand All @@ -406,7 +406,7 @@ public class GCItems {
public static final Item SMALL_OXYGEN_TANK = new OxygenTankItem(new Item.Properties(), 1620 * 10); // 16200 ticks
public static final Item MEDIUM_OXYGEN_TANK = new OxygenTankItem(new Item.Properties(), 1620 * 20); //32400 ticks
public static final Item LARGE_OXYGEN_TANK = new OxygenTankItem(new Item.Properties(), 1620 * 30); //48600 ticks
public static final Item INFINITE_OXYGEN_TANK = new InfiniteOxygenTankItem(new Item.Properties().rarity(Rarity.EPIC));
public static final Item INFINITE_OXYGEN_TANK = new InfiniteOxygenTankItem(new Item.Properties().stacksTo(1).rarity(Rarity.EPIC));

public static final Item SHIELD_CONTROLLER = new AccessoryItem(new Item.Properties());
public static final Item FREQUENCY_MODULE = new FrequencyModuleItem(new Item.Properties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
package dev.galacticraft.mod.content.item;

import dev.galacticraft.mod.Constant;
import dev.galacticraft.mod.client.util.ColorUtil;
import dev.galacticraft.mod.util.Translations;
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraft.network.chat.Style;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
Expand All @@ -35,10 +36,8 @@
import java.util.List;

public class InfiniteBatteryItem extends Item implements EnergyStorage {
private int ticks = (int) (Math.random() * 1000.0);

public InfiniteBatteryItem(Properties settings) {
super(settings.stacksTo(1));
super(settings);

EnergyStorage.ITEM.registerSelf(this);
}
Expand All @@ -50,7 +49,7 @@ public boolean isFoil(ItemStack stack) {

@Override
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltip, TooltipFlag type) {
tooltip.add(Component.translatable(Translations.Tooltip.ENERGY_REMAINING, Component.translatable(Translations.Tooltip.INFINITE).setStyle(Constant.Text.Color.getRainbow(ticks))));
tooltip.add(Component.translatable(Translations.Tooltip.ENERGY_REMAINING, Component.translatable(Translations.Tooltip.INFINITE).setStyle(Style.EMPTY.withColor(ColorUtil.getRainbow(15000)))));
tooltip.add(Component.translatable(Translations.Tooltip.CREATIVE_ONLY).setStyle(Constant.Text.Color.LIGHT_PURPLE_STYLE));
super.appendHoverText(stack, context, tooltip, type);
}
Expand All @@ -67,8 +66,7 @@ public int getBarWidth(ItemStack stack) {

@Override
public int getBarColor(ItemStack stack) {
if (++ticks > 1000) ticks = 0;
return Mth.hsvToRgb(this.ticks / 1000.0f, 1, 1);
return ColorUtil.getRainbow(15000);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
import com.google.common.collect.Iterators;
import dev.galacticraft.api.gas.Gases;
import dev.galacticraft.mod.Constant;
import dev.galacticraft.mod.client.util.ColorUtil;
import dev.galacticraft.mod.util.Translations;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.fabricmc.fabric.api.transfer.v1.storage.StorageView;
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraft.network.chat.Style;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
Expand All @@ -40,8 +41,6 @@
import java.util.List;

public class InfiniteOxygenTankItem extends Item implements Storage<FluidVariant>, StorageView<FluidVariant> {
private int ticks = (int) (Math.random() * 1000.0);

public InfiniteOxygenTankItem(Properties settings) {
super(settings);
}
Expand All @@ -64,7 +63,7 @@ public boolean isFoil(ItemStack stack) {
@Override
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltip, TooltipFlag type) {
super.appendHoverText(stack, context, tooltip, type);
tooltip.add(Component.translatable(Translations.Tooltip.OXYGEN_REMAINING, Component.translatable(Translations.Tooltip.INFINITE).setStyle(Constant.Text.Color.getRainbow(this.ticks))));
tooltip.add(Component.translatable(Translations.Tooltip.OXYGEN_REMAINING, Component.translatable(Translations.Tooltip.INFINITE).setStyle(Style.EMPTY.withColor(ColorUtil.getRainbow(15000)))));
tooltip.add(Component.translatable(Translations.Tooltip.CREATIVE_ONLY).setStyle(Constant.Text.Color.LIGHT_PURPLE_STYLE));
}

Expand All @@ -75,8 +74,7 @@ public int getBarWidth(ItemStack stack) {

@Override
public int getBarColor(ItemStack stack) {
if (++this.ticks > 1000) this.ticks = 0;
return Mth.hsvToRgb(this.ticks / 1000.0f, 1, 1);
return ColorUtil.getRainbow(15000);
}

@Override
Expand Down

0 comments on commit 6ed5986

Please sign in to comment.