Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.1] Dyeable Item Layers Incorrect


urbanxx001
 Share

Recommended Posts

After following a tutorial I still have a small problem (I know the anti-tut ppl will berate me). Layer0 is dyeable but returns a black color, and layer1 (overlay) returns the default color that layer0 should be. The layer0 texture is properly grayscale. Item code below. It's probably due to getItemColor, but I've toyed with it with no success

 

public class DyeableBackpackItem extends Item implements IBackpack {

   private final Backpack backpack;
   private static final String NBT_COLOR = "BackpackColor";

   public DyeableBackpackItem(Backpack backpack, Properties properties) {
      super(properties);
      this.backpack = backpack;
   }

   public static int getBackpackColor(ItemStack stack) {
      return stack.getOrCreateTag().getInt(NBT_COLOR);
   }

   public static void setBackpackColor(ItemStack stack, int color) {
      stack.getOrCreateTag().putInt(NBT_COLOR, color);
   }

   public static int getItemColor(ItemStack stack, int tintIndex) {
      if (tintIndex == 0) {
         return getBackpackColor(stack);
      }
      return 10511680;
   }

   @Override
   public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {

      ItemStack itemstack = playerIn.getHeldItem(handIn);

      if (playerIn.isSneaking()) {
         if (!worldIn.isRemote && playerIn instanceof ServerPlayerEntity) {

            double pX = playerIn.getPosX();
            double pY = playerIn.getPosY();
            double pZ = playerIn.getPosZ();

            worldIn.playSound(null, pX, pY + 0.5D, pZ, SoundEvents.ITEM_ARMOR_EQUIP_LEATHER, SoundCategory.PLAYERS, 1.0F, 1.0F);
            open((ServerPlayerEntity)playerIn, itemstack, handIn == Hand.MAIN_HAND ? playerIn.inventory.currentItem : -1);

            return ActionResult.resultConsume(itemstack);
         }
      }
      return ActionResult.resultFail(itemstack);
   }

   @Override
   public void open(ServerPlayerEntity player, ItemStack stack, int selectedSlot) {
      NetworkHooks.openGui(player, new SimpleNamedContainerProvider((id, playerInventory, openPlayer) -> new BackpackContainer(id, playerInventory, new BackpackInventory(stack, backpack.getInventorySize()), backpack, selectedSlot), stack.getDisplayName()), buffer -> {
         buffer.writeEnumValue(backpack);
         buffer.writeVarInt(selectedSlot);
      });
   }
   
   public Backpack getBackpack() {
      return backpack;
   }

   // Fixes bug

   @Override
   public CompoundNBT getShareTag(ItemStack stack) {
      if (ServerConfig.getInstance().shareAllNBTData.get()) {
         return super.getShareTag(stack);
      }
      if (!stack.hasTag()) {
         return null;
      }
      final CompoundNBT compound = stack.getTag().copy();
      compound.remove("Items");
      if (compound.isEmpty()) {
         return null;
      }
      return compound;
   }

   // Fixes bug
   
   @Override
   public boolean onDroppedByPlayer(ItemStack item, PlayerEntity player) {
      return !(player.openContainer instanceof BackpackContainer);
   }
}
Edited by urbanxx001
Link to comment
Share on other sites

Yeah. In the main class:

eventBus.addListener(ColorHandler::registerItemColors);

With:

public class ColorHandler {

    public static void registerItemColors(ColorHandlerEvent.Item event) {
        event.getItemColors().register(DyeableBackpackItem::getItemColor, ModItems.LEATHER_BACKPACK);
    }
}
Edited by urbanxx001
Link to comment
Share on other sites

34 minutes ago, urbanxx001 said:

The method is definitely called, again layer0 is dyeable, and the dyeing recipe uses getItemColor, it's just the default color is applied to layer1 instead of 0.

The default color is returned for layer1 because you are returning 10511680 in getItemColor() if the layer is not 0. Try changing the last return to -1.

  • Thanks 1
Link to comment
Share on other sites

4 hours ago, vemerion said:

Try changing the last return to -1.

That did the trick, thanks for your help yesterday and now today. I wonder why it wasn't that way in the tutorial. Fixed Layer0 by using fillItemGroup, I first avoided it as I thought it would register 2 instances of the item. 

