diff --git a/src/main/java/dan200/computercraft/client/ClientRegistry.java b/src/main/java/dan200/computercraft/client/ClientRegistry.java index 9c7c71a42..8a9c694c7 100644 --- a/src/main/java/dan200/computercraft/client/ClientRegistry.java +++ b/src/main/java/dan200/computercraft/client/ClientRegistry.java @@ -120,5 +120,4 @@ public final class ClientRegistry { .apply(spriteIdentifier.getTextureId()), ModelRotation.X0_Y0, identifier); } - } diff --git a/src/main/java/dan200/computercraft/client/FrameInfo.java b/src/main/java/dan200/computercraft/client/FrameInfo.java index 533f0a2bd..c55e03475 100644 --- a/src/main/java/dan200/computercraft/client/FrameInfo.java +++ b/src/main/java/dan200/computercraft/client/FrameInfo.java @@ -6,12 +6,15 @@ package dan200.computercraft.client; +import dan200.computercraft.ComputerCraft; +import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; - -public final class FrameInfo { +@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT ) +public final class FrameInfo +{ private static int tick; private static long renderFrame; static { @@ -41,4 +44,10 @@ public final class FrameInfo { renderFrame++; } } + + @SubscribeEvent + public static void onRenderTick( TickEvent.RenderTickEvent event ) + { + if( event.phase == TickEvent.Phase.START ) renderFrame++; + } } diff --git a/src/main/java/dan200/computercraft/shared/Capabilities.java b/src/main/java/dan200/computercraft/shared/Capabilities.java deleted file mode 100644 index ba820e183..000000000 --- a/src/main/java/dan200/computercraft/shared/Capabilities.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared; - -import dan200.computercraft.api.network.wired.IWiredElement; -import dan200.computercraft.api.peripheral.IPeripheral; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.CapabilityInject; - -public final class Capabilities -{ - @CapabilityInject( IPeripheral.class ) - public static Capability CAPABILITY_PERIPHERAL = null; - - @CapabilityInject( IWiredElement.class ) - public static Capability CAPABILITY_WIRED_ELEMENT = null; - - private Capabilities() - { - } -} diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java index b71d32e95..2aecaf544 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java @@ -12,25 +12,22 @@ import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerState; import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.inventory.ContainerComputer; -import dan200.computercraft.shared.util.CapabilityUtil; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.screen.ScreenHandler; import net.minecraft.util.math.Direction; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.util.LazyOptional; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import static dan200.computercraft.shared.Capabilities.CAPABILITY_PERIPHERAL; +import java.util.Optional; public class TileComputer extends TileComputerBase { private ComputerProxy proxy; - private LazyOptional peripheral; + private Optional peripheral; public TileComputer( ComputerFamily family, BlockEntityType type ) { @@ -87,30 +84,4 @@ public class TileComputer extends TileComputerBase { return new ContainerComputer( id, this ); } - - @Nonnull - @Override - public LazyOptional getCapability( @Nonnull Capability cap, @Nullable Direction side ) - { - if( cap == CAPABILITY_PERIPHERAL ) - { - if( peripheral == null ) - { - peripheral = LazyOptional.of( () -> { - if( proxy == null ) proxy = new ComputerProxy( () -> this ); - return new ComputerPeripheral( "computer", proxy ); - } ); - } - return peripheral.cast(); - } - - return super.getCapability( cap, side ); - } - - @Override - protected void invalidateCaps() - { - super.invalidateCaps(); - peripheral = CapabilityUtil.invalidate( peripheral ); - } } diff --git a/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java b/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java index be969f4d2..1affdb1dc 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java @@ -22,14 +22,13 @@ import dan200.computercraft.shared.network.NetworkMessage; import dan200.computercraft.shared.network.client.ComputerDataClientMessage; import dan200.computercraft.shared.network.client.ComputerDeletedClientMessage; import dan200.computercraft.shared.network.client.ComputerTerminalClientMessage; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundTag; import net.minecraft.screen.ScreenHandler; import net.minecraft.server.MinecraftServer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import net.minecraftforge.fml.server.ServerLifecycleHooks; -import net.minecraftforge.versions.mcp.MCPVersion; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -169,16 +168,16 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput if( hasTerminalChanged() || force ) { - // Send terminal state to clients who are currently interacting with the computer. - MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); + if (FabricLoader.getInstance().getGameInstance() instanceof MinecraftServer) { + // Send terminal state to clients who are currently interacting with the computer. + MinecraftServer server = (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - NetworkMessage packet = null; - for( PlayerEntity player : server.getPlayerManager().getPlayerList() ) - { - if( isInteracting( player ) ) - { - if( packet == null ) packet = createTerminalPacket(); - NetworkHandler.sendToPlayer( player, packet ); + NetworkMessage packet = null; + for (PlayerEntity player : server.getPlayerManager().getPlayerList()) { + if (isInteracting(player)) { + if (packet == null) packet = createTerminalPacket(); + NetworkHandler.sendToPlayer(player, packet); + } } } } @@ -347,7 +346,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput @Override public String getHostString() { - return String.format( "ComputerCraft %s (Minecraft %s)", ComputerCraftAPI.getInstalledVersion(), MCPVersion.getMCVersion() ); + return String.format( "ComputerCraft %s (Minecraft %s)", ComputerCraftAPI.getInstalledVersion(), "1.16.2" ); } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/network/container/ContainerData.java b/src/main/java/dan200/computercraft/shared/network/container/ContainerData.java index 003d9eadb..1fca53b95 100644 --- a/src/main/java/dan200/computercraft/shared/network/container/ContainerData.java +++ b/src/main/java/dan200/computercraft/shared/network/container/ContainerData.java @@ -12,33 +12,32 @@ import net.minecraft.screen.NamedScreenHandlerFactory; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraftforge.common.extensions.IForgeContainerType; -import net.minecraftforge.fml.network.NetworkHooks; import javax.annotation.Nonnull; import java.util.function.Consumer; import java.util.function.Function; /** - * An extension over the basic {@link IForgeContainerType}/{@link NetworkHooks#openGui(ServerPlayerEntity, INamedContainerProvider, Consumer)} + * An extension over the basic * hooks, with a more convenient way of reading and writing data. */ public interface ContainerData { void toBytes( PacketByteBuf buf ); - default void open( PlayerEntity player, NamedScreenHandlerFactory owner ) - { - NetworkHooks.openGui( (ServerPlayerEntity) player, owner, this::toBytes ); - } - - static ScreenHandlerType toType( Function reader, Factory factory ) - { - return IForgeContainerType.create( ( id, player, data ) -> factory.create( id, player, reader.apply( data ) ) ); - } - - interface Factory - { - C create( int id, @Nonnull PlayerInventory inventory, T data ); - } + //TODO Figure out what the heck to do here +// default void open( PlayerEntity player, NamedScreenHandlerFactory owner ) +// { +// NetworkHooks.openGui( (ServerPlayerEntity) player, owner, this::toBytes ); +// } +// +// static ScreenHandlerType toType( Function reader, Factory factory ) +// { +// return IForgeContainerType.create( ( id, player, data ) -> factory.create( id, player, reader.apply( data ) ) ); +// } +// +// interface Factory +// { +// C create( int id, @Nonnull PlayerInventory inventory, T data ); +// } } diff --git a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java index b92c980b1..dbfccb9e4 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java @@ -42,8 +42,6 @@ import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; import net.minecraft.util.collection.DefaultedList; import net.minecraft.world.World; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import javax.annotation.Nonnull; import javax.annotation.Nullable;