1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 03:00:30 +00:00

Simplify placement logic of various blocks

- For those where placement is stored in the metadata (computers),
   don't also set it in onBlockPlacedBy.
 - Remove .getDefaultState(int, EnumFacing) override, as this means we
   have more control over what is passed to us (namely, placer's
   direction too).
This commit is contained in:
SquidDev 2019-01-14 10:27:19 +00:00
parent 7fd19c43e9
commit 61daab910e
7 changed files with 19 additions and 95 deletions

View File

@ -10,7 +10,6 @@ import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@ -31,8 +30,6 @@ public abstract class BlockGeneric extends Block implements ITileEntityProvider
this.hasTileEntity = true;
}
protected abstract IBlockState getDefaultBlockState( int damage, EnumFacing placedSide );
protected abstract TileGeneric createTile( IBlockState state );
protected abstract TileGeneric createTile( int damage );
@ -53,14 +50,6 @@ public abstract class BlockGeneric extends Block implements ITileEntityProvider
}
}
@Nonnull
@Override
@Deprecated
public final IBlockState getStateForPlacement( World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, int damage, EntityLivingBase placer )
{
return getDefaultBlockState( damage, side );
}
@Override
public boolean removedByPlayer( @Nonnull IBlockState state, World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, boolean willHarvest )
{

View File

@ -87,14 +87,7 @@ public class BlockCommandComputer extends BlockComputerBase
@Override
protected IBlockState getDefaultBlockState( ComputerFamily family, EnumFacing placedSide )
{
if( placedSide.getAxis() != EnumFacing.Axis.Y )
{
return getDefaultState().withProperty( Properties.FACING, placedSide );
}
else
{
return getDefaultState();
}
return getDefaultState().withProperty( Properties.FACING, placedSide );
}
@Override
@ -114,20 +107,4 @@ public class BlockCommandComputer extends BlockComputerBase
{
return new TileCommandComputer();
}
@Override
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, @Nonnull ItemStack itemstack )
{
// Not sure why this is necessary
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileCommandComputer )
{
tile.setWorld( world ); // Not sure why this is necessary
tile.setPos( pos ); // Not sure why this is necessary
}
// Set direction
EnumFacing dir = DirectionUtil.fromEntityRot( player );
setDirection( world, pos, dir );
}
}

View File

@ -9,14 +9,12 @@ package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.items.ComputerItemFactory;
import dan200.computercraft.shared.util.DirectionUtil;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@ -97,24 +95,9 @@ public class BlockComputer extends BlockComputerBase
@Override
protected IBlockState getDefaultBlockState( ComputerFamily family, EnumFacing placedSide )
{
IBlockState state = getDefaultState();
if( placedSide.getAxis() != EnumFacing.Axis.Y )
{
state = state.withProperty( Properties.FACING, placedSide );
}
switch( family )
{
case Normal:
default:
{
return state.withProperty( Properties.ADVANCED, false );
}
case Advanced:
{
return state.withProperty( Properties.ADVANCED, true );
}
}
return getDefaultState()
.withProperty( Properties.FACING, placedSide )
.withProperty( Properties.ADVANCED, family == ComputerFamily.Advanced );
}
@Nonnull
@ -151,22 +134,6 @@ public class BlockComputer extends BlockComputerBase
return new TileComputer();
}
@Override
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, @Nonnull ItemStack stack )
{
// Not sure why this is necessary
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileComputer )
{
tile.setWorld( world ); // Not sure why this is necessary
tile.setPos( pos ); // Not sure why this is necessary
}
// Set direction
EnumFacing dir = DirectionUtil.fromEntityRot( player );
setDirection( world, pos, dir );
}
@Nonnull
@Override
public ItemStack getPickBlock( @Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player )

View File

@ -8,16 +8,18 @@ package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.shared.common.BlockDirectional;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.items.ItemComputerBase;
import dan200.computercraft.shared.util.DirectionUtil;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
public abstract class BlockComputerBase extends BlockDirectional
{
public BlockComputerBase( Material material )
@ -47,11 +49,12 @@ public abstract class BlockComputerBase extends BlockDirectional
protected abstract TileComputerBase createTile( ComputerFamily family );
@Nonnull
@Override
protected final IBlockState getDefaultBlockState( int damage, EnumFacing placedSide )
@Deprecated
public final IBlockState getStateForPlacement( World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, int damage, EntityLivingBase placer )
{
ItemComputerBase item = (ItemComputerBase) Item.getItemFromBlock( this );
return getDefaultBlockState( item.getFamily( damage ), placedSide );
return getDefaultBlockState( getFamily( damage ), DirectionUtil.fromEntityRot( placer ) );
}
@Override

View File

@ -560,14 +560,7 @@ public class BlockPeripheral extends BlockPeripheralBase
@Override
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, @Nonnull ItemStack stack )
{
// Not sure why this is necessary
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TilePeripheralBase )
{
tile.setWorld( world ); // Not sure why this is necessary
tile.setPos( pos ); // Not sure why this is necessary
}
switch( getPeripheralType( state ) )
{
case Speaker:

View File

@ -11,8 +11,8 @@ import dan200.computercraft.shared.common.TileGeneric;
import dan200.computercraft.shared.peripheral.PeripheralType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
@ -44,11 +44,12 @@ public abstract class BlockPeripheralBase extends BlockDirectional
return true; // ItemPeripheralBase handles this
}
@Nonnull
@Override
protected final IBlockState getDefaultBlockState( int damage, EnumFacing placedSide )
@Deprecated
public final IBlockState getStateForPlacement( World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, int damage, EntityLivingBase placer )
{
ItemPeripheralBase item = (ItemPeripheralBase) Item.getItemFromBlock( this );
return getDefaultBlockState( item.getPeripheralType( damage ), placedSide );
return getDefaultBlockState( getPeripheralType( damage ), side );
}
@Override

View File

@ -177,16 +177,10 @@ public class BlockTurtle extends BlockComputerBase
@Override
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, @Nonnull ItemStack itemstack )
{
// Not sure why this is necessary
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileTurtle )
if( tile instanceof TileTurtle && player instanceof EntityPlayer )
{
tile.setWorld( world ); // Not sure why this is necessary
tile.setPos( pos ); // Not sure why this is necessary
if( player instanceof EntityPlayer )
{
((TileTurtle) tile).setOwningPlayer( ((EntityPlayer) player).getGameProfile() );
}
((TileTurtle) tile).setOwningPlayer( ((EntityPlayer) player).getGameProfile() );
}
// Set direction