Skip to content

Commit

Permalink
Added support for heating/cooling armor trims
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Jan 3, 2024
1 parent b968989 commit 3d92616
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// 1.20.4 2024-01-03T18:57:51.0266812 Tags for minecraft:trim_material mod id toughasnails
35133e95f1c8fdd7a1c21afcc231fc0bffefb9a8 data/toughasnails/tags/trim_material/cooling_trims.json
35133e95f1c8fdd7a1c21afcc231fc0bffefb9a8 data/toughasnails/tags/trim_material/heating_trims.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,48 @@

import glitchcore.event.client.ItemTooltipEvent;
import glitchcore.event.client.RenderTooltipEvent;
import glitchcore.util.Environment;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.armortrim.ArmorTrim;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import toughasnails.core.ToughAsNails;
import toughasnails.init.ModConfig;
import toughasnails.init.ModTags;
import toughasnails.thirst.ThirstOverlayRenderer;

import java.util.Optional;

public class TooltipHandler
{
public static void onTooltip(ItemTooltipEvent event)
{
ItemStack stack = event.getStack();
Block block = Block.byItem(stack.getItem());
BlockState state = block.defaultBlockState();

// Don't display heating or cooling tooltips if temperature is disabled
if (!ModConfig.temperature.enableTemperature)
return;

if (state.is(ModTags.Blocks.HEATING_BLOCKS) || stack.is(ModTags.Items.HEATING_ARMOR))
if (!Environment.isClient())
throw new IllegalStateException("ItemTooltipEvent unexpectedly called on the server");

ItemStack stack = event.getStack();
Block block = Block.byItem(stack.getItem());
BlockState state = block.defaultBlockState();
Optional<ArmorTrim> trim = ArmorTrim.getTrim(Minecraft.getInstance().getConnection().registryAccess(), stack, true);

if (state.is(ModTags.Blocks.HEATING_BLOCKS) || stack.is(ModTags.Items.HEATING_ARMOR) || (trim.isPresent() && trim.get().material().is(ModTags.Trims.HEATING_TRIMS)))
{
event.getTooltip().add(Component.literal("\uD83D\uDD25 ").append(Component.translatable("desc.toughasnails.heating")).withStyle(ChatFormatting.GOLD));
}

if (state.is(ModTags.Blocks.COOLING_BLOCKS) || stack.is(ModTags.Items.COOLING_ARMOR))
if (state.is(ModTags.Blocks.COOLING_BLOCKS) || stack.is(ModTags.Items.COOLING_ARMOR) || (trim.isPresent() && trim.get().material().is(ModTags.Trims.COOLING_TRIMS)))
{
event.getTooltip().add(Component.literal("\u2744 ").append(Component.translatable("desc.toughasnails.cooling")).withStyle(ChatFormatting.AQUA));
}
Expand Down
17 changes: 17 additions & 0 deletions common/src/main/java/toughasnails/init/ModTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.armortrim.ArmorTrim;
import net.minecraft.world.item.armortrim.TrimMaterial;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import toughasnails.api.TANAPI;
import toughasnails.api.thirst.WaterType;
import toughasnails.core.ToughAsNails;

public class ModTags
{
Expand All @@ -18,6 +21,7 @@ public static void init()
Blocks.init();
Items.init();
Biomes.init();
Trims.init();
}

public static class Blocks
Expand Down Expand Up @@ -141,4 +145,17 @@ else if (biome.is(PURIFIED_WATER_BIOMES))
return WaterType.NORMAL;
}
}

public static class Trims
{
public static void init() {}

public static final TagKey<TrimMaterial> COOLING_TRIMS = create("cooling_trims");
public static final TagKey<TrimMaterial> HEATING_TRIMS = create("heating_trims");

private static TagKey<TrimMaterial> create(String name)
{
return TagKey.create(Registries.TRIM_MATERIAL, new ResourceLocation(ToughAsNails.MOD_ID, name));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import net.minecraft.tags.FluidTags;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.armortrim.ArmorTrim;
import net.minecraft.world.item.armortrim.TrimMaterial;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;
Expand Down Expand Up @@ -352,8 +355,20 @@ protected static TemperatureLevel armorModifier(Player player, TemperatureLevel
AtomicInteger heatingPieces = new AtomicInteger();

player.getArmorSlots().forEach((stack -> {
if (stack.is(ModTags.Items.COOLING_ARMOR)) coolingPieces.getAndIncrement();
if (stack.is(ModTags.Items.HEATING_ARMOR)) heatingPieces.getAndIncrement();
// Prevent doubling of effects if armor were to be tagged as heating/cooling and also had a heating/cooling trim applied
if (stack.is(ModTags.Items.COOLING_ARMOR) || stack.is(ModTags.Items.HEATING_ARMOR))
{
if (stack.is(ModTags.Items.COOLING_ARMOR)) coolingPieces.getAndIncrement();
if (stack.is(ModTags.Items.HEATING_ARMOR)) heatingPieces.getAndIncrement();
}
else
{
ArmorTrim.getTrim(player.level().registryAccess(), stack, true).ifPresent(armorTrim -> {
Holder<TrimMaterial> trimMaterial = armorTrim.material();
if (trimMaterial.is(ModTags.Trims.COOLING_TRIMS)) coolingPieces.getAndIncrement();
if (trimMaterial.is(ModTags.Trims.HEATING_TRIMS)) heatingPieces.getAndIncrement();
});
}
}));

// Prevent armor from sending players over the edge into hot or icy temperature levels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static void onGatherData(GatherDataEvent event)
generator.addProvider(event.includeServer(), new TANItemTagsProvider(output, datapackProvider.getRegistryProvider(), blocksTagProvider.contentsGetter(), existingFileHelper));
generator.addProvider(event.includeServer(), new TANBiomeTagsProvider(output, datapackProvider.getRegistryProvider(), existingFileHelper));
generator.addProvider(event.includeServer(), new TANDamageTypeTagsProvider(output, datapackProvider.getRegistryProvider(), existingFileHelper));
generator.addProvider(event.includeServer(), new TANTrimMaterialTagsProvider(output, datapackProvider.getRegistryProvider(), existingFileHelper));

// Client
generator.addProvider(event.includeClient(), new TANItemModelProvider(output, existingFileHelper));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright 2023, the Glitchfiend Team.
* All rights reserved.
******************************************************************************/
package toughasnails.forge.datagen.provider;

import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.PackOutput;
import net.minecraft.data.tags.TagsProvider;
import net.minecraft.world.item.armortrim.TrimMaterial;
import net.minecraft.world.item.armortrim.TrimMaterials;
import net.minecraftforge.common.data.ExistingFileHelper;
import org.jetbrains.annotations.Nullable;
import toughasnails.core.ToughAsNails;
import toughasnails.init.ModTags;

import java.util.concurrent.CompletableFuture;

public class TANTrimMaterialTagsProvider extends TagsProvider<TrimMaterial>
{
public TANTrimMaterialTagsProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, @Nullable ExistingFileHelper existingFileHelper)
{
super(output, Registries.TRIM_MATERIAL, lookupProvider, ToughAsNails.MOD_ID, existingFileHelper);
}

@Override
protected void addTags(HolderLookup.Provider provider)
{
this.tag(ModTags.Trims.COOLING_TRIMS);
this.tag(ModTags.Trims.HEATING_TRIMS);
}
}

0 comments on commit 3d92616

Please sign in to comment.