Prevent registration duplicate.
This commit is contained in:
parent
5a1500add2
commit
2a9619205f
|
@ -0,0 +1,26 @@
|
|||
package io.izzel.arclight.common.mixin.bukkit;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v.util.CraftLegacy;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Mixin(value = CraftLegacy.class, remap = false)
|
||||
public class CraftLegacyMixin {
|
||||
|
||||
private static Material[] moddedMaterials;
|
||||
|
||||
/**
|
||||
* @author IzzelAliz
|
||||
* @reason
|
||||
*/
|
||||
@Overwrite
|
||||
public static Material[] modern_values() {
|
||||
if (moddedMaterials == null) {
|
||||
moddedMaterials = Arrays.stream(Material.values()).filter(it -> !it.isLegacy()).toArray(Material[]::new);
|
||||
}
|
||||
return moddedMaterials;
|
||||
}
|
||||
}
|
|
@ -22,8 +22,11 @@ import java.util.function.Function;
|
|||
@Mixin(value = EntityType.class, remap = false)
|
||||
public class EntityTypeMixin implements EntityTypeBridge {
|
||||
|
||||
// @formatter:off
|
||||
@Shadow @Final @Mutable private NamespacedKey key;
|
||||
@Shadow @Final @Mutable private Class<? extends Entity> clazz;
|
||||
@Shadow @Final @Mutable private String name;
|
||||
// @formatter:on
|
||||
|
||||
private net.minecraft.entity.EntityType<?> handleType;
|
||||
private EntityPropertySpec spec;
|
||||
|
@ -32,6 +35,7 @@ public class EntityTypeMixin implements EntityTypeBridge {
|
|||
@Override
|
||||
public void bridge$setup(ResourceLocation location, net.minecraft.entity.EntityType<?> entityType, EntityPropertySpec spec) {
|
||||
this.key = CraftNamespacedKey.fromMinecraft(location);
|
||||
this.name = location.toString();
|
||||
this.handleType = entityType;
|
||||
this.spec = spec.clone();
|
||||
this.setup();
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.bukkit.potion.PotionEffectType;
|
|||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -70,7 +69,7 @@ public class BukkitRegistry {
|
|||
}
|
||||
if (!found) {
|
||||
String name = ResourceLocationUtil.standardize(location);
|
||||
entityType = EnumHelper.makeEnum(EntityType.class, name, i++, ENTITY_CTOR, ImmutableList.of(ResourceLocationUtil.standardize(location).toLowerCase(Locale.ROOT), Entity.class, -1));
|
||||
entityType = EnumHelper.makeEnum(EntityType.class, name, i++, ENTITY_CTOR, ImmutableList.of(location.getPath(), Entity.class, -1));
|
||||
((EntityTypeBridge) (Object) entityType).bridge$setup(location, type, entitySpec(location));
|
||||
newTypes.add(entityType);
|
||||
ArclightMod.LOGGER.debug("Registered {} as entity {}", location, entityType);
|
||||
|
@ -102,7 +101,7 @@ public class BukkitRegistry {
|
|||
String name = ResourceLocationUtil.standardize(entry.getKey());
|
||||
ArclightPotionEffect effect = new ArclightPotionEffect(entry.getValue(), name);
|
||||
PotionEffectType.registerPotionEffectType(effect);
|
||||
ArclightMod.LOGGER.debug("Registered {}: {} as potion", entry.getKey(), effect);
|
||||
ArclightMod.LOGGER.debug("Registered {} as potion {}", entry.getKey(), effect);
|
||||
}
|
||||
PotionEffectType.stopAcceptingRegistrations();
|
||||
ArclightMod.LOGGER.info("registry.potion", size - origin);
|
||||
|
@ -116,9 +115,9 @@ public class BukkitRegistry {
|
|||
for (Map.Entry<ResourceLocation, Block> entry : ForgeRegistries.BLOCKS.getEntries()) {
|
||||
ResourceLocation location = entry.getKey();
|
||||
Block block = entry.getValue();
|
||||
Material material = Material.matchMaterial(location.toString());
|
||||
String name = ResourceLocationUtil.standardize(location);
|
||||
Material material = BY_NAME.get(name);
|
||||
if (material == null) {
|
||||
String name = ResourceLocationUtil.standardize(location);
|
||||
material = EnumHelper.makeEnum(Material.class, name, i, MAT_CTOR, ImmutableList.of(i));
|
||||
((MaterialBridge) (Object) material).bridge$setupBlock(location, block, matSpec(location));
|
||||
BY_NAME.put(name, material);
|
||||
|
@ -139,9 +138,9 @@ public class BukkitRegistry {
|
|||
for (Map.Entry<ResourceLocation, Item> entry : ForgeRegistries.ITEMS.getEntries()) {
|
||||
ResourceLocation location = entry.getKey();
|
||||
Item item = entry.getValue();
|
||||
Material material = Material.matchMaterial(location.toString());
|
||||
String name = ResourceLocationUtil.standardize(location);
|
||||
Material material = BY_NAME.get(name);
|
||||
if (material == null) {
|
||||
String name = ResourceLocationUtil.standardize(location);
|
||||
material = EnumHelper.makeEnum(Material.class, name, i, MAT_CTOR, ImmutableList.of(i));
|
||||
((MaterialBridge) (Object) material).bridge$setupItem(location, item, matSpec(location));
|
||||
BY_NAME.put(name, material);
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.izzel.arclight.common.mod.util;
|
|||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import java.util.Locale;
|
||||
|
@ -11,7 +12,7 @@ public class ResourceLocationUtil {
|
|||
@Contract("null -> fail")
|
||||
public static String standardize(ResourceLocation location) {
|
||||
Preconditions.checkNotNull(location, "location");
|
||||
return location.toString()
|
||||
return (location.getNamespace().equals(NamespacedKey.MINECRAFT) ? location.getPath() : location.toString())
|
||||
.replace(':', '_')
|
||||
.replaceAll("\\s+", "_")
|
||||
.replaceAll("\\W", "")
|
||||
|
@ -19,7 +20,7 @@ public class ResourceLocationUtil {
|
|||
}
|
||||
|
||||
public static String standardizeLower(ResourceLocation location) {
|
||||
return location.toString()
|
||||
return (location.getNamespace().equals(NamespacedKey.MINECRAFT) ? location.getPath() : location.toString())
|
||||
.replace(':', '_')
|
||||
.replaceAll("\\s+", "_")
|
||||
.replaceAll("\\W", "")
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
"CraftEventFactoryMixin",
|
||||
"CraftInventoryMixin",
|
||||
"CraftItemFactoryMixin",
|
||||
"CraftLegacyMixin",
|
||||
"CraftMagicNumbersMixin",
|
||||
"CraftServerMixin",
|
||||
"CraftWorldMixin",
|
||||
|
|
|
@ -3,7 +3,7 @@ import java.nio.file.attribute.BasicFileAttributes
|
|||
|
||||
allprojects {
|
||||
group 'io.izzel.arclight'
|
||||
version '1.0.1'
|
||||
version '1.0.2-SNAPSHOT'
|
||||
|
||||
ext {
|
||||
agpVersion = '1.7'
|
||||
|
|
Loading…
Reference in New Issue
Block a user