mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-17 21:55:12 +00:00
Merge pull request #227 from SquidDev-CC/ComputerCraft/feature/improved-cable
Improving cable/wired modem interactions
This commit is contained in:
@@ -68,7 +68,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean removedByPlayer( @Nonnull IBlockState state, World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, boolean willHarvest )
|
||||
public boolean removedByPlayer( @Nonnull IBlockState state, World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, boolean willHarvest )
|
||||
{
|
||||
if( !world.isRemote )
|
||||
{
|
||||
@@ -122,7 +122,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final ItemStack getPickBlock( @Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player )
|
||||
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 )
|
||||
|
||||
@@ -7,21 +7,33 @@
|
||||
package dan200.computercraft.shared.peripheral.common;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.common.TileGeneric;
|
||||
import dan200.computercraft.shared.peripheral.PeripheralType;
|
||||
import dan200.computercraft.shared.peripheral.modem.TileCable;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
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.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.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;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockCable extends BlockPeripheralBase
|
||||
{
|
||||
@@ -30,7 +42,7 @@ public class BlockCable extends BlockPeripheralBase
|
||||
public static class Properties
|
||||
{
|
||||
public static final PropertyEnum<BlockCableModemVariant> MODEM = PropertyEnum.create( "modem", BlockCableModemVariant.class );
|
||||
public static final PropertyBool CABLE = PropertyBool.create( "cable" );
|
||||
public static final PropertyEnum<BlockCableCableVariant> CABLE = PropertyEnum.create( "cable", BlockCableCableVariant.class );
|
||||
public static final PropertyBool NORTH = PropertyBool.create( "north" );
|
||||
public static final PropertyBool SOUTH = PropertyBool.create( "south" );
|
||||
public static final PropertyBool EAST = PropertyBool.create( "east" );
|
||||
@@ -65,7 +77,7 @@ public class BlockCable extends BlockPeripheralBase
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
setDefaultState( this.blockState.getBaseState()
|
||||
.withProperty( Properties.MODEM, BlockCableModemVariant.None )
|
||||
.withProperty( Properties.CABLE, true )
|
||||
.withProperty( Properties.CABLE, BlockCableCableVariant.NONE )
|
||||
.withProperty( Properties.NORTH, false )
|
||||
.withProperty( Properties.SOUTH, false )
|
||||
.withProperty( Properties.EAST, false )
|
||||
@@ -99,17 +111,17 @@ public class BlockCable extends BlockPeripheralBase
|
||||
IBlockState state = getDefaultState();
|
||||
if( meta < 6 )
|
||||
{
|
||||
state = state.withProperty( Properties.CABLE, false );
|
||||
state = state.withProperty( Properties.CABLE, BlockCableCableVariant.NONE );
|
||||
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.getFront( meta ) ) );
|
||||
}
|
||||
else if( meta < 12 )
|
||||
{
|
||||
state = state.withProperty( Properties.CABLE, true );
|
||||
state = state.withProperty( Properties.CABLE, BlockCableCableVariant.ANY );
|
||||
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.getFront( meta - 6 ) ) );
|
||||
}
|
||||
else if( meta == 13 )
|
||||
{
|
||||
state = state.withProperty( Properties.CABLE, true );
|
||||
state = state.withProperty( Properties.CABLE, BlockCableCableVariant.ANY );
|
||||
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.None );
|
||||
}
|
||||
return state;
|
||||
@@ -119,7 +131,7 @@ public class BlockCable extends BlockPeripheralBase
|
||||
public int getMetaFromState( IBlockState state )
|
||||
{
|
||||
int meta = 0;
|
||||
boolean cable = state.getValue( Properties.CABLE );
|
||||
boolean cable = state.getValue( Properties.CABLE ) != BlockCableCableVariant.NONE;
|
||||
BlockCableModemVariant modem = state.getValue( Properties.MODEM );
|
||||
if( cable && modem != BlockCableModemVariant.None )
|
||||
{
|
||||
@@ -144,20 +156,20 @@ public class BlockCable extends BlockPeripheralBase
|
||||
case Cable:
|
||||
{
|
||||
return getDefaultState()
|
||||
.withProperty( Properties.CABLE, true )
|
||||
.withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
|
||||
.withProperty( Properties.MODEM, BlockCableModemVariant.None );
|
||||
}
|
||||
case WiredModem:
|
||||
default:
|
||||
{
|
||||
return getDefaultState()
|
||||
.withProperty( Properties.CABLE, false )
|
||||
.withProperty( Properties.CABLE, BlockCableCableVariant.NONE )
|
||||
.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( placedSide.getOpposite() ) );
|
||||
}
|
||||
case WiredModemWithCable:
|
||||
{
|
||||
return getDefaultState()
|
||||
.withProperty( Properties.CABLE, true )
|
||||
.withProperty( Properties.CABLE, BlockCableCableVariant.ANY )
|
||||
.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( placedSide.getOpposite() ) );
|
||||
}
|
||||
}
|
||||
@@ -165,7 +177,7 @@ public class BlockCable extends BlockPeripheralBase
|
||||
|
||||
private boolean doesConnect( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing dir )
|
||||
{
|
||||
if( !state.getValue( Properties.CABLE ) )
|
||||
if( state.getValue( Properties.CABLE ) == BlockCableCableVariant.NONE )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -191,11 +203,30 @@ public class BlockCable extends BlockPeripheralBase
|
||||
state = state.withProperty( Properties.UP, doesConnect( state, world, pos, EnumFacing.UP ) );
|
||||
state = state.withProperty( Properties.DOWN, doesConnect( state, world, pos, EnumFacing.DOWN ) );
|
||||
|
||||
if( state.getValue( Properties.CABLE ) != BlockCableCableVariant.NONE )
|
||||
{
|
||||
BlockCableCableVariant direction = null;
|
||||
if( state.getValue( Properties.WEST ) || state.getValue( Properties.EAST ) )
|
||||
{
|
||||
direction = direction == null ? BlockCableCableVariant.X_AXIS : BlockCableCableVariant.ANY;
|
||||
}
|
||||
if( state.getValue( Properties.DOWN ) || state.getValue( Properties.UP ) )
|
||||
{
|
||||
direction = direction == null ? BlockCableCableVariant.Y_AXIS : BlockCableCableVariant.ANY;
|
||||
}
|
||||
if( state.getValue( Properties.NORTH ) || state.getValue( Properties.SOUTH ) )
|
||||
{
|
||||
direction = direction == null ? BlockCableCableVariant.Z_AXIS : BlockCableCableVariant.ANY;
|
||||
}
|
||||
|
||||
state = state.withProperty( Properties.CABLE, direction == null ? BlockCableCableVariant.Z_AXIS : direction );
|
||||
}
|
||||
|
||||
int anim;
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TilePeripheralBase )
|
||||
{
|
||||
TilePeripheralBase peripheral = (TilePeripheralBase)tile;
|
||||
TilePeripheralBase peripheral = (TilePeripheralBase) tile;
|
||||
anim = peripheral.getAnim();
|
||||
}
|
||||
else
|
||||
@@ -208,7 +239,7 @@ public class BlockCable extends BlockPeripheralBase
|
||||
{
|
||||
modem = BlockCableModemVariant.values()[
|
||||
1 + 6 * anim + modem.getFacing().getIndex()
|
||||
];
|
||||
];
|
||||
}
|
||||
state = state.withProperty( Properties.MODEM, modem );
|
||||
|
||||
@@ -231,7 +262,7 @@ public class BlockCable extends BlockPeripheralBase
|
||||
@Override
|
||||
public PeripheralType getPeripheralType( IBlockState state )
|
||||
{
|
||||
boolean cable = state.getValue( Properties.CABLE );
|
||||
boolean cable = state.getValue( Properties.CABLE ) != BlockCableCableVariant.NONE;
|
||||
BlockCableModemVariant modem = state.getValue( Properties.MODEM );
|
||||
if( cable && modem != BlockCableModemVariant.None )
|
||||
{
|
||||
@@ -253,6 +284,132 @@ public class BlockCable extends BlockPeripheralBase
|
||||
return new TileCable();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@Deprecated
|
||||
public RayTraceResult collisionRayTrace( IBlockState blockState, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Vec3d start, @Nonnull Vec3d end )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
double newDistance = hit.hitVec.squareDistanceTo( startOff );
|
||||
if( newDistance <= distance )
|
||||
{
|
||||
distance = newDistance;
|
||||
result = hit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result == null ? null : new RayTraceResult( result.hitVec.addVector( pos.getX(), pos.getY(), pos.getZ() ), result.sideHit, pos );
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.collisionRayTrace( blockState, world, pos, start, end );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer( @Nonnull IBlockState state, World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, boolean willHarvest )
|
||||
{
|
||||
PeripheralType type = getPeripheralType( world, pos );
|
||||
if( type == PeripheralType.WiredModemWithCable )
|
||||
{
|
||||
RayTraceResult hit = state.collisionRayTrace( world, pos, WorldUtil.getRayStart( player ), WorldUtil.getRayEnd( player ) );
|
||||
if( hit != null )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileCable && tile.hasWorld() )
|
||||
{
|
||||
TileCable cable = (TileCable) tile;
|
||||
|
||||
ItemStack item;
|
||||
|
||||
AxisAlignedBB bb = cable.getModemBounds();
|
||||
if( WorldUtil.isVecInsideInclusive( bb, hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
|
||||
{
|
||||
world.setBlockState( pos, state.withProperty( Properties.MODEM, BlockCableModemVariant.None ), 3 );
|
||||
cable.modemChanged();
|
||||
item = PeripheralItemFactory.create( PeripheralType.WiredModem, null, 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
world.setBlockState( pos, state.withProperty( Properties.CABLE, BlockCableCableVariant.NONE ), 3 );
|
||||
item = PeripheralItemFactory.create( PeripheralType.Cable, null, 1 );
|
||||
}
|
||||
|
||||
cable.networkChanged();
|
||||
if( !world.isRemote && !player.capabilities.isCreativeMode ) dropItem( world, pos, item );
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.removedByPlayer( state, world, pos, player, willHarvest );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock( @Nonnull IBlockState state, RayTraceResult hit, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileCable && tile.hasWorld() )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
return PeripheralItemFactory.create( PeripheralType.Cable, null, 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileCable )
|
||||
{
|
||||
TileCable cable = (TileCable) tile;
|
||||
if( cable.getPeripheralType() != PeripheralType.WiredModem )
|
||||
{
|
||||
cable.networkChanged();
|
||||
}
|
||||
}
|
||||
|
||||
super.onBlockPlacedBy( world, pos, state, placer, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean isOpaqueCube( IBlockState state )
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package dan200.computercraft.shared.peripheral.common;
|
||||
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public enum BlockCableCableVariant implements IStringSerializable
|
||||
{
|
||||
NONE( "none" ),
|
||||
ANY( "any" ),
|
||||
X_AXIS( "x" ),
|
||||
Y_AXIS( "y" ),
|
||||
Z_AXIS( "z" ),;
|
||||
|
||||
private final String m_name;
|
||||
|
||||
BlockCableCableVariant( String name )
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public String getName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
}
|
||||
@@ -89,12 +89,12 @@ public class ItemCable extends ItemPeripheralBase
|
||||
{
|
||||
if( !stack.isEmpty() )
|
||||
{
|
||||
IBlockState newState = existingState.withProperty( BlockCable.Properties.CABLE, true );
|
||||
IBlockState newState = existingState.withProperty( BlockCable.Properties.CABLE, BlockCableCableVariant.ANY );
|
||||
world.setBlockState( pos, newState, 3 );
|
||||
SoundType soundType = newState.getBlock().getSoundType( newState, world, pos, player );
|
||||
world.playSound( null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F );
|
||||
stack.shrink( 1 );
|
||||
|
||||
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileCable )
|
||||
{
|
||||
@@ -143,7 +143,7 @@ public class ItemCable extends ItemPeripheralBase
|
||||
{
|
||||
if( !stack.isEmpty() )
|
||||
{
|
||||
IBlockState newState = offsetExistingState.withProperty( BlockCable.Properties.CABLE, true );
|
||||
IBlockState newState = offsetExistingState.withProperty( BlockCable.Properties.CABLE, BlockCableCableVariant.ANY );
|
||||
world.setBlockState( offset, newState, 3 );
|
||||
SoundType soundType = newState.getBlock().getSoundType( newState, world, offset, player );
|
||||
world.playSound( null, offset.getX() + 0.5, offset.getY() + 0.5, offset.getZ() + 0.5, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F );
|
||||
|
||||
@@ -46,8 +46,8 @@ import static dan200.computercraft.core.apis.ArgumentHelper.getString;
|
||||
public class TileCable extends TileModemBase
|
||||
implements IPacketNetwork
|
||||
{
|
||||
private static final double MIN = 0.375;
|
||||
private static final double MAX = 1 - MIN;
|
||||
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[]{
|
||||
@@ -359,6 +359,7 @@ public class TileCable extends TileModemBase
|
||||
((BlockGeneric)getBlockType()).dropItem( getWorld(), getPos(), PeripheralItemFactory.create( PeripheralType.WiredModem, getLabel(), 1 ) );
|
||||
setLabel( null );
|
||||
setBlockState( getBlockState().withProperty( BlockCable.Properties.MODEM, BlockCableModemVariant.None ) );
|
||||
if( modemChanged() ) networkChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -682,7 +683,7 @@ public class TileCable extends TileModemBase
|
||||
{
|
||||
if( !getWorld().isRemote )
|
||||
{
|
||||
if( !m_destroyed )
|
||||
if( !m_destroyed && getPeripheralType() != PeripheralType.WiredModem)
|
||||
{
|
||||
// If this modem is alive, rebuild the network
|
||||
searchNetwork( ( modem, distance ) ->
|
||||
@@ -712,6 +713,29 @@ public class TileCable extends TileModemBase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean modemChanged()
|
||||
{
|
||||
if( getWorld().isRemote ) return false;
|
||||
|
||||
boolean requiresUpdate = false;
|
||||
|
||||
PeripheralType type = getPeripheralType();
|
||||
if( type == PeripheralType.Cable )
|
||||
{
|
||||
m_attachedPeripheralID = -1;
|
||||
}
|
||||
|
||||
if( type != PeripheralType.WiredModemWithCable && m_peripheralAccessAllowed )
|
||||
{
|
||||
m_peripheralAccessAllowed = false;
|
||||
requiresUpdate = true;
|
||||
markDirty();
|
||||
updateAnim();
|
||||
}
|
||||
|
||||
return requiresUpdate;
|
||||
}
|
||||
|
||||
// private stuff
|
||||
|
||||
@@ -1041,4 +1065,10 @@ public class TileCable extends TileModemBase
|
||||
}
|
||||
//System.out.println( "Visited "+visited+" common" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRenderBreaking()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,18 @@
|
||||
|
||||
package dan200.computercraft.shared.util;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.*;
|
||||
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.World;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
@@ -47,9 +54,9 @@ public class WorldUtil
|
||||
}
|
||||
|
||||
// Check for entities
|
||||
float xStretch = (Math.abs(vecDir.x) > 0.25f) ? 0.0f : 1.0f;
|
||||
float yStretch = (Math.abs(vecDir.y) > 0.25f) ? 0.0f : 1.0f;
|
||||
float zStretch = (Math.abs(vecDir.z) > 0.25f) ? 0.0f : 1.0f;
|
||||
float xStretch = Math.abs(vecDir.x) > 0.25f ? 0.0f : 1.0f;
|
||||
float yStretch = Math.abs(vecDir.y) > 0.25f ? 0.0f : 1.0f;
|
||||
float zStretch = Math.abs(vecDir.z) > 0.25f ? 0.0f : 1.0f;
|
||||
AxisAlignedBB bigBox = new AxisAlignedBB(
|
||||
Math.min(vecStart.x, vecEnd.x) - 0.375f * xStretch,
|
||||
Math.min(vecStart.y, vecEnd.y) - 0.375f * yStretch,
|
||||
@@ -113,6 +120,35 @@ public class WorldUtil
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Vec3d getRayStart( EntityLivingBase entity )
|
||||
{
|
||||
return new Vec3d( entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ );
|
||||
}
|
||||
|
||||
public static Vec3d getRayEnd( EntityPlayer player) {
|
||||
double reach = 4.5;
|
||||
if( player instanceof EntityPlayerMP )
|
||||
{
|
||||
reach = ((EntityPlayerMP) player).interactionManager.getBlockReachDistance();
|
||||
}
|
||||
else if( player.getEntityWorld().isRemote )
|
||||
{
|
||||
reach = Minecraft.getMinecraft().playerController.getBlockReachDistance();
|
||||
}
|
||||
else if( player.capabilities.isCreativeMode )
|
||||
{
|
||||
reach = 5.0;
|
||||
}
|
||||
|
||||
Vec3d look = player.getLookVec();
|
||||
|
||||
return getRayStart( player ).addVector( look.x * reach, look.y * reach, look.z * reach );
|
||||
}
|
||||
|
||||
public static boolean isVecInsideInclusive(AxisAlignedBB bb , Vec3d vec) {
|
||||
return vec.x >= bb.minX && vec.x <= bb.maxX && vec.y >= bb.minY && vec.y <= bb.maxY && vec.z >= bb.minZ && vec.z <= bb.maxZ;
|
||||
}
|
||||
|
||||
public static void dropItemStack( @Nonnull ItemStack stack, World world, BlockPos pos )
|
||||
{
|
||||
dropItemStack( stack, world, pos, null );
|
||||
|
||||
Reference in New Issue
Block a user