Update bukkit registry related parts.

This commit is contained in:
IzzelAliz 2020-07-07 20:59:04 +08:00
parent 6cef5a799c
commit b7e0f30898
5 changed files with 35 additions and 5 deletions

View File

@ -28,6 +28,7 @@ public class SwitchTableFixer implements Implementer {
private static final Marker MARKER = MarkerManager.getMarker("SWITCH_TABLE");
private static final Set<String> ENUMS = ImmutableSet.<String>builder()
.add("org/bukkit/Material")
.add("org/bukkit/entity/EntityType")
.build();
public byte[] processClass(byte[] bytes) {

View File

@ -18,6 +18,10 @@ public interface MaterialBridge {
void bridge$setupItem(ResourceLocation key, Item item, MaterialPropertySpec spec);
void bridge$setBlock();
void bridge$setItem();
@Nullable
MaterialPropertySpec bridge$getSpec();

View File

@ -88,18 +88,29 @@ public abstract class MaterialMixin implements MaterialBridge {
private MaterialPropertySpec.MaterialType arclight$type = MaterialPropertySpec.MaterialType.VANILLA;
private MaterialPropertySpec arclight$spec;
private boolean arclight$block = false, arclight$item = false;
@Override
public void bridge$setBlock() {
this.arclight$block = true;
}
@Override
public void bridge$setItem() {
this.arclight$item = true;
}
@Inject(method = "isBlock", cancellable = true, at = @At("HEAD"))
private void arclight$isBlock(CallbackInfoReturnable<Boolean> cir) {
if (arclight$type != MaterialPropertySpec.MaterialType.VANILLA) {
cir.setReturnValue(arclight$type == MaterialPropertySpec.MaterialType.FORGE_BLOCK);
cir.setReturnValue(arclight$block);
}
}
@Inject(method = "isItem", cancellable = true, at = @At("HEAD"))
private void arclight$isItem(CallbackInfoReturnable<Boolean> cir) {
if (arclight$type != MaterialPropertySpec.MaterialType.VANILLA) {
cir.setReturnValue(arclight$type == MaterialPropertySpec.MaterialType.FORGE_ITEM);
cir.setReturnValue(arclight$item);
}
}
@ -238,14 +249,16 @@ public abstract class MaterialMixin implements MaterialBridge {
@Override
public void bridge$setupBlock(ResourceLocation key, Block block, MaterialPropertySpec spec) {
this.arclight$spec = spec.clone();
arclight$type = MaterialPropertySpec.MaterialType.FORGE_BLOCK;
arclight$type = MaterialPropertySpec.MaterialType.FORGE;
arclight$block = true;
arclight$setupCommon(key, block, block.asItem());
}
@Override
public void bridge$setupItem(ResourceLocation key, Item item, MaterialPropertySpec spec) {
this.arclight$spec = spec.clone();
arclight$type = MaterialPropertySpec.MaterialType.FORGE_ITEM;
arclight$type = MaterialPropertySpec.MaterialType.FORGE;
arclight$item = true;
arclight$setupCommon(key, null, item);
}

View File

@ -129,6 +129,12 @@ public class BukkitRegistry {
}
BLOCK_MATERIAL.put(block, material);
MATERIAL_BLOCK.put(material, block);
Item value = ForgeRegistries.ITEMS.getValue(location);
if (value != null) {
((MaterialBridge) (Object) material).bridge$setItem();
ITEM_MATERIAL.put(value, material);
MATERIAL_ITEM.put(material, value);
}
}
for (Map.Entry<ResourceLocation, Item> entry : ForgeRegistries.ITEMS.getEntries()) {
ResourceLocation location = entry.getKey();
@ -146,6 +152,12 @@ public class BukkitRegistry {
}
ITEM_MATERIAL.put(item, material);
MATERIAL_ITEM.put(material, item);
Block value = ForgeRegistries.BLOCKS.getValue(location);
if (value != null) {
((MaterialBridge) (Object) material).bridge$setBlock();
BLOCK_MATERIAL.put(value, material);
MATERIAL_BLOCK.put(material, value);
}
}
EnumHelper.addEnums(Material.class, list);
ArclightMod.LOGGER.info("registry.material", i - origin, blocks, items);

View File

@ -75,6 +75,6 @@ public class MaterialPropertySpec implements Cloneable {
}
public enum MaterialType {
VANILLA, FORGE_BLOCK, FORGE_ITEM
VANILLA, FORGE
}
}