mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-28 08:12:18 +00:00
Auto stash before merge of "fabric" and "origin/fabric"
This commit is contained in:
parent
84bca21b0c
commit
64f5ca02b3
@ -120,5 +120,4 @@ public final class ClientRegistry {
|
||||
.apply(spriteIdentifier.getTextureId()),
|
||||
ModelRotation.X0_Y0, identifier);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
@ -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<IPeripheral> CAPABILITY_PERIPHERAL = null;
|
||||
|
||||
@CapabilityInject( IWiredElement.class )
|
||||
public static Capability<IWiredElement> CAPABILITY_WIRED_ELEMENT = null;
|
||||
|
||||
private Capabilities()
|
||||
{
|
||||
}
|
||||
}
|
@ -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<IPeripheral> peripheral;
|
||||
private Optional<IPeripheral> peripheral;
|
||||
|
||||
public TileComputer( ComputerFamily family, BlockEntityType<? extends TileComputer> type )
|
||||
{
|
||||
@ -87,30 +84,4 @@ public class TileComputer extends TileComputerBase
|
||||
{
|
||||
return new ContainerComputer( id, this );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability( @Nonnull Capability<T> 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 );
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 <C extends ScreenHandler, T extends ContainerData> ScreenHandlerType<C> toType( Function<PacketByteBuf, T> reader, Factory<C, T> factory )
|
||||
{
|
||||
return IForgeContainerType.create( ( id, player, data ) -> factory.create( id, player, reader.apply( data ) ) );
|
||||
}
|
||||
|
||||
interface Factory<C extends ScreenHandler, T extends ContainerData>
|
||||
{
|
||||
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 <C extends ScreenHandler, T extends ContainerData> ScreenHandlerType<C> toType( Function<PacketByteBuf, T> reader, Factory<C, T> factory )
|
||||
// {
|
||||
// return IForgeContainerType.create( ( id, player, data ) -> factory.create( id, player, reader.apply( data ) ) );
|
||||
// }
|
||||
//
|
||||
// interface Factory<C extends ScreenHandler, T extends ContainerData>
|
||||
// {
|
||||
// C create( int id, @Nonnull PlayerInventory inventory, T data );
|
||||
// }
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user