Skip to content

Commit

Permalink
Added the SpecialMobDropHelper.
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSVK12 committed Dec 10, 2024
1 parent 8bc32d4 commit 00afbad
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/turniplabs/halplibe/helper/SpecialMobDropHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package turniplabs.halplibe.helper;

import net.minecraft.core.WeightedRandomBag;
import net.minecraft.core.WeightedRandomLootObject;

public class SpecialMobDropHelper {

/**
* Manipulates the loot that can drop when a creeper is killed by a skeleton.
*/
public static class Creeper {
private static final WeightedRandomBag<WeightedRandomLootObject> creeperDrops = new WeightedRandomBag<>();

public static void addDrop(WeightedRandomLootObject drop, int weight) {
creeperDrops.addEntry(drop,weight);
}

public static WeightedRandomBag<WeightedRandomLootObject> getDrops() {
return creeperDrops;
}
}

}
33 changes: 33 additions & 0 deletions src/main/java/turniplabs/halplibe/mixin/MobCreeperMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package turniplabs.halplibe.mixin;

import net.minecraft.core.WeightedRandomLootObject;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.entity.monster.MobCreeper;
import net.minecraft.core.entity.monster.MobMonster;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.world.World;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import turniplabs.halplibe.helper.SpecialMobDropHelper;

@Mixin(value = MobCreeper.class,remap = false)
public abstract class MobCreeperMixin extends MobMonster {

private MobCreeperMixin(@Nullable World world) {
super(world);
}

@Inject(method = "onDeath", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/entity/monster/MobCreeper;dropItem(II)Lnet/minecraft/core/entity/EntityItem;",shift = At.Shift.AFTER))
public void dropItemsOnDeath(Entity entityKilledBy, CallbackInfo ci) {
for (WeightedRandomLootObject entry : SpecialMobDropHelper.Creeper.getDrops().getEntries()) {
ItemStack stack = entry.getItemStack();
if(stack != null){
dropItem(stack,0.0f);
}
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/halplibe.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"I18nMixin",
"MinecraftMixin",
"MinecraftServerMixin",
"MobCreeperMixin",
"accessors.BlockAccessor",
"accessors.BlocksAccessor",
"accessors.EntityFireflyFXAccessor",
Expand Down

0 comments on commit 00afbad

Please sign in to comment.