Posted October 1, 20178 yr 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.
October 2, 20178 yr 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.
October 4, 20178 yr Author 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 October 4, 20178 yr 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.