-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cases now spawn in chest loot tables 1/4 times
- Loading branch information
1 parent
5d813cc
commit 05dabee
Showing
12 changed files
with
436 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package dev.marston.randomloot; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.google.common.base.Supplier; | ||
import com.google.common.base.Suppliers; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
import it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
import net.minecraft.data.PackOutput; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.storage.loot.LootContext; | ||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; | ||
import net.minecraftforge.common.data.GlobalLootModifierProvider; | ||
import net.minecraftforge.common.loot.IGlobalLootModifier; | ||
import net.minecraftforge.common.loot.LootModifier; | ||
import net.minecraftforge.registries.ForgeRegistries; | ||
|
||
public class CaseModifier extends LootModifier { | ||
private final Item item; | ||
|
||
public static final Supplier<Codec<CaseModifier>> CODEC = Suppliers.memoize(() -> RecordCodecBuilder.create( | ||
inst -> codecStart(inst).and(ForgeRegistries.ITEMS.getCodec().fieldOf("item").forGetter(m -> m.item)) | ||
.apply(inst, CaseModifier::new))); | ||
|
||
protected CaseModifier(LootItemCondition[] conditionsIn, Item item) { | ||
super(conditionsIn); | ||
this.item = item; | ||
|
||
} | ||
|
||
@Override | ||
public Codec<? extends IGlobalLootModifier> codec() { | ||
return CODEC.get(); | ||
} | ||
|
||
@Override | ||
protected @NotNull ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, | ||
LootContext context) { | ||
|
||
String path = context.getQueriedLootTableId().getPath() ; | ||
|
||
|
||
if (!path.contains("chests")) { | ||
return generatedLoot; | ||
} | ||
|
||
|
||
if (context.getRandom().nextFloat() < 0.25f) { | ||
generatedLoot.add(new ItemStack(item)); | ||
} | ||
|
||
return generatedLoot; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/dev/marston/randomloot/ModLootModifiers.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,21 @@ | ||
package dev.marston.randomloot; | ||
|
||
import net.minecraftforge.common.loot.IGlobalLootModifier; | ||
import net.minecraftforge.eventbus.api.IEventBus; | ||
import net.minecraftforge.registries.DeferredRegister; | ||
import net.minecraftforge.registries.ForgeRegistries; | ||
import net.minecraftforge.registries.RegistryObject; | ||
import com.mojang.serialization.Codec; | ||
|
||
public class ModLootModifiers { | ||
public static final DeferredRegister<Codec<? extends IGlobalLootModifier>> LOOT_MODIFIER_SERIALIZERS = | ||
DeferredRegister.create(ForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, RandomLootMod.MODID); | ||
|
||
public static final RegistryObject<Codec<? extends IGlobalLootModifier>> ADD_ITEM = | ||
LOOT_MODIFIER_SERIALIZERS.register("case_item", CaseModifier.CODEC); | ||
|
||
|
||
public static void register(IEventBus bus) { | ||
LOOT_MODIFIER_SERIALIZERS.register(bus); | ||
} | ||
} |
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
Oops, something went wrong.