mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 11:05:40 +00:00
Fix a vanilla bug with the blockstate ID map not being properly symmetric with respect to block.getStateFromMeta - closes #3012 properly but probably has a random MCJIRA ticket somewhere too.
This commit is contained in:
1 parent
5a3047fbc2
commit
ab64d1a166
3 files changed
+78
-1
No files matched your search
@@ -0,0 +1,61 @@
|
||||
package net.minecraftforge.fml.common.registry;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDirt;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Bootstrap;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.fml.common.DummyModContainer;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModMetadata;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Test block state mappings bidirectionality
|
||||
*/
|
||||
public class BlockStateMappingsTest
|
||||
{
|
||||
@BeforeClass
|
||||
public static void setup()
|
||||
{
|
||||
System.setProperty("fml.queryResult", "confirm");
|
||||
System.setProperty("fml.doNotBackup", "true");
|
||||
Loader.instance();
|
||||
Bootstrap.register();
|
||||
Loader.instance().setupTestHarness(new DummyModContainer(new ModMetadata() {{
|
||||
modId = "test";
|
||||
}}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlockStates()
|
||||
{
|
||||
// stems have a problem where the blockstate for meta 0 is not the same in the blockstate map and from block.getStateFromMeta
|
||||
// This test asserts that the two values should be equivalent
|
||||
// Specifically, in vanilla the state for meta 0 in the blockstatemap is facing=east,age=0 but the block says it's facing=up,age=0
|
||||
Block bl = Blocks.MELON_STEM;
|
||||
int id = Block.getIdFromBlock(bl);
|
||||
for (int meta = 0; meta < 8; meta++)
|
||||
{
|
||||
int realbsm = id << 4 | meta; // computed blockstateid for this meta
|
||||
IBlockState realst = bl.getStateFromMeta(meta); // The state that the block assigns to this meta
|
||||
int bsm = GameData.getBlockStateIDMap().get(realst); // The blockstateid for the meta's state
|
||||
IBlockState foundst = GameData.getBlockStateIDMap().getByValue(realbsm); // The state that is stored for the computed blockstateid
|
||||
assertEquals("Got computed blockstate ids that match", realbsm, bsm);
|
||||
assertEquals("Got equal states", realst, foundst);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user