mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Relocate TileEntity#onLoad call to after it's added to the world instead of the chunk so as to have a valid world reference (#3836)
This commit is contained in:
1 parent
56ed8fec1e
commit
003d0c601d
4 files changed
+134
-68
No files matched your search
@@ -0,0 +1,70 @@
|
||||
package net.minecraftforge.test;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Mod(modid = TileEntityLoadingTest.MOD_ID, name = "TileEntity#onLoad() test mod", version = "1.0")
|
||||
public class TileEntityLoadingTest
|
||||
{
|
||||
static final String MOD_ID = "te_loading_test";
|
||||
static final boolean DEBUG = false;
|
||||
|
||||
private static Logger logger;
|
||||
private static final Block testBlock = new TestBlock();
|
||||
|
||||
@Mod.EventHandler
|
||||
public static void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
GameRegistry.register(testBlock);
|
||||
GameRegistry.register(new ItemBlock(testBlock).setRegistryName(testBlock.getRegistryName()));
|
||||
GameRegistry.registerTileEntity(TestTE.class, testBlock.getRegistryName().toString());
|
||||
}
|
||||
|
||||
public static class TestBlock extends Block
|
||||
{
|
||||
static final String NAME = "test_block";
|
||||
|
||||
TestBlock()
|
||||
{
|
||||
super(Material.ANVIL);
|
||||
setRegistryName(NAME);
|
||||
setUnlocalizedName(MOD_ID + "." + NAME);
|
||||
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(IBlockState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, IBlockState state)
|
||||
{
|
||||
return new TestTE();
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestTE extends TileEntity
|
||||
{
|
||||
@Override
|
||||
public void onLoad()
|
||||
{
|
||||
logger.info("World: " + world + ", Pos: " + pos + ", State: " + world.getBlockState(pos));
|
||||
if (DEBUG) logger.trace("Stack trace:", new Exception());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user