-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GLM: `add_table`. Biome modifiers: `add_carvers`, `remove_carvers`, `add_spawn_costs`, `remove_spawn_costs`. Structure modifiers: `add_spawns`, `remove_spawns`, `clear_spawns`
- Loading branch information
1 parent
75f2348
commit 69d5eb0
Showing
7 changed files
with
514 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/net/neoforged/neoforge/common/loot/AddTableLootModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.common.loot; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.storage.loot.LootContext; | ||
import net.minecraft.world.level.storage.loot.LootTable; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; | ||
import net.neoforged.neoforge.common.NeoForgeMod; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* <p>Loot modifier that rolls one loot table (the "subtable" and adds the results to the loot being modified (the "target table"). | ||
* Loot modifiers are not rolled for the subtable, as that could result in the subtables' | ||
* items being modified twice (by downstream loot modifiers modifying the target table).</p> | ||
* | ||
* <p> Json format: | ||
* | ||
* <pre> | ||
* { | ||
* "type": "neoforge:add_table", | ||
* "conditions": [], // conditions block to predicate target tables by | ||
* "table": "namespace:loot_table_id" // subtable to roll loot for to add to the target table(s) | ||
* } | ||
* </pre> | ||
* | ||
* </p> | ||
*/ | ||
public class AddTableLootModifier extends LootModifier { | ||
/** | ||
* @see NeoForgeMod#ADD_TABLE_LOOT_MODIFIER_TYPE | ||
*/ | ||
@ApiStatus.Internal | ||
public static final Codec<AddTableLootModifier> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
IGlobalLootModifier.LOOT_CONDITIONS_CODEC.fieldOf("conditions").forGetter(glm -> glm.conditions), | ||
ResourceLocation.CODEC.fieldOf("table").forGetter(AddTableLootModifier::table)).apply(instance, AddTableLootModifier::new)); | ||
|
||
private final ResourceLocation table; | ||
|
||
protected AddTableLootModifier(LootItemCondition[] conditionsIn, ResourceLocation table) { | ||
super(conditionsIn); | ||
this.table = table; | ||
} | ||
|
||
public ResourceLocation table() { | ||
return this.table; | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@Override | ||
protected @NotNull ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) { | ||
LootTable extraTable = context.getResolver().getLootTable(this.table); | ||
// Don't run loot modifiers for subtables; | ||
// the added loot will be modifiable by downstream loot modifiers modifying the target table, | ||
// so if we modify it here then it could get modified twice. | ||
extraTable.getRandomItemsRaw(context, LootTable.createStackSplitter(context.getLevel(), generatedLoot::add)); | ||
return generatedLoot; | ||
} | ||
|
||
@Override | ||
public Codec<? extends IGlobalLootModifier> codec() { | ||
return NeoForgeMod.ADD_TABLE_LOOT_MODIFIER_TYPE.get(); | ||
} | ||
} |
Oops, something went wrong.