#1055: Use correct tile entity for trapped chest in CraftBlockStates

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
CraftBukkit/Spigot
2022-06-06 08:30:54 +10:00
parent 0fb296468e
commit 43ec2cdacc
2 changed files with 33 additions and 8 deletions

View File

@@ -1,9 +1,14 @@
package org.bukkit.craftbukkit.block;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.IRegistry;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ITileEntity;
import net.minecraft.world.level.block.entity.TileEntity;
import org.bukkit.Material;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.support.AbstractTestingBase;
@@ -20,6 +25,20 @@ public class BlockStateTest extends AbstractTestingBase {
if (block instanceof ITileEntity) {
assertTrue(material + " has BlockState of type " + blockStateType.getName() + ", but expected subtype of CraftBlockEntityState", isCraftBlockEntityState);
// check tile entity type
TileEntity tileEntity = ((ITileEntity) block).newBlockEntity(BlockPosition.ZERO, block.defaultBlockState());
TileEntity materialTileEntity = CraftBlockStates.createNewTileEntity(material);
if (tileEntity == null) {
if (CraftBlockStates.isTileEntityOptional(material)) {
continue;
}
fail(material + " has no tile entity, it be added to CraftBlockStates#isTileEntityOptional");
}
assertNotNull(material + " has no tile entity expected tile entity of type " + tileEntity.getClass(), materialTileEntity);
assertSame(material + " has unexpected tile entity type, expected " + tileEntity.getClass() + " but got " + tileEntity.getClass(), materialTileEntity.getClass(), tileEntity.getClass());
} else {
assertTrue(material + " has unexpected CraftBlockEntityState subytype " + blockStateType.getName() + " (but is not a tile)", !isCraftBlockEntityState);
}