Sky Chest TESR / Tile Entity Registration Changes
This commit is contained in:
@@ -21,10 +21,13 @@ package appeng.block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.features.TileDefinition;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -37,6 +40,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
@@ -59,11 +63,13 @@ import appeng.util.Platform;
|
||||
import appeng.util.SettingsFrom;
|
||||
|
||||
|
||||
public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntityProvider
|
||||
public abstract class AEBaseTileBlock<T extends AEBaseTile> extends AEBaseBlock
|
||||
{
|
||||
|
||||
@Nonnull
|
||||
private Class<? extends AEBaseTile> tileEntityType;
|
||||
private Class<T> tileEntityClass;
|
||||
@Nonnull
|
||||
private Supplier<T> tileEntityFactory;
|
||||
|
||||
public AEBaseTileBlock( final Block.Properties props )
|
||||
{
|
||||
@@ -107,10 +113,11 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity
|
||||
}
|
||||
|
||||
// TODO : Was this change needed?
|
||||
public void setTileEntity( final Class<? extends AEBaseTile> c )
|
||||
public void setTileEntity( final Class<T> tileEntityClass, Supplier<T> factory )
|
||||
{
|
||||
this.tileEntityType = c;
|
||||
this.setInventory( AEBaseInvTile.class.isAssignableFrom( c ) );
|
||||
this.tileEntityClass = tileEntityClass;
|
||||
this.tileEntityFactory = factory;
|
||||
this.setInventory( AEBaseInvTile.class.isAssignableFrom( tileEntityClass ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,22 +128,22 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity
|
||||
|
||||
private boolean hasBlockTileEntity()
|
||||
{
|
||||
return this.tileEntityType != null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public Class<? extends AEBaseTile> getTileEntityClass()
|
||||
public Class<T> getTileEntityClass()
|
||||
{
|
||||
return this.tileEntityType;
|
||||
return this.tileEntityClass;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T extends AEBaseTile> T getTileEntity( final IBlockReader w, final int x, final int y, final int z )
|
||||
public T getTileEntity( final IBlockReader w, final int x, final int y, final int z )
|
||||
{
|
||||
return this.getTileEntity( w, new BlockPos( x, y, z ) );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T extends AEBaseTile> T getTileEntity( final IBlockReader w, final BlockPos pos )
|
||||
public T getTileEntity( final IBlockReader w, final BlockPos pos )
|
||||
{
|
||||
if( !this.hasBlockTileEntity() )
|
||||
{
|
||||
@@ -144,9 +151,9 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity
|
||||
}
|
||||
|
||||
final TileEntity te = w.getTileEntity( pos );
|
||||
if( this.tileEntityType.isInstance( te ) )
|
||||
if( this.tileEntityClass.isInstance( te ) )
|
||||
{
|
||||
return (T) te;
|
||||
return this.tileEntityClass.cast(te);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -155,23 +162,7 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity
|
||||
@Override
|
||||
public final TileEntity createTileEntity( BlockState state, IBlockReader world )
|
||||
{
|
||||
if( this.hasBlockTileEntity() )
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.tileEntityType.newInstance();
|
||||
}
|
||||
catch( final InstantiationException e )
|
||||
{
|
||||
throw new IllegalStateException( "Failed to create a new instance of an illegal class " + this.tileEntityType, e );
|
||||
}
|
||||
catch( final IllegalAccessException e )
|
||||
{
|
||||
throw new IllegalStateException( "Failed to create a new instance of " + this.tileEntityType + ", because lack of permissions", e );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return this.tileEntityFactory.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,6 +35,6 @@ public class CrankRendering extends BlockRenderingCustomizer
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
|
||||
{
|
||||
rendering.tesr( new CrankTESR() );
|
||||
rendering.tileEntityRenderer( new CrankTESR() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class InscriberRendering extends BlockRenderingCustomizer
|
||||
@Override
|
||||
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
|
||||
{
|
||||
rendering.tesr( new InscriberTESR() );
|
||||
rendering.tileEntityRenderer( new InscriberTESR() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SkyCompassRendering extends BlockRenderingCustomizer
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
|
||||
{
|
||||
rendering.tesr( new SkyCompassTESR() );
|
||||
rendering.tileEntityRenderer( new SkyCompassTESR() );
|
||||
itemRendering.model( ITEM_MODEL );
|
||||
itemRendering.builtInModel( "models/block/builtin/sky_compass", new SkyCompassModel() );
|
||||
}
|
||||
|
||||
@@ -24,29 +24,28 @@ import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.EnumBlockRenderType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.helpers.ICustomCollision;
|
||||
import appeng.tile.storage.TileSkyChest;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class BlockSkyChest extends AEBaseTileBlock implements ICustomCollision
|
||||
public class BlockSkyChest extends AEBaseTileBlock<TileSkyChest>
|
||||
{
|
||||
|
||||
private static final double AABB_OFFSET_BOTTOM = 0.00;
|
||||
@@ -60,20 +59,20 @@ public class BlockSkyChest extends AEBaseTileBlock implements ICustomCollision
|
||||
|
||||
public final SkyChestType type;
|
||||
|
||||
public BlockSkyChest( final SkyChestType type )
|
||||
public BlockSkyChest( final SkyChestType type, Properties props )
|
||||
{
|
||||
super( Material.ROCK );
|
||||
this.setOpaque( this.setFullSize( false ) );
|
||||
this.lightOpacity = 0;
|
||||
this.setHardness( 50 );
|
||||
this.blockResistance = 150.0f;
|
||||
super( props );
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumBlockRenderType getRenderType( BlockState state )
|
||||
{
|
||||
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean propagatesSkylightDown(BlockState state, IBlockReader reader, BlockPos pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,29 +80,20 @@ public class BlockSkyChest extends AEBaseTileBlock implements ICustomCollision
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
Platform.openGUI( player, this.getTileEntity( w, pos ), AEPartLocation.fromFacing(hit), GuiBridge.GUI_SKYCHEST );
|
||||
// FIXME Platform.openGUI( player, this.getTileEntity( w, pos ), AEPartLocation.fromFacing(hit.getFace()), GuiBridge.GUI_SKYCHEST );
|
||||
}
|
||||
|
||||
return true;
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<AxisAlignedBB> getSelectedBoundingBoxesFromPool( final World w, final BlockPos pos, final Entity thePlayer, final boolean b )
|
||||
{
|
||||
final AxisAlignedBB aabb = this.computeAABB( w, pos );
|
||||
|
||||
return Collections.singletonList( aabb );
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
// TODO Cache this! It can't be that hard!
|
||||
AxisAlignedBB aabb = computeAABB(worldIn, pos);
|
||||
return VoxelShapes.create(aabb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCollidingBlockToList( final World w, final BlockPos pos, final AxisAlignedBB bb, final List<AxisAlignedBB> out, final Entity e )
|
||||
{
|
||||
final AxisAlignedBB aabb = this.computeAABB( w, pos );
|
||||
|
||||
out.add( aabb );
|
||||
}
|
||||
|
||||
private AxisAlignedBB computeAABB( final World w, final BlockPos pos )
|
||||
private AxisAlignedBB computeAABB(final IBlockReader w, final BlockPos pos )
|
||||
{
|
||||
final TileSkyChest sk = this.getTileEntity( w, pos );
|
||||
Direction o = Direction.UP;
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package appeng.block.storage;
|
||||
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -31,7 +30,6 @@ import appeng.client.render.tesr.SkyChestTESR;
|
||||
|
||||
public class SkyChestRenderingCustomizer extends BlockRenderingCustomizer
|
||||
{
|
||||
|
||||
private final BlockSkyChest.SkyChestType type;
|
||||
|
||||
public SkyChestRenderingCustomizer( BlockSkyChest.SkyChestType type )
|
||||
@@ -43,12 +41,11 @@ public class SkyChestRenderingCustomizer extends BlockRenderingCustomizer
|
||||
@Override
|
||||
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
|
||||
{
|
||||
rendering.tesr( new SkyChestTESR() );
|
||||
|
||||
// Register a custom non-tesr item model
|
||||
String modelName = this.getModelFromType();
|
||||
ModelResourceLocation model = new ModelResourceLocation( "appliedenergistics2:" + modelName, "inventory" );
|
||||
itemRendering.model( model ).variants( model );
|
||||
// FIXME: This should not be required anymore!
|
||||
// FIXME String modelName = this.getModelFromType();
|
||||
// FIXME ModelResourceLocation model = new ModelResourceLocation( "appliedenergistics2:" + modelName, "inventory" );
|
||||
// FIXME itemRendering.model( model ).variants( model );
|
||||
}
|
||||
|
||||
private String getModelFromType()
|
||||
|
||||
Reference in New Issue
Block a user