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

Expose getters for the detail registry too (#1188)

This commit is contained in:
Jonathan Coates 2022-10-22 00:42:07 +01:00 committed by GitHub
parent 9db3e6d2a0
commit 5d833ac634
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 234 additions and 92 deletions

View File

@ -6,6 +6,8 @@
package dan200.computercraft;
import com.google.auto.service.AutoService;
import dan200.computercraft.api.detail.BlockReference;
import dan200.computercraft.api.detail.DetailRegistry;
import dan200.computercraft.api.detail.IDetailProvider;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount;
@ -24,12 +26,16 @@ import dan200.computercraft.core.asm.GenericMethod;
import dan200.computercraft.core.filesystem.FileMount;
import dan200.computercraft.core.filesystem.ResourceMount;
import dan200.computercraft.impl.ComputerCraftAPIService;
import dan200.computercraft.impl.detail.DetailRegistryImpl;
import dan200.computercraft.shared.*;
import dan200.computercraft.shared.computer.core.ServerContext;
import dan200.computercraft.shared.peripheral.generic.GenericPeripheralProvider;
import dan200.computercraft.shared.peripheral.generic.data.DetailProviders;
import dan200.computercraft.shared.peripheral.generic.data.BlockData;
import dan200.computercraft.shared.peripheral.generic.data.FluidData;
import dan200.computercraft.shared.peripheral.generic.data.ItemData;
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
import dan200.computercraft.shared.wired.WiredNode;
import net.minecraft.item.ItemStack;
import net.minecraft.resources.IResourceManager;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
@ -40,6 +46,7 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
@ -53,6 +60,10 @@ import static dan200.computercraft.shared.Capabilities.CAPABILITY_WIRED_ELEMENT;
@AutoService( ComputerCraftAPIService.class )
public final class ComputerCraftAPIImpl implements ComputerCraftAPIService
{
private final DetailRegistry<ItemStack> itemStackDetails = new DetailRegistryImpl<>( ItemData::fillBasic );
private final DetailRegistry<BlockReference> blockDetails = new DetailRegistryImpl<>( BlockData::fillBasic );
private final DetailRegistry<FluidStack> fluidStackDetails = new DetailRegistryImpl<>( FluidData::fillBasic );
private String version;
public static InputStream getResourceFile( MinecraftServer server, String domain, String subPath )
@ -167,9 +178,26 @@ public final class ComputerCraftAPIImpl implements ComputerCraftAPIService
}
@Override
@Deprecated
@SuppressWarnings( "unchecked" )
public <T> void registerDetailProvider( @Nonnull Class<T> type, @Nonnull IDetailProvider<T> provider )
{
DetailProviders.registerProvider( type, provider );
if( type == ItemStack.class )
{
itemStackDetails.addProvider( (IDetailProvider<ItemStack>) provider );
}
else if( type == BlockReference.class )
{
blockDetails.addProvider( (IDetailProvider<BlockReference>) provider );
}
else if( type == FluidStack.class )
{
itemStackDetails.addProvider( (IDetailProvider<ItemStack>) provider );
}
else
{
throw new IllegalArgumentException( "Unknown detail provider " + type );
}
}
@Nonnull
@ -186,4 +214,22 @@ public final class ComputerCraftAPIImpl implements ComputerCraftAPIService
TileEntity tile = world.getBlockEntity( pos );
return tile == null ? LazyOptional.empty() : tile.getCapability( CAPABILITY_WIRED_ELEMENT, side );
}
@Override
public DetailRegistry<ItemStack> getItemStackDetailRegistry()
{
return itemStackDetails;
}
@Override
public DetailRegistry<BlockReference> getBlockInWorldDetailRegistry()
{
return blockDetails;
}
@Override
public DetailRegistry<FluidStack> getFluidStackDetailRegistry()
{
return fluidStackDetails;
}
}

View File

