Jump to content

Custom EntityProperty for Loot_Tables not working.


Thretcha

Recommended Posts

I want to make a loot table condition/Property which checks if the fishing hook is in a specific biome type.

Since Properties are limited to boolean checks my only idea was to make 28 biometype property classes.

All of them extend my InBiomeType class which implements EntityProperty.

I register them during preInit in my CommonProxy.

EntityPropertyManager.registerProperty(new InBiomeTypeBeach.Serializer());

 

My override for the Method testProperty(Random random, Entity entityIn) never gets called.

I know that my Property has been registered because a second call to registerProperty causes the expected Exception... property already registered.

Changing the namespace from minecraft to my mod id causes the expected unknown lootProperty excpeption.

Without the loot property the loot_table worked fine.

There seems to be no output in the console or log files indicating any error at all.

Here are all files mentioned:

Spoiler


 

public abstract class InBiomeType implements EntityProperty {

    public final boolean inBiomeType;
    public BiomeDictionary.Type type;


    public InBiomeType(boolean inBiomeType) {
        this.inBiomeType = inBiomeType;
    }
}


public class InBiomeTypeBeach extends InBiomeType {

    public InBiomeTypeBeach(boolean inBiomeType) {
        super(inBiomeType);
        this.type = BiomeDictionary.Type.BEACH;
    }

    @Override
    public boolean testProperty(Random random, Entity entityIn) {
        System.out.println("In testProperty:"+BiomeAndTypeHandler.isBiomeOfType(entityIn.getEntityWorld().getBiome(entityIn.getPosition()),this.type));
        return BiomeAndTypeHandler.isBiomeOfType(entityIn.getEntityWorld().getBiome(entityIn.getPosition()),this.type);
    }

    public static class Serializer extends EntityProperty.Serializer<InBiomeTypeBeach>
        {
            public Serializer()
            {
                super(new ResourceLocation("in_biome_type_beach"), InBiomeTypeBeach.class);
            }

            public JsonElement serialize(InBiomeTypeBeach property, JsonSerializationContext serializationContext)
            {
                return new JsonPrimitive(property.inBiomeType);
            }

            public InBiomeTypeBeach deserialize(JsonElement element, JsonDeserializationContext deserializationContext)
            {
                return new InBiomeTypeBeach(JsonUtils.getBoolean(element, "in_biome_type_beach"));
            }
        }

}

{
  "pools": [
    {
      "name":"main",
      "rolls": 1,
      "entries": [
        {
          "type": "item",
          "name": "minecraft:ender_pearl",
          "weight": 1,
          "conditions": [
            {
              "condition": "minecraft:entity_properties",
              "entity" : "this",
              "properties": {
                "minecraft:in_biome_type_beach" : true
              }
            }
          ]
        }
      ]
    }
  ]
}

@Mod.EventBusSubscriber
public abstract class CommonProxy {
public static Path configDirectory;
    public void preInit(FMLPreInitializationEvent event)
    {
        configDirectory= Paths.get(event.getModConfigurationDirectory().getPath().toString()+"\\"+ FishermansJourneyMod.MODID);

        System.out.println(configDirectory);
        EntityPropertyManager.registerProperty(new InBiomeTypeBeach.Serializer());
    }

    @SubscribeEvent
    public static void registerItems(RegistryEvent.Register<Item> event) {
        event.getRegistry().register(new ItemBaseFishingRod());
    }


    public void init(FMLInitializationEvent event)
    {
    }

    public void postInit(FMLPostInitializationEvent event)
    {
        BiomeAndTypeHandler.initBiomeAndTypeHandler();
    }
}

 

Registering the Custom Properties that way seem wrong to me.

Please tell me if there is a better or correct way to do this.

Ideally I would like to find a way to have Properties with String values that I can easily check so that I don't have to do it that way.

But that probably isn't that easy to do.

Link to comment
Share on other sites

Your property won't work because the fish hook doesn't include the looted entity in the LootContext it uses to generate fishing loot. It doesn't include the player either, so you can't check the biome of either entity. I'm working on a Forge PR to include the player, looted entity, damage source & player luck in all the loot contexts that they are applicable to and available to.

 

There are also two other issues with your property.

Firstly, a separate property for every class is completely unnecessary, you have complete control over the serialisation and deserialisation of your property. If you need info for your property, just figure out how to express it in string form, then you can specify it in the .json and deserialise it into whatever format you need. 

Secondly, you shouldn't be using the minecraft domain as your property is not part of vanilla Minecraft. Use your mod's mod ID as the domain.

Link to comment
Share on other sites

Thanks I think I fixed all the mentioned mistakes now only waiting for the Forge PR. :)

Also I read I should be registering my LootTable so I do that now.

 

*edit

I have seen your PR and am wondering why you chose to implement biome specific fishing loot as a Loot condition instead of a property ?

Is there any benefit to doing it that way or does it not really matter ?

Also I am using Biome.Registry in my code instead of ForgeRegistries.Biome to get a list of biomes is my approach wrong ?

Or am I just getting vanilla results with Biome.Registry and getting all modded and vanilla results with ForgeRegistries.Biome ?

