Skip to content

Commit

Permalink
victory against the mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
MBatt1 committed Oct 11, 2024
1 parent 29b51b1 commit f1a2e95
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.id.paradiselost.mixin.enchantment;

import net.id.paradiselost.tag.ParadiseLostItemTags;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import org.jetbrains.annotations.Nullable;
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;

@Mixin(EnchantmentHelper.class)
public class EnchantmentHelperMixin {

@Inject(method = "onTargetDamaged(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/damage/DamageSource;Lnet/minecraft/item/ItemStack;)V", at = @At(value = "HEAD"))
private static void onTargetDamaged(ServerWorld world, Entity target, DamageSource damageSource, @Nullable ItemStack weapon, CallbackInfo ci) {
if (target instanceof LivingEntity && weapon != null && weapon.isIn(ParadiseLostItemTags.IGNITING_TOOLS)) {
target.setFireTicks(120);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,35 @@
import net.id.paradiselost.entities.ParadiseLostEntityExtensions;
import net.id.paradiselost.entities.passive.moa.MoaAttributes;
import net.id.paradiselost.entities.passive.moa.MoaEntity;
import net.id.paradiselost.tag.ParadiseLostItemTags;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet;
import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.loot.function.LootFunctionTypes;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.SmeltingRecipe;
import net.minecraft.recipe.input.SingleStackRecipeInput;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

import java.util.Optional;
import java.util.function.Consumer;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends Entity implements ParadiseLostEntityExtensions {
Expand Down Expand Up @@ -58,4 +77,26 @@ private void getMoaMaxHealth(CallbackInfoReturnable<Float> cir) {
cir.cancel();
}
}

@ModifyArgs(method = "dropLoot", at = @At(value = "INVOKE", target = "Lnet/minecraft/loot/LootTable;generateLoot(Lnet/minecraft/loot/context/LootContextParameterSet;JLjava/util/function/Consumer;)V"))
private void dropSmeltedLoot(Args args) {
LootContextParameterSet lootContextParameterSet = args.get(0);
var weapon = lootContextParameterSet.get(LootContextParameters.DAMAGE_SOURCE).getWeaponStack();
if (weapon != null && weapon.isIn(ParadiseLostItemTags.IGNITING_TOOLS)) {
args.set(2, (Consumer<ItemStack>) this::dropStackInternal);
}
}

@Nullable
private ItemEntity dropStackInternal(ItemStack stack) {
Optional<RecipeEntry<SmeltingRecipe>> optional = this.getWorld().getRecipeManager().getFirstMatch(RecipeType.SMELTING, new SingleStackRecipeInput(stack), getWorld());
if (optional.isPresent()) {
ItemStack itemStack = (((RecipeEntry)optional.get()).value()).getResult(getWorld().getRegistryManager());
if (!itemStack.isEmpty()) {
return this.dropStack(itemStack.copyWithCount(stack.getCount()), 0.0F);
}
}
return this.dropStack(stack);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"add": false
},
{
"function": "minecraft:enchanted_count_increase"
"function": "minecraft:enchanted_count_increase",
"enchantment": "minecraft:looting",
"count": {
"type": "minecraft:uniform",
"min": 0,
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/paradise_lost.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"block.BlockMixin",
"block.CropBlockMixin",
"block.FarmlandBlockMixin",
"enchantment.EnchantmentHelperMixin",
"entity.BoatEntityMixin",
"entity.ChestBoatEntityMixin",
"entity.CowEntityMixin",
Expand Down

0 comments on commit f1a2e95

Please sign in to comment.