Skip to content

Commit

Permalink
Fix entity type CCE (#1285 #1163)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Mar 24, 2024
1 parent 362d93d commit c4f33fe
Show file tree
Hide file tree
Showing 10 changed files with 566 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
public interface DamagingProjectileEntityBridge extends EntityBridge {

void bridge$setBukkitYield(float yield);

void bridge$setDirection(double d0, double d1, double d2);
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
package io.izzel.arclight.common.mixin.bukkit;

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 org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.craftbukkit.v.entity.CraftAgeable;
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 @@ -50,54 +26,7 @@ public abstract class CraftEntityMixin implements org.bukkit.entity.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));
return;
}
cir.setReturnValue(new ArclightModMinecart(server, (AbstractMinecart) entity));
return;
}
if (entity instanceof Projectile) {
cir.setReturnValue(new ArclightModProjectile(server, entity));
return;
}
cir.setReturnValue(new ArclightModEntity(server, entity));
var craftEntity = (CraftEntity) EntityClassLookup.getEntityTypeData(entity).convertFunction().apply(server, entity);
cir.setReturnValue(craftEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.izzel.arclight.i18n.conf.EntityPropertySpec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.LivingEntity;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.v.CraftWorld;
Expand Down Expand Up @@ -63,7 +64,11 @@ private void setup() {
ServerLevel world = ((CraftWorld) loc.getWorld()).getHandle();
net.minecraft.world.entity.Entity entity = handleType.create(world);
if (entity != null) {
entity.absMoveTo(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
entity.moveTo(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
}
if (entity instanceof LivingEntity) {
entity.setYHeadRot(loc.getYaw());
entity.setYBodyRot(loc.getYaw());
}
return entity;
} else return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public void setDirection(double d0, double d1, double d2) {
this.zPower = d2 / d3 * 0.1D;
}

@Override
public void bridge$setDirection(double d0, double d1, double d2) {
this.setDirection(d0, d1, d2);
}

@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/AbstractHurtingProjectile;discard()V"))
private void arclight$despawn(CallbackInfo ci) {
this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.izzel.arclight.common.bridge.bukkit.EntityTypeBridge;
import io.izzel.arclight.common.bridge.bukkit.MaterialBridge;
import io.izzel.arclight.common.bridge.bukkit.SimpleRegistryBridge;
import io.izzel.arclight.common.mod.server.entity.EntityClassLookup;
import io.izzel.arclight.common.mod.util.ResourceLocationUtil;
import io.izzel.arclight.i18n.ArclightConfig;
import io.izzel.arclight.i18n.conf.EntityPropertySpec;
Expand Down Expand Up @@ -334,6 +335,7 @@ private static void loadEntities() {
ENTITY_NAME_MAP.put(location.toString(), entityType);
}
EnumHelper.addEnums(EntityType.class, newTypes);
EntityClassLookup.init();
ArclightServer.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);
}
}
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.vehicle.VehicleEntity;
import org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.craftbukkit.v.entity.CraftVehicle;

public class ArclightModVehicle extends CraftVehicle {

public ArclightModVehicle(CraftServer server, VehicleEntity entity) {
super(server, entity);
}
}
Loading

0 comments on commit c4f33fe

Please sign in to comment.