parent
03401a43b1
commit
43cafef3d4
@ -16,6 +16,8 @@ public interface MaterialBridge {
|
||||
|
||||
void bridge$setupBlock(ResourceLocation key, Block block, MaterialPropertySpec spec);
|
||||
|
||||
void bridge$setupVanillaBlock(MaterialPropertySpec spec);
|
||||
|
||||
void bridge$setupItem(ResourceLocation key, Item item, MaterialPropertySpec spec);
|
||||
|
||||
void bridge$setBlock();
|
||||
@ -34,4 +36,6 @@ public interface MaterialBridge {
|
||||
Function<CraftBlock, BlockState> bridge$blockStateFactory();
|
||||
|
||||
void bridge$setBlockStateFactory(Function<CraftBlock, BlockState> func);
|
||||
|
||||
boolean bridge$shouldApplyStateFactory();
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package io.izzel.arclight.common.mixin.bukkit;
|
||||
|
||||
import io.izzel.arclight.common.bridge.bukkit.MaterialBridge;
|
||||
import io.izzel.arclight.common.mod.util.ResourceLocationUtil;
|
||||
import io.izzel.arclight.i18n.conf.MaterialPropertySpec;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.bukkit.Material;
|
||||
@ -27,7 +26,7 @@ public abstract class CraftBlockMixin {
|
||||
@Inject(method = "getState", cancellable = true, at = @At("HEAD"))
|
||||
private void arclight$getState(CallbackInfoReturnable<BlockState> cir) {
|
||||
MaterialBridge bridge = (MaterialBridge) (Object) getType();
|
||||
if (bridge.bridge$getType() != MaterialPropertySpec.MaterialType.VANILLA) {
|
||||
if (bridge.bridge$shouldApplyStateFactory()) {
|
||||
cir.setReturnValue(bridge.bridge$blockStateFactory().apply((CraftBlock) (Object) this));
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,6 +256,14 @@ public abstract class MaterialMixin implements MaterialBridge {
|
||||
arclight$setupCommon(key, block, block.asItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bridge$setupVanillaBlock(MaterialPropertySpec spec) {
|
||||
if (spec != MaterialPropertySpec.EMPTY) {
|
||||
this.arclight$spec = spec.clone();
|
||||
this.setupBlockStateFunc();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bridge$setupItem(ResourceLocation key, Item item, MaterialPropertySpec spec) {
|
||||
this.arclight$spec = spec.clone();
|
||||
@ -264,6 +272,12 @@ public abstract class MaterialMixin implements MaterialBridge {
|
||||
arclight$setupCommon(key, null, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bridge$shouldApplyStateFactory() {
|
||||
return this.arclight$type != MaterialPropertySpec.MaterialType.VANILLA ||
|
||||
(this.arclight$spec != null && this.arclight$spec.blockStateClass != null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void arclight$setupCommon(ResourceLocation key, Block block, Item item) {
|
||||
this.key = CraftNamespacedKey.fromMinecraft(key);
|
||||
@ -338,7 +352,7 @@ public abstract class MaterialMixin implements MaterialBridge {
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
private void setupBlockStateFunc() {
|
||||
if (arclight$spec.blockStateClass != null) {
|
||||
if (arclight$spec.blockStateClass != null && !arclight$spec.blockStateClass.equalsIgnoreCase("auto")) {
|
||||
try {
|
||||
Class<?> cl = Class.forName(arclight$spec.blockStateClass);
|
||||
if (!CraftBlockState.class.isAssignableFrom(cl)) {
|
||||
|
||||
@ -222,6 +222,8 @@ public class BukkitRegistry {
|
||||
blocks++;
|
||||
ArclightMod.LOGGER.debug("Registered {} as block {}", location, material);
|
||||
list.add(material);
|
||||
} else {
|
||||
((MaterialBridge) (Object) material).bridge$setupVanillaBlock(matSpec(location));
|
||||
}
|
||||
BLOCK_MATERIAL.put(block, material);
|
||||
MATERIAL_BLOCK.put(material, block);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user