Jump to content

1.17.1 change an item texture depending on a value


KaboomRoads

Recommended Posts

i have a block that is very similar to the light block, i need the texture to change depending on the light level the block has i already have the light block thing functional but the only problem is changing the texture. this is the main json for the item.

{
  "parent": "item/generated",
  "textures": {
    "layer0": "mrmod:item/darkness"
  },
  "overrides": [
    { "predicate": { "level": 0.0000 }, "model": "mrmod:item/darkness_00" },
    { "predicate": { "level": 0.0625 }, "model": "mrmod:item/darkness_01" },
    { "predicate": { "level": 0.1250 }, "model": "mrmod:item/darkness_02" },
    { "predicate": { "level": 0.1875 }, "model": "mrmod:item/darkness_03" },
    { "predicate": { "level": 0.2500 }, "model": "mrmod:item/darkness_04" },
    { "predicate": { "level": 0.3125 }, "model": "mrmod:item/darkness_05" },
    { "predicate": { "level": 0.3750 }, "model": "mrmod:item/darkness_06" },
    { "predicate": { "level": 0.4375 }, "model": "mrmod:item/darkness_07" },
    { "predicate": { "level": 0.5000 }, "model": "mrmod:item/darkness_08" },
    { "predicate": { "level": 0.5625 }, "model": "mrmod:item/darkness_09" },
    { "predicate": { "level": 0.6250 }, "model": "mrmod:item/darkness_10" },
    { "predicate": { "level": 0.6875 }, "model": "mrmod:item/darkness_11" },
    { "predicate": { "level": 0.7500 }, "model": "mrmod:item/darkness_12" },
    { "predicate": { "level": 0.8125 }, "model": "mrmod:item/darkness_13" },
    { "predicate": { "level": 0.8750 }, "model": "mrmod:item/darkness_14" },
    { "predicate": { "level": 0.9375 }, "model": "mrmod:item/darkness_15" },
    { "predicate": { "level": -0.0625 }, "model": "mrmod:item/darkness_01" },
    { "predicate": { "level": -0.1250 }, "model": "mrmod:item/darkness_02" },
    { "predicate": { "level": -0.1875 }, "model": "mrmod:item/darkness_03" },
    { "predicate": { "level": -0.2500 }, "model": "mrmod:item/darkness_04" },
    { "predicate": { "level": -0.3125 }, "model": "mrmod:item/darkness_05" },
    { "predicate": { "level": -0.3750 }, "model": "mrmod:item/darkness_06" },
    { "predicate": { "level": -0.4375 }, "model": "mrmod:item/darkness_07" },
    { "predicate": { "level": -0.5000 }, "model": "mrmod:item/darkness_08" },
    { "predicate": { "level": -0.5625 }, "model": "mrmod:item/darkness_09" },
    { "predicate": { "level": -0.6250 }, "model": "mrmod:item/darkness_10" },
    { "predicate": { "level": -0.6875 }, "model": "mrmod:item/darkness_11" },
    { "predicate": { "level": -0.7500 }, "model": "mrmod:item/darkness_12" },
    { "predicate": { "level": -0.8125 }, "model": "mrmod:item/darkness_13" },
    { "predicate": { "level": -0.8750 }, "model": "mrmod:item/darkness_14" },
    { "predicate": { "level": -0.9375 }, "model": "mrmod:item/darkness_15" }
  ]
}

i think the problem is getting the predicate to work

Link to comment
Share on other sites

i also found a class called LightPredicate but i dont know how to do something like that

package net.minecraft.advancements.critereon;

import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.GsonHelper;

public class LightPredicate {
   public static final LightPredicate ANY = new LightPredicate(MinMaxBounds.Ints.ANY);
   private final MinMaxBounds.Ints composite;

   LightPredicate(MinMaxBounds.Ints pComposite) {
      this.composite = pComposite;
   }

   public boolean matches(ServerLevel pLevel, BlockPos pPos) {
      if (this == ANY) {
         return true;
      } else if (!pLevel.isLoaded(pPos)) {
         return false;
      } else {
         return this.composite.matches(pLevel.getMaxLocalRawBrightness(pPos));
      }
   }

   public JsonElement serializeToJson() {
      if (this == ANY) {
         return JsonNull.INSTANCE;
      } else {
         JsonObject jsonobject = new JsonObject();
         jsonobject.add("light", this.composite.serializeToJson());
         return jsonobject;
      }
   }

   public static LightPredicate fromJson(@Nullable JsonElement pJson) {
      if (pJson != null && !pJson.isJsonNull()) {
         JsonObject jsonobject = GsonHelper.convertToJsonObject(pJson, "light");
         MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(jsonobject.get("light"));
         return new LightPredicate(minmaxbounds$ints);
      } else {
         return ANY;
      }
   }

   public static class Builder {
      private MinMaxBounds.Ints composite = MinMaxBounds.Ints.ANY;

      public static LightPredicate.Builder light() {
         return new LightPredicate.Builder();
      }

      public LightPredicate.Builder setComposite(MinMaxBounds.Ints pComposite) {
         this.composite = pComposite;
         return this;
      }

      public LightPredicate build() {
         return new LightPredicate(this.composite);
      }
   }
}

 

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.