-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor bug fixes and poor support 1.13.2 (#63)
* Fix bug with FactionsUUID on 1.12.2 * Fix dismount bug on hight speed * 1.13.2 support * Whoops, fixed broken check on entity registered
- Loading branch information
Showing
7 changed files
with
674 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/eu/phiwa/dragontravel/nms/v1_13_R2/CustomEntityRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package eu.phiwa.dragontravel.nms.v1_13_R2; | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Random; | ||
import java.util.Set; | ||
|
||
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 { | ||
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 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); | ||
} | ||
|
||
public RegistryMaterials<EntityTypes<?>> getWrapped() { | ||
return wrapped; | ||
} | ||
|
||
@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); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/eu/phiwa/dragontravel/nms/v1_13_R2/EntityRegister.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package eu.phiwa.dragontravel.nms.v1_13_R2; | ||
|
||
import eu.phiwa.dragontravel.core.DragonTravel; | ||
import eu.phiwa.dragontravel.core.hooks.server.IEntityRegister; | ||
import net.minecraft.server.v1_13_R2.Entity; | ||
import net.minecraft.server.v1_13_R2.EntityTypes; | ||
import net.minecraft.server.v1_13_R2.MinecraftKey; | ||
import org.bukkit.Bukkit; | ||
|
||
public class EntityRegister implements IEntityRegister { | ||
private static CustomEntityRegistry ENTITY_REGISTRY; | ||
|
||
public void registerEntityClass(Class<?> clazz) { | ||
if (ENTITY_REGISTRY == null) | ||
return; | ||
|
||
Class<?> search = clazz; | ||
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) { | ||
EntityTypes<?> type = ENTITY_REGISTRY.findType(search); | ||
MinecraftKey key = ENTITY_REGISTRY.getKey(type); | ||
if (key == null) | ||
continue; | ||
int code = ENTITY_REGISTRY.a(type); | ||
ENTITY_REGISTRY.put(code, key, type); | ||
return; | ||
} | ||
throw new IllegalArgumentException("unable to find valid entity superclass for class " + clazz.toString()); | ||
} | ||
|
||
@Override | ||
public boolean registerEntity() { | ||
try { | ||
registerEntityClass(RyeDragon.class); | ||
return true; | ||
} catch (Exception e) { | ||
Bukkit.getLogger().info("[DragonTravel] [Error] Could not register the RyeDragon-entity!"); | ||
e.printStackTrace(); | ||
Bukkit.getPluginManager().disablePlugin(DragonTravel.getInstance()); | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.