-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8d146b
commit d95af5d
Showing
18 changed files
with
325 additions
and
86 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
src/generated/resources/.cache/171e510db94907b4e0ae3ec8c2888a9721eddd1e
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,4 @@ | ||
// 1.21 2024-08-03T01:13:59.9045726 Global Loot Modifiers : seidr | ||
b96a1c0bdb959e665bcc5b47474394305d4ea5f3 data/neoforge/loot_modifiers/global_loot_modifiers.json | ||
1fdd6144e2cba6d5491dac4dbebdf706877e6643 data/seidr/loot_modifiers/mineshaft_loot_modifiers.json | ||
49f03a6c5409a669c4827452551f2e0db73e597a data/seidr/loot_modifiers/nether_loot_modifiers.json |
7 changes: 7 additions & 0 deletions
7
src/generated/resources/data/neoforge/loot_modifiers/global_loot_modifiers.json
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,7 @@ | ||
{ | ||
"entries": [ | ||
"seidr:mineshaft_loot_modifiers", | ||
"seidr:nether_loot_modifiers" | ||
], | ||
"replace": false | ||
} |
36 changes: 36 additions & 0 deletions
36
src/generated/resources/data/seidr/loot_modifiers/mineshaft_loot_modifiers.json
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,36 @@ | ||
{ | ||
"type": "seidr:mineshaft_loot", | ||
"chanceToSpawn": 0.8, | ||
"conditions": [ | ||
{ | ||
"condition": "minecraft:any_of", | ||
"terms": [ | ||
{ | ||
"condition": "neoforge:loot_table_id", | ||
"loot_table_id": "minecraft:chests/abandoned_mineshaft" | ||
}, | ||
{ | ||
"condition": "neoforge:loot_table_id", | ||
"loot_table_id": "minecraft:chests/jungle_temple" | ||
} | ||
] | ||
} | ||
], | ||
"items": [ | ||
{ | ||
"data": { | ||
"count": 1, | ||
"id": "seidr:incomplete_undead_tablet" | ||
}, | ||
"weight": 70 | ||
}, | ||
{ | ||
"data": { | ||
"count": 1, | ||
"id": "seidr:effect_remove_tablet" | ||
}, | ||
"weight": 30 | ||
} | ||
], | ||
"totalWeight": 100 | ||
} |
43 changes: 43 additions & 0 deletions
43
src/generated/resources/data/seidr/loot_modifiers/nether_loot_modifiers.json
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,43 @@ | ||
{ | ||
"type": "seidr:mineshaft_loot", | ||
"chanceToSpawn": 0.8, | ||
"conditions": [ | ||
{ | ||
"condition": "minecraft:any_of", | ||
"terms": [ | ||
{ | ||
"condition": "neoforge:loot_table_id", | ||
"loot_table_id": "minecraft:chests/ruined_portal" | ||
}, | ||
{ | ||
"condition": "neoforge:loot_table_id", | ||
"loot_table_id": "minecraft:chests/nether_bridge" | ||
} | ||
] | ||
} | ||
], | ||
"items": [ | ||
{ | ||
"data": { | ||
"count": 1, | ||
"id": "seidr:attraction_tablet" | ||
}, | ||
"weight": 20 | ||
}, | ||
{ | ||
"data": { | ||
"count": 1, | ||
"id": "seidr:damaged_undead_tablet" | ||
}, | ||
"weight": 30 | ||
}, | ||
{ | ||
"data": { | ||
"count": 1, | ||
"id": "seidr:fireball_tablet" | ||
}, | ||
"weight": 60 | ||
} | ||
], | ||
"totalWeight": 110 | ||
} |
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
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
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
70 changes: 70 additions & 0 deletions
70
src/main/java/com/github/darksonic300/seidr/datagen/loot/modifiers/SeidrAddLootModifier.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,70 @@ | ||
package com.github.darksonic300.seidr.datagen.loot.modifiers; | ||
|
||
import com.google.common.base.Suppliers; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.MapCodec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.util.random.WeightedEntry; | ||
import net.minecraft.util.random.WeightedRandom; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.storage.loot.LootContext; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; | ||
import net.neoforged.neoforge.common.loot.IGlobalLootModifier; | ||
import net.neoforged.neoforge.common.loot.LootModifier; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
public class SeidrAddLootModifier extends LootModifier { | ||
|
||
public static final MapCodec<SeidrAddLootModifier> CODEC = RecordCodecBuilder.mapCodec(inst -> | ||
LootModifier.codecStart(inst).and(inst.group( | ||
WeightedEntry.Wrapper.codec(ItemStack.CODEC).listOf().fieldOf("items").forGetter(m -> m.items), | ||
Codec.INT.fieldOf("totalWeight").forGetter(m -> m.totalWeight), | ||
Codec.FLOAT.fieldOf("chanceToSpawn").forGetter(m -> m.chance) | ||
)).apply(inst, SeidrAddLootModifier::new) | ||
); | ||
|
||
public final List<WeightedEntry.Wrapper<ItemStack>> items; | ||
public final int totalWeight; | ||
public final float chance; | ||
|
||
public SeidrAddLootModifier(final LootItemCondition[] conditionsIn, List<WeightedEntry.Wrapper<ItemStack>> items, int totalWeight, float chance) { | ||
super(conditionsIn); | ||
this.items = items.stream().map(wrapper -> WeightedEntry.wrap(wrapper.data().copy(), wrapper.getWeight().asInt())).toList(); | ||
this.totalWeight = totalWeight; | ||
this.chance = chance; | ||
} | ||
|
||
@Override | ||
protected @NotNull ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) { | ||
|
||
// size of the loots | ||
int size = generatedLoot.size(); | ||
|
||
// is the loot full? | ||
boolean isFull = size == 27; | ||
|
||
// size diff for when it's not full | ||
int sizeDiff = 27-size; | ||
|
||
// if the loot is not full, for each slot remaining, have x chance to add one of our item in the empty slots | ||
if(!isFull) { | ||
for(int i = 0; i<= sizeDiff; i++) { | ||
if(context.getRandom().nextFloat() > chance) { | ||
WeightedRandom.getRandomItem(context.getRandom(), this.items, totalWeight).ifPresent(e -> generatedLoot.add(e.data())); | ||
} | ||
} | ||
} | ||
|
||
return generatedLoot; | ||
} | ||
|
||
@Override | ||
public MapCodec<? extends IGlobalLootModifier> codec() { | ||
return CODEC; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...n/java/com/github/darksonic300/seidr/datagen/loot/modifiers/SeidrGlobalLootModifiers.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,19 @@ | ||
package com.github.darksonic300.seidr.datagen.loot.modifiers; | ||
|
||
import com.github.darksonic300.seidr.Seidr; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.MapCodec; | ||
import net.neoforged.neoforge.common.loot.IGlobalLootModifier; | ||
import net.neoforged.neoforge.registries.DeferredHolder; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
import net.neoforged.neoforge.registries.NeoForgeRegistries; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class SeidrGlobalLootModifiers { | ||
public static final DeferredRegister<MapCodec<? extends IGlobalLootModifier>> LOOT_MODIFIERS = | ||
DeferredRegister.create(NeoForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, Seidr.MODID); | ||
|
||
public static final Supplier<MapCodec<SeidrAddLootModifier>> NETHER_LOOT_CODEC = LOOT_MODIFIERS.register("nether_loot", () -> SeidrAddLootModifier.CODEC); | ||
public static final Supplier<MapCodec<SeidrAddLootModifier>> MINESHAFT_LOOT_CODEC = LOOT_MODIFIERS.register("mineshaft_loot", () -> SeidrAddLootModifier.CODEC); | ||
} |
49 changes: 49 additions & 0 deletions
49
...main/java/com/github/darksonic300/seidr/datagen/loot/modifiers/SeidrLootDataProvider.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,49 @@ | ||
package com.github.darksonic300.seidr.datagen.loot.modifiers; | ||
|
||
import com.github.darksonic300.seidr.Seidr; | ||
import com.github.darksonic300.seidr.item.SeidrItems; | ||
import net.minecraft.core.HolderLookup; | ||
import net.minecraft.data.PackOutput; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.util.random.WeightedEntry; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; | ||
import net.neoforged.neoforge.common.data.GlobalLootModifierProvider; | ||
import net.neoforged.neoforge.common.loot.LootTableIdCondition; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class SeidrLootDataProvider extends GlobalLootModifierProvider { | ||
public SeidrLootDataProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) { | ||
super(output, registries, Seidr.MODID); | ||
} | ||
|
||
@Override | ||
protected void start() { | ||
add("nether_loot_modifiers", new SeidrAddLootModifier( | ||
new LootItemCondition[] { LootTableIdCondition.builder(ResourceLocation.fromNamespaceAndPath("minecraft", "chests/ruined_portal")) | ||
.or(LootTableIdCondition.builder(ResourceLocation.fromNamespaceAndPath("minecraft", "chests/nether_bridge"))) | ||
.build() }, | ||
List.of( | ||
WeightedEntry.wrap(new ItemStack(SeidrItems.ATTRACTION_TABLET.get(), 1), 20), | ||
WeightedEntry.wrap(new ItemStack(SeidrItems.DAMAGED_UNDEAD_TABLET.get(), 1), 30), | ||
WeightedEntry.wrap(new ItemStack(SeidrItems.FIREBALL_TABLET.get(), 1), 60) | ||
), | ||
110, | ||
0.8f | ||
)); | ||
|
||
add("mineshaft_loot_modifiers", new SeidrAddLootModifier( | ||
new LootItemCondition[] { LootTableIdCondition.builder(ResourceLocation.fromNamespaceAndPath("minecraft", "chests/abandoned_mineshaft")) | ||
.or(LootTableIdCondition.builder(ResourceLocation.fromNamespaceAndPath("minecraft", "chests/jungle_temple"))) | ||
.build() }, | ||
List.of( | ||
WeightedEntry.wrap(new ItemStack(SeidrItems.INCOMPLETE_UNDEAD_TABLET.get(), 1), 70), | ||
WeightedEntry.wrap(new ItemStack(SeidrItems.EFFECT_REMOVE_TABLET.get(), 1), 30) | ||
), | ||
100, | ||
0.8f | ||
)); | ||
} | ||
} |
Oops, something went wrong.