mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-26 15:03:18 +00:00
fix: preserve material property dispatch
This commit is contained in:
1 parent
fd29e0a737
commit
5995e366b7
4 files changed
+190
-21
No files matched your search
@@ -10,6 +10,7 @@ import net.minecraft.util.IIcon;
|
||||
|
||||
import codechicken.lib.render.CCRenderState;
|
||||
import codechicken.lib.render.uv.MultiIconTransformation;
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial;
|
||||
@@ -106,7 +107,7 @@ public class BlockMicroMaterial implements IMicroMaterial {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void loadIcons() {
|
||||
Block currentBlock = Block.getBlockFromName(blockKey);
|
||||
Block currentBlock = Block.getBlockFromName(blockKey());
|
||||
IIcon[] icons = new IIcon[6];
|
||||
for (int side = 0; side < icons.length; side++) {
|
||||
icons[side] = codechicken$microblock$BlockMicroMaterial$$safeIcon$1(currentBlock, side);
|
||||
@@ -116,7 +117,7 @@ public class BlockMicroMaterial implements IMicroMaterial {
|
||||
|
||||
public final IIcon codechicken$microblock$BlockMicroMaterial$$safeIcon$1(Block block, int side) {
|
||||
try {
|
||||
return MicroblockProxy.renderBlocks().getIconSafe(block.getIcon(side, meta));
|
||||
return MicroblockProxy.renderBlocks().getIconSafe(block.getIcon(side, meta()));
|
||||
} catch (Exception ignored) {
|
||||
return MicroblockProxy.renderBlocks().getIconSafe(null);
|
||||
}
|
||||
@@ -124,36 +125,33 @@ public class BlockMicroMaterial implements IMicroMaterial {
|
||||
|
||||
@Override
|
||||
public void renderMicroFace(Vector3 pos, int pass, Cuboid6 bounds) {
|
||||
MaterialRenderHelper$.MODULE$.start(pos, pass, icont).blockColour(getColour(pass)).lighting()
|
||||
.blockAndMeta(block, meta).render();
|
||||
MaterialRenderHelper$.MODULE$.start(pos, pass, icont()).blockColour(getColour(pass)).lighting()
|
||||
.blockAndMeta(block(), meta()).render();
|
||||
}
|
||||
|
||||
public int getColour(int pass) {
|
||||
if (pass == -1) {
|
||||
return (block.getBlockColor() << 8) | 0xFF;
|
||||
return (block().getBlockColor() << 8) | 0xFF;
|
||||
}
|
||||
CCRenderState state = CCRenderState.instance();
|
||||
return (block.colorMultiplier(
|
||||
state.lightMatrix.access,
|
||||
state.lightMatrix.pos.x,
|
||||
state.lightMatrix.pos.y,
|
||||
state.lightMatrix.pos.z) << 8) | 0xFF;
|
||||
BlockCoord pos = state.lightMatrix.pos;
|
||||
return (block().colorMultiplier(state.lightMatrix.access, pos.x, pos.y, pos.z) << 8) | 0xFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRenderInPass(int pass) {
|
||||
return block.canRenderInPass(pass);
|
||||
return block().canRenderInPass(pass);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getBreakingIcon(int side) {
|
||||
return block.getIcon(side, meta);
|
||||
return block().getIcon(side, meta());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return new ItemStack(block, 1, meta);
|
||||
return new ItemStack(block(), 1, meta());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -165,19 +163,19 @@ public class BlockMicroMaterial implements IMicroMaterial {
|
||||
public float getStrength(EntityPlayer player) {
|
||||
float hardness = 30F;
|
||||
try {
|
||||
hardness = block.getBlockHardness(null, 0, 0, 0);
|
||||
hardness = block().getBlockHardness(null, 0, 0, 0);
|
||||
} catch (Exception ignored) {}
|
||||
return player.getBreakSpeed(block, false, meta % 16, 0, -1, 0) / hardness;
|
||||
return player.getBreakSpeed(block(), false, meta() % 16, 0, -1, 0) / hardness;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTransparent() {
|
||||
return !block.isOpaqueCube();
|
||||
return !block().isOpaqueCube();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightValue() {
|
||||
return block.getLightValue();
|
||||
return block().getLightValue();
|
||||
}
|
||||
|
||||
public Seq<String> toolClasses() {
|
||||
@@ -186,16 +184,16 @@ public class BlockMicroMaterial implements IMicroMaterial {
|
||||
|
||||
@Override
|
||||
public int getCutterStrength() {
|
||||
return block.getHarvestLevel(meta % 16);
|
||||
return block().getHarvestLevel(meta() % 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block.SoundType getSound() {
|
||||
return block.stepSound;
|
||||
return block().stepSound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float explosionResistance(Entity entity) {
|
||||
return block.getExplosionResistance(entity);
|
||||
return block().getExplosionResistance(entity);
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,13 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -20,6 +22,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.objectweb.asm.Type;
|
||||
@@ -221,6 +225,151 @@ class BlockMicroMaterialCharacterizationTest {
|
||||
assertTrue(operations.stream().anyMatch(ColourMultiplier.class::isInstance));
|
||||
}
|
||||
|
||||
@Test
|
||||
void overriddenBlockAndMetadataDriveMaterialProperties() {
|
||||
Block block = new Block(Material.rock) {
|
||||
|
||||
@Override
|
||||
public int getHarvestLevel(int metadata) {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int colorMultiplier(IBlockAccess world, int x, int y, int z) {
|
||||
return 0x123456;
|
||||
}
|
||||
};
|
||||
block.setLightLevel(0.8f);
|
||||
block.setResistance(12);
|
||||
List<String> reads = new ArrayList<>();
|
||||
BlockMicroMaterial material = new BlockMicroMaterial(null, 0) {
|
||||
|
||||
@Override
|
||||
public Block block() {
|
||||
reads.add("block");
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int meta() {
|
||||
reads.add("meta");
|
||||
return 23;
|
||||
}
|
||||
};
|
||||
assertTrue(reads.isEmpty(), "Construction uses the argument before subclass state is initialized");
|
||||
assertEquals(block.getLightValue(), material.getLightValue());
|
||||
assertEquals(!block.isOpaqueCube(), material.isTransparent());
|
||||
assertEquals(7, material.getCutterStrength());
|
||||
assertSame(block.stepSound, material.getSound());
|
||||
assertEquals(block.getExplosionResistance(null), material.explosionResistance(null));
|
||||
assertEquals(block.canRenderInPass(1), material.canRenderInPass(1));
|
||||
assertEquals((block.getBlockColor() << 8) | 0xFF, material.getColour(-1));
|
||||
assertEquals(0x123456FF, material.getColour(0));
|
||||
reads.clear();
|
||||
assertNotNull(material.getItem());
|
||||
assertEquals(Arrays.asList("block", "meta"), reads);
|
||||
reads.clear();
|
||||
assertThrows(NullPointerException.class, () -> material.getStrength(null));
|
||||
assertEquals(Arrays.asList("block", "block", "meta"), reads);
|
||||
}
|
||||
|
||||
@Test
|
||||
void overriddenMetadataReachesBreakingAndSafeIcons() {
|
||||
IIcon icon = (IIcon) Proxy.newProxyInstance(
|
||||
IIcon.class.getClassLoader(),
|
||||
new Class<?>[] { IIcon.class },
|
||||
(proxy, method, arguments) -> { throw new AssertionError(method); });
|
||||
List<Integer> reads = new ArrayList<>();
|
||||
Block block = new Block(Material.rock) {
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(int side, int metadata) {
|
||||
reads.add(side);
|
||||
reads.add(metadata);
|
||||
return icon;
|
||||
}
|
||||
};
|
||||
BlockMicroMaterial material = new BlockMicroMaterial(null, 0) {
|
||||
|
||||
@Override
|
||||
public Block block() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int meta() {
|
||||
return 23;
|
||||
}
|
||||
};
|
||||
assertSame(icon, material.getBreakingIcon(2));
|
||||
assertSame(icon, material.codechicken$microblock$BlockMicroMaterial$$safeIcon$1(block, 4));
|
||||
assertEquals(Arrays.asList(2, 23, 4, 23), reads);
|
||||
}
|
||||
|
||||
@Test
|
||||
void overriddenBlockKeyIsReadBeforeLoadingIcons() {
|
||||
IllegalStateException failure = new IllegalStateException("block key unavailable");
|
||||
BlockMicroMaterial material = new BlockMicroMaterial(null, 0) {
|
||||
|
||||
@Override
|
||||
public String blockKey() {
|
||||
throw failure;
|
||||
}
|
||||
};
|
||||
assertSame(failure, assertThrows(IllegalStateException.class, material::loadIcons));
|
||||
}
|
||||
|
||||
@Test
|
||||
void overriddenIconsAndBlockPropertiesReachTheRenderPipeline() throws Exception {
|
||||
MultiIconTransformation icons = new MultiIconTransformation((IIcon) null);
|
||||
List<String> reads = new ArrayList<>();
|
||||
BlockMicroMaterial material = new BlockMicroMaterial(null, 0) {
|
||||
|
||||
@Override
|
||||
public MultiIconTransformation icont() {
|
||||
reads.add("icons");
|
||||
return icons;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColour(int pass) {
|
||||
reads.add("colour");
|
||||
return 0x89ABCDEF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block block() {
|
||||
reads.add("block");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int meta() {
|
||||
reads.add("meta");
|
||||
return 23;
|
||||
}
|
||||
};
|
||||
assertTrue(reads.isEmpty());
|
||||
CCRenderState state = CCRenderState.instance();
|
||||
state.resetInstance();
|
||||
BlockFace face = new BlockFace();
|
||||
face.side = 1;
|
||||
state.model = face;
|
||||
state.firstVertexIndex = 0;
|
||||
state.lastVertexIndex = 0;
|
||||
try {
|
||||
material.renderMicroFace(new Vector3(), -1, Cuboid6.full);
|
||||
assertEquals(Arrays.asList("icons", "colour", "block", "meta"), reads);
|
||||
Field operationsField = CCRenderPipeline.class.getDeclaredField("ops");
|
||||
operationsField.setAccessible(true);
|
||||
assertTrue(((List<?>) operationsField.get(state.pipeline)).contains(icons));
|
||||
} finally {
|
||||
state.resetInstance();
|
||||
MaterialRenderHelper.pass_$eq(0);
|
||||
MaterialRenderHelper.builder_$eq(null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertClass(Class<?> type, Class<?> superclass, boolean isFinal, Set<String> methods) {
|
||||
assertTrue(Modifier.isPublic(type.getModifiers()));
|
||||
assertEquals(isFinal, Modifier.isFinal(type.getModifiers()));
|
||||
|
||||
Reference in new issue
Block a user