Spoiler

public class InBiomeType implements EntityProperty {

    //the biome Type the entity should be in for the property to return true
    private final BiomeDictionary.Type biomeType;

    public InBiomeType(String typeString) {
        if (BiomeAndTypeHandler.isValidBiomeType(typeString)) {
            biomeType = BiomeAndTypeHandler.getBiomeType(typeString);
        } else {
            FishermansJourneyMod.logger.log(Level.ERROR, typeString + " mentioned in a Loot_Table is not a valid Biome Type");
            biomeType = null;
        }
    }

    //Currently not working because Loot context is empty
    //Waiting on a forge PR that adds all the entity information the every LootContext
    @Override
    public boolean testProperty(Random random, Entity entityIn) {
        if (BiomeAndTypeHandler.isBiomeOfType(entityIn.getEntityWorld().getBiome(entityIn.getPosition()), biomeType)) {
            return true;
        }
        return false;
    }

    public static class Serializer extends EntityProperty.Serializer<InBiomeType> {
        public Serializer() {
            //super(new ResourceLocation(FishermansJourneyMod.MODID + ":in_biome_type"), InBiomeType.class);
            super(new ResourceLocation(FishermansJourneyMod.MODID ,"in_biome_type"), InBiomeType.class);
        }

        public JsonElement serialize(InBiomeType property, JsonSerializationContext serializationContext) {
            return new JsonPrimitive(property.biomeType.toString());
        }

        public InBiomeType deserialize(JsonElement element, JsonDeserializationContext deserializationContext) {
            return new InBiomeType(JsonUtils.getString(element, "in_biome_type"));
        }
    }
}

@Mod.EventBusSubscriber
public abstract class CommonProxy {
public static Path configDirectory;
public static ResourceLocation baseLootTable;
    public void preInit(FMLPreInitializationEvent event)
    {
        configDirectory= Paths.get(event.getModConfigurationDirectory().getPath().toString()+"\\"+ FishermansJourneyMod.MODID);

        System.out.println(configDirectory);
        EntityPropertyManager.registerProperty(new InBiomeType.Serializer());
        baseLootTable = LootTableList.register(new ResourceLocation(FishermansJourneyMod.MODID, "gameplay/fishingbase"));
    }

    @SubscribeEvent
    public static void registerItems(RegistryEvent.Register<Item> event) {
        event.getRegistry().register(new ItemBaseFishingRod());
    }


    public void init(FMLInitializationEvent event)
    {
    }

    public void postInit(FMLPostInitializationEvent event)
    {
        BiomeAndTypeHandler.initBiomeAndTypeHandler();
    }
}

 


{
  "pools": [
    {
      "name":"main",
      "rolls": 1,
      "entries": [
        {
          "type": "item",
          "name": "minecraft:ender_pearl",
          "weight": 1,
          "conditions": [
            {
              "condition": "minecraft:entity_properties",
              "entity" : "this",
              "properties": {
                "fishermansjourney:in_biome_type" : "BEACH"
              }
            }
          ]
        }
      ]
    }
  ]
}

 

Edited by Thretcha
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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I was just trying to play my modded world when i randomly got this crash for no reason. I sorted through like every mod and eventually I realized it was LLibrary but I can't seem to find a solution to fix the crashing. I can't lose the world that I have that uses this mod please help me. Here's the report: https://pastebin.com/0D00B79i If anyone has a solution please let me know.  
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Ligawin88 adalah bocoran slot rekomendasi gacor dari Ligawin88 yang bisa anda temukan di SLOT Ligawin88. Situs SLOT Ligawin88 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ligawin88 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ligawin88 merupakan SLOT Ligawin88 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ligawin88. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ligawin88 hari ini yang telah disediakan SLOT Ligawin88. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ligawin88 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ligawin88 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ligawin88 di link SLOT Ligawin88.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Asusslot adalah bocoran slot rekomendasi gacor dari Asusslot yang bisa anda temukan di SLOT Asusslot. Situs SLOT Asusslot hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Asusslot terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Asusslot merupakan SLOT Asusslot hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Asusslot. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Asusslot hari ini yang telah disediakan SLOT Asusslot. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Asusslot terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Asusslot terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Asusslot di link SLOT Asusslot.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Galeri555 adalah bocoran slot rekomendasi gacor dari Galeri555 yang bisa anda temukan di SLOT Galeri555. Situs SLOT Galeri555 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Galeri555 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Galeri555 merupakan SLOT Galeri555 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Galeri555. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Galeri555 hari ini yang telah disediakan SLOT Galeri555. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Galeri555 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Galeri555 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Galeri555 di link SLOT Galeri555.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Kocok303 adalah bocoran slot rekomendasi gacor dari Kocok303 yang bisa anda temukan di SLOT Kocok303. Situs SLOT Kocok303 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Kocok303 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Kocok303 merupakan SLOT Kocok303 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Kocok303. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Kocok303 hari ini yang telah disediakan SLOT Kocok303. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Kocok303 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Kocok303 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Kocok303 di link SLOT Kocok303.
  • Topics

×
×
  • Create New...

Important Information

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