From 34760d3de488e695893d4eaa34a52705e675a1d3 Mon Sep 17 00:00:00 2001 From: Toad-Dev <748280+Toad-Dev@users.noreply.github.com> Date: Wed, 1 Dec 2021 13:37:36 -0800 Subject: [PATCH] Update to MC 1.18 Fabric api got rid of their BE syncing helper in favor of the vanilla system. In this commit BE syncing is probably horribly broken and needs to be looked over. I did the minimum to make it compile and run. --- build.gradle | 6 ++-- gradle.properties | 11 +++---- .../computercraft/api/turtle/FakePlayer.java | 2 +- .../gui/widgets/DynamicImageButton.java | 4 +-- .../shared/common/TileGeneric.java | 31 +++++++++++-------- .../shared/computer/apis/CommandAPI.java | 3 +- .../computer/blocks/TileComputerBase.java | 4 +-- .../peripheral/diskdrive/TileDiskDrive.java | 6 ++-- .../peripheral/modem/wired/TileCable.java | 10 +++--- .../modem/wired/TileWiredModemFull.java | 6 ++-- .../modem/wireless/TileWirelessModem.java | 4 +-- .../peripheral/monitor/TileMonitor.java | 6 ++-- .../peripheral/printer/TilePrinter.java | 5 ++- .../shared/turtle/blocks/TileTurtle.java | 5 ++- .../shared/util/TickScheduler.java | 6 +--- .../shared/util/WaterloggableHelpers.java | 3 +- src/main/resources/fabric.mod.json | 3 +- 17 files changed, 52 insertions(+), 63 deletions(-) diff --git a/build.gradle b/build.gradle index dfc18de3a..fc9295d3c 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { id 'fabric-loom' version '0.10-SNAPSHOT' } -def javaVersion = JavaLanguageVersion.of(16) +def javaVersion = JavaLanguageVersion.of(17) java { toolchain { languageVersion = javaVersion @@ -83,8 +83,8 @@ dependencies { include 'com.electronwill.night-config:toml:3.6.3' include "me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}" - modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:6.0.254-alpha" - modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:6.0.254-alpha" + //modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:6.0.254-alpha" + //modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:6.0.254-alpha" testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.0' diff --git a/gradle.properties b/gradle.properties index 149a41402..6d26d5f3c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,11 +5,10 @@ org.gradle.jvmargs=-Xmx1G mod_version=1.97.2 # Minecraft properties -mc_version=1.17.1 -fabric_api_version=0.40.1+1.17 -fabric_loader_version=0.12.0 +mc_version=1.18 +fabric_api_version=0.43.1+1.18 +fabric_loader_version=0.12.8 cloth_api_version=2.0.54 -cloth_config_version=5.0.34 -jankson_version=1.2.0 -modmenu_version=2.0.2 +cloth_config_version=6.0.42 +modmenu_version=3.0.0 diff --git a/src/main/java/dan200/computercraft/api/turtle/FakePlayer.java b/src/main/java/dan200/computercraft/api/turtle/FakePlayer.java index b1481f5c3..956d5f269 100644 --- a/src/main/java/dan200/computercraft/api/turtle/FakePlayer.java +++ b/src/main/java/dan200/computercraft/api/turtle/FakePlayer.java @@ -253,7 +253,7 @@ public class FakePlayer extends ServerPlayer } @Override - public void trackChunk( ChunkPos chunkPos, Packet packet, Packet packet2 ) + public void trackChunk( ChunkPos chunkPos, Packet packet ) { } diff --git a/src/main/java/dan200/computercraft/client/gui/widgets/DynamicImageButton.java b/src/main/java/dan200/computercraft/client/gui/widgets/DynamicImageButton.java index e14e0cde9..4d780a08c 100644 --- a/src/main/java/dan200/computercraft/client/gui/widgets/DynamicImageButton.java +++ b/src/main/java/dan200/computercraft/client/gui/widgets/DynamicImageButton.java @@ -71,12 +71,12 @@ public class DynamicImageButton extends Button RenderSystem.disableDepthTest(); int yTex = yTexStart; - if( isHovered() ) yTex += yDiffTex; + if( isHoveredOrFocused() ) yTex += yDiffTex; blit( stack, x, y, xTexStart.getAsInt(), yTex, width, height, textureWidth, textureHeight ); RenderSystem.enableDepthTest(); - if( isHovered() ) renderToolTip( stack, mouseX, mouseY ); + if( isHoveredOrFocused() ) renderToolTip( stack, mouseX, mouseY ); } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java index 7363d0b4b..d78411b21 100644 --- a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java +++ b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java @@ -6,9 +6,11 @@ package dan200.computercraft.shared.common; -import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientGamePacketListener; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; @@ -16,10 +18,11 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; +import org.jetbrains.annotations.Nullable; import javax.annotation.Nonnull; -public abstract class TileGeneric extends BlockEntity implements BlockEntityClientSerializable +public abstract class TileGeneric extends BlockEntity { public TileGeneric( BlockEntityType type, BlockPos pos, BlockState state ) { @@ -60,6 +63,11 @@ public abstract class TileGeneric extends BlockEntity implements BlockEntityClie { } + protected double getInteractRange( Player player ) + { + return 8.0; + } + public boolean isUsable( Player player, boolean ignoreRange ) { if( player == null || !player.isAlive() || getLevel().getBlockEntity( getBlockPos() ) != this ) @@ -76,28 +84,25 @@ public abstract class TileGeneric extends BlockEntity implements BlockEntityClie return player.getCommandSenderWorld() == getLevel() && player.distanceToSqr( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= range * range; } - protected double getInteractRange( Player player ) + @Override + public CompoundTag getUpdateTag() { - return 8.0; + CompoundTag nbt = new CompoundTag(); + writeDescription( nbt ); + return nbt; } + @Nullable @Override - public void fromClientTag( CompoundTag compoundTag ) + public Packet getUpdatePacket() { - readDescription( compoundTag ); + return ClientboundBlockEntityDataPacket.create( this ); } protected void readDescription( @Nonnull CompoundTag nbt ) { } - @Override - public CompoundTag toClientTag( CompoundTag compoundTag ) - { - writeDescription( compoundTag ); - return compoundTag; - } - protected void writeDescription( @Nonnull CompoundTag nbt ) { } diff --git a/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java b/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java index 25cce42ed..ca9d8175b 100644 --- a/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java +++ b/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java @@ -17,7 +17,6 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; -import net.minecraft.nbt.CompoundTag; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -252,7 +251,7 @@ public class CommandAPI implements ILuaAPI BlockEntity tile = world.getBlockEntity( pos ); if( tile != null ) { - table.put( "nbt", NBTUtil.toLua( tile.save( new CompoundTag() ) ) ); + table.put( "nbt", NBTUtil.toLua( tile.saveWithFullMetadata() ) ); } return table; diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java index 4cd86d5ef..8b0169e1a 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java @@ -330,9 +330,8 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT on = startOn = nbt.getBoolean( NBT_ON ); } - @Nonnull @Override - public CompoundTag save( @Nonnull CompoundTag nbt ) + public void saveAdditional( @Nonnull CompoundTag nbt ) { // Save ID, label and power state if( computerID >= 0 ) @@ -344,7 +343,6 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT nbt.putString( NBT_LABEL, label ); } nbt.putBoolean( NBT_ON, on ); - return super.save( nbt ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java index b209601b4..4f9b7914b 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java @@ -120,9 +120,8 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory } } - @Nonnull @Override - public CompoundTag save( @Nonnull CompoundTag nbt ) + public void saveAdditional( @Nonnull CompoundTag nbt ) { if( customName != null ) { @@ -135,7 +134,8 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory diskStack.save( item ); nbt.put( NBT_ITEM, item ); } - return super.save( nbt ); + + super.saveAdditional( nbt ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java index 4c8c7ebb5..7b57cee37 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java @@ -367,13 +367,13 @@ public class TileCable extends TileGeneric implements IPeripheralTile peripheral.read( nbt, "" ); } - @Nonnull @Override - public CompoundTag save( CompoundTag nbt ) + public void saveAdditional( CompoundTag nbt ) { nbt.putBoolean( NBT_PERIPHERAL_ENABLED, peripheralAccessAllowed ); peripheral.write( nbt, "" ); - return super.save( nbt ); + + super.saveAdditional( nbt ); } @Override @@ -397,9 +397,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile if( state != null ) return; if( !level.isClientSide ) { - level.getBlockTicks() - .scheduleTick( worldPosition, - getBlockState().getBlock(), 0 ); + level.scheduleTick( worldPosition, getBlockState().getBlock(), 0 ); } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java index 37de3790b..d5f67ab69 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java @@ -325,16 +325,16 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile } } - @Nonnull @Override - public CompoundTag save( CompoundTag nbt ) + public void saveAdditional( CompoundTag nbt ) { nbt.putBoolean( NBT_PERIPHERAL_ENABLED, peripheralAccessAllowed ); for( int i = 0; i < peripherals.length; i++ ) { peripherals[i].write( nbt, Integer.toString( i ) ); } - return super.save( nbt ); + + super.saveAdditional( nbt ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java index 809fa0761..79719198d 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java @@ -49,9 +49,7 @@ public class TileWirelessModem extends TileGeneric implements IPeripheralTile super.setBlockState( state ); if( state != null ) return; hasModemDirection = false; - level.getBlockTicks() - .scheduleTick( getBlockPos(), - getBlockState().getBlock(), 0 ); + level.scheduleTick( getBlockPos(), getBlockState().getBlock(), 0 ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java index f86791dad..d7b8f2aa4 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java @@ -305,15 +305,15 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile // Networking stuff - @Nonnull @Override - public CompoundTag save( CompoundTag nbt ) + public void saveAdditional( CompoundTag nbt ) { nbt.putInt( NBT_X, xIndex ); nbt.putInt( NBT_Y, yIndex ); nbt.putInt( NBT_WIDTH, width ); nbt.putInt( NBT_HEIGHT, height ); - return super.save( nbt ); + + super.saveAdditional( nbt ); } // @Override //TODO: make BlockEntityRenderer work with this, i guess. diff --git a/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java b/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java index 7f8dd4737..3732a3ce1 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java @@ -180,9 +180,8 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent ContainerHelper.loadAllItems( nbt, inventory ); } - @Nonnull @Override - public CompoundTag save( @Nonnull CompoundTag nbt ) + public void saveAdditional( @Nonnull CompoundTag nbt ) { if( customName != null ) { @@ -200,7 +199,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent // Write inventory ContainerHelper.saveAllItems( nbt, inventory ); - return super.save( nbt ); + super.saveAdditional( nbt ); } boolean isPrinting() diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java index e8aa67876..d5826752b 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -300,9 +300,8 @@ public class TileTurtle extends TileComputerBase protected void updateBlockState( ComputerState newState ) {} - @Nonnull @Override - public CompoundTag save( @Nonnull CompoundTag nbt ) + public void saveAdditional( @Nonnull CompoundTag nbt ) { // Write inventory ListTag nbttaglist = new ListTag(); @@ -321,7 +320,7 @@ public class TileTurtle extends TileComputerBase // Write brain nbt = brain.writeToNBT( nbt ); - return super.save( nbt ); + super.saveAdditional( nbt ); } // IDirectionalTile diff --git a/src/main/java/dan200/computercraft/shared/util/TickScheduler.java b/src/main/java/dan200/computercraft/shared/util/TickScheduler.java index 3ba67807b..d5b91017c 100644 --- a/src/main/java/dan200/computercraft/shared/util/TickScheduler.java +++ b/src/main/java/dan200/computercraft/shared/util/TickScheduler.java @@ -50,11 +50,7 @@ public final class TickScheduler if( world != null && pos != null && world.hasChunkAt( pos ) && world.getBlockEntity( pos ) == tile ) { - world.getBlockTicks() - .scheduleTick( pos, - tile.getBlockState() - .getBlock(), - 0 ); + world.scheduleTick( pos, tile.getBlockState().getBlock(), 0 ); } } } diff --git a/src/main/java/dan200/computercraft/shared/util/WaterloggableHelpers.java b/src/main/java/dan200/computercraft/shared/util/WaterloggableHelpers.java index 414c88c3e..b385138aa 100644 --- a/src/main/java/dan200/computercraft/shared/util/WaterloggableHelpers.java +++ b/src/main/java/dan200/computercraft/shared/util/WaterloggableHelpers.java @@ -50,8 +50,7 @@ public final class WaterloggableHelpers { if( state.getValue( WATERLOGGED ) ) { - world.getLiquidTicks() - .scheduleTick( pos, Fluids.WATER, Fluids.WATER.getTickDelay( world ) ); + world.scheduleTick( pos, Fluids.WATER, Fluids.WATER.getTickDelay( world ) ); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 3735cd251..ea2ea1bca 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -22,8 +22,7 @@ "depends": { "fabricloader": ">=0.11.3", "fabric": "*", - "minecraft": "1.17.x", - "java": ">=16" + "minecraft": "1.18" }, "suggests": { "modmenu": "*"