Allow turtles to use compostors

This commit is contained in:
Jonathan Coates 2021-05-14 18:32:52 +01:00
parent 4f0d311df7
commit de646b66b6
5 changed files with 572 additions and 3 deletions

View File

@ -5,9 +5,11 @@
*/
package dan200.computercraft.shared.util;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.ISidedInventoryProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
@ -23,6 +25,7 @@
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public final class InventoryUtil
{
@ -41,7 +44,8 @@ public static boolean areItemsStackable( @Nonnull ItemStack a, @Nonnull ItemStac
// Methods for finding inventories:
public static IItemHandler getInventory( World world, BlockPos pos, Direction side )
@Nullable
public static IItemHandler getInventory( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
{
// Look for tile with inventory
TileEntity tileEntity = world.getBlockEntity( pos );
@ -52,7 +56,7 @@ public static IItemHandler getInventory( World world, BlockPos pos, Direction si
{
return itemHandler.orElseThrow( NullPointerException::new );
}
else if( side != null && tileEntity instanceof ISidedInventory )
else if( tileEntity instanceof ISidedInventory )
{
return new SidedInvWrapper( (ISidedInventory) tileEntity, side );
}
@ -62,6 +66,13 @@ else if( tileEntity instanceof IInventory )
}
}
BlockState block = world.getBlockState( pos );
if( block.getBlock() instanceof ISidedInventoryProvider )
{
ISidedInventory inventory = ((ISidedInventoryProvider) block.getBlock()).getContainer( block, world, pos );
return new SidedInvWrapper( inventory, side );
}
// Look for entity with inventory
Vec3d vecStart = new Vec3d(
pos.getX() + 0.5 + 0.6 * side.getStepX(),

View File

@ -55,4 +55,11 @@ class TurtleTest {
*/
@GameTest
suspend fun `Place monitor`(context: TestContext) = context.checkComputerOk(10)
/**
* Checks computers can place into compostors. These are non-typical inventories, so
* worth ensuring.
*/
@GameTest
suspend fun `Use compostors`(context: TestContext) = context.checkComputerOk(11)
}

View File

@ -0,0 +1,3 @@
test.eq(true, turtle.dropDown(), "Drop items into compostor")
test.ok()

View File

@ -1,3 +1,3 @@
{
"computer": 9
"computer": 11
}

View File

@ -0,0 +1,548 @@
{
size: [5, 5, 5],
entities: [],
blocks: [
{
pos: [0, 0, 0],
state: 0
},
{
pos: [1, 0, 0],
state: 0
},
{
pos: [2, 0, 0],
state: 0
},
{
pos: [3, 0, 0],
state: 0
},
{
pos: [4, 0, 0],
state: 0
},
{
pos: [0, 0, 1],
state: 0
},
{
pos: [1, 0, 1],
state: 0
},
{
pos: [2, 0, 1],
state: 0
},
{
pos: [3, 0, 1],
state: 0
},
{
pos: [4, 0, 1],
state: 0
},
{
pos: [0, 0, 2],
state: 0
},
{
pos: [1, 0, 2],
state: 0
},
{
pos: [2, 0, 2],
state: 0
},
{
pos: [3, 0, 2],
state: 0
},
{
pos: [4, 0, 2],
state: 0
},
{
pos: [0, 0, 3],
state: 0
},
{
pos: [1, 0, 3],
state: 0
},
{
pos: [2, 0, 3],
state: 0
},
{
pos: [3, 0, 3],
state: 0
},
{
pos: [4, 0, 3],
state: 0
},
{
pos: [0, 0, 4],
state: 0
},
{
pos: [1, 0, 4],
state: 0
},
{
pos: [2, 0, 4],
state: 0
},
{
pos: [3, 0, 4],
state: 0
},
{
pos: [4, 0, 4],
state: 0
},
{
nbt: {
Owner: {
UpperId: 4039158846114182220L,
LowerId: -6876936588741668278L,
Name: "Dev"
},
Fuel: 0,
Label: "Uses Compostors",
Slot: 0,
Items: [
{
Slot: 0b,
id: "minecraft:spruce_sapling",
Count: 64b
}
],
id: "computercraft:turtle_normal",
ComputerId: 11,
On: 1b
},
pos: [2, 2, 2],
state: 1
},
{
pos: [0, 1, 0],
state: 2
},
{
pos: [1, 1, 0],
state: 2
},
{
pos: [2, 1, 0],
state: 2
},
{
pos: [3, 1, 0],
state: 2
},
{
pos: [4, 1, 0],
state: 2
},
{
pos: [0, 2, 0],
state: 2
},
{
pos: [1, 2, 0],
state: 2
},
{
pos: [2, 2, 0],
state: 2
},
{
pos: [3, 2, 0],
state: 2
},
{
pos: [4, 2, 0],
state: 2
},
{
pos: [0, 3, 0],
state: 2
},
{
pos: [1, 3, 0],
state: 2
},
{
pos: [2, 3, 0],
state: 2
},
{
pos: [3, 3, 0],
state: 2
},
{
pos: [4, 3, 0],
state: 2
},
{
pos: [0, 4, 0],
state: 2
},
{
pos: [1, 4, 0],
state: 2
},
{
pos: [2, 4, 0],
state: 2
},
{
pos: [3, 4, 0],
state: 2
},
{
pos: [4, 4, 0],
state: 2
},
{
pos: [0, 1, 1],
state: 2
},
{
pos: [1, 1, 1],
state: 2
},
{
pos: [2, 1, 1],
state: 2
},
{
pos: [3, 1, 1],
state: 2
},
{
pos: [4, 1, 1],
state: 2
},
{
pos: [0, 2, 1],
state: 2
},
{
pos: [1, 2, 1],
state: 2
},
{
pos: [2, 2, 1],
state: 2
},
{
pos: [3, 2, 1],
state: 2
},
{
pos: [4, 2, 1],
state: 2
},
{
pos: [0, 3, 1],
state: 2
},
{
pos: [1, 3, 1],
state: 2
},
{
pos: [2, 3, 1],
state: 2
},
{
pos: [3, 3, 1],
state: 2
},
{
pos: [4, 3, 1],
state: 2
},
{
pos: [0, 4, 1],
state: 2
},
{
pos: [1, 4, 1],
state: 2
},
{
pos: [2, 4, 1],
state: 2
},
{
pos: [3, 4, 1],
state: 2
},
{
pos: [4, 4, 1],
state: 2
},
{
pos: [0, 1, 2],
state: 2
},
{
pos: [1, 1, 2],
state: 2
},
{
pos: [2, 1, 2],
state: 3
},
{
pos: [3, 1, 2],
state: 2
},
{
pos: [4, 1, 2],
state: 2
},
{
pos: [0, 2, 2],
state: 2
},
{
pos: [1, 2, 2],
state: 2
},
{
pos: [3, 2, 2],
state: 2
},
{
pos: [4, 2, 2],
state: 2
},
{
pos: [0, 3, 2],
state: 2
},
{
pos: [1, 3, 2],
state: 2
},
{
pos: [2, 3, 2],
state: 2
},
{
pos: [3, 3, 2],
state: 2
},
{
pos: [4, 3, 2],
state: 2
},
{
pos: [0, 4, 2],
state: 2
},
{
pos: [1, 4, 2],
state: 2
},
{
pos: [2, 4, 2],
state: 2
},
{
pos: [3, 4, 2],
state: 2
},
{
pos: [4, 4, 2],
state: 2
},
{
pos: [0, 1, 3],
state: 2
},
{
pos: [1, 1, 3],
state: 2
},
{
pos: [2, 1, 3],
state: 2
},
{
pos: [3, 1, 3],
state: 2
},
{
pos: [4, 1, 3],
state: 2
},
{
pos: [0, 2, 3],
state: 2
},
{
pos: [1, 2, 3],
state: 2
},
{
pos: [2, 2, 3],
state: 2
},
{
pos: [3, 2, 3],
state: 2
},
{
pos: [4, 2, 3],
state: 2
},
{
pos: [0, 3, 3],
state: 2
},
{
pos: [1, 3, 3],
state: 2
},
{
pos: [2, 3, 3],
state: 2
},
{
pos: [3, 3, 3],
state: 2
},
{
pos: [4, 3, 3],
state: 2
},
{
pos: [0, 4, 3],
state: 2
},
{
pos: [1, 4, 3],
state: 2
},
{
pos: [2, 4, 3],
state: 2
},
{
pos: [3, 4, 3],
state: 2
},
{
pos: [4, 4, 3],
state: 2
},
{
pos: [0, 1, 4],
state: 2
},
{
pos: [1, 1, 4],
state: 2
},
{
pos: [2, 1, 4],
state: 2
},
{
pos: [3, 1, 4],
state: 2
},
{
pos: [4, 1, 4],
state: 2
},
{
pos: [0, 2, 4],
state: 2
},
{
pos: [1, 2, 4],
state: 2
},
{
pos: [2, 2, 4],
state: 2
},
{
pos: [3, 2, 4],
state: 2
},
{
pos: [4, 2, 4],
state: 2
},
{
pos: [0, 3, 4],
state: 2
},
{
pos: [1, 3, 4],
state: 2
},
{
pos: [2, 3, 4],
state: 2
},
{
pos: [3, 3, 4],
state: 2
},
{
pos: [4, 3, 4],
state: 2
},
{
pos: [0, 4, 4],
state: 2
},
{
pos: [1, 4, 4],
state: 2
},
{
pos: [2, 4, 4],
state: 2
},
{
pos: [3, 4, 4],
state: 2
},
{
pos: [4, 4, 4],
state: 2
}
],
palette: [
{
Name: "minecraft:polished_andesite"
},
{
Properties: {
waterlogged: "false",
facing: "south"
},
Name: "computercraft:turtle_normal"
},
{
Name: "minecraft:air"
},
{
Properties: {
level: "0"
},
Name: "minecraft:composter"
}
],
DataVersion: 2230
}