-
-
Notifications
You must be signed in to change notification settings - Fork 307
/
CustomEntityRegistry.java
88 lines (75 loc) · 2.49 KB
/
CustomEntityRegistry.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package net.citizensnpcs.nms.v1_13_R2.util;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.function.Supplier;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps;
import net.minecraft.server.v1_13_R2.EntityTypes;
import net.minecraft.server.v1_13_R2.MinecraftKey;
import net.minecraft.server.v1_13_R2.RegistryMaterials;
@SuppressWarnings("rawtypes")
public class CustomEntityRegistry extends RegistryMaterials implements Supplier<RegistryMaterials<EntityTypes<?>>> {
private final BiMap<MinecraftKey, EntityTypes> entities = HashBiMap.create();
private final BiMap<EntityTypes, MinecraftKey> entityClasses = this.entities.inverse();
private final Map<EntityTypes, Integer> entityIds = Maps.newHashMap();
private final RegistryMaterials<EntityTypes<?>> wrapped;
public CustomEntityRegistry(RegistryMaterials<EntityTypes<?>> original) {
this.wrapped = original;
}
@Override
public int a(Object key) {
if (entityIds.containsKey(key)) {
return entityIds.get(key);
}
return wrapped.a((EntityTypes) key);
}
@Override
public Object a(Random paramRandom) {
return wrapped.a(paramRandom);
}
@Override
public boolean c(MinecraftKey paramK) {
return wrapped.c(paramK);
}
public EntityTypes findType(Class<?> search) {
for (Object type : wrapped) {
if (((EntityTypes) type).c() == search) {
return (EntityTypes) type;
}
}
return null;
}
@Override
public RegistryMaterials<EntityTypes<?>> get() {
return wrapped;
}
@Override
public EntityTypes get(MinecraftKey key) {
if (entities.containsKey(key)) {
return entities.get(key);
}
return wrapped.get(key);
}
@Override
public MinecraftKey getKey(Object value) {
if (entityClasses.containsKey(value)) {
return entityClasses.get(value);
}
return wrapped.getKey((EntityTypes) value);
}
@Override
public Iterator<Object> iterator() {
return (Iterator) wrapped.iterator();
}
@Override
public Set<Object> keySet() {
return (Set) wrapped.keySet();
}
public void put(int entityId, MinecraftKey key, EntityTypes entityClass) {
entities.put(key, entityClass);
entityIds.put(entityClass, entityId);
}
}