Skip to content

Commit

Permalink
Fixed #359
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Jan 12, 2025
1 parent f380fc3 commit b395d26
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 89 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,4 @@ public class MixinSkeletonTrapGoal {
private void banner$jockey(CallbackInfo ci) {
this.horse.level().pushAddEntityReason(CreatureSpawnEvent.SpawnReason.JOCKEY);
}

@Redirect(method = "canUse",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/level/Level;hasNearbyAlivePlayer(DDDD)Z"))
private boolean banner$affectSpawn(Level instance, double x, double u, double z, double d) {
return this.horse.level().hasNearbyAlivePlayerThatAffectsSpawning(this.horse.getX(), this.horse.getY(), this.horse.getZ(), 10.0D); // Paper - Affects Spawning API
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ private static ZombieVillager zombifyVillager(ServerLevel level, Villager villag
return zombieVillager;
}

@Redirect(method = "hurt", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/level/Level;hasNearbyAlivePlayer(DDDD)Z"))
private boolean banner$affectSpawn(Level instance, double x, double y, double z, double d) {
return this.level().hasNearbyAlivePlayerThatAffectsSpawning((double) x, (double) y, (double) z, 7.0D);
}

@WrapWithCondition(method = "registerGoals",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/entity/ai/goal/GoalSelector;addGoal(ILnet/minecraft/world/entity/ai/goal/Goal;)V",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
package com.mohistmc.banner.mixin.world.level.spawner;

import java.util.Optional;
import io.izzel.arclight.mixin.Decorate;
import io.izzel.arclight.mixin.DecorationOps;
import io.izzel.arclight.mixin.Local;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.util.random.SimpleWeightedRandomList;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.SpawnData;
import org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(BaseSpawner.class)
public abstract class MixinBaseSpawner {
Expand All @@ -32,34 +29,19 @@ public abstract class MixinBaseSpawner {
this.spawnPotentials = SimpleWeightedRandomList.empty();
}

@Inject(method = "serverTick",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/server/level/ServerLevel;tryAddFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)Z"),
locals = LocalCapture.CAPTURE_FAILHARD)
private void banner$pushReason(ServerLevel serverLevel, BlockPos pos, CallbackInfo ci, boolean bl,
RandomSource randomSource, SpawnData spawnData, int i,
CompoundTag compoundTag, Optional optional, ListTag listTag,
int j, double d, double e, double f, BlockPos blockPos,
Entity entity) {
// Spigot Start
if (CraftEventFactory.callSpawnerSpawnEvent(entity, blockPos).isCancelled()) {
Entity vehicle = entity.getVehicle();
if (vehicle != null) {
vehicle.discard();
}
for (Entity passenger : entity.getIndirectPassengers()) {
passenger.discard();
}
return;
@Decorate(method = "serverTick", inject = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;checkSpawnObstruction(Lnet/minecraft/world/level/LevelReader;)Z"))
private void banner$nerf(@Local(ordinal = -1) Mob mob) {
if (mob.level().bridge$spigotConfig().nerfSpawnerMobs) {
mob.banner$setAware(false);
}
// Spigot End
serverLevel.pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SPAWNER);
}

@Redirect(method = "isNearPlayer",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/level/Level;hasNearbyAlivePlayer(DDDD)Z"))
private boolean banner$affectSpawn(Level instance, double x, double y, double z, double v) {
return instance.hasNearbyAlivePlayerThatAffectsSpawning(x, y, z, v); // Paper - Affects Spawning API
@Decorate(method = "serverTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;tryAddFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)Z"))
private boolean banner$pushReason(ServerLevel serverLevel, Entity entity, ServerLevel level, BlockPos pos) throws Throwable {
if (CraftEventFactory.callSpawnerSpawnEvent(entity, pos).isCancelled()) {
throw DecorationOps.jumpToLoopStart();
}
serverLevel.pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SPAWNER);
return (boolean) DecorationOps.callsite().invoke(serverLevel, entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@
"world.item.trading.MixinMerchant",
"world.item.trading.MixinMerchantOffer",
"world.level.MixinClipContext",
"world.level.MixinEntityGetter",
"world.level.MixinExplosion",
"world.level.MixinLevel",
"world.level.MixinLevelAccessor",
Expand Down
1 change: 0 additions & 1 deletion modules/banner-server/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"net/minecraft/class_1496": ["com/mohistmc/banner/injection/world/entity/InjectionAbstractHorse"],
"net/minecraft/class_1937": ["com/mohistmc/banner/injection/world/level/InjectionLevel"],
"net/minecraft/class_2881": ["com/mohistmc/banner/injection/world/level/dimension/end/InjectionEndDragonFight"],
"net/minecraft/class_1924": ["com/mohistmc/banner/injection/world/level/InjectionEntityGetter"],
"net/minecraft/class_1936": ["com/mohistmc/banner/injection/world/level/InjectionLevelAccessor"],
"net/minecraft/class_3765": ["com/mohistmc/banner/injection/world/entity/raid/InjectionRaid"],
"net/minecraft/class_1533": ["com/mohistmc/banner/injection/world/entity/decoration/InjectionItemFrame"],
Expand Down

0 comments on commit b395d26

Please sign in to comment.