Fix thrown egg NPE (#1202)

This commit is contained in:
IzzelAliz 2024-01-26 19:39:13 +08:00
parent 132b181f1d
commit 600f108d17
3 changed files with 16 additions and 6 deletions

View File

@ -1,12 +1,12 @@
package io.izzel.arclight.common.bridge.bukkit; package io.izzel.arclight.common.bridge.bukkit;
import io.izzel.arclight.i18n.conf.EntityPropertySpec; import io.izzel.arclight.i18n.conf.EntityPropertySpec;
import org.bukkit.Location;
import java.util.function.Function;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import org.bukkit.Location;
import java.util.function.Function;
public interface EntityTypeBridge { public interface EntityTypeBridge {
@ -14,6 +14,8 @@ public interface EntityTypeBridge {
EntityType<?> bridge$getHandle(); EntityType<?> bridge$getHandle();
void bridge$setHandle(EntityType<?> entityType);
EntityPropertySpec bridge$getSpec(); EntityPropertySpec bridge$getSpec();
Function<Location, ? extends Entity> bridge$entityFactory(); Function<Location, ? extends Entity> bridge$entityFactory();

View File

@ -4,6 +4,8 @@ import io.izzel.arclight.common.bridge.bukkit.EntityTypeBridge;
import io.izzel.arclight.common.mod.ArclightMod; import io.izzel.arclight.common.mod.ArclightMod;
import io.izzel.arclight.i18n.LocalizedException; import io.izzel.arclight.i18n.LocalizedException;
import io.izzel.arclight.i18n.conf.EntityPropertySpec; import io.izzel.arclight.i18n.conf.EntityPropertySpec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.v.CraftWorld; import org.bukkit.craftbukkit.v.CraftWorld;
@ -16,8 +18,6 @@ import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import java.util.function.Function; import java.util.function.Function;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
@Mixin(value = EntityType.class, remap = false) @Mixin(value = EntityType.class, remap = false)
public class EntityTypeMixin implements EntityTypeBridge { public class EntityTypeMixin implements EntityTypeBridge {
@ -75,6 +75,11 @@ public class EntityTypeMixin implements EntityTypeBridge {
return this.handleType; return this.handleType;
} }
@Override
public void bridge$setHandle(net.minecraft.world.entity.EntityType<?> entityType) {
this.handleType = entityType;
}
@Override @Override
public EntityPropertySpec bridge$getSpec() { public EntityPropertySpec bridge$getSpec() {
return spec; return spec;

View File

@ -338,7 +338,10 @@ public class BukkitRegistry {
boolean found = false; boolean found = false;
if (location.getNamespace().equals(NamespacedKey.MINECRAFT)) { if (location.getNamespace().equals(NamespacedKey.MINECRAFT)) {
entityType = EntityType.fromName(location.getPath()); entityType = EntityType.fromName(location.getPath());
if (entityType != null) found = true; if (entityType != null) {
found = true;
((EntityTypeBridge) (Object) entityType).bridge$setHandle(type);
}
else ArclightMod.LOGGER.warn("Not found {} in {}", location, EntityType.class); else ArclightMod.LOGGER.warn("Not found {} in {}", location, EntityType.class);
} }
if (!found) { if (!found) {