Skip to content

Commit

Permalink
Implemented item/block coloring
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Dec 30, 2023
1 parent dbfdb0e commit b31a62c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 49 deletions.
29 changes: 0 additions & 29 deletions common/src/main/java/toughasnails/client/handler/ColorHandler.java

This file was deleted.

10 changes: 10 additions & 0 deletions common/src/main/java/toughasnails/core/ToughAsNails.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.registries.Registries;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import toughasnails.api.TANAPI;
import toughasnails.init.*;
import toughasnails.temperature.TemperatureHandler;
import toughasnails.temperature.TemperatureOverlayRenderer;
Expand All @@ -22,6 +25,9 @@

public class ToughAsNails
{
public static final String MOD_ID = TANAPI.MOD_ID;
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);

public static void init()
{
ModConfig.init();
Expand Down Expand Up @@ -68,5 +74,9 @@ private static void addHandlers()
EventManager.addListener(ThirstHandler::onPlayerUseItem);
EventManager.addListener(ThirstHandler::onUseEmpty);
EventManager.addListener(ThirstHandler::onClientTick);

// Client handlers
EventManager.addListener(ModBlocks::registerBlockColors);
EventManager.addListener(ModItems::registerItemColors);
}
}
6 changes: 6 additions & 0 deletions common/src/main/java/toughasnails/init/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
******************************************************************************/
package toughasnails.init;

import glitchcore.event.client.RegisterColorsEvent;
import glitchcore.util.Environment;
import glitchcore.util.RenderTypeHelper;
import net.minecraft.client.renderer.RenderType;
Expand Down Expand Up @@ -39,6 +40,11 @@ public static void registerRenderers()
RenderTypeHelper.setRenderType(WATER_PURIFIER, cutoutRenderType);
}

public static void registerBlockColors(RegisterColorsEvent.Block event)
{
event.register((state, world, pos, tintIndex) -> 0x47DAFF, TANBlocks.RAIN_COLLECTOR);
}

private static Block register(BiConsumer<ResourceLocation, Block> func, String name, Block block)
{
func.accept(new ResourceLocation(TANAPI.MOD_ID, name), block);
Expand Down
12 changes: 12 additions & 0 deletions common/src/main/java/toughasnails/init/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
******************************************************************************/
package toughasnails.init;

import glitchcore.event.client.RegisterColorsEvent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.BlockItem;
Expand Down Expand Up @@ -51,6 +52,17 @@ public static void registerItems(BiConsumer<ResourceLocation, Item> func)
TANItems.WATER_PURIFIER = register(func, "water_purifier", new BlockItem(TANBlocks.WATER_PURIFIER, new Item.Properties()));
}

public static void registerItemColors(RegisterColorsEvent.Item event)
{
event.register((stack, tintIndex) -> {
return tintIndex > 0 ? -1 : ((DyeableWoolItem)stack.getItem()).getColor(stack);
}, TANItems.WOOL_HELMET, TANItems.WOOL_CHESTPLATE, TANItems.WOOL_LEGGINGS, TANItems.WOOL_BOOTS);

event.register((stack, tintIndex) -> {
return tintIndex > 0 ? -1 : ((LeafArmorItem)stack.getItem()).getColor(stack);
}, TANItems.LEAF_HELMET, TANItems.LEAF_CHESTPLATE, TANItems.LEAF_LEGGINGS, TANItems.LEAF_BOOTS);
}

private static Item register(BiConsumer<ResourceLocation, Item> func, String name, Item item)
{
func.accept(new ResourceLocation(TANAPI.MOD_ID, name), item);
Expand Down
22 changes: 3 additions & 19 deletions common/src/main/java/toughasnails/item/LeafArmorItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import net.minecraft.world.item.*;
import net.minecraft.world.level.FoliageColor;
import net.minecraft.world.level.Level;
import toughasnails.core.ToughAsNails;

import java.util.List;

public class LeafArmorItem extends ArmorItem implements DyeableLeatherItem
public class LeafArmorItem extends DyeableArmorItem
{
public LeafArmorItem(ArmorMaterial p_41091_, ArmorItem.Type type, Item.Properties p_41093_)
{
Expand All @@ -22,13 +23,7 @@ public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot,
if (!world.isClientSide())
return;

int color = FoliageColor.getDefaultColor();

if (world != null && entity != null)
{
color = BiomeColors.getAverageFoliageColor(world, entity.blockPosition());
}

int color = BiomeColors.getAverageFoliageColor(world, entity.blockPosition());
this.setColor(stack, color);
}

Expand All @@ -39,19 +34,8 @@ public int getColor(ItemStack p_41122_)
return compoundtag != null && compoundtag.contains("color", 99) ? compoundtag.getInt("color") : FoliageColor.getDefaultColor();
}

@Override
public void setColor(ItemStack p_41116_, int p_41117_)
{
p_41116_.getOrCreateTagElement("display").putInt("color", p_41117_);
}

@Override
public void clearColor(ItemStack p_41124_)
{
}

public static ItemStack dyeArmor(ItemStack p_41119_, List<DyeItem> p_41120_)
{
return p_41119_;
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ org.gradle.daemon=false

# Dependencies
nightconfig_version=3.6.7
glitchcore_version=1.0.0.13
glitchcore_version=1.0.0.14
serene_seasons_version=9.3.0.0

0 comments on commit b31a62c

Please sign in to comment.