mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 01:37:35 +01:00
#1055: Use correct tile entity for trapped chest in CraftBlockStates
By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
parent
0fb296468e
commit
43ec2cdacc
@ -23,6 +23,7 @@ import net.minecraft.world.level.block.entity.TileEntityBlastFurnace;
|
||||
import net.minecraft.world.level.block.entity.TileEntityBrewingStand;
|
||||
import net.minecraft.world.level.block.entity.TileEntityCampfire;
|
||||
import net.minecraft.world.level.block.entity.TileEntityChest;
|
||||
import net.minecraft.world.level.block.entity.TileEntityChestTrapped;
|
||||
import net.minecraft.world.level.block.entity.TileEntityCommand;
|
||||
import net.minecraft.world.level.block.entity.TileEntityComparator;
|
||||
import net.minecraft.world.level.block.entity.TileEntityConduit;
|
||||
@ -257,18 +258,12 @@ public final class CraftBlockStates {
|
||||
), CraftCampfire.class, CraftCampfire::new, TileEntityCampfire::new
|
||||
);
|
||||
|
||||
register(
|
||||
Arrays.asList(
|
||||
Material.CHEST,
|
||||
Material.TRAPPED_CHEST
|
||||
), CraftChest.class, CraftChest::new, TileEntityChest::new
|
||||
);
|
||||
|
||||
register(Material.BARREL, CraftBarrel.class, CraftBarrel::new, TileEntityBarrel::new);
|
||||
register(Material.BEACON, CraftBeacon.class, CraftBeacon::new, TileEntityBeacon::new);
|
||||
register(Material.BELL, CraftBell.class, CraftBell::new, TileEntityBell::new);
|
||||
register(Material.BLAST_FURNACE, CraftBlastFurnace.class, CraftBlastFurnace::new, TileEntityBlastFurnace::new);
|
||||
register(Material.BREWING_STAND, CraftBrewingStand.class, CraftBrewingStand::new, TileEntityBrewingStand::new);
|
||||
register(Material.CHEST, CraftChest.class, CraftChest::new, TileEntityChest::new);
|
||||
register(Material.COMPARATOR, CraftComparator.class, CraftComparator::new, TileEntityComparator::new);
|
||||
register(Material.CONDUIT, CraftConduit.class, CraftConduit::new, TileEntityConduit::new);
|
||||
register(Material.DAYLIGHT_DETECTOR, CraftDaylightDetector.class, CraftDaylightDetector::new, TileEntityLightDetector::new);
|
||||
@ -288,6 +283,7 @@ public final class CraftBlockStates {
|
||||
register(Material.SMOKER, CraftSmoker.class, CraftSmoker::new, TileEntitySmoker::new);
|
||||
register(Material.SPAWNER, CraftCreatureSpawner.class, CraftCreatureSpawner::new, TileEntityMobSpawner::new);
|
||||
register(Material.STRUCTURE_BLOCK, CraftStructureBlock.class, CraftStructureBlock::new, TileEntityStructure::new);
|
||||
register(Material.TRAPPED_CHEST, CraftChest.class, CraftChest::new, TileEntityChestTrapped::new);
|
||||
}
|
||||
|
||||
private static void register(Material blockType, BlockStateFactory<?> factory) {
|
||||
@ -324,6 +320,16 @@ public final class CraftBlockStates {
|
||||
return getFactory(material).blockStateType;
|
||||
}
|
||||
|
||||
public static TileEntity createNewTileEntity(Material material) {
|
||||
BlockStateFactory<?> factory = getFactory(material);
|
||||
|
||||
if (factory instanceof BlockEntityStateFactory) {
|
||||
return ((BlockEntityStateFactory<?, ?>) factory).createTileEntity(BlockPosition.ZERO, CraftMagicNumbers.getBlock(material).defaultBlockState());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static BlockState getBlockState(Block block) {
|
||||
Preconditions.checkNotNull(block, "block is null");
|
||||
CraftBlock craftBlock = (CraftBlock) block;
|
||||
@ -371,7 +377,7 @@ public final class CraftBlockStates {
|
||||
return factory.createBlockState(world, blockPosition, blockData, tileEntity);
|
||||
}
|
||||
|
||||
private static boolean isTileEntityOptional(Material material) {
|
||||
public static boolean isTileEntityOptional(Material material) {
|
||||
return material == Material.MOVING_PISTON;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user