@ -6,6 +6,7 @@
package dan200.computercraft.api;
import dan200.computercraft.api.detail.BlockReference;
import dan200.computercraft.api.detail.DetailRegistry;
import dan200.computercraft.api.detail.IDetailProvider;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount;
@ -234,7 +235,9 @@ public final class ComputerCraftAPI
* {@link FluidStack} or {@link ItemStack}.
* @param provider The detail provider to register.
* @param <T> The type of object that this provider can provide details for.
* @deprecated Use {@link DetailRegistry#addProvider(IDetailProvider)} to register your provider.
*/
@Deprecated
public static <T> void registerDetailProvider( @Nonnull Class<T> type, @Nonnull IDetailProvider<T> provider )
{
getInstance().registerDetailProvider( type, provider );

View File

@ -0,0 +1,32 @@
/*
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.detail;
import dan200.computercraft.impl.ComputerCraftAPIService;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
/**
* {@link DetailRegistry}s for built-in Minecraft types.
*/
public class DetailRegistries
{
/**
* Provides details for {@link ItemStack}s.
*/
public static final DetailRegistry<ItemStack> ITEM_STACK = ComputerCraftAPIService.get().getItemStackDetailRegistry();
/**
* Provides details for {@link BlockReference}, a reference to a {@link Block} in the world.
*/
public static final DetailRegistry<BlockReference> BLOCK_IN_WORLD = ComputerCraftAPIService.get().getBlockInWorldDetailRegistry();
/**
* Provides details for {@link FluidStack}.
*/
public static final DetailRegistry<FluidStack> FLUID_STACK = ComputerCraftAPIService.get().getFluidStackDetailRegistry();
}

View File

@ -0,0 +1,49 @@
/*
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.detail;
import org.jetbrains.annotations.ApiStatus;
import java.util.Map;
/**
* A registry which provides computer-visible detail about in-game objects such as blocks, items or fluids.
* <p>
* These are used by computer methods such as {@code turtle.getItemDetail()} or {@code turtle.inspect()}.
* <p>
* Specific instances of this registry are available from {@link DetailRegistries} and loader-specific versions
* also in this package.
*
* @param <T> The type of object that this registry provides details for.
*/
@ApiStatus.NonExtendable
public interface DetailRegistry<T>
{
/**
* Registers a detail provider.
*
* @param provider The detail provider to register.
* @see IDetailProvider
*/
void addProvider( IDetailProvider<T> provider );
/**
* Compute basic details about an object. This is cheaper than computing all details operation, and so is suitable
* for when you need to compute the details for a large number of values.
*
* @param object The object to get details for.
* @return The basic details.
*/
Map<String, Object> getBasicDetails( T object );
/**
* Compute all details about an object, using {@link #getBasicDetails(Object)} and any registered providers.
*
* @param object The object to get details for.
* @return The computed details.
*/
Map<String, Object> getDetails( T object );
}

View File

@ -9,10 +9,13 @@ import javax.annotation.Nonnull;
import java.util.Map;
/**
* This interface is used to provide details about a block, fluid, or item.
* Provide details about a block, fluid, or item.
* <p>
* When implementing this interface, be careful to only expose information the player can see through normal gameplay.
* Computers shouldn't break progression or mechanics of other mods.
*
* @param <T> The type of object that this provider can provide details for.
* @see dan200.computercraft.api.ComputerCraftAPI#registerDetailProvider(Class, IDetailProvider)
* @see DetailRegistry
*/
@FunctionalInterface
public interface IDetailProvider<T>
@ -21,7 +24,7 @@ public interface IDetailProvider<T>
* Provide additional details for the given object. This method is called by functions such as
* {@code turtle.getItemDetail()} and {@code turtle.inspect()}. New properties should be added to the given
* {@link Map}, {@code data}.
*
* <p>
* This method is always called on the server thread, so it is safe to interact with the world here, but you should
* take care to avoid long blocking operations as this will stall the server and other computers.
*

View File

@ -6,6 +6,8 @@
package dan200.computercraft.impl;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.detail.BlockReference;
import dan200.computercraft.api.detail.DetailRegistry;
import dan200.computercraft.api.detail.IDetailProvider;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount;
@ -19,12 +21,14 @@ import dan200.computercraft.api.peripheral.IPeripheralProvider;
import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidStack;
import org.jetbrains.annotations.ApiStatus;
import javax.annotation.Nonnull;
@ -76,6 +80,7 @@ public interface ComputerCraftAPIService
void registerAPIFactory( @Nonnull ILuaAPIFactory factory );
@Deprecated
<T> void registerDetailProvider( @Nonnull Class<T> type, @Nonnull IDetailProvider<T> provider );
@Nonnull
@ -84,6 +89,12 @@ public interface ComputerCraftAPIService
@Nonnull
LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side );
DetailRegistry<ItemStack> getItemStackDetailRegistry();
DetailRegistry<BlockReference> getBlockInWorldDetailRegistry();
DetailRegistry<FluidStack> getFluidStackDetailRegistry();
class Instance
{
static final @Nullable ComputerCraftAPIService INSTANCE;

View File

@ -0,0 +1,55 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.impl.detail;
import dan200.computercraft.api.detail.DetailRegistry;
import dan200.computercraft.api.detail.IDetailProvider;
import java.util.*;
/**
* Concrete implementation of {@link DetailRegistry}.
*
* @param <T> The type of object that this registry provides details for.
*/
public class DetailRegistryImpl<T> implements DetailRegistry<T>
{
private final Collection<IDetailProvider<T>> providers = new ArrayList<>();
private final IDetailProvider<T> basic;
public DetailRegistryImpl( IDetailProvider<T> basic )
{
this.basic = basic;
providers.add( basic );
}
@Override
public synchronized void addProvider( IDetailProvider<T> provider )
{
Objects.requireNonNull( provider, "provider cannot be null" );
if( !providers.contains( provider ) ) providers.add( provider );
}
@Override
public Map<String, Object> getBasicDetails( T object )
{
Objects.requireNonNull( object, "object cannot be null" );
Map<String, Object> map = new HashMap<>( 4 );
basic.provideDetails( map, object );
return map;
}
@Override
public Map<String, Object> getDetails( T object )
{
Objects.requireNonNull( object, "object cannot be null" );
Map<String, Object> map = new HashMap<>();
for( IDetailProvider<T> provider : providers ) provider.provideDetails( map, object );
return map;
}
}

View File

@ -7,6 +7,7 @@ package dan200.computercraft.shared;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.detail.DetailRegistries;
import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.peripheral.IPeripheral;
@ -40,6 +41,9 @@ import dan200.computercraft.shared.network.container.HeldItemContainerData;
import dan200.computercraft.shared.peripheral.diskdrive.BlockDiskDrive;
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
import dan200.computercraft.shared.peripheral.generic.data.BlockData;
import dan200.computercraft.shared.peripheral.generic.data.FluidData;
import dan200.computercraft.shared.peripheral.generic.data.ItemData;
import dan200.computercraft.shared.peripheral.generic.methods.EnergyMethods;
import dan200.computercraft.shared.peripheral.generic.methods.FluidMethods;
import dan200.computercraft.shared.peripheral.generic.methods.InventoryMethods;
@ -375,6 +379,10 @@ public final class Registry
ComputerCraftAPI.registerGenericCapability( CapabilityEnergy.ENERGY );
ComputerCraftAPI.registerGenericCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY );
DetailRegistries.ITEM_STACK.addProvider( ItemData::fill );
DetailRegistries.BLOCK_IN_WORLD.addProvider( BlockData::fill );
DetailRegistries.FLUID_STACK.addProvider( FluidData::fill );
// Mod integration code.
if( ModList.get().isLoaded( MoreRedIntegration.MOD_ID ) ) MoreRedIntegration.initialise();
}