Edited by urbanxx001
Link to comment
Share on other sites

10 hours ago, urbanxx001 said:

That did the trick, thanks for your help yesterday and now today. I wonder why it wasn't that way in the tutorial. Fixed Layer0 by using fillItemGroup, I first avoided it as I thought it would register 2 instances of the item. 

No problem, glad I could be of help :) 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • I have installed a forge server, and tried launching it. It launches as a vanilla server if I run the file called "minecraft_server.1.16.5.jar" If i run the file called "forge-1.16.5-36.2.23.jar", nothing at all happens, it just creates a log with these 2 lines: [19Jan2022 16:08:29.340] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.23, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge] [19Jan2022 16:08:29.345] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 17.0.1 by Oracle Corporation I have also tried running both files (since I don't know which one I'm supposed to use) using the command line like this: java -Xmx6000M -Xms6000M -jar {serverName}.jar nogui pause If I run the the server file, i get a vanilla server as well. If i run the forge file, the log file looks the same as before, and I get this result in the terminal: D:\MCS\VH>java -Xmx6000M -Xms6000M -jar forge-1.16.5-36.2.23.jar nogui 2022-01-19 16:16:32,476 main WARN Advanced terminal features are not available in this environment [16:16:32] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.23, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, nogui] [16:16:32] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 17.0.1 by Oracle Corporation Exception in thread "main" java.lang.IllegalAccessError: class cpw.mods.modlauncher.SecureJarHandler (in unnamed module @0xadd0edd) cannot access class sun.security.util.ManifestEntryVerifier (in module java.base) because module java.base does not export sun.security.util to unnamed module @0xadd0edd at cpw.mods.modlauncher.SecureJarHandler.lambda$static$1(SecureJarHandler.java:41) at cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck(LamdbaExceptionUtils.java:95) at cpw.mods.modlauncher.SecureJarHandler.<clinit>(SecureJarHandler.java:41) at cpw.mods.modlauncher.Launcher.lambda$new$6(Launcher.java:55) at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:52) at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:47) at cpw.mods.modlauncher.Environment.computePropertyIfAbsent(Environment.java:62) at cpw.mods.modlauncher.Launcher.<init>(Launcher.java:55) at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63) at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60) at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) D:\MCS\VH>pause Press any key to continue . . . I have also tried launching old servers that I had on SkyFactory 3 that worked fine before, but they have stopped working too. When I launch them I get this result: Starting Sky Factory 3 Server... A problem occurred running the Server launcher.java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:62) at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:31) Caused by: java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap') at net.minecraft.launchwrapper.Launch.<init>(Launch.java:34) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) ... 6 more Press any key to continue . . . I assume this means that something has changed on my pc, causing forge servers not to run correctly, but I cannot imagine what that could be. I hope this is enough information to be able to help
    • Check it out, you won't regret https://shrinke.me/I0iwHJ3
    • These should be static initializers and the fields should be final. That is the point of DeferredRegister. Your code looks fine and should work, however you can use EnchantmentHelper.getItemEnchantmentLevel if you just want the level for one Enchantment. This call will be more efficient as it does not need to build the whole enchantment map.
    • Hi, I am trying to determine if item has specific enchant. I have tried with EnchantmentHelper, however statement is not returning true for item that is enchanted: // Get item in main hand. ItemStack item = player.getMainHandItem(); // Get list of enchantements on item. Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(item); // IF: Timber is enchanted on item. if(enchantments.containsKey(ToolEnchantments.TIMBER.get())) { // Mine the block at the position. mineBlock(world, blockPos, item); } My guess is that simple object comparison won't do? What would be proper way to check if enchantment is present on item?   This is how ToolEnchantments.TIMBER is defined:   public final class ToolEnchantments { public static DeferredRegister<Enchantment> REGISTRY; public static RegistryObject<Enchantment> BLOOM; public static RegistryObject<Enchantment> TIMBER; public static void register(IEventBus eventBus) { REGISTRY = DeferredRegister.create(ForgeRegistries.ENCHANTMENTS, ExperimentalMod.MODID); REGISTRY.register("bloom", () -> new BloomEnchantment()); REGISTRY.register("timber", () -> new TimberEnchantment()); REGISTRY.register(eventBus); } }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.