Skip to content

Commit

Permalink
Fix entity type CCE (#1163)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Mar 24, 2024
1 parent aeb7246 commit 3e554e6
Show file tree
Hide file tree
Showing 6 changed files with 502 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
package io.izzel.arclight.common.mixin.bukkit;

import io.izzel.arclight.common.mod.server.entity.ArclightFakePlayer;
import io.izzel.arclight.common.mod.server.entity.ArclightModChestedHorse;
import io.izzel.arclight.common.mod.server.entity.ArclightModEntity;
import io.izzel.arclight.common.mod.server.entity.ArclightModHorse;
import io.izzel.arclight.common.mod.server.entity.ArclightModMinecart;
import io.izzel.arclight.common.mod.server.entity.ArclightModMinecartContainer;
import io.izzel.arclight.common.mod.server.entity.ArclightModMob;
import io.izzel.arclight.common.mod.server.entity.ArclightModProjectile;
import io.izzel.arclight.common.mod.server.entity.ArclightModRaider;
import net.minecraft.world.entity.AgeableMob;
import io.izzel.arclight.common.mod.server.entity.EntityClassLookup;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.FlyingMob;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.TamableAnimal;
import net.minecraft.world.entity.animal.AbstractGolem;
import net.minecraft.world.entity.animal.horse.AbstractChestedHorse;
import net.minecraft.world.entity.animal.horse.AbstractHorse;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.entity.raid.Raider;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.entity.vehicle.AbstractMinecartContainer;
import net.minecraft.world.entity.boss.EnderDragonPart;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraftforge.common.util.FakePlayer;
import org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.craftbukkit.v.entity.CraftAgeable;
import org.bukkit.craftbukkit.v.entity.CraftComplexPart;
import org.bukkit.craftbukkit.v.entity.CraftEnderDragonPart;
import org.bukkit.craftbukkit.v.entity.CraftEntity;
import org.bukkit.craftbukkit.v.entity.CraftFlying;
import org.bukkit.craftbukkit.v.entity.CraftGolem;
import org.bukkit.craftbukkit.v.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v.entity.CraftTameableAnimal;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -47,59 +27,18 @@ public abstract class CraftEntityMixin implements org.bukkit.entity.Entity {
private static void arclight$fakePlayer(CraftServer server, Entity entity, CallbackInfoReturnable<CraftEntity> cir) {
if (entity instanceof FakePlayer) {
cir.setReturnValue(new ArclightFakePlayer(server, (FakePlayer) entity));
}
}

@Inject(method = "getEntity", cancellable = true, at = @At(value = "NEW", target = "java/lang/AssertionError"))
private static void arclight$modEntity(CraftServer server, Entity entity, CallbackInfoReturnable<CraftEntity> cir) {
if (entity instanceof LivingEntity) {
if (entity instanceof Mob) {
if (entity instanceof AgeableMob) {
if (entity instanceof AbstractHorse) {
if (entity instanceof AbstractChestedHorse) {
cir.setReturnValue(new ArclightModChestedHorse(server, (AbstractChestedHorse) entity));
return;
}
cir.setReturnValue(new ArclightModHorse(server, (AbstractHorse) entity));
return;
}
if (entity instanceof TamableAnimal) {
cir.setReturnValue(new CraftTameableAnimal(server, (TamableAnimal) entity));
return;
}
cir.setReturnValue(new CraftAgeable(server, (AgeableMob) entity));
return;
}
if (entity instanceof FlyingMob) {
cir.setReturnValue(new CraftFlying(server, (FlyingMob) entity));
return;
}
if (entity instanceof Raider) {
cir.setReturnValue(new ArclightModRaider(server, (Raider) entity));
return;
}
if (entity instanceof AbstractGolem) {
cir.setReturnValue(new CraftGolem(server, (AbstractGolem) entity));
return;
}
cir.setReturnValue(new ArclightModMob(server, (Mob) entity));
return;
}
cir.setReturnValue(new CraftLivingEntity(server, (LivingEntity) entity));
return;
}
if (entity instanceof AbstractMinecart) {
if (entity instanceof AbstractMinecartContainer) {
cir.setReturnValue(new ArclightModMinecartContainer(server, (AbstractMinecartContainer) entity));
if (entity instanceof EnderDragonPart part) {
if (part.parentMob instanceof EnderDragon) {
cir.setReturnValue(new CraftEnderDragonPart(server, (EnderDragonPart) entity));
return;
}
cir.setReturnValue(new ArclightModMinecart(server, (AbstractMinecart) entity));
return;
}
if (entity instanceof Projectile) {
cir.setReturnValue(new ArclightModProjectile(server, entity));

cir.setReturnValue(new CraftComplexPart(server, (EnderDragonPart) entity));
return;
}
cir.setReturnValue(new ArclightModEntity(server, entity));
var convert = EntityClassLookup.getConvert(entity);
cir.setReturnValue((CraftEntity) convert.apply(server, entity));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.izzel.arclight.common.bridge.bukkit.MaterialBridge;
import io.izzel.arclight.common.bridge.bukkit.SimpleRegistryBridge;
import io.izzel.arclight.common.mod.ArclightMod;
import io.izzel.arclight.common.mod.server.entity.EntityClassLookup;
import io.izzel.arclight.common.mod.util.ResourceLocationUtil;
import io.izzel.arclight.common.mod.util.types.ArclightEnchantment;
import io.izzel.arclight.common.mod.util.types.ArclightPotionEffect;
Expand Down Expand Up @@ -354,6 +355,7 @@ private static void loadEntities() {
ENTITY_NAME_MAP.put(location.toString(), entityType);
}
EnumHelper.addEnums(EntityType.class, newTypes);
EntityClassLookup.init();
ArclightMod.LOGGER.info("registry.entity-type", newTypes.size());
}

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

import net.minecraft.world.entity.monster.AbstractSkeleton;
import org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.craftbukkit.v.entity.CraftAbstractSkeleton;
import org.bukkit.entity.Skeleton;
import org.jetbrains.annotations.NotNull;

public class ArclightModAbstractSkeleton extends CraftAbstractSkeleton {
public ArclightModAbstractSkeleton(CraftServer server, AbstractSkeleton entity) {
super(server, entity);
}

@NotNull
@Override
public Skeleton.SkeletonType getSkeletonType() {
return Skeleton.SkeletonType.NORMAL;
}

@Override
public void setSkeletonType(Skeleton.SkeletonType type) {
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.izzel.arclight.common.mod.server.entity;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.Projectile;
import org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.craftbukkit.v.entity.CraftProjectile;

public class ArclightModProjectile extends CraftProjectile {

public ArclightModProjectile(CraftServer server, Entity entity) {
super(server, (Projectile) entity);
public ArclightModProjectile(CraftServer server, Projectile entity) {
super(server, entity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.izzel.arclight.common.mod.server.entity;

import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
import org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.craftbukkit.v.entity.CraftThrowableProjectile;

public class ArclightModThrowableProjectile extends CraftThrowableProjectile {

public ArclightModThrowableProjectile(CraftServer server, ThrowableItemProjectile entity) {
super(server, entity);
}
}
Loading

0 comments on commit 3e554e6

Please sign in to comment.