mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-13 11:40:29 +00:00
Move several methods from TileGeneric to blocks
- getPickBlock is now implemented directly on computers and turtles, rather than on the tile. - Bounding boxes are handled on the block rather than tile. This ends up being a little ugly in the case of BlockPeripheral, but it's not the end of the world. - Explosion resistance is only implemented for turtles now.
This commit is contained in:
parent
f61f7df2d8
commit
2c87e66db8
@ -43,10 +43,10 @@ import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import dan200.computercraft.shared.media.items.ItemTreasureDisk;
|
||||
import dan200.computercraft.shared.network.ComputerCraftPacket;
|
||||
import dan200.computercraft.shared.network.PacketHandler;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
||||
import dan200.computercraft.shared.peripheral.common.BlockPeripheral;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModemFull;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModemFull;
|
||||
import dan200.computercraft.shared.peripheral.modem.wireless.BlockAdvancedModem;
|
||||
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
|
||||
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
|
||||
|
@ -3,7 +3,7 @@ package dan200.computercraft.client.render;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.peripheral.PeripheralType;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.CableBounds;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
@ -12,7 +12,6 @@ import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
@ -24,8 +23,8 @@ import org.lwjgl.opengl.GL11;
|
||||
public class RenderOverlayCable
|
||||
{
|
||||
private static final float EXPAND = 0.002f;
|
||||
private static final double MIN = TileCable.MIN - EXPAND;
|
||||
private static final double MAX = TileCable.MAX + EXPAND;
|
||||
private static final double MIN = CableBounds.MIN - EXPAND;
|
||||
private static final double MAX = CableBounds.MAX + EXPAND;
|
||||
|
||||
@SubscribeEvent
|
||||
public void drawHighlight( DrawBlockHighlightEvent event )
|
||||
@ -38,13 +37,10 @@ public class RenderOverlayCable
|
||||
IBlockState state = world.getBlockState( pos );
|
||||
if( state.getBlock() != ComputerCraft.Blocks.cable ) return;
|
||||
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile == null || !(tile instanceof TileCable) ) return;
|
||||
state = state.getActualState( world, pos );
|
||||
|
||||
event.setCanceled( true );
|
||||
TileCable cable = (TileCable) tile;
|
||||
|
||||
PeripheralType type = cable.getPeripheralType();
|
||||
PeripheralType type = ComputerCraft.Blocks.cable.getPeripheralType( state );
|
||||
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0 );
|
||||
@ -63,9 +59,9 @@ public class RenderOverlayCable
|
||||
GlStateManager.translate( -x + pos.getX(), -y + pos.getY(), -z + pos.getZ() );
|
||||
}
|
||||
|
||||
if( type != PeripheralType.Cable && WorldUtil.isVecInsideInclusive( cable.getModemBounds(), event.getTarget().hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
|
||||
if( type != PeripheralType.Cable && WorldUtil.isVecInsideInclusive( CableBounds.getModemBounds( state ), event.getTarget().hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
|
||||
{
|
||||
RenderGlobal.drawSelectionBoundingBox( cable.getModemBounds(), 0, 0, 0, 0.4f );
|
||||
RenderGlobal.drawSelectionBoundingBox( CableBounds.getModemBounds( state ), 0, 0, 0, 0.4f );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -4,6 +4,7 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.peripheral.PeripheralType;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCableModemVariant;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.CableBounds;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.block.Block;
|
||||
@ -52,7 +53,7 @@ public class TileEntityCableRenderer extends TileEntitySpecialRenderer<TileCable
|
||||
if( block != ComputerCraft.Blocks.cable ) return;
|
||||
|
||||
state = state.getActualState( world, pos );
|
||||
if( te.getPeripheralType() != PeripheralType.Cable && WorldUtil.isVecInsideInclusive( te.getModemBounds(), hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
|
||||
if( te.getPeripheralType() != PeripheralType.Cable && WorldUtil.isVecInsideInclusive( CableBounds.getModemBounds( state ), hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
|
||||
{
|
||||
state = block.getDefaultState().withProperty( BlockCable.Properties.MODEM, state.getValue( BlockCable.Properties.MODEM ) );
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public abstract class BlockDirectional extends BlockGeneric
|
||||
public EnumFacing getDirection( IBlockAccess world, BlockPos pos )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof IDirectionalTile )
|
||||
if( tile instanceof IDirectionalTile )
|
||||
{
|
||||
IDirectionalTile directional = (IDirectionalTile) tile;
|
||||
return directional.getDirection();
|
||||
@ -34,7 +34,7 @@ public abstract class BlockDirectional extends BlockGeneric
|
||||
public void setDirection( World world, BlockPos pos, EnumFacing dir )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof IDirectionalTile )
|
||||
if( tile instanceof IDirectionalTile )
|
||||
{
|
||||
IDirectionalTile directional = (IDirectionalTile) tile;
|
||||
directional.setDirection( dir );
|
||||
|
@ -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.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@ -18,20 +17,13 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BlockGeneric extends Block implements
|
||||
ITileEntityProvider
|
||||
public abstract class BlockGeneric extends Block implements ITileEntityProvider
|
||||
{
|
||||
protected BlockGeneric( Material material )
|
||||
{
|
||||
@ -54,7 +46,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
public final void getDrops( @Nonnull NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, @Nonnull IBlockState state, int fortune )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
if( tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
generic.getDroppedItems( drops, false );
|
||||
@ -88,7 +80,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
// Get items to drop
|
||||
NonNullList<ItemStack> drops = NonNullList.create();
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
if( tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
generic.getDroppedItems( drops, creative );
|
||||
@ -115,34 +107,21 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
super.breakBlock( world, pos, newState );
|
||||
world.removeTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
if( tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
generic.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getPickBlock( @Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.getPickedItem();
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean onBlockActivated( World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
if( tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.onActivate( player, side, hitX, hitY, hitZ );
|
||||
return generic.onActivate( player, hand, side, hitX, hitY, hitZ );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -152,7 +131,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
public final void neighborChanged( IBlockState state, World world, BlockPos pos, Block block, BlockPos neighorPos )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
if( tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
generic.onNeighbourChange();
|
||||
@ -170,113 +149,6 @@ public abstract class BlockGeneric extends Block implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isSideSolid( IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, EnumFacing side )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.isSolidOnSide( side.ordinal() );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean canBeReplacedByLeaves( @Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos )
|
||||
{
|
||||
return false; // Generify me if anyone ever feels the need to change this
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExplosionResistance( World world, BlockPos pos, @Nullable Entity exploder, Explosion explosion )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
if( generic.isImmuneToExplosion( exploder ) )
|
||||
{
|
||||
return 2000.0f;
|
||||
}
|
||||
}
|
||||
return super.getExplosionResistance( world, pos, exploder, explosion );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public final AxisAlignedBB getBoundingBox( IBlockState state, IBlockAccess world, BlockPos pos )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.getBounds();
|
||||
}
|
||||
return FULL_BLOCK_AABB;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public final AxisAlignedBB getSelectedBoundingBox( IBlockState state, @Nonnull World world, @Nonnull BlockPos pos )
|
||||
{
|
||||
return getBoundingBox( state, world, pos ).offset( pos );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final AxisAlignedBB getCollisionBoundingBox( IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
|
||||
// Get collision bounds
|
||||
List<AxisAlignedBB> collision = new ArrayList<>( 1 );
|
||||
generic.getCollisionBounds( collision );
|
||||
|
||||
// Return the union of the collision bounds
|
||||
if( collision.size() > 0 )
|
||||
{
|
||||
AxisAlignedBB aabb = collision.get( 0 );
|
||||
for( int i = 1; i < collision.size(); i++ )
|
||||
{
|
||||
aabb = aabb.union( collision.get( i ) );
|
||||
}
|
||||
return aabb;
|
||||
}
|
||||
}
|
||||
return FULL_BLOCK_AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void addCollisionBoxToList( IBlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull AxisAlignedBB bigBox, @Nonnull List<AxisAlignedBB> list, Entity entity, boolean p_185477_7_ )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
|
||||
// Get collision bounds
|
||||
List<AxisAlignedBB> collision = new ArrayList<>( 1 );
|
||||
generic.getCollisionBounds( collision );
|
||||
|
||||
// Add collision bounds to list
|
||||
if( collision.size() > 0 )
|
||||
{
|
||||
for( AxisAlignedBB localBounds : collision )
|
||||
{
|
||||
addCollisionBoxToList( pos, bigBox, list, localBounds );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean canProvidePower( IBlockState state )
|
||||
@ -288,7 +160,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
public final boolean canConnectRedstone( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
if( tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.getRedstoneConnectivity( side );
|
||||
@ -301,7 +173,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
public final int getStrongPower( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing oppositeSide )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
|
||||
if( tile instanceof TileGeneric && tile.hasWorld() )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.getRedstoneOutput( oppositeSide.getOpposite() );
|
||||
@ -319,7 +191,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
public boolean getBundledRedstoneConnectivity( World world, BlockPos pos, EnumFacing side )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
if( tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.getBundledRedstoneConnectivity( side );
|
||||
@ -330,7 +202,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
|
||||
if( tile instanceof TileGeneric && tile.hasWorld() )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.getBundledRedstoneOutput( side );
|
||||
@ -351,4 +223,12 @@ public abstract class BlockGeneric extends Block implements
|
||||
{
|
||||
return createTile( damage );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideSolid( IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, EnumFacing side )
|
||||
{
|
||||
// We need to override this as the default implementation uses isNormalCube, which returns false if
|
||||
// it can provide power.
|
||||
return isFullCube( state );
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.network.ComputerCraftPacket;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@ -18,21 +17,16 @@ import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class TileGeneric extends TileEntity
|
||||
{
|
||||
public TileGeneric()
|
||||
{
|
||||
}
|
||||
|
||||
public void requestTileEntityUpdate()
|
||||
{
|
||||
if( getWorld().isRemote )
|
||||
@ -54,11 +48,7 @@ public abstract class TileGeneric extends TileEntity
|
||||
public BlockGeneric getBlock()
|
||||
{
|
||||
Block block = getWorld().getBlockState( getPos() ).getBlock();
|
||||
if( block != null && block instanceof BlockGeneric )
|
||||
{
|
||||
return (BlockGeneric) block;
|
||||
}
|
||||
return null;
|
||||
return block instanceof BlockGeneric ? (BlockGeneric) block : null;
|
||||
}
|
||||
|
||||
protected final IBlockState getBlockState()
|
||||
@ -84,12 +74,7 @@ public abstract class TileGeneric extends TileEntity
|
||||
{
|
||||
}
|
||||
|
||||
public ItemStack getPickedItem()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean onActivate( EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -102,27 +87,6 @@ public abstract class TileGeneric extends TileEntity
|
||||
{
|
||||
}
|
||||
|
||||
public boolean isSolidOnSide( int side )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isImmuneToExplosion( Entity exploder )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public AxisAlignedBB getBounds()
|
||||
{
|
||||
return new AxisAlignedBB( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
|
||||
}
|
||||
|
||||
public void getCollisionBounds( @Nonnull List<AxisAlignedBB> bounds )
|
||||
{
|
||||
bounds.add( getBounds() );
|
||||
}
|
||||
|
||||
public boolean getRedstoneConnectivity( EnumFacing side )
|
||||
{
|
||||
return false;
|
||||
@ -150,21 +114,13 @@ public abstract class TileGeneric extends TileEntity
|
||||
|
||||
public boolean isUsable( EntityPlayer player, boolean ignoreRange )
|
||||
{
|
||||
if( player != null && player.isEntityAlive() )
|
||||
{
|
||||
if( getWorld().getTileEntity( getPos() ) == this )
|
||||
{
|
||||
if( !ignoreRange )
|
||||
{
|
||||
double range = getInteractRange( player );
|
||||
BlockPos pos = getPos();
|
||||
return player.getEntityWorld() == getWorld() &&
|
||||
player.getDistanceSq( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= (range * range);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if( player == null || !player.isEntityAlive() || getWorld().getTileEntity( getPos() ) != this ) return false;
|
||||
if( ignoreRange ) return true;
|
||||
|
||||
double range = getInteractRange( player );
|
||||
BlockPos pos = getPos();
|
||||
return player.getEntityWorld() == getWorld() &&
|
||||
player.getDistanceSq( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= (range * range);
|
||||
}
|
||||
|
||||
protected void writeDescription( @Nonnull NBTTagCompound nbttagcompound )
|
||||
|
@ -9,6 +9,7 @@ package dan200.computercraft.shared.computer.blocks;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
import dan200.computercraft.shared.computer.items.ComputerItemFactory;
|
||||
import dan200.computercraft.shared.computer.items.ItemComputer;
|
||||
import dan200.computercraft.shared.util.DirectionUtil;
|
||||
import net.minecraft.block.material.Material;
|
||||
@ -18,11 +19,13 @@ 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.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -181,4 +184,12 @@ public class BlockComputer extends BlockComputerBase
|
||||
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 )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
return tile instanceof TileComputer ? ComputerItemFactory.create( (TileComputer) tile ) : super.getPickBlock( state, target, world, pos, player );
|
||||
}
|
||||
}
|
||||
|
@ -75,12 +75,6 @@ public class TileComputer extends TileComputerBase
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickedItem()
|
||||
{
|
||||
return ComputerItemFactory.create( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openGUI( EntityPlayer player )
|
||||
{
|
||||
|
@ -116,22 +116,15 @@ public abstract class TileComputerBase extends TileGeneric
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivate( EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
ItemStack currentItem = player.getHeldItem( EnumHand.MAIN_HAND );
|
||||
ItemStack currentItem = player.getHeldItem( hand );
|
||||
if( !currentItem.isEmpty() && currentItem.getItem() == Items.NAME_TAG && canNameWithTag( player ) )
|
||||
{
|
||||
// Label to rename computer
|
||||
if( !getWorld().isRemote )
|
||||
{
|
||||
if( currentItem.hasDisplayName() )
|
||||
{
|
||||
setLabel( currentItem.getDisplayName() );
|
||||
}
|
||||
else
|
||||
{
|
||||
setLabel( null );
|
||||
}
|
||||
setLabel( currentItem.hasDisplayName() ? currentItem.getDisplayName() : null );
|
||||
currentItem.shrink( 1 );
|
||||
}
|
||||
return true;
|
||||
|
@ -9,6 +9,7 @@ package dan200.computercraft.shared.peripheral.common;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.peripheral.PeripheralType;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
|
||||
import dan200.computercraft.shared.peripheral.modem.ModemBounds;
|
||||
import dan200.computercraft.shared.peripheral.modem.wireless.TileWirelessModem;
|
||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
|
||||
@ -25,6 +26,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
@ -662,4 +664,16 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
// This normally uses the default state
|
||||
return isOpaqueCube( state ) ? 255 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public AxisAlignedBB getBoundingBox( IBlockState state, IBlockAccess source, BlockPos pos )
|
||||
{
|
||||
if( getPeripheralType( state ) == PeripheralType.WirelessModem )
|
||||
{
|
||||
return ModemBounds.getBounds( getDirection( source, pos ) );
|
||||
}
|
||||
|
||||
return super.getBoundingBox( state, source, pos );
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,13 @@ 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.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -63,4 +67,12 @@ public abstract class BlockPeripheralBase extends BlockDirectional
|
||||
{
|
||||
return getPeripheralType( world.getBlockState( pos ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getPickBlock( @Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
return tile instanceof IPeripheralTile ? PeripheralItemFactory.create( (IPeripheralTile) tile ) : super.getPickBlock( state, target, world, pos, player );
|
||||
}
|
||||
}
|
||||
|
@ -53,12 +53,6 @@ public abstract class TilePeripheralBase extends TileGeneric
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickedItem()
|
||||
{
|
||||
return PeripheralItemFactory.create( this );
|
||||
}
|
||||
|
||||
// IPeripheralTile implementation
|
||||
|
||||
@Override
|
||||
|
@ -87,20 +87,20 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivate( EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
if( player.isSneaking() )
|
||||
{
|
||||
// Try to put a disk into the drive
|
||||
if( !getWorld().isRemote )
|
||||
{
|
||||
ItemStack disk = player.getHeldItem( EnumHand.MAIN_HAND );
|
||||
ItemStack disk = player.getHeldItem( hand );
|
||||
if( !disk.isEmpty() && getStackInSlot( 0 ).isEmpty() )
|
||||
{
|
||||
if( ComputerCraft.getMedia( disk ) != null )
|
||||
{
|
||||
setInventorySlotContents( 0, disk );
|
||||
player.setHeldItem( EnumHand.MAIN_HAND, ItemStack.EMPTY );
|
||||
player.setHeldItem( hand, ItemStack.EMPTY );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.peripheral.modem;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ModemBounds
|
||||
{
|
||||
private static final AxisAlignedBB[] BOXES = new AxisAlignedBB[] {
|
||||
new AxisAlignedBB( 0.125, 0.0, 0.125, 0.875, 0.1875, 0.875 ), // Down
|
||||
new AxisAlignedBB( 0.125, 0.8125, 0.125, 0.875, 1.0, 0.875 ), // Up
|
||||
new AxisAlignedBB( 0.125, 0.125, 0.0, 0.875, 0.875, 0.1875 ), // North
|
||||
new AxisAlignedBB( 0.125, 0.125, 0.8125, 0.875, 0.875, 1.0 ), // South
|
||||
new AxisAlignedBB( 0.0, 0.125, 0.125, 0.1875, 0.875, 0.875 ), // West
|
||||
new AxisAlignedBB( 0.8125, 0.125, 0.125, 1.0, 0.875, 0.875 ), // East
|
||||
};
|
||||
|
||||
@Nonnull
|
||||
public static AxisAlignedBB getBounds( EnumFacing facing )
|
||||
{
|
||||
int direction = facing.ordinal();
|
||||
return direction < BOXES.length ? BOXES[direction] : Block.FULL_BLOCK_AABB;
|
||||
}
|
||||
}
|
@ -9,23 +9,13 @@ package dan200.computercraft.shared.peripheral.modem;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.shared.common.BlockGeneric;
|
||||
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public abstract class TileModemBase extends TilePeripheralBase
|
||||
{
|
||||
private static final AxisAlignedBB[] BOXES = new AxisAlignedBB[] {
|
||||
new AxisAlignedBB( 0.125, 0.0, 0.125, 0.875, 0.1875, 0.875 ), // Down
|
||||
new AxisAlignedBB( 0.125, 0.8125, 0.125, 0.875, 1.0, 0.875 ), // Up
|
||||
new AxisAlignedBB( 0.125, 0.125, 0.0, 0.875, 0.875, 0.1875 ), // North
|
||||
new AxisAlignedBB( 0.125, 0.125, 0.8125, 0.875, 0.875, 1.0 ), // South
|
||||
new AxisAlignedBB( 0.0, 0.125, 0.125, 0.1875, 0.875, 0.875 ), // West
|
||||
new AxisAlignedBB( 0.8125, 0.125, 0.125, 1.0, 0.875, 0.875 ), // East
|
||||
};
|
||||
|
||||
protected ModemPeripheral m_modem;
|
||||
|
||||
@ -46,12 +36,6 @@ public abstract class TileModemBase extends TilePeripheralBase
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolidOnSide( int side )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighbourChange()
|
||||
{
|
||||
@ -64,14 +48,6 @@ public abstract class TileModemBase extends TilePeripheralBase
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public AxisAlignedBB getBounds()
|
||||
{
|
||||
int direction = getDirection().ordinal();
|
||||
return direction >= 0 && direction < BOXES.length ? BOXES[direction] : Block.FULL_BLOCK_AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
package dan200.computercraft.shared.peripheral.modem.wired;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.common.TileGeneric;
|
||||
import dan200.computercraft.shared.peripheral.PeripheralType;
|
||||
import dan200.computercraft.shared.peripheral.common.BlockPeripheralBase;
|
||||
import dan200.computercraft.shared.peripheral.common.PeripheralItemFactory;
|
||||
@ -18,6 +18,7 @@ import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockFaceShape;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
@ -34,6 +35,7 @@ import net.minecraft.world.World;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockCable extends BlockPeripheralBase
|
||||
@ -50,6 +52,13 @@ public class BlockCable extends BlockPeripheralBase
|
||||
public static final PropertyBool WEST = PropertyBool.create( "west" );
|
||||
public static final PropertyBool UP = PropertyBool.create( "up" );
|
||||
public static final PropertyBool DOWN = PropertyBool.create( "down" );
|
||||
|
||||
static final EnumMap<EnumFacing, PropertyBool> CONNECTIONS =
|
||||
new EnumMap<>( new ImmutableMap.Builder<EnumFacing, PropertyBool>()
|
||||
.put( EnumFacing.DOWN, DOWN ).put( EnumFacing.UP, UP )
|
||||
.put( EnumFacing.NORTH, NORTH ).put( EnumFacing.SOUTH, SOUTH )
|
||||
.put( EnumFacing.WEST, WEST ).put( EnumFacing.EAST, EAST )
|
||||
.build() );
|
||||
}
|
||||
|
||||
// Members
|
||||
@ -230,51 +239,60 @@ public class BlockCable extends BlockPeripheralBase
|
||||
return new TileCable();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public AxisAlignedBB getBoundingBox( IBlockState state, IBlockAccess source, BlockPos pos )
|
||||
{
|
||||
return CableBounds.getBounds( state.getActualState( source, pos ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addCollisionBoxToList( IBlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull AxisAlignedBB bigBox, @Nonnull List<AxisAlignedBB> list, Entity entity, boolean isActualState )
|
||||
{
|
||||
if( !isActualState ) state = state.getActualState( world, pos );
|
||||
|
||||
// Get collision bounds
|
||||
List<AxisAlignedBB> collision = new ArrayList<>( 1 );
|
||||
CableBounds.getBounds( state, collision );
|
||||
for( AxisAlignedBB localBounds : collision ) addCollisionBoxToList( pos, bigBox, list, localBounds );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@Deprecated
|
||||
public RayTraceResult collisionRayTrace( IBlockState blockState, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Vec3d start, @Nonnull Vec3d end )
|
||||
public RayTraceResult collisionRayTrace( IBlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Vec3d start, @Nonnull Vec3d end )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile instanceof TileGeneric && tile.hasWorld() )
|
||||
double distance = Double.POSITIVE_INFINITY;
|
||||
RayTraceResult result = null;
|
||||
|
||||
List<AxisAlignedBB> bounds = new ArrayList<AxisAlignedBB>( 7 );
|
||||
CableBounds.getBounds( state.getActualState( world, pos ), bounds );
|
||||
|
||||
Vec3d startOff = start.subtract( pos.getX(), pos.getY(), pos.getZ() );
|
||||
Vec3d endOff = end.subtract( pos.getX(), pos.getY(), pos.getZ() );
|
||||
|
||||
for( AxisAlignedBB bb : bounds )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
|
||||
double distance = Double.POSITIVE_INFINITY;
|
||||
RayTraceResult result = null;
|
||||
|
||||
List<AxisAlignedBB> bounds = new ArrayList<AxisAlignedBB>( 7 );
|
||||
generic.getCollisionBounds( bounds );
|
||||
|
||||
Vec3d startOff = start.subtract( pos.getX(), pos.getY(), pos.getZ() );
|
||||
Vec3d endOff = end.subtract( pos.getX(), pos.getY(), pos.getZ() );
|
||||
|
||||
for( AxisAlignedBB bb : bounds )
|
||||
RayTraceResult hit = bb.calculateIntercept( startOff, endOff );
|
||||
if( hit != null )
|
||||
{
|
||||
RayTraceResult hit = bb.calculateIntercept( startOff, endOff );
|
||||
if( hit != null )
|
||||
double newDistance = hit.hitVec.squareDistanceTo( startOff );
|
||||
if( newDistance <= distance )
|
||||
{
|
||||
double newDistance = hit.hitVec.squareDistanceTo( startOff );
|
||||
if( newDistance <= distance )
|
||||
{
|
||||
distance = newDistance;
|
||||
result = hit;
|
||||
}
|
||||
distance = newDistance;
|
||||
result = hit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result == null ? null : new RayTraceResult( result.hitVec.add( pos.getX(), pos.getY(), pos.getZ() ), result.sideHit, pos );
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.collisionRayTrace( blockState, world, pos, start, end );
|
||||
}
|
||||
return result == null ? null : new RayTraceResult( result.hitVec.add( pos.getX(), pos.getY(), pos.getZ() ), result.sideHit, pos );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer( @Nonnull IBlockState state, World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, boolean willHarvest )
|
||||
{
|
||||
PeripheralType type = getPeripheralType( world, pos );
|
||||
PeripheralType type = getPeripheralType( state );
|
||||
if( type == PeripheralType.WiredModemWithCable )
|
||||
{
|
||||
RayTraceResult hit = state.collisionRayTrace( world, pos, WorldUtil.getRayStart( player ), WorldUtil.getRayEnd( player ) );
|
||||
@ -287,7 +305,7 @@ public class BlockCable extends BlockPeripheralBase
|
||||
|
||||
ItemStack item;
|
||||
|
||||
AxisAlignedBB bb = cable.getModemBounds();
|
||||
AxisAlignedBB bb = CableBounds.getModemBounds( state );
|
||||
if( WorldUtil.isVecInsideInclusive( bb, hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
|
||||
{
|
||||
world.setBlockState( pos, state.withProperty( Properties.MODEM, BlockCableModemVariant.None ), 3 );
|
||||
@ -315,30 +333,14 @@ public class BlockCable extends BlockPeripheralBase
|
||||
@Override
|
||||
public ItemStack getPickBlock( @Nonnull IBlockState state, RayTraceResult hit, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile instanceof TileCable && tile.hasWorld() )
|
||||
PeripheralType type = getPeripheralType( state );
|
||||
if( type == PeripheralType.WiredModemWithCable )
|
||||
{
|
||||
TileCable cable = (TileCable) tile;
|
||||
PeripheralType type = getPeripheralType( state );
|
||||
|
||||
if( type == PeripheralType.WiredModemWithCable )
|
||||
{
|
||||
if( hit == null || WorldUtil.isVecInsideInclusive( cable.getModemBounds(), hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
|
||||
{
|
||||
return PeripheralItemFactory.create( PeripheralType.WiredModem, null, 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
return PeripheralItemFactory.create( PeripheralType.Cable, null, 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PeripheralItemFactory.create( type, null, 1 );
|
||||
}
|
||||
type = hit == null || WorldUtil.isVecInsideInclusive( CableBounds.getModemBounds( state ), hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) )
|
||||
? PeripheralType.WiredModem : PeripheralType.Cable;
|
||||
}
|
||||
|
||||
return PeripheralItemFactory.create( PeripheralType.Cable, null, 1 );
|
||||
return PeripheralItemFactory.create( type, null, 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.peripheral.modem.wired;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import dan200.computercraft.shared.peripheral.modem.ModemBounds;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
|
||||
import static dan200.computercraft.shared.peripheral.modem.wired.BlockCable.Properties.*;
|
||||
|
||||
public final class CableBounds
|
||||
{
|
||||
public static final double MIN = 0.375;
|
||||
public static final double MAX = 1 - MIN;
|
||||
|
||||
private static final AxisAlignedBB SHAPE_CABLE_CORE = new AxisAlignedBB( MIN, MIN, MIN, MAX, MAX, MAX );
|
||||
private static final EnumMap<EnumFacing, AxisAlignedBB> SHAPE_CABLE_ARM =
|
||||
new EnumMap<>( new ImmutableMap.Builder<EnumFacing, AxisAlignedBB>()
|
||||
.put( EnumFacing.DOWN, new AxisAlignedBB( MIN, 0, MIN, MAX, MIN, MAX ) )
|
||||
.put( EnumFacing.UP, new AxisAlignedBB( MIN, MAX, MIN, MAX, 1, MAX ) )
|
||||
.put( EnumFacing.NORTH, new AxisAlignedBB( MIN, MIN, 0, MAX, MAX, MIN ) )
|
||||
.put( EnumFacing.SOUTH, new AxisAlignedBB( MIN, MIN, MAX, MAX, MAX, 1 ) )
|
||||
.put( EnumFacing.WEST, new AxisAlignedBB( 0, MIN, MIN, MIN, MAX, MAX ) )
|
||||
.put( EnumFacing.EAST, new AxisAlignedBB( MAX, MIN, MIN, 1, MAX, MAX ) )
|
||||
.build()
|
||||
);
|
||||
|
||||
private static final AxisAlignedBB[] SHAPES = new AxisAlignedBB[(1 << 6) * 7];
|
||||
private static final AxisAlignedBB[] CABLE_SHAPES = new AxisAlignedBB[1 << 6];
|
||||
|
||||
private CableBounds()
|
||||
{
|
||||
}
|
||||
|
||||
private static int getCableIndex( IBlockState state )
|
||||
{
|
||||
int index = 0;
|
||||
for( EnumFacing facing : EnumFacing.VALUES )
|
||||
{
|
||||
if( state.getValue( CONNECTIONS.get( facing ) ) ) index |= 1 << facing.ordinal();
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
private static AxisAlignedBB getCableBounds( int index )
|
||||
{
|
||||
AxisAlignedBB bounds = CABLE_SHAPES[index];
|
||||
if( bounds != null ) return bounds;
|
||||
|
||||
bounds = SHAPE_CABLE_CORE;
|
||||
for( EnumFacing facing : EnumFacing.VALUES )
|
||||
{
|
||||
if( (index & (1 << facing.ordinal())) != 0 )
|
||||
{
|
||||
bounds = bounds.union( SHAPE_CABLE_ARM.get( facing ) );
|
||||
}
|
||||
}
|
||||
|
||||
return CABLE_SHAPES[index] = bounds;
|
||||
}
|
||||
|
||||
public static AxisAlignedBB getCableBounds( IBlockState state )
|
||||
{
|
||||
if( !state.getValue( CABLE ) ) return BlockCable.NULL_AABB;
|
||||
return getCableBounds( getCableIndex( state ) );
|
||||
}
|
||||
|
||||
public static void getCableBounds( IBlockState state, List<AxisAlignedBB> bounds )
|
||||
{
|
||||
if( !state.getValue( CABLE ) ) return;
|
||||
|
||||
bounds.add( SHAPE_CABLE_CORE );
|
||||
for( EnumFacing facing : EnumFacing.VALUES )
|
||||
{
|
||||
if( state.getValue( CONNECTIONS.get( facing ) ) ) bounds.add( SHAPE_CABLE_ARM.get( facing ) );
|
||||
}
|
||||
}
|
||||
|
||||
public static AxisAlignedBB getModemBounds( IBlockState state )
|
||||
{
|
||||
EnumFacing facing = state.getValue( MODEM ).getFacing();
|
||||
return facing == null ? Block.NULL_AABB : ModemBounds.getBounds( facing );
|
||||
}
|
||||
|
||||
public static AxisAlignedBB getBounds( IBlockState state )
|
||||
{
|
||||
if( !state.getValue( CABLE ) ) return getModemBounds( state );
|
||||
|
||||
EnumFacing facing = state.getValue( MODEM ).getFacing();
|
||||
int cableIndex = getCableIndex( state );
|
||||
int index = cableIndex + ((facing == null ? 0 : facing.ordinal() + 1) << 6);
|
||||
|
||||
AxisAlignedBB shape = SHAPES[index];
|
||||
if( shape != null ) return shape;
|
||||
|
||||
shape = getCableBounds( cableIndex );
|
||||
if( facing != null ) shape = shape.union( ModemBounds.getBounds( facing ) );
|
||||
return SHAPES[index] = shape;
|
||||
}
|
||||
|
||||
public static void getBounds( IBlockState state, List<AxisAlignedBB> bounds )
|
||||
{
|
||||
EnumFacing facing = state.getValue( MODEM ).getFacing();
|
||||
if( facing != null ) bounds.add( getModemBounds( state ) );
|
||||
getCableBounds( state, bounds );
|
||||
}
|
||||
}
|
@ -24,8 +24,8 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
@ -35,24 +35,10 @@ import net.minecraftforge.common.capabilities.Capability;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TileCable extends TileModemBase
|
||||
{
|
||||
public static final double MIN = 0.375;
|
||||
public static final double MAX = 1 - MIN;
|
||||
|
||||
private static final AxisAlignedBB BOX_CENTRE = new AxisAlignedBB( MIN, MIN, MIN, MAX, MAX, MAX );
|
||||
private static final AxisAlignedBB[] BOXES = new AxisAlignedBB[] {
|
||||
new AxisAlignedBB( MIN, 0, MIN, MAX, MIN, MAX ), // Down
|
||||
new AxisAlignedBB( MIN, MAX, MIN, MAX, 1, MAX ), // Up
|
||||
new AxisAlignedBB( MIN, MIN, 0, MAX, MAX, MIN ), // North
|
||||
new AxisAlignedBB( MIN, MIN, MAX, MAX, MAX, 1 ), // South
|
||||
new AxisAlignedBB( 0, MIN, MIN, MIN, MAX, MAX ), // West
|
||||
new AxisAlignedBB( MAX, MIN, MIN, 1, MAX, MAX ), // East
|
||||
};
|
||||
|
||||
private static class CableElement extends WiredModemElement
|
||||
{
|
||||
private final TileCable m_entity;
|
||||
@ -187,15 +173,8 @@ public class TileCable extends TileModemBase
|
||||
public EnumFacing getDirection()
|
||||
{
|
||||
IBlockState state = getBlockState();
|
||||
BlockCableModemVariant modem = state.getValue( BlockCable.Properties.MODEM );
|
||||
if( modem != BlockCableModemVariant.None )
|
||||
{
|
||||
return modem.getFacing();
|
||||
}
|
||||
else
|
||||
{
|
||||
return EnumFacing.NORTH;
|
||||
}
|
||||
EnumFacing facing = state.getValue( BlockCable.Properties.MODEM ).getFacing();
|
||||
return facing != null ? facing : EnumFacing.NORTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -233,19 +212,6 @@ public class TileCable extends TileModemBase
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickedItem()
|
||||
{
|
||||
if( getPeripheralType() == PeripheralType.WiredModemWithCable )
|
||||
{
|
||||
return PeripheralItemFactory.create( PeripheralType.WiredModem, getLabel(), 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.getPickedItem();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighbourChange()
|
||||
{
|
||||
@ -300,100 +266,8 @@ public class TileCable extends TileModemBase
|
||||
}
|
||||
}
|
||||
|
||||
public AxisAlignedBB getModemBounds()
|
||||
{
|
||||
return super.getBounds();
|
||||
}
|
||||
|
||||
private AxisAlignedBB getCableBounds()
|
||||
{
|
||||
double xMin = 0.375;
|
||||
double yMin = 0.375;
|
||||
double zMin = 0.375;
|
||||
double xMax = 0.625;
|
||||
double yMax = 0.625;
|
||||
double zMax = 0.625;
|
||||
BlockPos pos = getPos();
|
||||
World world = getWorld();
|
||||
|
||||
IBlockState state = getBlockState();
|
||||
if( BlockCable.doesConnectVisually( state, world, pos, EnumFacing.WEST ) )
|
||||
{
|
||||
xMin = 0.0;
|
||||
}
|
||||
if( BlockCable.doesConnectVisually( state, world, pos, EnumFacing.EAST ) )
|
||||
{
|
||||
xMax = 1.0;
|
||||
}
|
||||
if( BlockCable.doesConnectVisually( state, world, pos, EnumFacing.DOWN ) )
|
||||
{
|
||||
yMin = 0.0;
|
||||
}
|
||||
if( BlockCable.doesConnectVisually( state, world, pos, EnumFacing.UP ) )
|
||||
{
|
||||
yMax = 1.0;
|
||||
}
|
||||
if( BlockCable.doesConnectVisually( state, world, pos, EnumFacing.NORTH ) )
|
||||
{
|
||||
zMin = 0.0;
|
||||
}
|
||||
if( BlockCable.doesConnectVisually( state, world, pos, EnumFacing.SOUTH ) )
|
||||
{
|
||||
zMax = 1.0;
|
||||
}
|
||||
return new AxisAlignedBB( xMin, yMin, zMin, xMax, yMax, zMax );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public AxisAlignedBB getBounds()
|
||||
{
|
||||
PeripheralType type = getPeripheralType();
|
||||
switch( type )
|
||||
{
|
||||
case WiredModem:
|
||||
default:
|
||||
{
|
||||
return getModemBounds();
|
||||
}
|
||||
case Cable:
|
||||
{
|
||||
return getCableBounds();
|
||||
}
|
||||
case WiredModemWithCable:
|
||||
{
|
||||
AxisAlignedBB modem = getModemBounds();
|
||||
AxisAlignedBB cable = getCableBounds();
|
||||
return modem.union( cable );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getCollisionBounds( @Nonnull List<AxisAlignedBB> bounds )
|
||||
{
|
||||
PeripheralType type = getPeripheralType();
|
||||
if( type == PeripheralType.WiredModem || type == PeripheralType.WiredModemWithCable )
|
||||
{
|
||||
bounds.add( getModemBounds() );
|
||||
}
|
||||
if( type == PeripheralType.Cable || type == PeripheralType.WiredModemWithCable )
|
||||
{
|
||||
bounds.add( BOX_CENTRE );
|
||||
|
||||
IBlockState state = getBlockState();
|
||||
for( EnumFacing facing : EnumFacing.VALUES )
|
||||
{
|
||||
if( BlockCable.doesConnectVisually( state, world, pos, facing ) )
|
||||
{
|
||||
bounds.add( BOXES[facing.ordinal()] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivate( EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
if( getPeripheralType() == PeripheralType.WiredModemWithCable && !player.isSneaking() )
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ import dan200.computercraft.shared.wired.CapabilityWiredElement;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
@ -170,15 +170,8 @@ public class TileWiredModemFull extends TilePeripheralBase
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public AxisAlignedBB getBounds()
|
||||
{
|
||||
return BlockCable.FULL_BLOCK_AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivate( EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
if( !getWorld().isRemote )
|
||||
{
|
||||
|
@ -10,6 +10,7 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.peripheral.PeripheralType;
|
||||
import dan200.computercraft.shared.peripheral.common.BlockPeripheralBase;
|
||||
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
|
||||
import dan200.computercraft.shared.peripheral.modem.ModemBounds;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.properties.PropertyDirection;
|
||||
import net.minecraft.block.state.BlockFaceShape;
|
||||
@ -17,6 +18,7 @@ import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
@ -74,7 +76,7 @@ public class BlockAdvancedModem extends BlockPeripheralBase
|
||||
int anim;
|
||||
EnumFacing dir;
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TilePeripheralBase )
|
||||
if( tile instanceof TilePeripheralBase )
|
||||
{
|
||||
TilePeripheralBase peripheral = (TilePeripheralBase) tile;
|
||||
anim = peripheral.getAnim();
|
||||
@ -137,4 +139,10 @@ public class BlockAdvancedModem extends BlockPeripheralBase
|
||||
{
|
||||
return BlockFaceShape.UNDEFINED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox( IBlockState state, IBlockAccess source, BlockPos pos )
|
||||
{
|
||||
return ModemBounds.getBounds( state.getValue( Properties.FACING ) );
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@ -107,7 +108,7 @@ public class TileMonitor extends TilePeripheralBase
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivate( EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
if( !player.isSneaking() && getFront() == side )
|
||||
{
|
||||
|
@ -23,6 +23,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
@ -74,7 +75,7 @@ public class TilePrinter extends TilePeripheralBase
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivate( EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
if( !player.isSneaking() )
|
||||
{
|
||||
|
@ -35,7 +35,9 @@ import dan200.computercraft.shared.media.recipes.DiskRecipe;
|
||||
import dan200.computercraft.shared.media.recipes.PrintoutRecipe;
|
||||
import dan200.computercraft.shared.network.ComputerCraftPacket;
|
||||
import dan200.computercraft.shared.peripheral.commandblock.CommandBlockPeripheralProvider;
|
||||
import dan200.computercraft.shared.peripheral.common.*;
|
||||
import dan200.computercraft.shared.peripheral.common.BlockPeripheral;
|
||||
import dan200.computercraft.shared.peripheral.common.DefaultPeripheralProvider;
|
||||
import dan200.computercraft.shared.peripheral.common.ItemPeripheral;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.*;
|
||||
|
@ -10,19 +10,25 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.blocks.BlockComputerBase;
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
|
||||
import dan200.computercraft.shared.util.DirectionUtil;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyDirection;
|
||||
import net.minecraft.block.state.BlockFaceShape;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.projectile.EntityFireball;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumBlockRenderType;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -120,6 +126,18 @@ public class BlockTurtle extends BlockComputerBase
|
||||
return getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public AxisAlignedBB getBoundingBox( IBlockState state, IBlockAccess world, BlockPos pos )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
Vec3d offset = tile instanceof TileTurtle ? ((TileTurtle) tile).getRenderOffset( 1.0f ) : Vec3d.ZERO;
|
||||
return new AxisAlignedBB(
|
||||
offset.x + 0.125, offset.y + 0.125, offset.z + 0.125,
|
||||
offset.x + 0.875, offset.y + 0.875, offset.z + 0.875
|
||||
);
|
||||
}
|
||||
|
||||
private ComputerFamily getFamily()
|
||||
{
|
||||
if( this == ComputerCraft.Blocks.turtleAdvanced )
|
||||
@ -166,7 +184,7 @@ public class BlockTurtle extends BlockComputerBase
|
||||
{
|
||||
// Not sure why this is necessary
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileTurtle )
|
||||
if( tile instanceof TileTurtle )
|
||||
{
|
||||
tile.setWorld( world ); // Not sure why this is necessary
|
||||
tile.setPos( pos ); // Not sure why this is necessary
|
||||
@ -180,4 +198,24 @@ public class BlockTurtle extends BlockComputerBase
|
||||
EnumFacing dir = DirectionUtil.fromEntityRot( player );
|
||||
setDirection( world, pos, dir.getOpposite() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public float getExplosionResistance( Entity exploder )
|
||||
{
|
||||
if( getFamily() == ComputerFamily.Advanced && (exploder instanceof EntityLivingBase || exploder instanceof EntityFireball) )
|
||||
{
|
||||
return 2000;
|
||||
}
|
||||
|
||||
return super.getExplosionResistance( exploder );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack getPickBlock( @Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
return tile instanceof TileTurtle ? TurtleItemFactory.create( (TileTurtle) tile ) : super.getPickBlock( state, target, world, pos, player );
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,7 @@ import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
|
||||
import dan200.computercraft.shared.util.InventoryUtil;
|
||||
import dan200.computercraft.shared.util.RedstoneUtil;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.projectile.EntityFireball;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@ -35,7 +32,6 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
@ -183,19 +179,13 @@ public class TileTurtle extends TileComputerBase
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickedItem()
|
||||
{
|
||||
return TurtleItemFactory.create( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivate( EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
{
|
||||
// Request description from server
|
||||
requestTileEntityUpdate();
|
||||
|
||||
// Apply dye
|
||||
ItemStack currentItem = player.getHeldItem( EnumHand.MAIN_HAND );
|
||||
ItemStack currentItem = player.getHeldItem( hand );
|
||||
if( !currentItem.isEmpty() )
|
||||
{
|
||||
if( currentItem.getItem() == Items.DYE )
|
||||
@ -225,7 +215,7 @@ public class TileTurtle extends TileComputerBase
|
||||
m_brain.setColour( -1 );
|
||||
if( !player.capabilities.isCreativeMode )
|
||||
{
|
||||
player.setHeldItem( EnumHand.MAIN_HAND, new ItemStack( Items.BUCKET ) );
|
||||
player.setHeldItem( hand, new ItemStack( Items.BUCKET ) );
|
||||
player.inventory.markDirty();
|
||||
}
|
||||
}
|
||||
@ -235,7 +225,7 @@ public class TileTurtle extends TileComputerBase
|
||||
}
|
||||
|
||||
// Open GUI or whatever
|
||||
return super.onActivate( player, side, hitX, hitY, hitZ );
|
||||
return super.onActivate( player, hand, side, hitX, hitY, hitZ );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -250,36 +240,6 @@ public class TileTurtle extends TileComputerBase
|
||||
ComputerCraft.openTurtleGUI( player, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolidOnSide( int side )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isImmuneToExplosion( Entity exploder )
|
||||
{
|
||||
if( getFamily() == ComputerFamily.Advanced )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return exploder != null && (exploder instanceof EntityLivingBase || exploder instanceof EntityFireball);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public AxisAlignedBB getBounds()
|
||||
{
|
||||
Vec3d offset = getRenderOffset( 1.0f );
|
||||
return new AxisAlignedBB(
|
||||
offset.x + 0.125, offset.y + 0.125, offset.z + 0.125,
|
||||
offset.x + 0.875, offset.y + 0.875, offset.z + 0.875
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double getInteractRange( EntityPlayer player )
|
||||
{
|
||||
|
@ -19,7 +19,10 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||
import dan200.computercraft.shared.util.*;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import dan200.computercraft.shared.util.ColourUtils;
|
||||
import dan200.computercraft.shared.util.Holiday;
|
||||
import dan200.computercraft.shared.util.HolidayUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.MoverType;
|
||||
@ -999,7 +1002,7 @@ public class TurtleBrain implements ITurtleAccess
|
||||
}
|
||||
default:
|
||||
{
|
||||
return new Vec3d( 0.0, 0.0, 0.0 );
|
||||
return Vec3d.ZERO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||
import dan200.computercraft.api.turtle.event.TurtleBlockEvent;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
@ -53,7 +54,8 @@ public class TurtleMoveCommand implements ITurtleCommand
|
||||
}
|
||||
|
||||
// Check existing block is air or replaceable
|
||||
Block block = oldWorld.getBlockState( newPosition ).getBlock();
|
||||
IBlockState state = oldWorld.getBlockState( newPosition );
|
||||
Block block = state.getBlock();
|
||||
if( block != null &&
|
||||
!oldWorld.isAirBlock( newPosition ) &&
|
||||
!WorldUtil.isLiquidBlock( oldWorld, newPosition ) &&
|
||||
@ -63,7 +65,7 @@ public class TurtleMoveCommand implements ITurtleCommand
|
||||
}
|
||||
|
||||
// Check there isn't anything in the way
|
||||
AxisAlignedBB aabb = ((TurtleBrain) turtle).getOwner().getBounds();
|
||||
AxisAlignedBB aabb = state.getBoundingBox( oldWorld, oldPosition );
|
||||
aabb = aabb.offset(
|
||||
newPosition.getX(),
|
||||
newPosition.getY(),
|
||||
|
Loading…
Reference in New Issue
Block a user