1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-07 17:03:00 +00:00

Switch to Mojang mappings

ForgeGradle (probably sensibly) yells at me about doing this. However:
 - There's a reasonable number of mods doing this, which establishes
   some optimistic precedent.
 - The licence update in Aug 2020 now allows you to use them for
   "development purposes". I guess source code counts??
 - I'm fairly sure this is also compatible with the CCPL - there's an
   exception for Minecraft code.

The main motivation for this is to make the Fabric port a little
easier. Hopefully folks (maybe me in the future, we'll see) will no
longer have to deal with mapping hell when merging - only mod loader
hell.
This commit is contained in:
Jonathan Coates
2021-01-09 19:22:58 +00:00
parent c864576619
commit 34b5ede326
178 changed files with 1789 additions and 1738 deletions

View File

@@ -308,7 +308,7 @@ public class TurtleAPI implements ILuaAPI
public final int getItemCount( Optional<Integer> slot ) throws LuaException
{
int actualSlot = checkSlot( slot ).orElse( turtle.getSelectedSlot() );
return turtle.getInventory().getStackInSlot( actualSlot ).getCount();
return turtle.getInventory().getItem( actualSlot ).getCount();
}
/**
@@ -324,7 +324,7 @@ public class TurtleAPI implements ILuaAPI
public final int getItemSpace( Optional<Integer> slot ) throws LuaException
{
int actualSlot = checkSlot( slot ).orElse( turtle.getSelectedSlot() );
ItemStack stack = turtle.getInventory().getStackInSlot( actualSlot );
ItemStack stack = turtle.getInventory().getItem( actualSlot );
return stack.isEmpty() ? 64 : Math.min( stack.getMaxStackSize(), 64 ) - stack.getCount();
}
@@ -600,7 +600,7 @@ public class TurtleAPI implements ILuaAPI
private Object[] getItemDetail( int slot, boolean detailed )
{
ItemStack stack = turtle.getInventory().getStackInSlot( slot );
ItemStack stack = turtle.getInventory().getItem( slot );
if( stack.isEmpty() ) return new Object[] { null };
Map<String, Object> table = detailed

View File

@@ -44,11 +44,13 @@ import javax.annotation.Nullable;
import static dan200.computercraft.shared.util.WaterloggableHelpers.*;
import static net.minecraft.state.properties.BlockStateProperties.WATERLOGGED;
import net.minecraft.block.Block.Properties;
public class BlockTurtle extends BlockComputerBase<TileTurtle> implements IWaterLoggable
{
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
private static final VoxelShape DEFAULT_SHAPE = VoxelShapes.create(
private static final VoxelShape DEFAULT_SHAPE = VoxelShapes.box(
0.125, 0.125, 0.125,
0.875, 0.875, 0.875
);
@@ -56,14 +58,14 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements IWater
public BlockTurtle( Properties settings, ComputerFamily family, RegistryObject<? extends TileEntityType<? extends TileTurtle>> type )
{
super( settings, family, type );
setDefaultState( getStateContainer().getBaseState()
.with( FACING, Direction.NORTH )
.with( WATERLOGGED, false )
registerDefaultState( getStateDefinition().any()
.setValue( FACING, Direction.NORTH )
.setValue( WATERLOGGED, false )
);
}
@Override
protected void fillStateContainer( StateContainer.Builder<Block, BlockState> builder )
protected void createBlockStateDefinition( StateContainer.Builder<Block, BlockState> builder )
{
builder.add( FACING, WATERLOGGED );
}
@@ -71,7 +73,7 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements IWater
@Nonnull
@Override
@Deprecated
public BlockRenderType getRenderType( @Nonnull BlockState state )
public BlockRenderType getRenderShape( @Nonnull BlockState state )
{
return BlockRenderType.ENTITYBLOCK_ANIMATED;
}
@@ -81,18 +83,18 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements IWater
@Deprecated
public VoxelShape getShape( @Nonnull BlockState state, IBlockReader world, @Nonnull BlockPos pos, @Nonnull ISelectionContext context )
{
TileEntity tile = world.getTileEntity( pos );
TileEntity tile = world.getBlockEntity( pos );
Vec3d offset = tile instanceof TileTurtle ? ((TileTurtle) tile).getRenderOffset( 1.0f ) : Vec3d.ZERO;
return offset.equals( Vec3d.ZERO ) ? DEFAULT_SHAPE : DEFAULT_SHAPE.withOffset( offset.x, offset.y, offset.z );
return offset.equals( Vec3d.ZERO ) ? DEFAULT_SHAPE : DEFAULT_SHAPE.move( offset.x, offset.y, offset.z );
}
@Nullable
@Override
public BlockState getStateForPlacement( BlockItemUseContext placement )
{
return getDefaultState()
.with( FACING, placement.getPlacementHorizontalFacing() )
.with( WATERLOGGED, getWaterloggedStateForPlacement( placement ) );
return defaultBlockState()
.setValue( FACING, placement.getHorizontalDirection() )
.setValue( WATERLOGGED, getWaterloggedStateForPlacement( placement ) );
}
@Nonnull
@@ -106,19 +108,19 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements IWater
@Nonnull
@Override
@Deprecated
public BlockState updatePostPlacement( @Nonnull BlockState state, @Nonnull Direction side, @Nonnull BlockState otherState, @Nonnull IWorld world, @Nonnull BlockPos pos, @Nonnull BlockPos otherPos )
public BlockState updateShape( @Nonnull BlockState state, @Nonnull Direction side, @Nonnull BlockState otherState, @Nonnull IWorld world, @Nonnull BlockPos pos, @Nonnull BlockPos otherPos )
{
updateWaterloggedPostPlacement( state, world, pos );
return state;
}
@Override
public void onBlockPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable LivingEntity player, @Nonnull ItemStack stack )
public void setPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable LivingEntity player, @Nonnull ItemStack stack )
{
super.onBlockPlacedBy( world, pos, state, player, stack );
super.setPlacedBy( world, pos, state, player, stack );
TileEntity tile = world.getTileEntity( pos );
if( !world.isRemote && tile instanceof TileTurtle )
TileEntity tile = world.getBlockEntity( pos );
if( !world.isClientSide && tile instanceof TileTurtle )
{
TileTurtle turtle = (TileTurtle) tile;

View File

@@ -86,10 +86,10 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
protected ServerComputer createComputer( int instanceID, int id )
{
ServerComputer computer = new ServerComputer(
getWorld(), id, label, instanceID, getFamily(),
getLevel(), id, label, instanceID, getFamily(),
ComputerCraft.turtleTermWidth, ComputerCraft.turtleTermHeight
);
computer.setPosition( getPos() );
computer.setPosition( getBlockPos() );
computer.addAPI( new TurtleAPI( computer.getAPIEnvironment(), getAccess() ) );
m_brain.setupComputer( computer );
return computer;
@@ -109,15 +109,15 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
super.destroy();
// Drop contents
if( !getWorld().isRemote )
if( !getLevel().isClientSide )
{
int size = getSizeInventory();
int size = getContainerSize();
for( int i = 0; i < size; i++ )
{
ItemStack stack = getStackInSlot( i );
ItemStack stack = getItem( i );
if( !stack.isEmpty() )
{
WorldUtil.dropItemStack( stack, getWorld(), getPos() );
WorldUtil.dropItemStack( stack, getLevel(), getBlockPos() );
}
}
}
@@ -127,7 +127,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
// Just turn off any redstone we had on
for( Direction dir : DirectionUtil.FACINGS )
{
RedstoneUtil.propagateRedstoneOutput( getWorld(), getPos(), dir );
RedstoneUtil.propagateRedstoneOutput( getLevel(), getBlockPos(), dir );
}
}
}
@@ -154,13 +154,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
public ActionResultType onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit )
{
// Apply dye
ItemStack currentItem = player.getHeldItem( hand );
ItemStack currentItem = player.getItemInHand( hand );
if( !currentItem.isEmpty() )
{
if( currentItem.getItem() instanceof DyeItem )
{
// Dye to change turtle colour
if( !getWorld().isRemote )
if( !getLevel().isClientSide )
{
DyeColor dye = ((DyeItem) currentItem.getItem()).getDyeColor();
if( m_brain.getDyeColour() != dye )
@@ -177,15 +177,15 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
else if( currentItem.getItem() == Items.WATER_BUCKET && m_brain.getColour() != -1 )
{
// Water to remove turtle colour
if( !getWorld().isRemote )
if( !getLevel().isClientSide )
{
if( m_brain.getColour() != -1 )
{
m_brain.setColour( -1 );
if( !player.isCreative() )
{
player.setHeldItem( hand, new ItemStack( Items.BUCKET ) );
player.inventory.markDirty();
player.setItemInHand( hand, new ItemStack( Items.BUCKET ) );
player.inventory.setChanged();
}
}
}
@@ -214,15 +214,15 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
{
super.tick();
m_brain.update();
if( !getWorld().isRemote && m_inventoryChanged )
if( !getLevel().isClientSide && m_inventoryChanged )
{
ServerComputer computer = getServerComputer();
if( computer != null ) computer.queueEvent( "turtle_inventory" );
m_inventoryChanged = false;
for( int n = 0; n < getSizeInventory(); n++ )
for( int n = 0; n < getContainerSize(); n++ )
{
m_previousInventory.set( n, getStackInSlot( n ).copy() );
m_previousInventory.set( n, getItem( n ).copy() );
}
}
}
@@ -256,9 +256,9 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
}
@Override
public void read( @Nonnull CompoundNBT nbt )
public void load( @Nonnull CompoundNBT nbt )
{
super.read( nbt );
super.load( nbt );
// Read inventory
ListNBT nbttaglist = nbt.getList( "Items", Constants.NBT.TAG_COMPOUND );
@@ -268,9 +268,9 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
{
CompoundNBT tag = nbttaglist.getCompound( i );
int slot = tag.getByte( "Slot" ) & 0xff;
if( slot < getSizeInventory() )
if( slot < getContainerSize() )
{
m_inventory.set( slot, ItemStack.read( tag ) );
m_inventory.set( slot, ItemStack.of( tag ) );
m_previousInventory.set( slot, m_inventory.get( slot ).copy() );
}
}
@@ -281,7 +281,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Nonnull
@Override
public CompoundNBT write( @Nonnull CompoundNBT nbt )
public CompoundNBT save( @Nonnull CompoundNBT nbt )
{
// Write inventory
ListNBT nbttaglist = new ListNBT();
@@ -291,7 +291,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
{
CompoundNBT tag = new CompoundNBT();
tag.putByte( "Slot", (byte) i );
m_inventory.get( i ).write( tag );
m_inventory.get( i ).save( tag );
nbttaglist.add( tag );
}
}
@@ -300,7 +300,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
// Write brain
nbt = m_brain.writeToNBT( nbt );
return super.write( nbt );
return super.save( nbt );
}
@Override
@@ -314,13 +314,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override
public Direction getDirection()
{
return getBlockState().get( BlockTurtle.FACING );
return getBlockState().getValue( BlockTurtle.FACING );
}
public void setDirection( Direction dir )
{
if( dir.getAxis() == Direction.Axis.Y ) dir = Direction.NORTH;
world.setBlockState( pos, getBlockState().with( BlockTurtle.FACING, dir ) );
level.setBlockAndUpdate( worldPosition, getBlockState().setValue( BlockTurtle.FACING, dir ) );
updateOutput();
updateInput();
onTileEntityChange();
@@ -373,13 +373,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
void setOwningPlayer( GameProfile player )
{
m_brain.setOwningPlayer( player );
markDirty();
setChanged();
}
// IInventory
@Override
public int getSizeInventory()
public int getContainerSize()
{
return INVENTORY_SIZE;
}
@@ -396,32 +396,32 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Nonnull
@Override
public ItemStack getStackInSlot( int slot )
public ItemStack getItem( int slot )
{
return slot >= 0 && slot < INVENTORY_SIZE ? m_inventory.get( slot ) : ItemStack.EMPTY;
}
@Nonnull
@Override
public ItemStack removeStackFromSlot( int slot )
public ItemStack removeItemNoUpdate( int slot )
{
ItemStack result = getStackInSlot( slot );
setInventorySlotContents( slot, ItemStack.EMPTY );
ItemStack result = getItem( slot );
setItem( slot, ItemStack.EMPTY );
return result;
}
@Nonnull
@Override
public ItemStack decrStackSize( int slot, int count )
public ItemStack removeItem( int slot, int count )
{
if( count == 0 ) return ItemStack.EMPTY;
ItemStack stack = getStackInSlot( slot );
ItemStack stack = getItem( slot );
if( stack.isEmpty() ) return ItemStack.EMPTY;
if( stack.getCount() <= count )
{
setInventorySlotContents( slot, ItemStack.EMPTY );
setItem( slot, ItemStack.EMPTY );
return stack;
}
@@ -431,7 +431,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
}
@Override
public void setInventorySlotContents( int i, @Nonnull ItemStack stack )
public void setItem( int i, @Nonnull ItemStack stack )
{
if( i >= 0 && i < INVENTORY_SIZE && !InventoryUtil.areItemsEqual( stack, m_inventory.get( i ) ) )
{
@@ -441,7 +441,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
}
@Override
public void clear()
public void clearContent()
{
boolean changed = false;
for( int i = 0; i < INVENTORY_SIZE; i++ )
@@ -457,14 +457,14 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
}
@Override
public void markDirty()
public void setChanged()
{
super.markDirty();
super.setChanged();
if( !m_inventoryChanged )
{
for( int n = 0; n < getSizeInventory(); n++ )
for( int n = 0; n < getContainerSize(); n++ )
{
if( !ItemStack.areItemStacksEqual( getStackInSlot( n ), m_previousInventory.get( n ) ) )
if( !ItemStack.matches( getItem( n ), m_previousInventory.get( n ) ) )
{
m_inventoryChanged = true;
break;
@@ -474,20 +474,20 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
}
@Override
public boolean isUsableByPlayer( @Nonnull PlayerEntity player )
public boolean stillValid( @Nonnull PlayerEntity player )
{
return isUsable( player, false );
}
private void onInventoryDefinitelyChanged()
{
super.markDirty();
super.setChanged();
m_inventoryChanged = true;
}
public void onTileEntityChange()
{
super.markDirty();
super.setChanged();
}
// Networking stuff

View File

@@ -124,7 +124,7 @@ public class TurtleBrain implements ITurtleAccess
public void update()
{
World world = getWorld();
if( !world.isRemote )
if( !world.isClientSide )
{
// Advance movement
updateCommands();
@@ -273,20 +273,20 @@ public class TurtleBrain implements ITurtleAccess
@Override
public World getWorld()
{
return m_owner.getWorld();
return m_owner.getLevel();
}
@Nonnull
@Override
public BlockPos getPosition()
{
return m_owner.getPos();
return m_owner.getBlockPos();
}
@Override
public boolean teleportTo( @Nonnull World world, @Nonnull BlockPos pos )
{
if( world.isRemote || getWorld().isRemote )
if( world.isClientSide || getWorld().isClientSide )
{
throw new UnsupportedOperationException( "Cannot teleport on the client" );
}
@@ -294,7 +294,7 @@ public class TurtleBrain implements ITurtleAccess
// Cache info about the old turtle (so we don't access this after we delete ourselves)
World oldWorld = getWorld();
TileTurtle oldOwner = m_owner;
BlockPos oldPos = m_owner.getPos();
BlockPos oldPos = m_owner.getBlockPos();
BlockState oldBlock = m_owner.getBlockState();
if( oldWorld == world && oldPos.equals( pos ) )
@@ -307,31 +307,31 @@ public class TurtleBrain implements ITurtleAccess
if( !world.isAreaLoaded( pos, 0 ) ) return false;
// Ensure we're inside the world border
if( !world.getWorldBorder().contains( pos ) ) return false;
if( !world.getWorldBorder().isWithinBounds( pos ) ) return false;
IFluidState existingFluid = world.getBlockState( pos ).getFluidState();
BlockState newState = oldBlock
// We only mark this as waterlogged when travelling into a source block. This prevents us from spreading
// fluid by creating a new source when moving into a block, causing the next block to be almost full and
// then moving into that.
.with( WATERLOGGED, existingFluid.isTagged( FluidTags.WATER ) && existingFluid.isSource() );
.setValue( WATERLOGGED, existingFluid.is( FluidTags.WATER ) && existingFluid.isSource() );
oldOwner.notifyMoveStart();
try
{
// Create a new turtle
if( world.setBlockState( pos, newState, 0 ) )
if( world.setBlock( pos, newState, 0 ) )
{
Block block = world.getBlockState( pos ).getBlock();
if( block == oldBlock.getBlock() )
{
TileEntity newTile = world.getTileEntity( pos );
TileEntity newTile = world.getBlockEntity( pos );
if( newTile instanceof TileTurtle )
{
// Copy the old turtle state into the new turtle
TileTurtle newTurtle = (TileTurtle) newTile;
newTurtle.setWorldAndPos( world, pos );
newTurtle.setLevelAndPosition( world, pos );
newTurtle.transferStateFrom( oldOwner );
newTurtle.createServerComputer().setWorld( world );
newTurtle.createServerComputer().setPosition( pos );
@@ -365,7 +365,7 @@ public class TurtleBrain implements ITurtleAccess
public Vec3d getVisualPosition( float f )
{
Vec3d offset = getRenderOffset( f );
BlockPos pos = m_owner.getPos();
BlockPos pos = m_owner.getBlockPos();
return new Vec3d(
pos.getX() + 0.5 + offset.x,
pos.getY() + 0.5 + offset.y,
@@ -376,7 +376,7 @@ public class TurtleBrain implements ITurtleAccess
@Override
public float getVisualYaw( float f )
{
float yaw = getDirection().getHorizontalAngle();
float yaw = getDirection().toYRot();
switch( m_animation )
{
case TURN_LEFT:
@@ -423,9 +423,9 @@ public class TurtleBrain implements ITurtleAccess
@Override
public void setSelectedSlot( int slot )
{
if( getWorld().isRemote ) throw new UnsupportedOperationException( "Cannot set the slot on the client" );
if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot set the slot on the client" );
if( slot >= 0 && slot < m_owner.getSizeInventory() )
if( slot >= 0 && slot < m_owner.getContainerSize() )
{
m_selectedSlot = slot;
m_owner.onTileEntityChange();
@@ -481,7 +481,7 @@ public class TurtleBrain implements ITurtleAccess
@Override
public boolean consumeFuel( int fuel )
{
if( getWorld().isRemote ) throw new UnsupportedOperationException( "Cannot consume fuel on the client" );
if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot consume fuel on the client" );
if( !isFuelNeeded() ) return true;
@@ -497,7 +497,7 @@ public class TurtleBrain implements ITurtleAccess
@Override
public void addFuel( int fuel )
{
if( getWorld().isRemote ) throw new UnsupportedOperationException( "Cannot add fuel on the client" );
if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot add fuel on the client" );
int addition = Math.max( fuel, 0 );
setFuelLevel( getFuelLevel() + addition );
@@ -513,7 +513,7 @@ public class TurtleBrain implements ITurtleAccess
@Override
public MethodResult executeCommand( @Nonnull ITurtleCommand command )
{
if( getWorld().isRemote ) throw new UnsupportedOperationException( "Cannot run commands on the client" );
if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot run commands on the client" );
// Issue command
int commandID = issueCommand( command );
@@ -523,7 +523,7 @@ public class TurtleBrain implements ITurtleAccess
@Override
public void playAnimation( @Nonnull TurtleAnimation animation )
{
if( getWorld().isRemote ) throw new UnsupportedOperationException( "Cannot play animations on the client" );
if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot play animations on the client" );
m_animation = animation;
if( m_animation == TurtleAnimation.SHORT_WAIT )
@@ -636,7 +636,7 @@ public class TurtleBrain implements ITurtleAccess
if( upgrade != null ) m_upgrades.put( side, upgrade );
// Notify clients and create peripherals
if( m_owner.getWorld() != null )
if( m_owner.getLevel() != null )
{
updatePeripherals( m_owner.createServerComputer() );
m_owner.updateBlock();
@@ -694,9 +694,9 @@ public class TurtleBrain implements ITurtleAccess
double distance = -1.0 + getAnimationFraction( f );
return new Vec3d(
distance * dir.getXOffset(),
distance * dir.getYOffset(),
distance * dir.getZOffset()
distance * dir.getStepX(),
distance * dir.getStepY(),
distance * dir.getStepZ()
);
}
default:
@@ -848,41 +848,41 @@ public class TurtleBrain implements ITurtleAccess
float pushFrac = 1.0f - (float) (m_animationProgress + 1) / ANIM_DURATION;
float push = Math.max( pushFrac + 0.0125f, 0.0f );
if( moveDir.getXOffset() < 0 )
if( moveDir.getStepX() < 0 )
{
minX += moveDir.getXOffset() * push;
minX += moveDir.getStepX() * push;
}
else
{
maxX -= moveDir.getXOffset() * push;
maxX -= moveDir.getStepX() * push;
}
if( moveDir.getYOffset() < 0 )
if( moveDir.getStepY() < 0 )
{
minY += moveDir.getYOffset() * push;
minY += moveDir.getStepY() * push;
}
else
{
maxY -= moveDir.getYOffset() * push;
maxY -= moveDir.getStepY() * push;
}
if( moveDir.getZOffset() < 0 )
if( moveDir.getStepZ() < 0 )
{
minZ += moveDir.getZOffset() * push;
minZ += moveDir.getStepZ() * push;
}
else
{
maxZ -= moveDir.getZOffset() * push;
maxZ -= moveDir.getStepZ() * push;
}
AxisAlignedBB aabb = new AxisAlignedBB( minX, minY, minZ, maxX, maxY, maxZ );
List<Entity> list = world.getEntitiesWithinAABB( Entity.class, aabb, EntityPredicates.NOT_SPECTATING );
List<Entity> list = world.getEntitiesOfClass( Entity.class, aabb, EntityPredicates.NO_SPECTATORS );
if( !list.isEmpty() )
{
double pushStep = 1.0f / ANIM_DURATION;
double pushStepX = moveDir.getXOffset() * pushStep;
double pushStepY = moveDir.getYOffset() * pushStep;
double pushStepZ = moveDir.getZOffset() * pushStep;
double pushStepX = moveDir.getStepX() * pushStep;
double pushStepY = moveDir.getStepY() * pushStep;
double pushStepZ = moveDir.getStepZ() * pushStep;
for( Entity entity : list )
{
entity.move( MoverType.PISTON, new Vec3d( pushStepX, pushStepY, pushStepZ ) );
@@ -892,7 +892,7 @@ public class TurtleBrain implements ITurtleAccess
}
// Advance valentines day easter egg
if( world.isRemote && m_animation == TurtleAnimation.MOVE_FORWARD && m_animationProgress == 4 )
if( world.isClientSide && m_animation == TurtleAnimation.MOVE_FORWARD && m_animationProgress == 4 )
{
// Spawn love pfx if valentines day
Holiday currentHoliday = HolidayUtil.getCurrentHoliday();
@@ -901,14 +901,14 @@ public class TurtleBrain implements ITurtleAccess
Vec3d position = getVisualPosition( 1.0f );
if( position != null )
{
double x = position.x + world.rand.nextGaussian() * 0.1;
double y = position.y + 0.5 + world.rand.nextGaussian() * 0.1;
double z = position.z + world.rand.nextGaussian() * 0.1;
double x = position.x + world.random.nextGaussian() * 0.1;
double y = position.y + 0.5 + world.random.nextGaussian() * 0.1;
double z = position.z + world.random.nextGaussian() * 0.1;
world.addParticle(
ParticleTypes.HEART, x, y, z,
world.rand.nextGaussian() * 0.02,
world.rand.nextGaussian() * 0.02,
world.rand.nextGaussian() * 0.02
world.random.nextGaussian() * 0.02,
world.random.nextGaussian() * 0.02,
world.random.nextGaussian() * 0.02
);
}
}

View File

@@ -38,15 +38,15 @@ public class TurtleCompareCommand implements ITurtleCommand
Direction direction = m_direction.toWorldDir( turtle );
// Get currently selected stack
ItemStack selectedStack = turtle.getInventory().getStackInSlot( turtle.getSelectedSlot() );
ItemStack selectedStack = turtle.getInventory().getItem( turtle.getSelectedSlot() );
// Get stack representing thing in front
World world = turtle.getWorld();
BlockPos oldPosition = turtle.getPosition();
BlockPos newPosition = oldPosition.offset( direction );
BlockPos newPosition = oldPosition.relative( direction );
ItemStack lookAtStack = ItemStack.EMPTY;
if( !world.isAirBlock( newPosition ) )
if( !world.isEmptyBlock( newPosition ) )
{
BlockState lookAtState = world.getBlockState( newPosition );
Block lookAtBlock = lookAtState.getBlock();
@@ -69,7 +69,7 @@ public class TurtleCompareCommand implements ITurtleCommand
// (try 5 times to try and beat random number generators)
for( int i = 0; i < 5 && lookAtStack.isEmpty(); i++ )
{
List<ItemStack> drops = Block.getDrops( lookAtState, (ServerWorld) world, newPosition, world.getTileEntity( newPosition ) );
List<ItemStack> drops = Block.getDrops( lookAtState, (ServerWorld) world, newPosition, world.getBlockEntity( newPosition ) );
if( !drops.isEmpty() )
{
for( ItemStack drop : drops )

View File

@@ -26,8 +26,8 @@ public class TurtleCompareToCommand implements ITurtleCommand
@Override
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
{
ItemStack selectedStack = turtle.getInventory().getStackInSlot( turtle.getSelectedSlot() );
ItemStack stack = turtle.getInventory().getStackInSlot( m_slot );
ItemStack selectedStack = turtle.getInventory().getItem( turtle.getSelectedSlot() );
ItemStack stack = turtle.getInventory().getItem( m_slot );
if( InventoryUtil.areItemsStackable( selectedStack, stack ) )
{
return TurtleCommandResult.success();

View File

@@ -34,9 +34,9 @@ public class TurtleDetectCommand implements ITurtleCommand
// Check if thing in front is air or not
World world = turtle.getWorld();
BlockPos oldPosition = turtle.getPosition();
BlockPos newPosition = oldPosition.offset( direction );
BlockPos newPosition = oldPosition.relative( direction );
return !WorldUtil.isLiquidBlock( world, newPosition ) && !world.isAirBlock( newPosition )
return !WorldUtil.isLiquidBlock( world, newPosition ) && !world.isEmptyBlock( newPosition )
? TurtleCommandResult.success()
: TurtleCommandResult.failure();
}

View File

@@ -56,7 +56,7 @@ public class TurtleDropCommand implements ITurtleCommand
// Get inventory for thing in front
World world = turtle.getWorld();
BlockPos oldPosition = turtle.getPosition();
BlockPos newPosition = oldPosition.offset( direction );
BlockPos newPosition = oldPosition.relative( direction );
Direction side = direction.getOpposite();
IItemHandler inventory = InventoryUtil.getInventory( world, newPosition, side );
@@ -95,7 +95,7 @@ public class TurtleDropCommand implements ITurtleCommand
{
// Drop the item into the world
WorldUtil.dropItemStack( stack, world, oldPosition, direction );
world.playBroadcastSound( 1000, newPosition, 0 );
world.globalLevelEvent( 1000, newPosition, 0 );
turtle.playAnimation( TurtleAnimation.WAIT );
return TurtleCommandResult.success();
}

View File

@@ -39,7 +39,7 @@ public class TurtleInspectCommand implements ITurtleCommand
// Check if thing in front is air or not
World world = turtle.getWorld();
BlockPos oldPosition = turtle.getPosition();
BlockPos newPosition = oldPosition.offset( direction );
BlockPos newPosition = oldPosition.relative( direction );
BlockState state = world.getBlockState( newPosition );
if( state.getBlock().isAir( state, world, newPosition ) )

View File

@@ -45,7 +45,7 @@ public class TurtleMoveCommand implements ITurtleCommand
// Check if we can move
World oldWorld = turtle.getWorld();
BlockPos oldPosition = turtle.getPosition();
BlockPos newPosition = oldPosition.offset( direction );
BlockPos newPosition = oldPosition.relative( direction );
TurtlePlayer turtlePlayer = TurtlePlaceCommand.createPlayer( turtle, oldPosition, direction );
TurtleCommandResult canEnterResult = canEnter( turtlePlayer, oldWorld, newPosition );
@@ -56,7 +56,7 @@ public class TurtleMoveCommand implements ITurtleCommand
// Check existing block is air or replaceable
BlockState state = oldWorld.getBlockState( newPosition );
if( !oldWorld.isAirBlock( newPosition ) &&
if( !oldWorld.isEmptyBlock( newPosition ) &&
!WorldUtil.isLiquidBlock( oldWorld, newPosition ) &&
!state.getMaterial().isReplaceable() )
{
@@ -64,13 +64,13 @@ public class TurtleMoveCommand implements ITurtleCommand
}
// Check there isn't anything in the way
VoxelShape collision = state.getCollisionShape( oldWorld, oldPosition ).withOffset(
VoxelShape collision = state.getCollisionShape( oldWorld, oldPosition ).move(
newPosition.getX(),
newPosition.getY(),
newPosition.getZ()
);
if( !oldWorld.checkNoEntityCollision( null, collision ) )
if( !oldWorld.isUnobstructed( null, collision ) )
{
if( !ComputerCraft.turtlesCanPush || m_direction == MoveDirection.UP || m_direction == MoveDirection.DOWN )
{
@@ -78,15 +78,15 @@ public class TurtleMoveCommand implements ITurtleCommand
}
// Check there is space for all the pushable entities to be pushed
List<Entity> list = oldWorld.getEntitiesWithinAABB( Entity.class, getBox( collision ), x -> x != null && x.isAlive() && x.preventEntitySpawning );
List<Entity> list = oldWorld.getEntitiesOfClass( Entity.class, getBox( collision ), x -> x != null && x.isAlive() && x.blocksBuilding );
for( Entity entity : list )
{
AxisAlignedBB pushedBB = entity.getBoundingBox().offset(
direction.getXOffset(),
direction.getYOffset(),
direction.getZOffset()
AxisAlignedBB pushedBB = entity.getBoundingBox().move(
direction.getStepX(),
direction.getStepY(),
direction.getStepZ()
);
if( !oldWorld.checkNoEntityCollision( null, VoxelShapes.create( pushedBB ) ) )
if( !oldWorld.isUnobstructed( null, VoxelShapes.create( pushedBB ) ) )
{
return TurtleCommandResult.failure( "Movement obstructed" );
}
@@ -137,7 +137,7 @@ public class TurtleMoveCommand implements ITurtleCommand
{
return TurtleCommandResult.failure( position.getY() < 0 ? "Too low to move" : "Too high to move" );
}
if( !World.isValid( position ) ) return TurtleCommandResult.failure( "Cannot leave the world" );
if( !World.isInWorldBounds( position ) ) return TurtleCommandResult.failure( "Cannot leave the world" );
// Check spawn protection
if( ComputerCraft.turtlesObeyBlockProtection && !TurtlePermissions.isBlockEnterable( world, position, turtlePlayer ) )
@@ -146,7 +146,7 @@ public class TurtleMoveCommand implements ITurtleCommand
}
if( !world.isAreaLoaded( position, 0 ) ) return TurtleCommandResult.failure( "Cannot leave loaded world" );
if( !world.getWorldBorder().contains( position ) )
if( !world.getWorldBorder().isWithinBounds( position ) )
{
return TurtleCommandResult.failure( "Cannot pass the world border" );
}
@@ -156,7 +156,7 @@ public class TurtleMoveCommand implements ITurtleCommand
private static AxisAlignedBB getBox( VoxelShape shape )
{
return shape.isEmpty() ? EMPTY_BOX : shape.getBoundingBox();
return shape.isEmpty() ? EMPTY_BOX : shape.bounds();
}
private static final AxisAlignedBB EMPTY_BOX = new AxisAlignedBB( 0, 0, 0, 0, 0, 0 );

View File

@@ -56,7 +56,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
{
// Get thing to place
ItemStack stack = turtle.getInventory().getStackInSlot( turtle.getSelectedSlot() );
ItemStack stack = turtle.getInventory().getItem( turtle.getSelectedSlot() );
if( stack.isEmpty() )
{
return TurtleCommandResult.failure( "No items to place" );
@@ -64,10 +64,10 @@ public class TurtlePlaceCommand implements ITurtleCommand
// Remember old block
Direction direction = m_direction.toWorldDir( turtle );
BlockPos coordinates = turtle.getPosition().offset( direction );
BlockPos coordinates = turtle.getPosition().relative( direction );
// Create a fake player, and orient it appropriately
BlockPos playerPosition = turtle.getPosition().offset( direction );
BlockPos playerPosition = turtle.getPosition().relative( direction );
TurtlePlayer turtlePlayer = createPlayer( turtle, playerPosition, direction );
TurtleBlockEvent.Place place = new TurtleBlockEvent.Place( turtle, turtlePlayer, turtle.getWorld(), coordinates, stack );
@@ -82,8 +82,8 @@ public class TurtlePlaceCommand implements ITurtleCommand
if( remainder != stack )
{
// Put the remaining items back
turtle.getInventory().setInventorySlotContents( turtle.getSelectedSlot(), remainder );
turtle.getInventory().markDirty();
turtle.getInventory().setItem( turtle.getSelectedSlot(), remainder );
turtle.getInventory().setChanged();
// Animate and return success
turtle.playAnimation( TurtleAnimation.WAIT );
@@ -109,7 +109,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
public static ItemStack deploy( @Nonnull ItemStack stack, ITurtleAccess turtle, Direction direction, Object[] extraArguments, String[] outErrorMessage )
{
// Create a fake player, and orient it appropriately
BlockPos playerPosition = turtle.getPosition().offset( direction );
BlockPos playerPosition = turtle.getPosition().relative( direction );
TurtlePlayer turtlePlayer = createPlayer( turtle, playerPosition, direction );
return deploy( stack, turtle, turtlePlayer, direction, extraArguments, outErrorMessage );
@@ -126,7 +126,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
// Deploy on the block immediately in front
BlockPos position = turtle.getPosition();
BlockPos newPosition = position.offset( direction );
BlockPos newPosition = position.relative( direction );
remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition, direction.getOpposite(), extraArguments, true, outErrorMessage );
if( remainder != stack )
{
@@ -134,7 +134,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
}
// Deploy on the block one block away
remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.offset( direction ), direction.getOpposite(), extraArguments, false, outErrorMessage );
remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.relative( direction ), direction.getOpposite(), extraArguments, false, outErrorMessage );
if( remainder != stack )
{
return remainder;
@@ -143,7 +143,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
if( direction.getAxis() != Direction.Axis.Y )
{
// Deploy down on the block in front
remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.down(), Direction.UP, extraArguments, false, outErrorMessage );
remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.below(), Direction.UP, extraArguments, false, outErrorMessage );
if( remainder != stack )
{
return remainder;
@@ -177,31 +177,31 @@ public class TurtlePlaceCommand implements ITurtleCommand
// Stop intersection with the turtle itself
if( turtle.getPosition().equals( position ) )
{
posX += 0.48 * direction.getXOffset();
posY += 0.48 * direction.getYOffset();
posZ += 0.48 * direction.getZOffset();
posX += 0.48 * direction.getStepX();
posY += 0.48 * direction.getStepY();
posZ += 0.48 * direction.getStepZ();
}
if( direction.getAxis() != Direction.Axis.Y )
{
turtlePlayer.rotationYaw = direction.getHorizontalAngle();
turtlePlayer.rotationPitch = 0.0f;
turtlePlayer.yRot = direction.toYRot();
turtlePlayer.xRot = 0.0f;
}
else
{
turtlePlayer.rotationYaw = turtle.getDirection().getHorizontalAngle();
turtlePlayer.rotationPitch = DirectionUtil.toPitchAngle( direction );
turtlePlayer.yRot = turtle.getDirection().toYRot();
turtlePlayer.xRot = DirectionUtil.toPitchAngle( direction );
}
turtlePlayer.setRawPosition( posX, posY, posZ );
turtlePlayer.prevPosX = posX;
turtlePlayer.prevPosY = posY;
turtlePlayer.prevPosZ = posZ;
turtlePlayer.prevRotationPitch = turtlePlayer.rotationPitch;
turtlePlayer.prevRotationYaw = turtlePlayer.rotationYaw;
turtlePlayer.setPosRaw( posX, posY, posZ );
turtlePlayer.xo = posX;
turtlePlayer.yo = posY;
turtlePlayer.zo = posZ;
turtlePlayer.xRotO = turtlePlayer.xRot;
turtlePlayer.yRotO = turtlePlayer.yRot;
turtlePlayer.rotationYawHead = turtlePlayer.rotationYaw;
turtlePlayer.prevRotationYawHead = turtlePlayer.rotationYawHead;
turtlePlayer.yHeadRot = turtlePlayer.yRot;
turtlePlayer.yHeadRotO = turtlePlayer.yHeadRot;
}
@Nonnull
@@ -210,8 +210,8 @@ public class TurtlePlaceCommand implements ITurtleCommand
// See if there is an entity present
final World world = turtle.getWorld();
final BlockPos position = turtle.getPosition();
Vec3d turtlePos = turtlePlayer.getPositionVec();
Vec3d rayDir = turtlePlayer.getLook( 1.0f );
Vec3d turtlePos = turtlePlayer.position();
Vec3d rayDir = turtlePlayer.getViewVector( 1.0f );
Pair<Entity, Vec3d> hit = WorldUtil.rayTraceEntities( world, turtlePos, rayDir, 1.5 );
if( hit == null )
{
@@ -235,7 +235,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
ActionResultType cancelResult = ForgeHooks.onInteractEntityAt( turtlePlayer, hitEntity, hitPos, Hand.MAIN_HAND );
if( cancelResult == null )
{
cancelResult = hitEntity.applyPlayerInteraction( turtlePlayer, hitPos, Hand.MAIN_HAND );
cancelResult = hitEntity.interactAt( turtlePlayer, hitPos, Hand.MAIN_HAND );
}
if( cancelResult == ActionResultType.SUCCESS )
@@ -252,13 +252,13 @@ public class TurtlePlaceCommand implements ITurtleCommand
}
else if( cancelResult == null )
{
if( hitEntity.processInitialInteract( turtlePlayer, Hand.MAIN_HAND ) )
if( hitEntity.interact( turtlePlayer, Hand.MAIN_HAND ) )
{
placed = true;
}
else if( hitEntity instanceof LivingEntity )
{
placed = stackCopy.interactWithEntity( turtlePlayer, (LivingEntity) hitEntity, Hand.MAIN_HAND );
placed = stackCopy.interactEnemy( turtlePlayer, (LivingEntity) hitEntity, Hand.MAIN_HAND );
if( placed ) turtlePlayer.loadInventory( stackCopy );
}
}
@@ -273,7 +273,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
// Put everything we collected into the turtles inventory, then return
ItemStack remainder = turtlePlayer.unloadInventory( turtle );
if( !placed && ItemStack.areItemStacksEqual( stack, remainder ) )
if( !placed && ItemStack.matches( stack, remainder ) )
{
return stack;
}
@@ -290,15 +290,15 @@ public class TurtlePlaceCommand implements ITurtleCommand
private static boolean canDeployOnBlock( @Nonnull BlockItemUseContext context, ITurtleAccess turtle, TurtlePlayer player, BlockPos position, Direction side, boolean allowReplaceable, String[] outErrorMessage )
{
World world = turtle.getWorld();
if( !World.isValid( position ) || world.isAirBlock( position ) ||
(context.getItem().getItem() instanceof BlockItem && WorldUtil.isLiquidBlock( world, position )) )
if( !World.isInWorldBounds( position ) || world.isEmptyBlock( position ) ||
(context.getItemInHand().getItem() instanceof BlockItem && WorldUtil.isLiquidBlock( world, position )) )
{
return false;
}
BlockState state = world.getBlockState( position );
boolean replaceable = state.isReplaceable( context );
boolean replaceable = state.canBeReplaced( context );
if( !allowReplaceable && replaceable ) return false;
if( ComputerCraft.turtlesObeyBlockProtection )
@@ -306,7 +306,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
// Check spawn protection
boolean editable = replaceable
? TurtlePermissions.isBlockEditable( world, position, player )
: TurtlePermissions.isBlockEditable( world, position.offset( side ), player );
: TurtlePermissions.isBlockEditable( world, position.relative( side ), player );
if( !editable )
{
if( outErrorMessage != null ) outErrorMessage[0] = "Cannot place in protected area";
@@ -322,16 +322,16 @@ public class TurtlePlaceCommand implements ITurtleCommand
{
// Re-orient the fake player
Direction playerDir = side.getOpposite();
BlockPos playerPosition = position.offset( side );
BlockPos playerPosition = position.relative( side );
orientPlayer( turtle, turtlePlayer, playerPosition, playerDir );
ItemStack stackCopy = stack.copy();
turtlePlayer.loadInventory( stackCopy );
// Calculate where the turtle would hit the block
float hitX = 0.5f + side.getXOffset() * 0.5f;
float hitY = 0.5f + side.getYOffset() * 0.5f;
float hitZ = 0.5f + side.getZOffset() * 0.5f;
float hitX = 0.5f + side.getStepX() * 0.5f;
float hitY = 0.5f + side.getStepY() * 0.5f;
float hitZ = 0.5f + side.getStepZ() * 0.5f;
if( Math.abs( hitY - 0.5f ) < 0.01f )
{
hitY = 0.45f;
@@ -350,7 +350,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
// Do the deploying (put everything in the players inventory)
boolean placed = false;
TileEntity existingTile = turtle.getWorld().getTileEntity( position );
TileEntity existingTile = turtle.getWorld().getBlockEntity( position );
// See PlayerInteractionManager.processRightClickBlock
// TODO: ^ Check we're still consistent.
@@ -363,7 +363,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
turtlePlayer.loadInventory( stackCopy );
}
else if( event.getUseItem() != Event.Result.DENY &&
stackCopy.onItemUse( context ) == ActionResultType.SUCCESS )
stackCopy.useOn( context ) == ActionResultType.SUCCESS )
{
placed = true;
turtlePlayer.loadInventory( stackCopy );
@@ -379,11 +379,11 @@ public class TurtlePlaceCommand implements ITurtleCommand
}
else if( actionResult == null )
{
ActionResult<ItemStack> result = stackCopy.useItemRightClick( turtle.getWorld(), turtlePlayer, Hand.MAIN_HAND );
if( result.getType() == ActionResultType.SUCCESS && !ItemStack.areItemStacksEqual( stack, result.getResult() ) )
ActionResult<ItemStack> result = stackCopy.use( turtle.getWorld(), turtlePlayer, Hand.MAIN_HAND );
if( result.getResult() == ActionResultType.SUCCESS && !ItemStack.matches( stack, result.getObject() ) )
{
placed = true;
turtlePlayer.loadInventory( result.getResult() );
turtlePlayer.loadInventory( result.getObject() );
}
}
}
@@ -394,10 +394,10 @@ public class TurtlePlaceCommand implements ITurtleCommand
if( extraArguments != null && extraArguments.length >= 1 && extraArguments[0] instanceof String )
{
World world = turtle.getWorld();
TileEntity tile = world.getTileEntity( position );
TileEntity tile = world.getBlockEntity( position );
if( tile == null || tile == existingTile )
{
tile = world.getTileEntity( position.offset( side ) );
tile = world.getBlockEntity( position.relative( side ) );
}
if( tile instanceof SignTileEntity )
{
@@ -405,33 +405,33 @@ public class TurtlePlaceCommand implements ITurtleCommand
String s = (String) extraArguments[0];
String[] split = s.split( "\n" );
int firstLine = split.length <= 2 ? 1 : 0;
for( int i = 0; i < signTile.signText.length; i++ )
for( int i = 0; i < signTile.messages.length; i++ )
{
if( i >= firstLine && i < firstLine + split.length )
{
if( split[i - firstLine].length() > 15 )
{
signTile.signText[i] = new StringTextComponent( split[i - firstLine].substring( 0, 15 ) );
signTile.messages[i] = new StringTextComponent( split[i - firstLine].substring( 0, 15 ) );
}
else
{
signTile.signText[i] = new StringTextComponent( split[i - firstLine] );
signTile.messages[i] = new StringTextComponent( split[i - firstLine] );
}
}
else
{
signTile.signText[i] = new StringTextComponent( "" );
signTile.messages[i] = new StringTextComponent( "" );
}
}
signTile.markDirty();
world.notifyBlockUpdate( tile.getPos(), tile.getBlockState(), tile.getBlockState(), 3 );
signTile.setChanged();
world.sendBlockUpdated( tile.getBlockPos(), tile.getBlockState(), tile.getBlockState(), 3 );
}
}
}
// Put everything we collected into the turtles inventory, then return
ItemStack remainder = turtlePlayer.unloadInventory( turtle );
if( !placed && ItemStack.areItemStacksEqual( stack, remainder ) )
if( !placed && ItemStack.matches( stack, remainder ) )
{
return stack;
}

View File

@@ -61,7 +61,7 @@ public final class TurtlePlayer extends FakePlayer
// Constructing a player overrides the "active player" variable in advancements. As fake players cannot
// get advancements, this prevents a normal player who has placed a turtle from getting advancements.
// We try to locate the "actual" player and restore them.
ServerPlayerEntity actualPlayer = world.getServer().getPlayerList().getPlayerByUUID( profile.getId() );
ServerPlayerEntity actualPlayer = world.getServer().getPlayerList().getPlayer( profile.getId() );
if( actualPlayer != null ) player.getAdvancements().setPlayer( actualPlayer );
}
@@ -75,19 +75,19 @@ public final class TurtlePlayer extends FakePlayer
private void setState( ITurtleAccess turtle )
{
if( openContainer != container )
if( containerMenu != inventoryMenu )
{
ComputerCraft.log.warn( "Turtle has open container ({})", openContainer );
closeContainer();
ComputerCraft.log.warn( "Turtle has open container ({})", containerMenu );
doCloseContainer();
}
BlockPos position = turtle.getPosition();
setRawPosition( position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5 );
setPosRaw( position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5 );
rotationYaw = turtle.getDirection().getHorizontalAngle();
rotationPitch = 0.0f;
yRot = turtle.getDirection().toYRot();
xRot = 0.0f;
inventory.clear();
inventory.clearContent();
}
public static TurtlePlayer get( ITurtleAccess access )
@@ -97,7 +97,7 @@ public final class TurtlePlayer extends FakePlayer
TurtleBrain brain = (TurtleBrain) access;
TurtlePlayer player = brain.m_cachedPlayer;
if( player == null || player.getGameProfile() != getProfile( access.getOwningPlayer() )
|| player.getEntityWorld() != access.getWorld() )
|| player.getCommandSenderWorld() != access.getWorld() )
{
player = brain.m_cachedPlayer = create( brain );
}
@@ -112,22 +112,22 @@ public final class TurtlePlayer extends FakePlayer
public void loadInventory( @Nonnull ItemStack currentStack )
{
// Load up the fake inventory
inventory.currentItem = 0;
inventory.setInventorySlotContents( 0, currentStack );
inventory.selected = 0;
inventory.setItem( 0, currentStack );
}
public ItemStack unloadInventory( ITurtleAccess turtle )
{
// Get the item we placed with
ItemStack results = inventory.getStackInSlot( 0 );
inventory.setInventorySlotContents( 0, ItemStack.EMPTY );
ItemStack results = inventory.getItem( 0 );
inventory.setItem( 0, ItemStack.EMPTY );
// Store (or drop) anything else we found
BlockPos dropPosition = turtle.getPosition();
Direction dropDirection = turtle.getDirection().getOpposite();
for( int i = 0; i < inventory.getSizeInventory(); i++ )
for( int i = 0; i < inventory.getContainerSize(); i++ )
{
ItemStack stack = inventory.getStackInSlot( i );
ItemStack stack = inventory.getItem( i );
if( !stack.isEmpty() )
{
ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), turtle.getSelectedSlot() );
@@ -135,10 +135,10 @@ public final class TurtlePlayer extends FakePlayer
{
WorldUtil.dropItemStack( remainder, turtle.getWorld(), dropPosition, dropDirection );
}
inventory.setInventorySlotContents( i, ItemStack.EMPTY );
inventory.setItem( i, ItemStack.EMPTY );
}
}
inventory.markDirty();
inventory.setChanged();
return results;
}
@@ -150,9 +150,9 @@ public final class TurtlePlayer extends FakePlayer
}
@Override
public Vec3d getPositionVector()
public Vec3d getCommandSenderWorldPosition()
{
return getPositionVec();
return position();
}
@Override
@@ -170,18 +170,18 @@ public final class TurtlePlayer extends FakePlayer
//region Code which depends on the connection
@Nonnull
@Override
public OptionalInt openContainer( @Nullable INamedContainerProvider prover )
public OptionalInt openMenu( @Nullable INamedContainerProvider prover )
{
return OptionalInt.empty();
}
@Override
public void sendEnterCombat()
public void onEnterCombat()
{
}
@Override
public void sendEndCombat()
public void onLeaveCombat()
{
}
@@ -197,7 +197,7 @@ public final class TurtlePlayer extends FakePlayer
}
@Override
public void openSignEditor( @Nonnull SignTileEntity signTile )
public void openTextEdit( @Nonnull SignTileEntity signTile )
{
}
@@ -207,32 +207,32 @@ public final class TurtlePlayer extends FakePlayer
}
@Override
public void openBook( @Nonnull ItemStack stack, @Nonnull Hand hand )
public void openItemGui( @Nonnull ItemStack stack, @Nonnull Hand hand )
{
}
@Override
public void closeScreen()
public void closeContainer()
{
}
@Override
public void updateHeldItem()
public void broadcastCarriedItem()
{
}
@Override
protected void onNewPotionEffect( @Nonnull EffectInstance id )
protected void onEffectAdded( @Nonnull EffectInstance id )
{
}
@Override
protected void onChangedPotionEffect( @Nonnull EffectInstance id, boolean apply )
protected void onEffectUpdated( @Nonnull EffectInstance id, boolean apply )
{
}
@Override
protected void onFinishedPotionEffect( @Nonnull EffectInstance effect )
protected void onEffectRemoved( @Nonnull EffectInstance effect )
{
}
//endregion

View File

@@ -29,7 +29,7 @@ public class TurtleRefuelCommand implements ITurtleCommand
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
{
int slot = turtle.getSelectedSlot();
ItemStack stack = turtle.getInventory().getStackInSlot( slot );
ItemStack stack = turtle.getInventory().getItem( slot );
if( stack.isEmpty() ) return TurtleCommandResult.failure( "No items to combust" );
TurtleRefuelEvent event = new TurtleRefuelEvent( turtle, stack );

View File

@@ -52,7 +52,7 @@ public class TurtleSuckCommand implements ITurtleCommand
// Get inventory for thing in front
World world = turtle.getWorld();
BlockPos turtlePosition = turtle.getPosition();
BlockPos blockPosition = turtlePosition.offset( direction );
BlockPos blockPosition = turtlePosition.relative( direction );
Direction side = direction.getOpposite();
IItemHandler inventory = InventoryUtil.getInventory( world, blockPosition, side );
@@ -97,7 +97,7 @@ public class TurtleSuckCommand implements ITurtleCommand
blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(),
blockPosition.getX() + 1.0, blockPosition.getY() + 1.0, blockPosition.getZ() + 1.0
);
List<ItemEntity> list = world.getEntitiesWithinAABB( ItemEntity.class, aabb, EntityPredicates.IS_ALIVE );
List<ItemEntity> list = world.getEntitiesOfClass( ItemEntity.class, aabb, EntityPredicates.ENTITY_STILL_ALIVE );
if( list.isEmpty() ) return TurtleCommandResult.failure( "No items to take" );
for( ItemEntity entity : list )
@@ -141,7 +141,7 @@ public class TurtleSuckCommand implements ITurtleCommand
}
// Play fx
world.playBroadcastSound( 1000, turtlePosition, 0 ); // BLOCK_DISPENSER_DISPENSE
world.globalLevelEvent( 1000, turtlePosition, 0 ); // BLOCK_DISPENSER_DISPENSE
turtle.playAnimation( TurtleAnimation.WAIT );
return TurtleCommandResult.success();
}

View File

@@ -38,13 +38,13 @@ public class TurtleTurnCommand implements ITurtleCommand
{
case LEFT:
{
turtle.setDirection( turtle.getDirection().rotateYCCW() );
turtle.setDirection( turtle.getDirection().getCounterClockWise() );
turtle.playAnimation( TurtleAnimation.TURN_LEFT );
return TurtleCommandResult.success();
}
case RIGHT:
{
turtle.setDirection( turtle.getDirection().rotateY() );
turtle.setDirection( turtle.getDirection().getClockWise() );
turtle.playAnimation( TurtleAnimation.TURN_RIGHT );
return TurtleCommandResult.success();
}

View File

@@ -40,7 +40,7 @@ public class ContainerTurtle extends ContainerComputerBase
super( Registry.ModContainers.TURTLE.get(), id, canUse, computer, family );
this.properties = properties;
trackIntArray( properties );
addDataSlots( properties );
// Turtle inventory
for( int y = 0; y < 4; y++ )
@@ -70,7 +70,7 @@ public class ContainerTurtle extends ContainerComputerBase
public ContainerTurtle( int id, PlayerInventory player, TurtleBrain turtle )
{
this(
id, p -> turtle.getOwner().isUsableByPlayer( p ), turtle.getOwner().createServerComputer(), turtle.getFamily(),
id, p -> turtle.getOwner().stillValid( p ), turtle.getOwner().createServerComputer(), turtle.getFamily(),
player, turtle.getInventory(), (SingleIntArray) turtle::getSelectedSlot
);
}
@@ -91,24 +91,24 @@ public class ContainerTurtle extends ContainerComputerBase
@Nonnull
private ItemStack tryItemMerge( PlayerEntity player, int slotNum, int firstSlot, int lastSlot, boolean reverse )
{
Slot slot = inventorySlots.get( slotNum );
Slot slot = slots.get( slotNum );
ItemStack originalStack = ItemStack.EMPTY;
if( slot != null && slot.getHasStack() )
if( slot != null && slot.hasItem() )
{
ItemStack clickedStack = slot.getStack();
ItemStack clickedStack = slot.getItem();
originalStack = clickedStack.copy();
if( !mergeItemStack( clickedStack, firstSlot, lastSlot, reverse ) )
if( !moveItemStackTo( clickedStack, firstSlot, lastSlot, reverse ) )
{
return ItemStack.EMPTY;
}
if( clickedStack.isEmpty() )
{
slot.putStack( ItemStack.EMPTY );
slot.set( ItemStack.EMPTY );
}
else
{
slot.onSlotChanged();
slot.setChanged();
}
if( clickedStack.getCount() != originalStack.getCount() )
@@ -125,7 +125,7 @@ public class ContainerTurtle extends ContainerComputerBase
@Nonnull
@Override
public ItemStack transferStackInSlot( @Nonnull PlayerEntity player, int slotNum )
public ItemStack quickMoveStack( @Nonnull PlayerEntity player, int slotNum )
{
if( slotNum >= 0 && slotNum < 16 )
{

View File

@@ -27,6 +27,8 @@ import javax.annotation.Nullable;
import static dan200.computercraft.shared.turtle.core.TurtleBrain.*;
import net.minecraft.item.Item.Properties;
public class ItemTurtle extends ItemComputerBase implements ITurtleItem
{
public ItemTurtle( BlockTurtle block, Properties settings )
@@ -38,7 +40,7 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem
{
// Build the stack
ItemStack stack = new ItemStack( this );
if( label != null ) stack.setDisplayName( new StringTextComponent( label ) );
if( label != null ) stack.setHoverName( new StringTextComponent( label ) );
if( id >= 0 ) stack.getOrCreateTag().putInt( NBT_ID, id );
IColouredItem.setColourBasic( stack, colour );
if( fuelLevel > 0 ) stack.getOrCreateTag().putInt( NBT_FUEL, fuelLevel );
@@ -58,9 +60,9 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem
}
@Override
public void fillItemGroup( @Nonnull ItemGroup group, @Nonnull NonNullList<ItemStack> list )
public void fillItemCategory( @Nonnull ItemGroup group, @Nonnull NonNullList<ItemStack> list )
{
if( !isInGroup( group ) ) return;
if( !allowdedIn( group ) ) return;
ComputerFamily family = getFamily();
@@ -73,9 +75,9 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem
@Nonnull
@Override
public ITextComponent getDisplayName( @Nonnull ItemStack stack )
public ITextComponent getName( @Nonnull ItemStack stack )
{
String baseString = getTranslationKey( stack );
String baseString = getDescriptionId( stack );
ITurtleUpgrade left = getUpgrade( stack, TurtleSide.LEFT );
ITurtleUpgrade right = getUpgrade( stack, TurtleSide.RIGHT );
if( left != null && right != null )

View File

@@ -17,6 +17,8 @@ import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
import dan200.computercraft.shared.computer.recipe.ComputerFamilyRecipe.Serializer;
public final class TurtleRecipe extends ComputerFamilyRecipe
{
private TurtleRecipe( ResourceLocation identifier, String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result, ComputerFamily family )

View File

@@ -29,14 +29,14 @@ public final class TurtleUpgradeRecipe extends SpecialRecipe
}
@Override
public boolean canFit( int x, int y )
public boolean canCraftInDimensions( int x, int y )
{
return x >= 3 && y >= 1;
}
@Nonnull
@Override
public ItemStack getRecipeOutput()
public ItemStack getResultItem()
{
return TurtleItemFactory.create( -1, null, -1, ComputerFamily.NORMAL, null, null, 0, null );
}
@@ -44,12 +44,12 @@ public final class TurtleUpgradeRecipe extends SpecialRecipe
@Override
public boolean matches( @Nonnull CraftingInventory inventory, @Nonnull World world )
{
return !getCraftingResult( inventory ).isEmpty();
return !assemble( inventory ).isEmpty();
}
@Nonnull
@Override
public ItemStack getCraftingResult( @Nonnull CraftingInventory inventory )
public ItemStack assemble( @Nonnull CraftingInventory inventory )
{
// Scan the grid for a row containing a turtle and 1 or 2 items
ItemStack leftItem = ItemStack.EMPTY;
@@ -64,7 +64,7 @@ public final class TurtleUpgradeRecipe extends SpecialRecipe
boolean finishedRow = false;
for( int x = 0; x < inventory.getWidth(); x++ )
{
ItemStack item = inventory.getStackInSlot( x + y * inventory.getWidth() );
ItemStack item = inventory.getItem( x + y * inventory.getWidth() );
if( !item.isEmpty() )
{
if( finishedRow )
@@ -122,7 +122,7 @@ public final class TurtleUpgradeRecipe extends SpecialRecipe
// Turtle is already found, just check this row is empty
for( int x = 0; x < inventory.getWidth(); x++ )
{
ItemStack item = inventory.getStackInSlot( x + y * inventory.getWidth() );
ItemStack item = inventory.getItem( x + y * inventory.getWidth() );
if( !item.isEmpty() )
{
return ItemStack.EMPTY;

View File

@@ -45,12 +45,12 @@ public class TurtleHoe extends TurtleTool
if( !super.canBreakBlock( state, world, pos, player ) ) return false;
Material material = state.getMaterial();
return material == Material.PLANTS ||
return material == Material.PLANT ||
material == Material.CACTUS ||
material == Material.GOURD ||
material == Material.VEGETABLE ||
material == Material.LEAVES ||
material == Material.OCEAN_PLANT ||
material == Material.TALL_PLANTS;
material == Material.WATER_PLANT ||
material == Material.REPLACEABLE_PLANT;
}
@Nonnull

View File

@@ -56,7 +56,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
if( x < m_xStart || x >= m_xStart + 3 ||
y < m_yStart || y >= m_yStart + 3 )
{
if( !m_turtle.getInventory().getStackInSlot( x + y * TileTurtle.INVENTORY_WIDTH ).isEmpty() )
if( !m_turtle.getInventory().getItem( x + y * TileTurtle.INVENTORY_WIDTH ).isEmpty() )
{
return null;
}
@@ -65,13 +65,13 @@ public class TurtleInventoryCrafting extends CraftingInventory
}
// Check the actual crafting
return m_turtle.getWorld().getRecipeManager().getRecipe( IRecipeType.CRAFTING, this, m_turtle.getWorld() ).orElse( null );
return m_turtle.getWorld().getRecipeManager().getRecipeFor( IRecipeType.CRAFTING, this, m_turtle.getWorld() ).orElse( null );
}
@Nullable
public List<ItemStack> doCrafting( World world, int maxCount )
{
if( world.isRemote || !(world instanceof ServerWorld) ) return null;
if( world.isClientSide || !(world instanceof ServerWorld) ) return null;
// Find out what we can craft
IRecipe<CraftingInventory> recipe = tryCrafting( 0, 0 );
@@ -88,11 +88,11 @@ public class TurtleInventoryCrafting extends CraftingInventory
ArrayList<ItemStack> results = new ArrayList<>();
for( int i = 0; i < maxCount && recipe.matches( this, world ); i++ )
{
ItemStack result = recipe.getCraftingResult( this );
ItemStack result = recipe.assemble( this );
if( result.isEmpty() ) break;
results.add( result );
result.onCrafting( world, player, result.getCount() );
result.onCraftedBy( world, player, result.getCount() );
BasicEventHooks.firePlayerCraftingEvent( player, result, this );
ForgeHooks.setCraftingPlayer( player );
@@ -101,13 +101,13 @@ public class TurtleInventoryCrafting extends CraftingInventory
for( int slot = 0; slot < remainders.size(); slot++ )
{
ItemStack existing = getStackInSlot( slot );
ItemStack existing = getItem( slot );
ItemStack remainder = remainders.get( slot );
if( !existing.isEmpty() )
{
decrStackSize( slot, 1 );
existing = getStackInSlot( slot );
removeItem( slot, 1 );
existing = getItem( slot );
}
if( remainder.isEmpty() ) continue;
@@ -116,12 +116,12 @@ public class TurtleInventoryCrafting extends CraftingInventory
// afterwards).
if( existing.isEmpty() )
{
setInventorySlotContents( slot, remainder );
setItem( slot, remainder );
}
else if( ItemStack.areItemsEqual( existing, remainder ) && ItemStack.areItemStackTagsEqual( existing, remainder ) )
else if( ItemStack.isSame( existing, remainder ) && ItemStack.tagMatches( existing, remainder ) )
{
remainder.grow( existing.getCount() );
setInventorySlotContents( slot, remainder );
setItem( slot, remainder );
}
else
{
@@ -157,74 +157,74 @@ public class TurtleInventoryCrafting extends CraftingInventory
// IInventory implementation
@Override
public int getSizeInventory()
public int getContainerSize()
{
return getWidth() * getHeight();
}
@Nonnull
@Override
public ItemStack getStackInSlot( int i )
public ItemStack getItem( int i )
{
i = modifyIndex( i );
return m_turtle.getInventory().getStackInSlot( i );
return m_turtle.getInventory().getItem( i );
}
@Nonnull
@Override
public ItemStack removeStackFromSlot( int i )
public ItemStack removeItemNoUpdate( int i )
{
i = modifyIndex( i );
return m_turtle.getInventory().removeStackFromSlot( i );
return m_turtle.getInventory().removeItemNoUpdate( i );
}
@Nonnull
@Override
public ItemStack decrStackSize( int i, int size )
public ItemStack removeItem( int i, int size )
{
i = modifyIndex( i );
return m_turtle.getInventory().decrStackSize( i, size );
return m_turtle.getInventory().removeItem( i, size );
}
@Override
public void setInventorySlotContents( int i, @Nonnull ItemStack stack )
public void setItem( int i, @Nonnull ItemStack stack )
{
i = modifyIndex( i );
m_turtle.getInventory().setInventorySlotContents( i, stack );
m_turtle.getInventory().setItem( i, stack );
}
@Override
public int getInventoryStackLimit()
public int getMaxStackSize()
{
return m_turtle.getInventory().getInventoryStackLimit();
return m_turtle.getInventory().getMaxStackSize();
}
@Override
public void markDirty()
public void setChanged()
{
m_turtle.getInventory().markDirty();
m_turtle.getInventory().setChanged();
}
@Override
public boolean isUsableByPlayer( @Nonnull PlayerEntity player )
public boolean stillValid( @Nonnull PlayerEntity player )
{
return true;
}
@Override
public boolean isItemValidForSlot( int i, @Nonnull ItemStack stack )
public boolean canPlaceItem( int i, @Nonnull ItemStack stack )
{
i = modifyIndex( i );
return m_turtle.getInventory().isItemValidForSlot( i, stack );
return m_turtle.getInventory().canPlaceItem( i, stack );
}
@Override
public void clear()
public void clearContent()
{
for( int i = 0; i < getSizeInventory(); i++ )
for( int i = 0; i < getContainerSize(); i++ )
{
int j = modifyIndex( i );
m_turtle.getInventory().setInventorySlotContents( j, ItemStack.EMPTY );
m_turtle.getInventory().setItem( j, ItemStack.EMPTY );
}
}
}

View File

@@ -144,7 +144,7 @@ public class TurtleModem extends AbstractTurtleUpgrade
public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side )
{
// Advance the modem
if( !turtle.getWorld().isRemote )
if( !turtle.getWorld().isClientSide )
{
IPeripheral peripheral = turtle.getPeripheral( side );
if( peripheral instanceof Peripheral )

View File

@@ -45,16 +45,16 @@ public class TurtleShovel extends TurtleTool
if( !super.canBreakBlock( state, world, pos, player ) ) return false;
Material material = state.getMaterial();
return material == Material.EARTH ||
return material == Material.DIRT ||
material == Material.SAND ||
material == Material.SNOW ||
material == Material.TOP_SNOW ||
material == Material.CLAY ||
material == Material.SNOW_BLOCK ||
material == Material.PLANTS ||
material == Material.SNOW ||
material == Material.PLANT ||
material == Material.CACTUS ||
material == Material.GOURD ||
material == Material.VEGETABLE ||
material == Material.LEAVES ||
material == Material.TALL_PLANTS;
material == Material.REPLACEABLE_PLANT;
}
@Nonnull

View File

@@ -37,9 +37,9 @@ public class TurtleSword extends TurtleTool
if( !super.canBreakBlock( state, world, pos, player ) ) return false;
Material material = state.getMaterial();
return material == Material.PLANTS ||
return material == Material.PLANT ||
material == Material.LEAVES ||
material == Material.TALL_PLANTS ||
material == Material.REPLACEABLE_PLANT ||
material == Material.WOOL ||
material == Material.WEB;
}

View File

@@ -78,7 +78,7 @@ public class TurtleTool extends AbstractTurtleUpgrade
// Check we've not got anything vaguely interesting on the item. We allow other mods to add their
// own NBT, with the understanding such details will be lost to the mist of time.
if( stack.isDamaged() || stack.isEnchanted() || stack.hasDisplayName() ) return false;
if( stack.isDamaged() || stack.isEnchanted() || stack.hasCustomHoverName() ) return false;
if( tag.contains( "AttributeModifiers", Constants.NBT.TAG_LIST ) &&
!tag.getList( "AttributeModifiers", Constants.NBT.TAG_COMPOUND ).isEmpty() )
{
@@ -123,7 +123,7 @@ public class TurtleTool extends AbstractTurtleUpgrade
Block block = state.getBlock();
return !state.isAir( world, pos )
&& block != Blocks.BEDROCK
&& state.getPlayerRelativeBlockHardness( player, world, pos ) > 0
&& state.getDestroyProgress( player, world, pos ) > 0
&& block.canEntityDestroy( state, world, pos, player );
}
@@ -137,14 +137,14 @@ public class TurtleTool extends AbstractTurtleUpgrade
// Create a fake player, and orient it appropriately
World world = turtle.getWorld();
BlockPos position = turtle.getPosition();
TileEntity turtleTile = turtle instanceof TurtleBrain ? ((TurtleBrain) turtle).getOwner() : world.getTileEntity( position );
TileEntity turtleTile = turtle instanceof TurtleBrain ? ((TurtleBrain) turtle).getOwner() : world.getBlockEntity( position );
if( turtleTile == null ) return TurtleCommandResult.failure( "Turtle has vanished from existence." );
final TurtlePlayer turtlePlayer = TurtlePlaceCommand.createPlayer( turtle, position, direction );
// See if there is an entity present
Vec3d turtlePos = turtlePlayer.getPositionVec();
Vec3d rayDir = turtlePlayer.getLook( 1.0f );
Vec3d turtlePos = turtlePlayer.position();
Vec3d rayDir = turtlePlayer.getViewVector( 1.0f );
Pair<Entity, Vec3d> hit = WorldUtil.rayTraceEntities( world, turtlePos, rayDir, 1.5 );
if( hit != null )
{
@@ -155,7 +155,7 @@ public class TurtleTool extends AbstractTurtleUpgrade
Entity hitEntity = hit.getKey();
// Fire several events to ensure we have permissions.
if( MinecraftForge.EVENT_BUS.post( new AttackEntityEvent( turtlePlayer, hitEntity ) ) || !hitEntity.canBeAttackedWithItem() )
if( MinecraftForge.EVENT_BUS.post( new AttackEntityEvent( turtlePlayer, hitEntity ) ) || !hitEntity.isAttackable() )
{
return TurtleCommandResult.failure( "Nothing to attack here" );
}
@@ -171,26 +171,26 @@ public class TurtleTool extends AbstractTurtleUpgrade
// Attack the entity
boolean attacked = false;
if( !hitEntity.hitByEntity( turtlePlayer ) )
if( !hitEntity.skipAttackInteraction( turtlePlayer ) )
{
float damage = (float) turtlePlayer.getAttribute( SharedMonsterAttributes.ATTACK_DAMAGE ).getValue();
damage *= getDamageMultiplier();
if( damage > 0.0f )
{
DamageSource source = DamageSource.causePlayerDamage( turtlePlayer );
DamageSource source = DamageSource.playerAttack( turtlePlayer );
if( hitEntity instanceof ArmorStandEntity )
{
// Special case for armor stands: attack twice to guarantee destroy
hitEntity.attackEntityFrom( source, damage );
hitEntity.hurt( source, damage );
if( hitEntity.isAlive() )
{
hitEntity.attackEntityFrom( source, damage );
hitEntity.hurt( source, damage );
}
attacked = true;
}
else
{
if( hitEntity.attackEntityFrom( source, damage ) )
if( hitEntity.hurt( source, damage ) )
{
attacked = true;
}
@@ -217,11 +217,11 @@ public class TurtleTool extends AbstractTurtleUpgrade
// Get ready to dig
World world = turtle.getWorld();
BlockPos turtlePosition = turtle.getPosition();
TileEntity turtleTile = turtle instanceof TurtleBrain ? ((TurtleBrain) turtle).getOwner() : world.getTileEntity( turtlePosition );
TileEntity turtleTile = turtle instanceof TurtleBrain ? ((TurtleBrain) turtle).getOwner() : world.getBlockEntity( turtlePosition );
if( turtleTile == null ) return TurtleCommandResult.failure( "Turtle has vanished from existence." );
BlockPos blockPosition = turtlePosition.offset( direction );
if( world.isAirBlock( blockPosition ) || WorldUtil.isLiquidBlock( world, blockPosition ) )
BlockPos blockPosition = turtlePosition.relative( direction );
if( world.isEmptyBlock( blockPosition ) || WorldUtil.isLiquidBlock( world, blockPosition ) )
{
return TurtleCommandResult.failure( "Nothing to dig here" );
}
@@ -262,21 +262,21 @@ public class TurtleTool extends AbstractTurtleUpgrade
// Consume the items the block drops
DropConsumer.set( world, blockPosition, turtleDropConsumer( turtleTile, turtle ) );
TileEntity tile = world.getTileEntity( blockPosition );
TileEntity tile = world.getBlockEntity( blockPosition );
// Much of this logic comes from PlayerInteractionManager#tryHarvestBlock, so it's a good idea
// to consult there before making any changes.
// Play the destruction sound and particles
world.playEvent( 2001, blockPosition, Block.getStateId( state ) );
world.levelEvent( 2001, blockPosition, Block.getId( state ) );
// Destroy the block
boolean canHarvest = state.canHarvestBlock( world, blockPosition, turtlePlayer );
boolean canBreak = state.removedByPlayer( world, blockPosition, turtlePlayer, canHarvest, fluidState );
if( canBreak ) state.getBlock().onPlayerDestroy( world, blockPosition, state );
if( canBreak ) state.getBlock().destroy( world, blockPosition, state );
if( canHarvest && canBreak )
{
state.getBlock().harvestBlock( world, turtlePlayer, blockPosition, state, tile, turtlePlayer.getHeldItemMainhand() );
state.getBlock().playerDestroy( world, turtlePlayer, blockPosition, state, tile, turtlePlayer.getMainHandItem() );
}
stopConsuming( turtleTile, turtle );