Jump to content

Recommended Posts

Posted

Hello I feel like I have been looking forever now, I am attempting to make my item spawn in simple mob spawner dungeons and need help. I know I have to use global loot modifiers and have tried using the forge documentation but I cannot make any sense of it and would really appreciate some help. HELPP

Posted

Show what you've tried.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Well okay but I removed all my main Java code

Here is my global_loot_modifiers.json

{
	"replace": false,
	"entries": [
		"spacerulerwillmagicmod:tatted_book_dungeons"
	]
}
{
  "conditions": [
    {
      "condition": "minecraft:match_tool",
      "predicate": {
        "item": "minecraft:shears"
      }
    },
    {
      "condition": "block_state_property",
      "block":"minecraft:wheat"
    }
  ],
  "seedItem": "minecraft:wheat_seeds",
  "numSeeds": 3,
  "replacement": "minecraft:wheat"
}

Here is my other JSON.

You'll immediately notice it has nothing to do with dungeons, thats because I copied it straight from the docs. I don't know how to change the condition to make it affect a simple dungeon chest and my json doesn't have like an autocorrect when you start typing so I didn't know if what I tried would change anything at all. I also looked for the simple dungeon loot table in the game files to help me, but I couldn't find it it seems to be in a different place than all the other structures.

 

I have basically emptied the java code of anything so they are like empty methods at the moment. I do not know how to make it related to simple dungeons

 public static class EventHandlers {

        @SubscribeEvent
        public static void registerModifierSerializers(@Nonnull final RegistryEvent.Register<GlobalLootModifierSerializer<?>> event) {
            if (ENABLE) {
                event.getRegistry().register(
                        new TatteredBookModifier.Serializer().setRegistryName(new ResourceLocation(mod_id, "tattered_book_dungeons"))
                );            
            }
        }
    }

 

 


    private static class TatteredBookModifier extends LootModifier {
    	
        public TatteredBookModifier(ILootCondition[] conditionsIn) {
            super(conditionsIn);
        }

        @Nonnull
        @Override
        public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
         
            return generatedLoot;
        }
        
        private static class Serializer extends GlobalLootModifierSerializer<TatteredBookModifier> {

            @Override
            public TatteredBookModifier read(ResourceLocation name, JsonObject object, ILootCondition[] conditionsIn) {
            
                return new TatteredBookModifier(conditionsIn);
            }

    		@Override
    		public JsonObject write(TatteredBookModifier instance) {
    			// TODO Auto-generated method stub
    			return null;
    		}
        }
    }

 

 

 

 

 

Posted

Have you checked if doApply is being called? You'll still have to use sears on wheat with your json as it is right now.

 

As for updating the conditions, you need to find the point in the vanilla code where the dungeon loot table gets invoked and check the LootParameters passed. You can then use LootConditions to match those parameters.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I have tried to copy the code for the wheat thing exactly as in the documentation, just to see If I can get it to work on anything and it doesn't work. All I have changed is the name of the registry event to tattered_book_dungeons in prep for when I make it affect the dungeons, and the class names to TatteredBookModifier. Do apply is not being called, i tested using a print.

 

@EventBusSubscriber(modid = mod_id, bus = EventBusSubscriber.Bus.MOD)
    public static class EventHandlers {
	        @SubscribeEvent
	        public static void registerModifierSerializers(@Nonnull final RegistryEvent.Register<GlobalLootModifierSerializer<?>> event) {
	            if (ENABLE) {
	                event.getRegistry().register(
	                        new TatteredBookModifier.Serializer().setRegistryName(new ResourceLocation(mod_id,"tattered_book_dungeons"))
	                );
	            }
	           
	    }
    }
    
    private static class TatteredBookModifier extends LootModifier {
        private final int numSeedsToConvert;
        private final Item itemToCheck;
        private final Item itemReward;
        public TatteredBookModifier(ILootCondition[] conditionsIn, int numSeeds, Item itemCheck, Item reward) {
            super(conditionsIn);
            numSeedsToConvert = numSeeds;
            itemToCheck = itemCheck;
            itemReward = reward;
        }

        @Nonnull
        @Override
        public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
            //
            // Additional conditions can be checked, though as much as possible should be parameterized via JSON data.
            // It is better to write a new ILootCondition implementation than to do things here.
            //
        	System.out.println("BRUHHHH");
            int numSeeds = 0;
            for(ItemStack stack : generatedLoot) {
                if(stack.getItem() == itemToCheck)
                    numSeeds+=stack.getCount();
            }
            if(numSeeds >= numSeedsToConvert) {
                generatedLoot.removeIf(x -> x.getItem() == itemToCheck);
                generatedLoot.add(new ItemStack(itemReward, (numSeeds/numSeedsToConvert)));
                numSeeds = numSeeds%numSeedsToConvert;
                if(numSeeds > 0)
                    generatedLoot.add(new ItemStack(itemToCheck, numSeeds));
            }
            return generatedLoot;
        }

        private static class Serializer extends GlobalLootModifierSerializer<TatteredBookModifier> {

            @Override
            public TatteredBookModifier read(ResourceLocation name, JsonObject object, ILootCondition[] conditionsIn) {
                int numSeeds = JSONUtils.getInt(object, "numSeeds");
                Item seed = ForgeRegistries.ITEMS.getValue(new ResourceLocation((JSONUtils.getString(object, "seedItem"))));
                Item wheat = ForgeRegistries.ITEMS.getValue(new ResourceLocation(JSONUtils.getString(object, "replacement")));
                return new TatteredBookModifier(conditionsIn, numSeeds, seed, wheat);
            }

			@Override
			public JsonObject write(TatteredBookModifier instance) {
				// TODO Auto-generated method stub
				return null;
			}
        }
    }

 

 

{
	"replace": false,
	"entries": [
		"spacerulerwillmagicmod:tattered_book_dungeons"
	]
}
{
  "conditions": [
    {
      "condition": "minecraft:match_tool",
      "predicate": {
        "item": "minecraft:shears"
      }
    },
    {
      "condition": "block_state_property",
      "block":"minecraft:wheat"
    }
  ],
  "seedItem": "minecraft:wheat_seeds",
  "numSeeds": 10,
  "replacement": "minecraft:wheat"
}

 

 

Maybe my JSON files are stored in the wrong directory?

image.png.8a8d88b30402995137f89d815e30ca0d.png

 

Posted
29 minutes ago, diesieben07 said:

Do not do this. Always register all your registry entries. Do not do it conditionally. Additionally I would recommend you use DeferredRegister to manage your registry entries.

I think that came from him copying the testmod file.

But yes, don't conditionally register stuff.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.