View File

@ -9,9 +9,9 @@ import com.mojang.brigadier.tree.CommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.detail.BlockReference;
import dan200.computercraft.api.detail.DetailRegistries;
import dan200.computercraft.api.lua.*;
import dan200.computercraft.shared.computer.blocks.TileCommandComputer;
import dan200.computercraft.shared.peripheral.generic.data.BlockData;
import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
@ -78,7 +78,7 @@ public class CommandAPI implements ILuaAPI
{
// Get the details of the block
BlockReference block = new BlockReference( world, pos );
Map<String, Object> table = BlockData.fill( new HashMap<>(), block );
Map<String, Object> table = DetailRegistries.BLOCK_IN_WORLD.getDetails( block );
TileEntity tile = block.getBlockEntity();
if( tile != null ) table.put( "nbt", NBTUtil.toLua( tile.save( new CompoundNBT() ) ) );

View File

@ -15,8 +15,7 @@ import java.util.Map;
public class BlockData
{
@Nonnull
public static <T extends Map<? super String, Object>> T fill( @Nonnull T data, @Nonnull BlockReference block )
public static void fillBasic( @Nonnull Map<? super String, Object> data, @Nonnull BlockReference block )
{
BlockState state = block.getState();
@ -29,11 +28,11 @@ public class BlockData
stateTable.put( property.getName(), getPropertyValue( property, entry.getValue() ) );
}
data.put( "state", stateTable );
data.put( "tags", DataHelpers.getTags( state.getBlock().getTags() ) );
}
DetailProviders.fillData( BlockReference.class, data, block );
return data;
public static void fill( @Nonnull Map<? super String, Object> data, @Nonnull BlockReference block )
{
data.put( "tags", DataHelpers.getTags( block.getState().getBlock().getTags() ) );
}
@SuppressWarnings( { "unchecked", "rawtypes" } )

View File

@ -1,43 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.peripheral.generic.data;
import dan200.computercraft.api.detail.BlockReference;
import dan200.computercraft.api.detail.IDetailProvider;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import java.util.*;
public final class DetailProviders
{
private static final Map<Class<?>, Collection<IDetailProvider<?>>> allProviders = new HashMap<>();
public static synchronized <T> void registerProvider( Class<T> type, IDetailProvider<T> provider )
{
Objects.requireNonNull( type, "type cannot be null" );
Objects.requireNonNull( provider, "provider cannot be null" );
if( type != BlockReference.class && type != ItemStack.class && type != FluidStack.class )
{
throw new IllegalArgumentException( "type must be assignable from BlockReference, ItemStack or FluidStack" );
}
allProviders.computeIfAbsent( type, k -> new LinkedHashSet<>() ).add( provider );
}
@SuppressWarnings( "unchecked" )
public static <T> void fillData( Class<T> type, Map<? super String, Object> data, T value )
{
Collection<IDetailProvider<T>> providers = (Collection<IDetailProvider<T>>) (Object) allProviders.get( type );
if( providers == null ) return;
for( IDetailProvider<T> provider : providers )
{
provider.provideDetails( data, value );
}
}
}

View File

@ -12,22 +12,14 @@ import java.util.Map;
public class FluidData
{
@Nonnull
public static <T extends Map<? super String, Object>> T fillBasic( @Nonnull T data, @Nonnull FluidStack stack )
public static void fillBasic( @Nonnull Map<? super String, Object> data, @Nonnull FluidStack stack )
{
data.put( "name", DataHelpers.getId( stack.getFluid() ) );
data.put( "amount", stack.getAmount() );
return data;
}
@Nonnull
public static <T extends Map<? super String, Object>> T fill( @Nonnull T data, @Nonnull FluidStack stack )
public static void fill( @Nonnull Map<? super String, Object> data, @Nonnull FluidStack stack )
{
fillBasic( data, stack );
data.put( "tags", DataHelpers.getTags( stack.getFluid().getTags() ) );
DetailProviders.fillData( FluidStack.class, data, stack );
return data;
}
}

View File

@ -33,26 +33,18 @@ public class ItemData
{
data.put( "name", DataHelpers.getId( stack.getItem() ) );
data.put( "count", stack.getCount() );
return data;
}
@Nonnull
public static <T extends Map<? super String, Object>> T fillBasic( @Nonnull T data, @Nonnull ItemStack stack )
public static void fillBasic( @Nonnull Map<? super String, Object> data, @Nonnull ItemStack stack )
{
fillBasicSafe( data, stack );
String hash = NBTUtil.getNBTHash( stack.getTag() );
if( hash != null ) data.put( "nbt", hash );
return data;
}
@Nonnull
public static <T extends Map<? super String, Object>> T fill( @Nonnull T data, @Nonnull ItemStack stack )
public static void fill( @Nonnull Map<? super String, Object> data, @Nonnull ItemStack stack )
{
if( stack.isEmpty() ) return data;
fillBasic( data, stack );
data.put( "displayName", stack.getHoverName().getString() );
data.put( "maxCount", stack.getMaxStackSize() );
@ -99,10 +91,6 @@ public class ItemData
{
data.put( "unbreakable", true );
}
DetailProviders.fillData( ItemStack.class, data, stack );
return data;
}
@Nullable

View File

@ -6,13 +6,13 @@
package dan200.computercraft.shared.peripheral.generic.methods;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.detail.DetailRegistries;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.peripheral.GenericPeripheral;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.PeripheralType;
import dan200.computercraft.shared.peripheral.generic.data.FluidData;
import net.minecraft.fluid.Fluid;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
@ -73,7 +73,7 @@ public class FluidMethods implements GenericPeripheral
for( int i = 0; i < size; i++ )
{
FluidStack stack = fluids.getFluidInTank( i );
if( !stack.isEmpty() ) result.put( i + 1, FluidData.fillBasic( new HashMap<>( 4 ), stack ) );
if( !stack.isEmpty() ) result.put( i + 1, DetailRegistries.FLUID_STACK.getBasicDetails( stack ) );
}
return result;

View File

@ -6,13 +6,13 @@
package dan200.computercraft.shared.peripheral.generic.methods;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.detail.DetailRegistries;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.peripheral.GenericPeripheral;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.PeripheralType;
import dan200.computercraft.shared.peripheral.generic.data.ItemData;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@ -96,7 +96,7 @@ public class InventoryMethods implements GenericPeripheral
for( int i = 0; i < size; i++ )
{
ItemStack stack = inventory.getStackInSlot( i );
if( !stack.isEmpty() ) result.put( i + 1, ItemData.fillBasic( new HashMap<>( 4 ), stack ) );
if( !stack.isEmpty() ) result.put( i + 1, DetailRegistries.ITEM_STACK.getBasicDetails( stack ) );
}
return result;
@ -146,7 +146,7 @@ public class InventoryMethods implements GenericPeripheral
assertBetween( slot, 1, inventory.getSlots(), "Slot out of range (%s)" );
ItemStack stack = inventory.getStackInSlot( slot - 1 );
return stack.isEmpty() ? null : ItemData.fill( new HashMap<>(), stack );
return stack.isEmpty() ? null : DetailRegistries.ITEM_STACK.getDetails( stack );
}
/**

View File

@ -5,6 +5,7 @@
*/
package dan200.computercraft.shared.turtle.apis;
import dan200.computercraft.api.detail.DetailRegistries;
import dan200.computercraft.api.lua.*;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleCommand;
@ -822,7 +823,7 @@ public class TurtleAPI implements ILuaAPI
if( stack.isEmpty() ) return new Object[] { null };
Map<String, Object> table = detailed
? ItemData.fill( new HashMap<>(), stack )
? DetailRegistries.ITEM_STACK.getDetails( stack )
: ItemData.fillBasicSafe( new HashMap<>(), stack );
TurtleActionEvent event = new TurtleInspectItemEvent( turtle, stack, table, detailed );

