Jump to content

MLGDuckboi

Members
  • Posts

    11
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

MLGDuckboi's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Another issue: My loot modifier won't load, the log just says it can't parse it, as well as a NullPointerException error. Do I have to specify that my class should be used to parse it somewhere? All related files below: data/forge/loot_modifiers/global_loot_modifiers.json { "replace": false, "entries": [ "calebsmod:golden_touch" ] } data/calebsmod/loot_modifiers/golden_touch.json { "conditions": [ { "condition": "minecraft:entity_properties", "entity": "this", "predicate": { "effects": { "calebsmod:golden_touch": {} } } } ], "chance_per_level": 0.2, "drop": { "min": 1, "max": 3, "item": "minecraft:gold" } } LootModification public class LootModification extends LootModifier { private final int minDrop; private final int maxDrop; private final Item replacementItem; private final float chancePerLvl; public LootModification(ILootCondition[] conditionsIn, int minDrop, int maxDrop, Item itemDrop, float chancePerLvl) { super(conditionsIn); this.minDrop = minDrop; this.maxDrop = maxDrop; this.replacementItem = itemDrop; this.chancePerLvl = chancePerLvl; } @Nonnull @Override public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) { LivingEntity entity = (LivingEntity)context.getParamOrNull(LootParameters.THIS_ENTITY); Random random = new Random(); if (entity.getEffect(ModEffects.GOLDEN_TOUCH.get()).getAmplifier() * chancePerLvl > random.nextFloat()) { generatedLoot.removeAll(generatedLoot); generatedLoot.add(new ItemStack(replacementItem, minDrop + random.nextInt(maxDrop - minDrop))); } return generatedLoot; } public static class Serializer extends GlobalLootModifierSerializer<LootModification> { @Override public LootModification read(ResourceLocation name, JsonObject object, ILootCondition[] conditionsIn) { float chance = JSONUtils.getAsFloat(object, "chance_per_level"); int max = JSONUtils.getAsInt(object, "drop.max"); int min = JSONUtils.getAsInt(object, "drop.min"); Item drop = ForgeRegistries.ITEMS.getValue(new ResourceLocation((JSONUtils.getAsString(object, "drop.item")))); return new LootModification(conditionsIn, min, max, drop, chance); } @Override public JsonObject write(LootModification instance) { JsonObject json = makeConditions(instance.conditions); json.addProperty("chance_per_level", instance.chancePerLvl); json.addProperty("drop.min", instance.minDrop); json.addProperty("drop.max", instance.maxDrop); json.addProperty("drop.item", ForgeRegistries.ITEMS.getKey(instance.replacementItem).toString()); return json; } } }
  2. Update: Sorry, I cant seem to figure out where LootParameters comes into my class. public class LootModification extends LootModifier { private final int minDrop; private final int maxDrop; private final Item replacementItem; private final int chancePerLvl; public LootModification(ILootCondition[] conditionsIn, int minDrop, int maxDrop, Item itemDrop, int chancePerLvl) { super(conditionsIn); this.minDrop = minDrop; this.maxDrop = maxDrop; this.replacementItem = itemDrop; this.chancePerLvl = chancePerLvl; } @Nonnull @Override public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) { return generatedLoot; } public static class Serializer extends GlobalLootModifierSerializer<LootModification> { @Override public LootModification read(ResourceLocation name, JsonObject object, ILootCondition[] conditionsIn) { int chance = JSONUtils.getAsInt(object, "chance_per_level"); int max = JSONUtils.getAsInt(object, "drop.max"); int min = JSONUtils.getAsInt(object, "drop.min"); Item drop = ForgeRegistries.ITEMS.getValue(new ResourceLocation((JSONUtils.getAsString(object, "drop.item")))); return new LootModification(conditionsIn, min, max, drop, chance); } @Override public JsonObject write(LootModification instance) { JsonObject json = makeConditions(instance.conditions); json.addProperty("chance_per_level", instance.chancePerLvl); json.addProperty("drop.min", instance.minDrop); json.addProperty("drop.max", instance.maxDrop); json.addProperty("drop.item", ForgeRegistries.ITEMS.getKey(instance.replacementItem).toString()); return json; } } } Could you point me in the right direction?
  3. Thanks, that helps a ton
  4. I am trying to make a loot modifier which has varying effects based off the level of a certain status effect a player has. My modifier JSON currently checks if the player has the status effect. { "conditions": [ { "condition": "minecraft:entity_properties", "entity": "this", "predicate": { "effects": { "calebsmod:golden_touch": {} } } } ], "chance_per_level": 20, "drop": { "min": 1, "max": 3, "item": "minecraft:gold" } } Basically, "chance_per_level" dictates the chance of a block dropping somewhere between one and three gold (as defined in "drop") per level of my effect, calebsmod:golden_touch. For example, level 1 is 20% chance for gold, level 2 is 40% chance, and so on. What I'm stuck on is in my LootModifier class in the doApply method, how to get the level of the effect on the given entity. The only solution I can think of is making a loot modifier JSON for each level of the effect, but I was hoping there might be a better way. Thanks in advance!
  5. I was using it to spawn extra items when a block is broken, but now I'm looking into loot modifiers since they are closer to what I need
  6. To pass to a blocks spawnDrops() method, casting worked fine
  7. Sorry, bit new to programming, what do you mean by "cast it"? Edit: Nevermind, figured it out
  8. I am using the event BlockEvent.BreakEvent, and I want to know how to get a World instance from the event. Using getWorld() returns an IWorld instance, so that won't help. Thanks in advance.
  9. You're a lifesaver, thanks
  10. Almost works like I want it to, but doesn't work in creative for some reason? Edit: The method is called when loot is spawned, and loot isn't spawned in creative, I assume thats problem
  11. I'm trying to make it so when my block is broken, it gets replaced by another block, but this code won't work: @Override public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) { super.onBlockHarvested(worldIn, pos, state, player); worldIn.setBlockState(pos, modBlocks.STAKE.get().getDefaultState(), 3); } I changed pos to pos.up(), and it worked correctly (placed the block above itself when broken), but setting the block and the current position doesn't work. Help?
×
×
  • Create New...

Important Information

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