Skip to content

Commit

Permalink
Fix mixin conflict with architectury api (#1282)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Mar 24, 2024
1 parent c4f33fe commit df8ea44
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public interface BaseSpawnerBridge {

boolean bridge$forge$checkSpawnRules(Mob mob, ServerLevelAccessor level, MobSpawnType spawnType, SpawnData spawnData);
boolean bridge$forge$checkSpawnRules(Mob mob, ServerLevelAccessor level, MobSpawnType spawnType, SpawnData spawnData, boolean result);

void bridge$forge$finalizeSpawnerSpawn(Mob mob, ServerLevelAccessor level, DifficultyInstance difficulty, @Nullable SpawnGroupData spawnData, @Nullable CompoundTag spawnTag);
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void serverTick(ServerLevel level, BlockPos pos) {

entity.moveTo(entity.getX(), entity.getY(), entity.getZ(), level.random.nextFloat() * 360.0F, 0.0F);
if (entity instanceof Mob mob) {
if (this.bridge$forge$checkSpawnRules(mob, level, MobSpawnType.SPAWNER, spawnData)) {
if (this.bridge$forge$checkSpawnRules(mob, level, MobSpawnType.SPAWNER, spawnData, spawnData.getCustomSpawnRules().isEmpty() && !mob.checkSpawnRules(level, MobSpawnType.SPAWNER) || !mob.checkSpawnObstruction(level))) {
continue;
}

Expand Down Expand Up @@ -169,8 +169,8 @@ public void serverTick(ServerLevel level, BlockPos pos) {
}

@Override
public boolean bridge$forge$checkSpawnRules(Mob mob, ServerLevelAccessor level, MobSpawnType spawnType, SpawnData spawnData) {
return spawnData.getCustomSpawnRules().isEmpty() && !mob.checkSpawnRules(level, MobSpawnType.SPAWNER) || !mob.checkSpawnObstruction(level);
public boolean bridge$forge$checkSpawnRules(Mob mob, ServerLevelAccessor level, MobSpawnType spawnType, SpawnData spawnData, boolean result) {
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.izzel.arclight.common.mod.server.entity;

import io.izzel.arclight.api.Unsafe;
import io.izzel.arclight.common.bridge.bukkit.EntityTypeBridge;
import io.izzel.arclight.common.bridge.core.entity.projectile.DamagingProjectileEntityBridge;
import io.izzel.arclight.common.mod.server.ArclightServer;
Expand Down Expand Up @@ -66,6 +65,7 @@
import net.minecraft.world.entity.animal.horse.TraderLlama;
import net.minecraft.world.entity.animal.horse.ZombieHorse;
import net.minecraft.world.entity.animal.sniffer.Sniffer;
import net.minecraft.world.entity.boss.EnderDragonPart;
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraft.world.entity.boss.wither.WitherBoss;
Expand Down Expand Up @@ -219,14 +219,10 @@ private static <R extends HangingEntity> Function<CraftEntityTypes.SpawnData, R>
}

public static void init() {
Unsafe.ensureClassInitialized(CraftEntityTypes.class);
Map<org.bukkit.entity.EntityType, CraftEntityTypes.EntityTypeData<?, ?>> entityTypeData = Unsafe.getStatic(CraftEntityTypes.class, "ENTITY_TYPE_DATA");

var allEntityClasses = new HashSet<Class<?>>();
for (var entry : entityTypeData.entrySet()) {
var bukkitType = entry.getKey();
for (var bukkitType : org.bukkit.entity.EntityType.values()) {
Class<? extends org.bukkit.entity.Entity> entityClass = bukkitType.getEntityClass();
if (!allEntityClasses.contains(entityClass)) {
if (entityClass != null && !allEntityClasses.contains(entityClass)) {
var next = new LinkedList<Class<?>>();
next.add(entityClass);
while (!next.isEmpty()) {
Expand Down Expand Up @@ -367,6 +363,7 @@ private static Class<? extends CraftEntity> forName(String name) {
add(AbstractGolem.class, new EntityClass<>(org.bukkit.entity.Golem.class, org.bukkit.craftbukkit.v.entity.CraftGolem.class, org.bukkit.craftbukkit.v.entity.CraftGolem::new));
add(Player.class, new EntityClass<>(org.bukkit.entity.HumanEntity.class, org.bukkit.craftbukkit.v.entity.CraftHumanEntity.class, org.bukkit.craftbukkit.v.entity.CraftHumanEntity::new));
add(AbstractFish.class, new EntityClass<>(org.bukkit.entity.Fish.class, org.bukkit.craftbukkit.v.entity.CraftFish.class, org.bukkit.craftbukkit.v.entity.CraftFish::new));
add(EnderDragonPart.class, new EntityClass<>(org.bukkit.entity.EnderDragonPart.class, org.bukkit.craftbukkit.v.entity.CraftEnderDragonPart.class, org.bukkit.craftbukkit.v.entity.CraftEnderDragonPart::new));

// vanilla mob types
add(ElderGuardian.class, new EntityClass<>(org.bukkit.entity.ElderGuardian.class, org.bukkit.craftbukkit.v.entity.CraftElderGuardian.class, org.bukkit.craftbukkit.v.entity.CraftElderGuardian::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.SpawnData;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.MobSpawnEvent;
import net.minecraftforge.eventbus.api.Event;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(BaseSpawner.class)
public class BaseSpawnerMixin_Forge implements BaseSpawnerBridge {

@Override
public boolean bridge$forge$checkSpawnRules(Mob mob, ServerLevelAccessor level, MobSpawnType spawnType, SpawnData spawnData) {
return !ForgeEventFactory.checkSpawnPositionSpawner(mob, level, MobSpawnType.SPAWNER, spawnData, (BaseSpawner) (Object) this);
public boolean bridge$forge$checkSpawnRules(Mob mob, ServerLevelAccessor level, MobSpawnType spawnType, SpawnData spawnData, boolean original) {
var spawnEvent = new MobSpawnEvent.PositionCheck(mob, level, spawnType, null);
MinecraftForge.EVENT_BUS.post(spawnEvent);
var result = spawnEvent.getResult();
if (result == Event.Result.DEFAULT) {
return original;
}
return result == Event.Result.ALLOW;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.SpawnData;
import net.neoforged.bus.api.Event;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.neoforge.event.entity.living.MobSpawnEvent;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(BaseSpawner.class)
public abstract class BaseSpawnerMixin_NeoForge implements BaseSpawnerBridge {

@Override
public boolean bridge$forge$checkSpawnRules(Mob mob, ServerLevelAccessor level, MobSpawnType spawnType, SpawnData spawnData) {
return !EventHooks.checkSpawnPositionSpawner(mob, level, MobSpawnType.SPAWNER, spawnData, (BaseSpawner) (Object) this);
public boolean bridge$forge$checkSpawnRules(Mob mob, ServerLevelAccessor level, MobSpawnType spawnType, SpawnData spawnData, boolean original) {
var event = new MobSpawnEvent.PositionCheck(mob, level, spawnType, null);
NeoForge.EVENT_BUS.post(event);
if (event.getResult() == Event.Result.DEFAULT) {
return original;
}
return event.getResult() == Event.Result.ALLOW;
}

@Override
Expand Down

0 comments on commit df8ea44

Please sign in to comment.