Backport a few more methods

This commit is contained in:
fullwall 2024-11-02 19:33:55 +08:00
parent b6214c1bff
commit 93b87d35ad
7 changed files with 165 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Stream;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
@ -37,11 +38,26 @@ public class CustomEntityRegistry extends RegistryMaterials implements Supplier<
return wrapped.a(paramRandom); return wrapped.a(paramRandom);
} }
@Override
public MinecraftKey b() {
return wrapped.b();
}
@Override @Override
public boolean c(MinecraftKey paramK) { public boolean c(MinecraftKey paramK) {
return wrapped.c(paramK); return wrapped.c(paramK);
} }
@Override
public boolean d() {
return wrapped.d();
}
@Override
public Stream<EntityTypes<?>> f() {
return wrapped.f();
}
public EntityTypes findType(Class<?> search) { public EntityTypes findType(Class<?> search) {
for (Object type : wrapped) { for (Object type : wrapped) {
if (((EntityTypes) type).c() == search) if (((EntityTypes) type).c() == search)

View File

@ -6,6 +6,7 @@ import java.util.Optional;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Stream;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
@ -25,6 +26,11 @@ public class CustomEntityRegistry extends RegistryBlocks implements Supplier<Reg
this.wrapped = original; this.wrapped = original;
} }
@Override
public MinecraftKey a() {
return wrapped.a();
}
@Override @Override
public int a(Object key) { public int a(Object key) {
if (entityIds.containsKey(key)) if (entityIds.containsKey(key))
@ -37,6 +43,16 @@ public class CustomEntityRegistry extends RegistryBlocks implements Supplier<Reg
return wrapped.a(paramRandom); return wrapped.a(paramRandom);
} }
@Override
public boolean c() {
return wrapped.c();
}
@Override
public Stream<EntityTypes<?>> d() {
return wrapped.d();
}
public EntityTypes findType(Class<?> search) { public EntityTypes findType(Class<?> search) {
return minecraftClassMap.inverse().get(search); return minecraftClassMap.inverse().get(search);
/* /*

View File

@ -6,6 +6,7 @@ import java.util.Optional;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Stream;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
@ -25,6 +26,11 @@ public class CustomEntityRegistry extends RegistryBlocks implements Supplier<Reg
this.wrapped = original; this.wrapped = original;
} }
@Override
public MinecraftKey a() {
return wrapped.a();
}
@Override @Override
public int a(Object key) { public int a(Object key) {
if (entityIds.containsKey(key)) if (entityIds.containsKey(key))
@ -37,6 +43,16 @@ public class CustomEntityRegistry extends RegistryBlocks implements Supplier<Reg
return wrapped.a(paramRandom); return wrapped.a(paramRandom);
} }
@Override
public boolean c() {
return wrapped.c();
}
@Override
public Stream<EntityTypes<?>> d() {
return wrapped.d();
}
public EntityTypes findType(Class<?> search) { public EntityTypes findType(Class<?> search) {
return minecraftClassMap.inverse().get(search); return minecraftClassMap.inverse().get(search);
/* /*

View File

@ -3,10 +3,12 @@ package net.citizensnpcs.nms.v1_16_R3.util;
import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandle;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional; import java.util.Optional;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Stream;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
@ -31,6 +33,11 @@ public class CustomEntityRegistry extends RegistryBlocks implements Supplier<Reg
this.wrapped = original; this.wrapped = original;
} }
@Override
public MinecraftKey a() {
return wrapped.a();
}
@Override @Override
public int a(Object key) { public int a(Object key) {
if (entityIds.containsKey(key)) if (entityIds.containsKey(key))
@ -48,16 +55,31 @@ public class CustomEntityRegistry extends RegistryBlocks implements Supplier<Reg
return wrapped.a(key); return wrapped.a(key);
} }
@Override
public Lifecycle b() {
return wrapped.b();
}
@Override @Override
public Optional c(Object key) { public Optional c(Object key) {
return wrapped.c((EntityTypes<?>) key); return wrapped.c((EntityTypes<?>) key);
} }
@Override
public Set<Entry<ResourceKey<EntityTypes<?>>, EntityTypes<?>>> d() {
return wrapped.d();
}
@Override @Override
public Object d(ResourceKey key) { public Object d(ResourceKey key) {
return wrapped.d(key); return wrapped.d(key);
} }
@Override
public ResourceKey<? extends IRegistry<EntityTypes<?>>> f() {
return wrapped.f();
}
public EntityTypes findType(Class<?> search) { public EntityTypes findType(Class<?> search) {
return minecraftClassMap.inverse().get(search); return minecraftClassMap.inverse().get(search);
/* /*
@ -75,6 +97,11 @@ public class CustomEntityRegistry extends RegistryBlocks implements Supplier<Reg
return this.wrapped.fromId(var0); return this.wrapped.fromId(var0);
} }
@Override
public Stream<EntityTypes<?>> g() {
return wrapped.g();
}
@Override @Override
public RegistryBlocks<EntityTypes<?>> get() { public RegistryBlocks<EntityTypes<?>> get() {
return wrapped; return wrapped;

View File

@ -7,6 +7,7 @@ import java.util.Optional;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Stream;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
@ -162,6 +163,11 @@ public class CustomEntityRegistry extends DefaultedRegistry implements Supplier<
return this.wrapped.containsKey(var0); return this.wrapped.containsKey(var0);
} }
@Override
public Lifecycle elementsLifecycle() {
return wrapped.elementsLifecycle();
}
@Override @Override
public Set<Object> entrySet() { public Set<Object> entrySet() {
return (Set) wrapped.entrySet(); return (Set) wrapped.entrySet();
@ -242,16 +248,31 @@ public class CustomEntityRegistry extends DefaultedRegistry implements Supplier<
return (Iterator) wrapped.iterator(); return (Iterator) wrapped.iterator();
} }
@Override
public ResourceKey<? extends Registry<EntityType<?>>> key() {
return wrapped.key();
}
@Override @Override
public Set<Object> keySet() { public Set<Object> keySet() {
return (Set) wrapped.keySet(); return (Set) wrapped.keySet();
} }
@Override
public Lifecycle lifecycle(Object type) {
return wrapped.lifecycle((EntityType<?>) type);
}
public void put(int entityId, ResourceLocation key, EntityType entityClass) { public void put(int entityId, ResourceLocation key, EntityType entityClass) {
entities.put(key, entityClass); entities.put(key, entityClass);
entityIds.put(entityClass, entityId); entityIds.put(entityClass, entityId);
} }
@Override
public Stream stream() {
return wrapped.stream();
}
private static final MethodHandle IREGISTRY_LIFECYCLE = NMS.getFirstGetter(Registry.class, Lifecycle.class); private static final MethodHandle IREGISTRY_LIFECYCLE = NMS.getFirstGetter(Registry.class, Lifecycle.class);
// replace regex // replace regex
// .*?> ([A-Z_]+).*?of\((.*?)::new.*?$ // .*?> ([A-Z_]+).*?of\((.*?)::new.*?$

View File

@ -13,10 +13,14 @@ import java.util.stream.Stream;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.mojang.serialization.Codec;
import com.mojang.serialization.Lifecycle; import com.mojang.serialization.Lifecycle;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.minecraft.core.DefaultedRegistry; import net.minecraft.core.DefaultedRegistry;
import net.minecraft.core.Holder;
import net.minecraft.core.Holder.Reference;
import net.minecraft.core.IdMap;
import net.minecraft.core.MappedRegistry; import net.minecraft.core.MappedRegistry;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
@ -152,6 +156,16 @@ public class CustomEntityRegistry extends DefaultedRegistry implements Supplier<
this.wrapped = original; this.wrapped = original;
} }
@Override
public IdMap<Holder<EntityType<?>>> asHolderIdMap() {
return wrapped.asHolderIdMap();
}
@Override
public void bindTags(Map var0) {
wrapped.bindTags(var0);
}
@Override @Override
public Object byId(int var0) { public Object byId(int var0) {
return this.wrapped.byId(var0); return this.wrapped.byId(var0);
@ -162,6 +176,11 @@ public class CustomEntityRegistry extends DefaultedRegistry implements Supplier<
return this.wrapped.byIdOrThrow(var0); return this.wrapped.byIdOrThrow(var0);
} }
@Override
public Codec byNameCodec() {
return wrapped.byNameCodec();
}
@Override @Override
public boolean containsKey(ResourceKey var0) { public boolean containsKey(ResourceKey var0) {
return this.wrapped.containsKey(var0); return this.wrapped.containsKey(var0);
@ -172,6 +191,16 @@ public class CustomEntityRegistry extends DefaultedRegistry implements Supplier<
return this.wrapped.containsKey(var0); return this.wrapped.containsKey(var0);
} }
@Override
public Reference createIntrusiveHolder(Object type) {
return this.wrapped.createIntrusiveHolder((EntityType<?>) type);
}
@Override
public Lifecycle elementsLifecycle() {
return wrapped.elementsLifecycle();
}
@Override @Override
public Set<Object> entrySet() { public Set<Object> entrySet() {
return (Set) wrapped.entrySet(); return (Set) wrapped.entrySet();
@ -189,6 +218,11 @@ public class CustomEntityRegistry extends DefaultedRegistry implements Supplier<
*/ */
} }
@Override
public Registry<EntityType<?>> freeze() {
return wrapped.freeze();
}
@Override @Override
public DefaultedRegistry<EntityType<?>> get() { public DefaultedRegistry<EntityType<?>> get() {
return wrapped; return wrapped;
@ -272,26 +306,56 @@ public class CustomEntityRegistry extends DefaultedRegistry implements Supplier<
return wrapped.getTags(); return wrapped.getTags();
} }
@Override
public boolean isKnownTagName(TagKey key) {
return wrapped.isKnownTagName(key);
}
@Override @Override
public Iterator<Object> iterator() { public Iterator<Object> iterator() {
return (Iterator) wrapped.iterator(); return (Iterator) wrapped.iterator();
} }
@Override
public ResourceKey<? extends Registry<EntityType<?>>> key() {
return wrapped.key();
}
@Override @Override
public Set<Object> keySet() { public Set<Object> keySet() {
return (Set) wrapped.keySet(); return (Set) wrapped.keySet();
} }
@Override
public Lifecycle lifecycle() {
return wrapped.lifecycle();
}
@Override
public Lifecycle lifecycle(Object type) {
return wrapped.lifecycle((EntityType<?>) type);
}
public void put(int entityId, ResourceLocation key, EntityType entityClass) { public void put(int entityId, ResourceLocation key, EntityType entityClass) {
entities.put(key, entityClass); entities.put(key, entityClass);
entityIds.put(entityClass, entityId); entityIds.put(entityClass, entityId);
} }
@Override
public void resetTags() {
wrapped.resetTags();
}
@Override @Override
public int size() { public int size() {
return wrapped.size(); return wrapped.size();
} }
@Override
public Stream<EntityType<?>> stream() {
return wrapped.stream();
}
private static final MethodHandle IREGISTRY_CUSTOM_HOLDER_PROVDER = NMS.getFirstGetter(MappedRegistry.class, private static final MethodHandle IREGISTRY_CUSTOM_HOLDER_PROVDER = NMS.getFirstGetter(MappedRegistry.class,
Function.class); Function.class);
private static final MethodHandle IREGISTRY_LIFECYCLE = NMS.getFirstGetter(Registry.class, Lifecycle.class); private static final MethodHandle IREGISTRY_LIFECYCLE = NMS.getFirstGetter(Registry.class, Lifecycle.class);

View File

@ -316,6 +316,11 @@ public class CustomEntityRegistry extends DefaultedMappedRegistry<EntityType<?>>
return wrapped.iterator(); return wrapped.iterator();
} }
@Override
public ResourceKey<? extends Registry<EntityType<?>>> key() {
return wrapped.key();
}
@Override @Override
public Set<ResourceLocation> keySet() { public Set<ResourceLocation> keySet() {
return wrapped.keySet(); return wrapped.keySet();