From 3ad6219d76b74366f0526708f7f038d74ee20eda Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Tue, 21 Dec 2021 21:09:31 +0100 Subject: [PATCH] Added Linking tool coloring --- .../functionalstorage/FunctionalStorage.java | 23 +++++++++++++++++++ .../block/tile/ArmoryCabinetTile.java | 2 ++ .../block/tile/DrawerControllerTile.java | 2 ++ .../item/LinkingToolItem.java | 6 ++--- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java index 1eda0cc..56fe4fa 100644 --- a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java +++ b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java @@ -22,8 +22,10 @@ import com.hrznstudio.titanium.event.handler.EventManager; import com.hrznstudio.titanium.module.ModuleController; import com.hrznstudio.titanium.recipe.generator.TitaniumRecipeProvider; import com.hrznstudio.titanium.tab.AdvancedTitaniumTab; +import net.minecraft.client.color.item.ItemColors; import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.data.tags.BlockTagsProvider; +import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -31,6 +33,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.client.event.ColorHandlerEvent; import net.minecraftforge.client.event.EntityRenderersEvent; import net.minecraftforge.client.model.generators.ItemModelProvider; import net.minecraftforge.common.util.NonNullLazy; @@ -41,8 +44,11 @@ import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.jline.utils.Colors; +import java.awt.*; import java.util.*; +import java.util.List; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -131,6 +137,23 @@ public class FunctionalStorage extends ModuleController { registerRenderers.registerBlockEntityRenderer(((BasicTileBlock)COMPACTING_DRAWER.get()).getTileEntityType(), p_173571_ -> new CompactingDrawerRenderer()); }).subscribe(); + EventManager.mod(ColorHandlerEvent.Item.class).process(item -> { + item.getItemColors().register((stack, tint) -> { + CompoundTag tag = stack.getOrCreateTag(); + LinkingToolItem.LinkingMode linkingMode = LinkingToolItem.LinkingMode.valueOf(tag.getString(LinkingToolItem.NBT_MODE)); + LinkingToolItem.ActionMode linkingAction = LinkingToolItem.ActionMode.valueOf(tag.getString(LinkingToolItem.NBT_ACTION)); + if (tint == 3 && tag.contains(LinkingToolItem.NBT_CONTROLLER)){ + return Color.RED.getRGB(); + } + if (tint == 1){ + return linkingMode.getColor().getValue(); + } + if (tint == 2){ + return linkingAction.getColor().getValue(); + } + return 0xffffff; + }, LINKING_TOOL.get()); + }).subscribe(); } @Override diff --git a/src/main/java/com/buuz135/functionalstorage/block/tile/ArmoryCabinetTile.java b/src/main/java/com/buuz135/functionalstorage/block/tile/ArmoryCabinetTile.java index cc2a0ad..f715d86 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/tile/ArmoryCabinetTile.java +++ b/src/main/java/com/buuz135/functionalstorage/block/tile/ArmoryCabinetTile.java @@ -18,6 +18,8 @@ import javax.annotation.Nullable; public class ArmoryCabinetTile extends ControllableDrawerTile{ + //TODO Not sync nbt + @Save public ArmoryCabinetInventoryHandler handler; private final LazyOptional lazyStorage; diff --git a/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerControllerTile.java b/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerControllerTile.java index cf9a5f3..c137678 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerControllerTile.java +++ b/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerControllerTile.java @@ -26,6 +26,8 @@ import java.util.List; public class DrawerControllerTile extends ControllableDrawerTile{ + //TODO Not sync nbt + @Save private ConnectedDrawers connectedDrawers; public ControllerInventoryHandler handler; diff --git a/src/main/java/com/buuz135/functionalstorage/item/LinkingToolItem.java b/src/main/java/com/buuz135/functionalstorage/item/LinkingToolItem.java index e1b4b6a..4a72bed 100644 --- a/src/main/java/com/buuz135/functionalstorage/item/LinkingToolItem.java +++ b/src/main/java/com/buuz135/functionalstorage/item/LinkingToolItem.java @@ -32,9 +32,9 @@ import java.util.Locale; public class LinkingToolItem extends BasicItem { - private final String NBT_MODE = "Mode"; - private final String NBT_CONTROLLER = "Controller"; - private final String NBT_ACTION = "Action"; + public static final String NBT_MODE = "Mode"; + public static final String NBT_CONTROLLER = "Controller"; + public static final String NBT_ACTION = "Action"; public LinkingToolItem() { super(new Properties().tab(FunctionalStorage.TAB).stacksTo(1));