Skip to content

Commit

Permalink
Changed drop event to mixin
Browse files Browse the repository at this point in the history
(idk maybe priorities will be more consistant now)
Now the fabric and neoforge versions have the same death handling entry
  • Loading branch information
B1n-ry committed Sep 18, 2024
1 parent 9f529f4 commit 651bec1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/main/java/com/b1n_ry/yigd/events/ServerEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@
import java.util.UUID;

public class ServerEventHandler {
@SubscribeEvent
public void onDrop(LivingDeathEvent event) {
LivingEntity e = event.getEntity();
if (e.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY)) return;
if (!(e instanceof ServerPlayer player)) return;

Yigd.DEATH_HANDLER.onPlayerDeath(player, player.serverLevel(), player.position(), event.getSource());
}

@SubscribeEvent
public void onEndOfTick(ServerTickEvent.Post event) {
List<Runnable> methodsToRun = new ArrayList<>(Yigd.END_OF_TICK);
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/b1n_ry/yigd/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.b1n_ry.yigd.mixin;

import com.b1n_ry.yigd.DeathHandler;
import com.b1n_ry.yigd.Yigd;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.GameRules;
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(value = LivingEntity.class, priority = 500)
public class LivingEntityMixin {
@Inject(method = "dropAllDeathLoot", at = @At("HEAD"))
private void onDeath(ServerLevel level, DamageSource damageSource, CallbackInfo ci) {
LivingEntity entity = (LivingEntity) (Object) this;

if (!(entity instanceof ServerPlayer player)) return;

if (!player.isDeadOrDying()) return;
if (player.isSpectator()) return;

if (level.getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY)) return;

Yigd.DEATH_HANDLER.onPlayerDeath(player, level, player.position(), damageSource);
}
}
1 change: 1 addition & 0 deletions src/main/resources/yigd.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"CompassItemMixin",
"EndPlatformFeatureMixin",
"LevelChunkMixin",
"LivingEntityMixin",
"RegistryDataLoaderMixin"
],
"client": [
Expand Down

0 comments on commit 651bec1

Please sign in to comment.