Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted (edited)

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

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

    • UPDATE: this seems to be an Arch-specific issue. Switching to Ubuntu server fixed EVERYTHING.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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