View File

@ -6,11 +6,11 @@
package dan200.computercraft.shared.turtle.core;
import dan200.computercraft.api.detail.BlockReference;
import dan200.computercraft.api.detail.DetailRegistries;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleCommand;
import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.api.turtle.event.TurtleBlockEvent;
import dan200.computercraft.shared.peripheral.generic.data.BlockData;
import net.minecraft.block.BlockState;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
@ -18,7 +18,6 @@ import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;
public class TurtleInspectCommand implements ITurtleCommand
@ -49,7 +48,7 @@ public class TurtleInspectCommand implements ITurtleCommand
return TurtleCommandResult.failure( "No block to inspect" );
}
Map<String, Object> table = BlockData.fill( new HashMap<>(), block );
Map<String, Object> table = DetailRegistries.BLOCK_IN_WORLD.getDetails( block );
// Fire the event, exiting if it is cancelled
TurtlePlayer turtlePlayer = TurtlePlayer.getWithPosition( turtle, oldPosition, direction );

View File

@ -1,7 +1,7 @@
package dan200.computercraft.ingame
import dan200.computercraft.api.ComputerCraftAPI
import dan200.computercraft.api.detail.BasicItemDetailProvider
import dan200.computercraft.api.detail.DetailRegistries
import dan200.computercraft.ingame.api.*
import dan200.computercraft.ingame.api.Timeouts.COMPUTER_TIMEOUT
import dan200.computercraft.shared.media.items.ItemPrintout
@ -83,8 +83,7 @@ class Turtle_Test {
.thenComputerOk(marker = "initial")
.thenExecute {
// Register a dummy provider for printout items
ComputerCraftAPI.registerDetailProvider(
ItemStack::class.java,
DetailRegistries.ITEM_STACK.addProvider(
object : BasicItemDetailProvider<ItemPrintout>("printout", ItemPrintout::class.java) {
override fun provideDetails(data: MutableMap<in String, Any>, stack: ItemStack, item: ItemPrintout) {
data["type"] = item.type.toString();