Jump to content

[1.16.1] Entity Global Loot Modifier Not Working


EnderUnknown

Recommended Posts

I was wondering how to specify the entity in a global loot modifier. I am able to set a condition, such as killed_by_player, and it works properly but my item drops regardless of the entity that I kill, whereas I only want the item to be appended to the Strider's loot table. Here is my JSON file:

{
  "type":"corruption:strider_socks",
  "conditions": [
    {
		"condition":"minecraft:random_chance_with_looting",
		"chance":0.5,
		"looting_multiplier":0.2
    },
	{
		"condition": "minecraft:entity_properties",
		"predicate": {
		  "type": "minecraft:strider"
		},
		"entity": "this"
	  }
  ],
  "item": "corruption:lava_waders"
}

All that my StriderSocks LootModifier class does is add the lava waders to the generated loot. (I have followed the documentation of Global Loot Modifiers, but all of the example are for blocks.)

Any help would be appreciated!

Link to comment
Share on other sites

  • EnderUnknown changed the title to [1.16.1] Entity Global Loot Modifier Not Working

Its been a while since I looked and while I thought there was an existing ILootCondition that checked the entity slain, if there isn't, you can always make one.

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.

Link to comment
Share on other sites

Okay, I was unable to find an existing one so I made my own. When I reload data packs, I get a message that in short says corruption:entity_slain wasn't recognized. I presume that is because I didn't register it properly. I looked for a forge registry but LootConditionType didn't have a registry event so I just registered it into in the same ways the vanilla ones are. (I know one is never supposed to do that and I was going to fix it once I made sure that everything else was working as I am new to making ILootConditions) Anyway, here is my code and maybe someone can help:

strider_socks.json

{
  "type":"corruption:strider_socks",
  "conditions": [
    {
		"condition":"minecraft:random_chance_with_looting",
		"chance":0.5,
		"looting_multiplier":0.2
    },
	{
		"condition": "corruption:entity_slain",
		"entity":"minecraft:strider" 
	}
  ],
  "item": "corruption:lava_waders"
}

 

EntitySlain.java

package com.enderunknown.corruption.util.loot;

import java.util.Set;

import com.google.common.collect.ImmutableSet;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.loot.ILootSerializer;
import net.minecraft.loot.LootConditionType;
import net.minecraft.loot.LootContext;
import net.minecraft.loot.LootParameter;
import net.minecraft.loot.LootParameters;
import net.minecraft.loot.conditions.ILootCondition;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;

public class EntitySlain implements ILootCondition {
   private final EntityType<?> entityType;

   public EntitySlain(EntityType<?> entityType) {
      this.entityType = entityType;
   }

   public LootConditionType func_230419_b_() {
      return CorruptionLootConditionManager.ENTITY_SLAIN;
   }

   public Set<LootParameter<?>> getRequiredParameters() {
      return ImmutableSet.of(LootParameters.THIS_ENTITY);
   }

   public boolean test(LootContext context) {
      Entity entity = context.get(LootParameters.THIS_ENTITY);
      return entity != null && this.entityType.getTags() == entity.getType().getTags();
   }

   public static class Builder implements ILootCondition.IBuilder {
	      private final EntityType<?> entity;

	      public Builder(EntityType<?> entityIn) {
	         this.entity = entityIn;
	      }

	      public ILootCondition build() {
	         return new EntitySlain(this.entity);
	      }
	   }

   public static class Serializer implements ILootSerializer<EntitySlain> {
      public void func_230424_a_(JsonObject p_230424_1_, EntitySlain p_230424_2_, JsonSerializationContext p_230424_3_) {
    	  p_230424_1_.addProperty("entity", Registry.ENTITY_TYPE.getKey(p_230424_2_.entityType).toString());
      }

      public EntitySlain func_230423_a_(JsonObject p_230423_1_, JsonDeserializationContext p_230423_2_) {
    	  ResourceLocation resourcelocation = new ResourceLocation(JSONUtils.getString(p_230423_1_, "entity"));
          EntityType<?> entityT = Registry.ENTITY_TYPE.getValue(resourcelocation).orElseThrow(() -> {
             return new IllegalArgumentException("Can't find block " + resourcelocation);
          });
         return new EntitySlain(entityT);
      }
   }
}

 

CorruptionLootConditionManager.java

package com.enderunknown.corruption.util.loot;

import java.util.function.Predicate;

import net.minecraft.loot.ILootSerializer;
import net.minecraft.loot.LootConditionType;
import net.minecraft.loot.LootTypesManager;
import net.minecraft.loot.conditions.ILootCondition;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;

public class CorruptionLootConditionManager {
   public static final LootConditionType ENTITY_SLAIN = register("entity_slain", new EntitySlain.Serializer());

   private static LootConditionType register(String name, ILootSerializer<? extends ILootCondition> serializer) {
      return Registry.register(Registry.field_239704_ba_, new ResourceLocation("corruption:"+name), new LootConditionType(serializer));
	   
   }

   public static Object register() {
      return LootTypesManager.func_237389_a_(Registry.field_239704_ba_, "condition", "condition", ILootCondition::func_230419_b_).func_237395_a_();
   }

   public static <T> Predicate<T> and(Predicate<T>[] p_216305_0_) {
      switch(p_216305_0_.length) {
      case 0:
         return (p_216304_0_) -> {
            return true;
         };
      case 1:
         return p_216305_0_[0];
      case 2:
         return p_216305_0_[0].and(p_216305_0_[1]);
      default:
         return (p_216307_1_) -> {
            for(Predicate<T> predicate : p_216305_0_) {
               if (!predicate.test(p_216307_1_)) {
                  return false;
               }
            }

            return true;
         };
      }
   }

   public static <T> Predicate<T> or(Predicate<T>[] p_216306_0_) {
      switch(p_216306_0_.length) {
      case 0:
         return (p_216308_0_) -> {
            return false;
         };
      case 1:
         return p_216306_0_[0];
      case 2:
         return p_216306_0_[0].or(p_216306_0_[1]);
      default:
         return (p_216309_1_) -> {
            for(Predicate<T> predicate : p_216306_0_) {
               if (predicate.test(p_216309_1_)) {
                  return true;
               }
            }

            return false;
         };
      }
   }
}

I did my best to keep these as similar to the vanilla classes as possible.

Thanks! 

Edited by EnderUnknown
Clarity
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.