Skip to content

Commit

Permalink
Fixed severside crashing on Fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed May 19, 2024
1 parent 294d56b commit cb84b86
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
8 changes: 4 additions & 4 deletions common/src/main/java/toughasnails/init/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public static void registerItems(BiConsumer<ResourceLocation, Item> func)
// Items
TANItems.THERMOMETER = register(func, "thermometer", new Item(new Item.Properties().stacksTo(1)));

TANItems.LEAF_HELMET = register(func, "leaf_helmet", new ArmorItem(ModArmorMaterials.LEAF, ArmorItem.Type.HELMET, (new Item.Properties())));
TANItems.LEAF_CHESTPLATE = register(func, "leaf_chestplate", new ArmorItem(ModArmorMaterials.LEAF, ArmorItem.Type.CHESTPLATE, (new Item.Properties())));
TANItems.LEAF_LEGGINGS = register(func, "leaf_leggings", new ArmorItem(ModArmorMaterials.LEAF, ArmorItem.Type.LEGGINGS, (new Item.Properties())));
TANItems.LEAF_BOOTS = register(func, "leaf_boots", new ArmorItem(ModArmorMaterials.LEAF, ArmorItem.Type.BOOTS, (new Item.Properties())));
TANItems.LEAF_HELMET = register(func, "leaf_helmet", new LeafArmorItem(ModArmorMaterials.LEAF, ArmorItem.Type.HELMET, (new Item.Properties())));
TANItems.LEAF_CHESTPLATE = register(func, "leaf_chestplate", new LeafArmorItem(ModArmorMaterials.LEAF, ArmorItem.Type.CHESTPLATE, (new Item.Properties())));
TANItems.LEAF_LEGGINGS = register(func, "leaf_leggings", new LeafArmorItem(ModArmorMaterials.LEAF, ArmorItem.Type.LEGGINGS, (new Item.Properties())));
TANItems.LEAF_BOOTS = register(func, "leaf_boots", new LeafArmorItem(ModArmorMaterials.LEAF, ArmorItem.Type.BOOTS, (new Item.Properties())));

TANItems.WOOL_HELMET = register(func, "wool_helmet", new ArmorItem(ModArmorMaterials.WOOL, ArmorItem.Type.HELMET, (new Item.Properties())));
TANItems.WOOL_CHESTPLATE = register(func, "wool_chestplate", new ArmorItem(ModArmorMaterials.WOOL, ArmorItem.Type.CHESTPLATE, (new Item.Properties())));
Expand Down
30 changes: 30 additions & 0 deletions common/src/main/java/toughasnails/item/LeafArmorItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright 2024, the Glitchfiend Team.
* All rights reserved.
******************************************************************************/
package toughasnails.item;

import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.DyedItemColor;
import net.minecraft.world.level.Level;
import toughasnails.api.item.TANItems;

public class LeafArmorItem extends ArmorItem
{
public LeafArmorItem(Holder<ArmorMaterial> $$0, Type $$1, Properties $$2) {
super($$0, $$1, $$2);
}

@Override
public void inventoryTick(ItemStack stack, Level level, Entity entity, int p_41407_, boolean p_41408_)
{
if (stack.getItem() == TANItems.LEAF_BOOTS || stack.getItem() == TANItems.LEAF_LEGGINGS || stack.getItem() == TANItems.LEAF_CHESTPLATE || stack.getItem() == TANItems.LEAF_HELMET)
stack.set(DataComponents.DYED_COLOR, new DyedItemColor(BiomeColors.getAverageFoliageColor(entity.level(), entity.blockPosition()), false));
}
}
7 changes: 0 additions & 7 deletions common/src/main/java/toughasnails/mixin/MixinPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ public void onTick(CallbackInfo ci)
Player player = (Player)(Object)this;
TemperatureHandler.onPlayerTick(player);
ThirstHandler.onPlayerTick(player);

for (int i = 0; i < player.getInventory().getContainerSize(); i++)
{
ItemStack stack = player.getInventory().getItem(i);
if (stack.getItem() == TANItems.LEAF_BOOTS || stack.getItem() == TANItems.LEAF_LEGGINGS || stack.getItem() == TANItems.LEAF_CHESTPLATE || stack.getItem() == TANItems.LEAF_HELMET)
stack.set(DataComponents.DYED_COLOR, new DyedItemColor(BiomeColors.getAverageFoliageColor(player.level(), player.blockPosition()), false));
}
}

@Override
Expand Down

0 comments on commit cb84b86

Please sign in to comment.