From b11d4bb20900843b4b10e5f9a09a6c017f82f6e6 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Tue, 7 May 2019 20:40:55 +0100 Subject: [PATCH] Bump to 1.14.1pr1 Which means bumping mappings version. Oh boy, this was not a bundle of laughs... --- build.gradle | 4 +- gradle.properties | 2 +- .../api/AbstractTurtleUpgrade.java | 6 +-- .../api/pocket/AbstractPocketUpgrade.java | 6 +-- .../api/turtle/event/FakePlayer.java | 16 +++---- .../client/ClientTableFormatter.java | 14 +++--- .../computercraft/client/gui/GuiComputer.java | 4 +- .../client/render/ItemMapLikeRenderer.java | 4 +- .../core/filesystem/ResourceMount.java | 37 +++++++-------- .../dan200/computercraft/shared/Registry.java | 6 +-- .../shared/command/CommandComputerCraft.java | 16 +++---- .../shared/command/CommandCopy.java | 13 +++--- .../shared/command/Exceptions.java | 8 ++-- .../command/arguments/RepeatArgumentType.java | 8 ++-- .../builder/HelpingArgumentBuilder.java | 20 ++++----- .../shared/command/text/ChatHelpers.java | 45 +++++++++---------- .../command/text/ServerTableFormatter.java | 14 +++--- .../shared/command/text/TableBuilder.java | 16 +++---- .../shared/command/text/TableFormatter.java | 34 +++++++------- .../shared/common/BlockGeneric.java | 4 +- .../shared/computer/blocks/BlockComputer.java | 6 +-- .../computer/blocks/BlockComputerBase.java | 4 +- .../computer/blocks/TileCommandComputer.java | 14 +++--- .../computer/blocks/TileComputerBase.java | 12 ++--- .../shared/computer/core/ComputerState.java | 6 +-- .../inventory/ContainerViewComputer.java | 6 +-- .../shared/computer/items/ItemComputer.java | 4 +- .../computer/items/ItemComputerBase.java | 16 +++---- .../shared/media/items/ItemDisk.java | 16 +++---- .../shared/media/items/ItemPrintout.java | 8 ++-- .../shared/media/items/ItemTreasureDisk.java | 8 ++-- .../shared/network/NetworkHandler.java | 2 +- .../client/ChatTableClientMessage.java | 12 ++--- .../peripheral/diskdrive/BlockDiskDrive.java | 2 +- .../peripheral/diskdrive/DiskDriveState.java | 6 +-- .../peripheral/diskdrive/TileDiskDrive.java | 9 ++-- .../peripheral/modem/wired/BlockCable.java | 6 +-- .../modem/wired/BlockWiredModemFull.java | 2 +- .../modem/wired/CableModemVariant.java | 6 +-- .../modem/wired/ItemBlockCable.java | 6 +-- .../peripheral/modem/wired/TileCable.java | 6 +-- .../modem/wired/TileWiredModemFull.java | 8 ++-- .../modem/wireless/BlockWirelessModem.java | 10 ++--- .../peripheral/monitor/BlockMonitor.java | 6 +-- .../peripheral/monitor/MonitorEdgeState.java | 6 +-- .../peripheral/printer/BlockPrinter.java | 2 +- .../peripheral/printer/TilePrinter.java | 9 ++-- .../peripheral/speaker/BlockSpeaker.java | 2 +- .../peripheral/speaker/SpeakerPeripheral.java | 2 +- .../pocket/items/ItemPocketComputer.java | 24 +++++----- .../shared/turtle/blocks/BlockTurtle.java | 10 ++--- .../turtle/core/TurtleCompareCommand.java | 2 +- .../turtle/core/TurtlePlaceCommand.java | 26 +++++------ .../shared/turtle/items/ItemTurtle.java | 26 +++++------ .../shared/turtle/upgrades/TurtleTool.java | 2 +- .../shared/util/ItemStorage.java | 1 - .../shared/util/NamedBlockEntityType.java | 25 +++++++++-- .../computercraft/shared/util/RecordUtil.java | 4 +- .../core/filesystem/ResourceMountTest.java | 2 +- 59 files changed, 306 insertions(+), 295 deletions(-) diff --git a/build.gradle b/build.gradle index 7e454d49f..3b2478d43 100644 --- a/build.gradle +++ b/build.gradle @@ -53,7 +53,7 @@ configurations { dependencies { minecraft "com.mojang:minecraft:${mc_version}" mappings "net.fabricmc:yarn:${mc_version}+build.${mappings_version}" - modCompile "net.fabricmc:fabric-loader:0.4.2+build.132" + modCompile "net.fabricmc:fabric-loader:0.4.6+build.141" modCompile "net.fabricmc:fabric:0.2.7+build.126" /* @@ -151,7 +151,7 @@ task proguard(type: ProGuardTask, dependsOn: jar) { // LWJGL and Apache bundle Java 9 versions, which is great, but rather breaks Proguard dontwarn 'module-info' - dontwarn 'org.apache.**,org.lwjgl.**' + dontwarn 'org.apache.**,org.lwjgl.**,javax.crypto.SecretKey' } task proguardMove(dependsOn: proguard) { diff --git a/gradle.properties b/gradle.properties index 146d66068..043f788b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,5 +2,5 @@ mod_version=1.82.4 # Minecraft properties -mc_version=1.14 +mc_version=1.14.1 Pre-Release 1 mappings_version=1 diff --git a/src/main/java/dan200/computercraft/api/AbstractTurtleUpgrade.java b/src/main/java/dan200/computercraft/api/AbstractTurtleUpgrade.java index 97b0ea343..45f86d961 100644 --- a/src/main/java/dan200/computercraft/api/AbstractTurtleUpgrade.java +++ b/src/main/java/dan200/computercraft/api/AbstractTurtleUpgrade.java @@ -8,7 +8,7 @@ package dan200.computercraft.api; import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.api.turtle.TurtleUpgradeType; -import net.minecraft.item.ItemProvider; +import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; import net.minecraft.util.SystemUtil; @@ -35,7 +35,7 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade this.stack = stack; } - protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, ItemProvider item ) + protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, ItemConvertible item ) { this( id, type, adjective, new ItemStack( item ) ); } @@ -45,7 +45,7 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade this( id, type, SystemUtil.createTranslationKey( "upgrade", id ) + ".adjective", stack ); } - protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, ItemProvider item ) + protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, ItemConvertible item ) { this( id, type, new ItemStack( item ) ); } diff --git a/src/main/java/dan200/computercraft/api/pocket/AbstractPocketUpgrade.java b/src/main/java/dan200/computercraft/api/pocket/AbstractPocketUpgrade.java index 489897b30..a29602a23 100644 --- a/src/main/java/dan200/computercraft/api/pocket/AbstractPocketUpgrade.java +++ b/src/main/java/dan200/computercraft/api/pocket/AbstractPocketUpgrade.java @@ -6,7 +6,7 @@ package dan200.computercraft.api.pocket; -import net.minecraft.item.ItemProvider; +import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; import net.minecraft.util.SystemUtil; @@ -31,12 +31,12 @@ public abstract class AbstractPocketUpgrade implements IPocketUpgrade this.stack = stack; } - protected AbstractPocketUpgrade( Identifier identifier, String adjective, ItemProvider item ) + protected AbstractPocketUpgrade( Identifier identifier, String adjective, ItemConvertible item ) { this( identifier, adjective, new ItemStack( item ) ); } - protected AbstractPocketUpgrade( Identifier id, ItemProvider item ) + protected AbstractPocketUpgrade( Identifier id, ItemConvertible item ) { this( id, SystemUtil.createTranslationKey( "upgrade", id ) + ".adjective", new ItemStack( item ) ); } diff --git a/src/main/java/dan200/computercraft/api/turtle/event/FakePlayer.java b/src/main/java/dan200/computercraft/api/turtle/event/FakePlayer.java index 927439bf4..d7163b32f 100644 --- a/src/main/java/dan200/computercraft/api/turtle/event/FakePlayer.java +++ b/src/main/java/dan200/computercraft/api/turtle/event/FakePlayer.java @@ -25,6 +25,8 @@ import net.minecraft.network.ClientConnection; import net.minecraft.network.NetworkSide; import net.minecraft.network.NetworkState; import net.minecraft.network.Packet; +import net.minecraft.network.chat.ChatMessageType; +import net.minecraft.network.chat.Component; import net.minecraft.recipe.Recipe; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; @@ -34,14 +36,12 @@ import net.minecraft.server.network.packet.VehicleMoveC2SPacket; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvent; -import net.minecraft.text.ChatMessageType; -import net.minecraft.text.TextComponent; import net.minecraft.util.DefaultedList; import net.minecraft.util.Hand; +import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Vec3d; import net.minecraft.village.TraderOfferList; import net.minecraft.world.GameMode; -import net.minecraft.world.chunk.ChunkPos; import net.minecraft.world.dimension.DimensionType; import javax.annotation.Nullable; @@ -135,7 +135,7 @@ public class FakePlayer extends ServerPlayerEntity public void method_14241() { } @Override - public void addChatMessage( TextComponent textComponent, boolean status ) { } + public void addChatMessage( Component textComponent, boolean status ) { } @Override protected void method_6040() { } @@ -162,7 +162,7 @@ public class FakePlayer extends ServerPlayerEntity public void setGameMode( GameMode gameMode ) { } @Override - public void sendChatMessage( TextComponent textComponent, ChatMessageType chatMessageType ) { } + public void sendChatMessage( Component textComponent, ChatMessageType chatMessageType ) { } @Override public String getServerBrand() @@ -214,7 +214,7 @@ public class FakePlayer extends ServerPlayerEntity } @Override - public void disconnect( TextComponent message ) { } + public void disconnect( Component message ) { } @Override public void onRequestCommandCompletions( RequestCommandCompletionsC2SPacket packet ) { } @@ -230,7 +230,7 @@ public class FakePlayer extends ServerPlayerEntity { FakeConnection() { - super( NetworkSide.SERVER ); + super( NetworkSide.CLIENTBOUND ); } @Override @@ -244,7 +244,7 @@ public class FakePlayer extends ServerPlayerEntity } @Override - public void disconnect( TextComponent message ) + public void disconnect( Component message ) { } diff --git a/src/main/java/dan200/computercraft/client/ClientTableFormatter.java b/src/main/java/dan200/computercraft/client/ClientTableFormatter.java index 581e43022..2410d57b5 100644 --- a/src/main/java/dan200/computercraft/client/ClientTableFormatter.java +++ b/src/main/java/dan200/computercraft/client/ClientTableFormatter.java @@ -10,12 +10,12 @@ import dan200.computercraft.shared.command.text.ChatHelpers; import dan200.computercraft.shared.command.text.TableBuilder; import dan200.computercraft.shared.command.text.TableFormatter; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import net.minecraft.ChatFormat; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.hud.ChatHud; import net.minecraft.client.util.TextComponentUtil; -import net.minecraft.text.TextComponent; -import net.minecraft.text.TextFormat; +import net.minecraft.network.chat.Component; import net.minecraft.util.math.MathHelper; import org.apache.commons.lang3.StringUtils; @@ -35,7 +35,7 @@ public class ClientTableFormatter implements TableFormatter @Override @Nullable - public TextComponent getPadding( TextComponent component, int width ) + public Component getPadding( Component component, int width ) { int extraWidth = width - getWidth( component ); if( extraWidth <= 0 ) return null; @@ -46,7 +46,7 @@ public class ClientTableFormatter implements TableFormatter int spaces = MathHelper.floor( extraWidth / spaceWidth ); int extra = extraWidth - (int) (spaces * spaceWidth); - return ChatHelpers.coloured( StringUtils.repeat( ' ', spaces ) + StringUtils.repeat( (char) 712, extra ), TextFormat.GRAY ); + return ChatHelpers.coloured( StringUtils.repeat( ' ', spaces ) + StringUtils.repeat( (char) 712, extra ), ChatFormat.GRAY ); } @Override @@ -56,20 +56,20 @@ public class ClientTableFormatter implements TableFormatter } @Override - public int getWidth( TextComponent component ) + public int getWidth( Component component ) { return renderer().getStringWidth( component.getFormattedText() ); } @Override - public void writeLine( int id, TextComponent component ) + public void writeLine( int id, Component component ) { MinecraftClient mc = MinecraftClient.getInstance(); ChatHud chat = mc.inGameHud.getChatHud(); // Trim the text if it goes over the allowed length int maxWidth = MathHelper.floor( chat.getWidth() / chat.getScale() ); - List list = TextComponentUtil.wrapLines( component, maxWidth, mc.textRenderer, false, false ); + List list = TextComponentUtil.wrapLines( component, maxWidth, mc.textRenderer, false, false ); if( !list.isEmpty() ) chat.addMessage( list.get( 0 ), id ); } diff --git a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java index 3d437c858..7b8861e72 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java @@ -17,7 +17,7 @@ import dan200.computercraft.shared.computer.inventory.ContainerComputer; import net.minecraft.client.gui.ContainerScreen; import net.minecraft.container.Container; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.text.StringTextComponent; +import net.minecraft.network.chat.TextComponent; import net.minecraft.util.Identifier; import org.lwjgl.glfw.GLFW; @@ -38,7 +38,7 @@ public class GuiComputer extends ContainerScreen public GuiComputer( T container, PlayerInventory player, ComputerFamily family, ClientComputer computer, int termWidth, int termHeight ) { - super( container, player, new StringTextComponent( "" ) ); + super( container, player, new TextComponent( "" ) ); m_family = family; m_computer = computer; diff --git a/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java index 537fd3354..7549bf394 100644 --- a/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java @@ -31,14 +31,14 @@ public abstract class ItemMapLikeRenderer PlayerEntity player = MinecraftClient.getInstance().player; GlStateManager.pushMatrix(); - if( hand == Hand.MAIN && player.getOffHandStack().isEmpty() ) + if( hand == Hand.MAIN_HAND && player.getOffHandStack().isEmpty() ) { renderItemFirstPersonCenter( pitch, equipProgress, swingProgress, stack ); } else { renderItemFirstPersonSide( - hand == Hand.MAIN ? player.getMainHand() : player.getMainHand().getOpposite(), + hand == Hand.MAIN_HAND ? player.getMainHand() : player.getMainHand().getOpposite(), equipProgress, swingProgress, stack ); } diff --git a/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java b/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java index 9953560a0..33f790549 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java @@ -11,7 +11,10 @@ import com.google.common.cache.CacheBuilder; import com.google.common.io.ByteStreams; import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.core.apis.handles.ArrayByteChannel; -import net.minecraft.resource.*; +import net.minecraft.resource.ReloadableResourceManager; +import net.minecraft.resource.Resource; +import net.minecraft.resource.ResourceManager; +import net.minecraft.resource.ResourceReloadListener; import net.minecraft.util.Identifier; import net.minecraft.util.profiler.Profiler; @@ -23,6 +26,8 @@ import java.io.InputStream; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; public class ResourceMount implements IMount @@ -241,7 +246,7 @@ public class ResourceMount implements IMount * While people should really be keeping a permanent reference to this, some people construct it every * method call, so let's make this as small as possible. */ - static class Listener extends SupplyingResourceReloadListener + static class Listener implements ResourceReloadListener { private static final Listener INSTANCE = new Listener(); @@ -249,23 +254,19 @@ public class ResourceMount implements IMount private final Set managers = Collections.newSetFromMap( new WeakHashMap<>() ); @Override - protected synchronized Void load( ResourceManager manager, Profiler profiler ) - { - profiler.push( "Mount reloading" ); - try - { - for( ResourceMount mount : mounts ) mount.load(); - } - finally - { - profiler.pop(); - } - return null; - } - - @Override - protected void apply( Void res, ResourceManager manager, Profiler profiler ) + public CompletableFuture reload( Synchronizer synchronizer, ResourceManager resourceManager, Profiler profiler, Profiler profiler1, Executor executor, Executor executor1 ) { + return CompletableFuture.runAsync( () -> { + profiler.push( "Mount reloading" ); + try + { + for( ResourceMount mount : mounts ) mount.load(); + } + finally + { + profiler.pop(); + } + }, executor ); } synchronized void add( ReloadableResourceManager manager, ResourceMount mount ) diff --git a/src/main/java/dan200/computercraft/shared/Registry.java b/src/main/java/dan200/computercraft/shared/Registry.java index ac487bf43..d4ea3f64e 100644 --- a/src/main/java/dan200/computercraft/shared/Registry.java +++ b/src/main/java/dan200/computercraft/shared/Registry.java @@ -48,11 +48,7 @@ import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; import net.minecraft.block.Block; import net.minecraft.block.Material; import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.item.BlockItem; +import net.minecraft.item.*; import net.minecraft.recipe.RecipeSerializer; import net.minecraft.util.Identifier; import net.minecraft.util.registry.MutableRegistry; diff --git a/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java b/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java index c8c90a466..304ec0ed2 100644 --- a/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java +++ b/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java @@ -23,11 +23,11 @@ import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.network.Containers; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -256,9 +256,9 @@ public final class CommandComputerCraft ); } - private static TextComponent linkComputer( ServerCommandSource source, ServerComputer serverComputer, int computerId ) + private static Component linkComputer( ServerCommandSource source, ServerComputer serverComputer, int computerId ) { - TextComponent out = new StringTextComponent( "" ); + TextComponent out = new TextComponent( "" ); // Append the computer instance if( serverComputer == null ) @@ -298,7 +298,7 @@ public final class CommandComputerCraft return out; } - private static TextComponent linkPosition( ServerCommandSource context, ServerComputer computer ) + private static Component linkPosition( ServerCommandSource context, ServerComputer computer ) { if( UserLevel.OP.test( context ) ) { @@ -344,7 +344,7 @@ public final class CommandComputerCraft timings.sort( Comparator.comparing( x -> x.get( sortField ) ).reversed() ); - TextComponent[] headers = new TextComponent[1 + fields.size()]; + Component[] headers = new Component[1 + fields.size()]; headers[0] = translate( "commands.computercraft.track.dump.computer" ); for( int i = 0; i < fields.size(); i++ ) headers[i + 1] = translate( fields.get( i ).translationKey() ); TableBuilder table = new TableBuilder( TRACK_ID, headers ); @@ -354,9 +354,9 @@ public final class CommandComputerCraft Computer computer = entry.getComputer(); ServerComputer serverComputer = computer == null ? null : lookup.get( computer ); - TextComponent computerComponent = linkComputer( source, serverComputer, entry.getComputerId() ); + Component computerComponent = linkComputer( source, serverComputer, entry.getComputerId() ); - TextComponent[] row = new TextComponent[1 + fields.size()]; + Component[] row = new Component[1 + fields.size()]; row[0] = computerComponent; for( int i = 0; i < fields.size(); i++ ) row[i + 1] = text( entry.getFormatted( fields.get( i ) ) ); table.row( row ); diff --git a/src/main/java/dan200/computercraft/shared/command/CommandCopy.java b/src/main/java/dan200/computercraft/shared/command/CommandCopy.java index ddd41fc80..dd4871c3c 100644 --- a/src/main/java/dan200/computercraft/shared/command/CommandCopy.java +++ b/src/main/java/dan200/computercraft/shared/command/CommandCopy.java @@ -9,12 +9,11 @@ package dan200.computercraft.shared.command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import net.minecraft.client.MinecraftClient; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; -import net.minecraft.text.TranslatableTextComponent; -import net.minecraft.text.event.ClickEvent; -import net.minecraft.text.event.HoverEvent; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; @@ -53,10 +52,10 @@ public final class CommandCopy public static TextComponent createCopyText( String text ) { - StringTextComponent name = new StringTextComponent( text ); + TextComponent name = new TextComponent( text ); name.getStyle() .setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, PREFIX + text ) ) - .setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new TranslatableTextComponent( "gui.computercraft.tooltip.copy" ) ) ); + .setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new TranslatableComponent( "gui.computercraft.tooltip.copy" ) ) ); return name; } } diff --git a/src/main/java/dan200/computercraft/shared/command/Exceptions.java b/src/main/java/dan200/computercraft/shared/command/Exceptions.java index 78862dbb2..756d5e1da 100644 --- a/src/main/java/dan200/computercraft/shared/command/Exceptions.java +++ b/src/main/java/dan200/computercraft/shared/command/Exceptions.java @@ -9,7 +9,7 @@ package dan200.computercraft.shared.command; import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType; import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.text.TranslatableTextComponent; +import net.minecraft.network.chat.TranslatableComponent; public final class Exceptions { @@ -28,16 +28,16 @@ public final class Exceptions private static SimpleCommandExceptionType translated( String key ) { - return new SimpleCommandExceptionType( new TranslatableTextComponent( key ) ); + return new SimpleCommandExceptionType( new TranslatableComponent( key ) ); } private static DynamicCommandExceptionType translated1( String key ) { - return new DynamicCommandExceptionType( x -> new TranslatableTextComponent( key, x ) ); + return new DynamicCommandExceptionType( x -> new TranslatableComponent( key, x ) ); } private static Dynamic2CommandExceptionType translated2( String key ) { - return new Dynamic2CommandExceptionType( ( x, y ) -> new TranslatableTextComponent( key, x, y ) ); + return new Dynamic2CommandExceptionType( ( x, y ) -> new TranslatableComponent( key, x, y ) ); } } diff --git a/src/main/java/dan200/computercraft/shared/command/arguments/RepeatArgumentType.java b/src/main/java/dan200/computercraft/shared/command/arguments/RepeatArgumentType.java index 14e0495b5..3648f19e9 100644 --- a/src/main/java/dan200/computercraft/shared/command/arguments/RepeatArgumentType.java +++ b/src/main/java/dan200/computercraft/shared/command/arguments/RepeatArgumentType.java @@ -17,8 +17,8 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import net.minecraft.command.arguments.ArgumentTypes; import net.minecraft.command.arguments.serialize.ArgumentSerializer; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; import net.minecraft.util.PacketByteBuf; import javax.annotation.Nonnull; @@ -143,7 +143,7 @@ public final class RepeatArgumentType implements ArgumentType> { boolean isList = buf.readBoolean(); ArgumentType child = ArgumentTypes.fromPacket( buf ); - TextComponent message = buf.readTextComponent(); + Component message = buf.readTextComponent(); BiConsumer, ?> appender = isList ? ( list, x ) -> list.addAll( (Collection) x ) : List::add; return new RepeatArgumentType( child, appender, isList, new SimpleCommandExceptionType( message ) ); } @@ -160,7 +160,7 @@ public final class RepeatArgumentType implements ArgumentType> { Message message = arg.some.create().getRawMessage(); if( message instanceof TextComponent ) return (TextComponent) message; - return new StringTextComponent( message.getString() ); + return new TextComponent( message.getString() ); } } } diff --git a/src/main/java/dan200/computercraft/shared/command/builder/HelpingArgumentBuilder.java b/src/main/java/dan200/computercraft/shared/command/builder/HelpingArgumentBuilder.java index 6b8b4f22d..9d676f50e 100644 --- a/src/main/java/dan200/computercraft/shared/command/builder/HelpingArgumentBuilder.java +++ b/src/main/java/dan200/computercraft/shared/command/builder/HelpingArgumentBuilder.java @@ -13,11 +13,11 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.LiteralCommandNode; +import net.minecraft.ChatFormat; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; -import net.minecraft.text.TextFormat; -import net.minecraft.text.event.ClickEvent; import javax.annotation.Nonnull; import java.util.ArrayList; @@ -133,9 +133,9 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder { @@ -165,7 +165,7 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder context, CommandNode node, String id, String command ) + private static Component getHelp( CommandContext context, CommandNode node, String id, String command ) { // An ugly hack to extract usage information from the dispatcher. We generate a temporary node, generate // the shorthand usage, and emit that. @@ -174,7 +174,7 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder T coloured( T component, TextFormat colour ) + public static T coloured( T component, ChatFormat colour ) { component.getStyle().setColor( colour ); return component; } - public static TextComponent text( String text ) + public static Component text( String text ) { - return new StringTextComponent( text == null ? "" : text ); + return new TextComponent( text == null ? "" : text ); } - public static TextComponent translate( String text ) + public static Component translate( String text ) { - return new TranslatableTextComponent( text == null ? "" : text ); + return new TranslatableComponent( text == null ? "" : text ); } - public static TextComponent translate( String text, Object... args ) + public static Component translate( String text, Object... args ) { - return new TranslatableTextComponent( text == null ? "" : text, args ); + return new TranslatableComponent( text == null ? "" : text, args ); } - public static TextComponent list( TextComponent... children ) + public static Component list( Component... children ) { - TextComponent component = new StringTextComponent( "" ); - for( TextComponent child : children ) + Component component = new TextComponent( "" ); + for( Component child : children ) { component.append( child ); } return component; } - public static TextComponent position( BlockPos pos ) + public static Component position( BlockPos pos ) { if( pos == null ) return translate( "commands.computercraft.generic.no_position" ); return translate( "commands.computercraft.generic.position", pos.getX(), pos.getY(), pos.getZ() ); } - public static TextComponent bool( boolean value ) + public static Component bool( boolean value ) { return value - ? coloured( translate( "commands.computercraft.generic.yes" ), TextFormat.GREEN ) - : coloured( translate( "commands.computercraft.generic.no" ), TextFormat.RED ); + ? coloured( translate( "commands.computercraft.generic.yes" ), ChatFormat.GREEN ) + : coloured( translate( "commands.computercraft.generic.no" ), ChatFormat.RED ); } - public static TextComponent link( TextComponent component, String command, TextComponent toolTip ) + public static Component link( Component component, String command, Component toolTip ) { Style style = component.getStyle(); - if( style.getColor() == null ) style.setColor( TextFormat.YELLOW ); + if( style.getColor() == null ) style.setColor( ChatFormat.YELLOW ); style.setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, command ) ); style.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, toolTip ) ); return component; } - public static TextComponent header( String text ) + public static Component header( String text ) { return coloured( text, HEADER ); } diff --git a/src/main/java/dan200/computercraft/shared/command/text/ServerTableFormatter.java b/src/main/java/dan200/computercraft/shared/command/text/ServerTableFormatter.java index ed2fa61b1..9762920bd 100644 --- a/src/main/java/dan200/computercraft/shared/command/text/ServerTableFormatter.java +++ b/src/main/java/dan200/computercraft/shared/command/text/ServerTableFormatter.java @@ -6,9 +6,9 @@ package dan200.computercraft.shared.command.text; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; import org.apache.commons.lang3.StringUtils; import javax.annotation.Nullable; @@ -23,12 +23,12 @@ public class ServerTableFormatter implements TableFormatter } @Override - public @Nullable - TextComponent getPadding( TextComponent component, int width ) + @Nullable + public Component getPadding( Component component, int width ) { int extraWidth = width - getWidth( component ); if( extraWidth <= 0 ) return null; - return new StringTextComponent( StringUtils.repeat( ' ', extraWidth ) ); + return new TextComponent( StringUtils.repeat( ' ', extraWidth ) ); } @Override @@ -38,13 +38,13 @@ public class ServerTableFormatter implements TableFormatter } @Override - public int getWidth( TextComponent component ) + public int getWidth( Component component ) { return component.getText().length(); } @Override - public void writeLine( int id, TextComponent component ) + public void writeLine( int id, Component component ) { source.sendFeedback( component, false ); } diff --git a/src/main/java/dan200/computercraft/shared/command/text/TableBuilder.java b/src/main/java/dan200/computercraft/shared/command/text/TableBuilder.java index 7cf2ea170..d3d73beb5 100644 --- a/src/main/java/dan200/computercraft/shared/command/text/TableBuilder.java +++ b/src/main/java/dan200/computercraft/shared/command/text/TableBuilder.java @@ -9,9 +9,9 @@ package dan200.computercraft.shared.command.text; import dan200.computercraft.shared.command.CommandUtils; import dan200.computercraft.shared.network.NetworkHandler; import dan200.computercraft.shared.network.client.ChatTableClientMessage; +import net.minecraft.network.chat.Component; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.TextComponent; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -22,11 +22,11 @@ public class TableBuilder { private final int id; private int columns = -1; - private final TextComponent[] headers; - private final ArrayList rows = new ArrayList<>(); + private final Component[] headers; + private final ArrayList rows = new ArrayList<>(); private int additional; - public TableBuilder( int id, @Nonnull TextComponent... headers ) + public TableBuilder( int id, @Nonnull Component... headers ) { if( id < 0 ) throw new IllegalArgumentException( "ID must be positive" ); this.id = id; @@ -45,13 +45,13 @@ public class TableBuilder { if( id < 0 ) throw new IllegalArgumentException( "ID must be positive" ); this.id = id; - this.headers = new TextComponent[headers.length]; + this.headers = new Component[headers.length]; columns = headers.length; for( int i = 0; i < headers.length; i++ ) this.headers[i] = ChatHelpers.header( headers[i] ); } - public void row( @Nonnull TextComponent... row ) + public void row( @Nonnull Component... row ) { if( columns == -1 ) columns = row.length; if( row.length != columns ) throw new IllegalArgumentException( "Row is the incorrect length" ); @@ -85,13 +85,13 @@ public class TableBuilder } @Nullable - public TextComponent[] getHeaders() + public Component[] getHeaders() { return headers; } @Nonnull - public List getRows() + public List getRows() { return rows; } diff --git a/src/main/java/dan200/computercraft/shared/command/text/TableFormatter.java b/src/main/java/dan200/computercraft/shared/command/text/TableFormatter.java index 408d0ce6e..eb244eaea 100644 --- a/src/main/java/dan200/computercraft/shared/command/text/TableFormatter.java +++ b/src/main/java/dan200/computercraft/shared/command/text/TableFormatter.java @@ -6,9 +6,9 @@ package dan200.computercraft.shared.command.text; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; -import net.minecraft.text.TextFormat; +import net.minecraft.ChatFormat; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; import org.apache.commons.lang3.StringUtils; import javax.annotation.Nullable; @@ -18,8 +18,8 @@ import static dan200.computercraft.shared.command.text.ChatHelpers.translate; public interface TableFormatter { - TextComponent SEPARATOR = coloured( "| ", TextFormat.GRAY ); - TextComponent HEADER = coloured( "=", TextFormat.GRAY ); + Component SEPARATOR = coloured( "| ", ChatFormat.GRAY ); + Component HEADER = coloured( "=", ChatFormat.GRAY ); /** * Get additional padding for the component @@ -29,7 +29,7 @@ public interface TableFormatter * @return The padding for this component, or {@code null} if none is needed. */ @Nullable - TextComponent getPadding( TextComponent component, int width ); + Component getPadding( Component component, int width ); /** * Get the minimum padding between each column @@ -38,9 +38,9 @@ public interface TableFormatter */ int getColumnPadding(); - int getWidth( TextComponent component ); + int getWidth( Component component ); - void writeLine( int id, TextComponent component ); + void writeLine( int id, Component component ); default int display( TableBuilder table ) { @@ -50,13 +50,13 @@ public interface TableFormatter int columns = table.getColumns(); int[] maxWidths = new int[columns]; - TextComponent[] headers = table.getHeaders(); + Component[] headers = table.getHeaders(); if( headers != null ) { for( int i = 0; i < columns; i++ ) maxWidths[i] = getWidth( headers[i] ); } - for( TextComponent[] row : table.getRows() ) + for( Component[] row : table.getRows() ) { for( int i = 0; i < row.length; i++ ) { @@ -77,11 +77,11 @@ public interface TableFormatter if( headers != null ) { - StringTextComponent line = new StringTextComponent( "" ); + TextComponent line = new TextComponent( "" ); for( int i = 0; i < columns - 1; i++ ) { line.append( headers[i] ); - TextComponent padding = getPadding( headers[i], maxWidths[i] ); + Component padding = getPadding( headers[i], maxWidths[i] ); if( padding != null ) line.append( padding ); line.append( SEPARATOR ); } @@ -93,16 +93,16 @@ public interface TableFormatter // it a tad prettier. int rowCharWidth = getWidth( HEADER ); int rowWidth = totalWidth / rowCharWidth + (totalWidth % rowCharWidth == 0 ? 0 : 1); - writeLine( rowId++, coloured( StringUtils.repeat( HEADER.getText(), rowWidth ), TextFormat.GRAY ) ); + writeLine( rowId++, coloured( StringUtils.repeat( HEADER.getText(), rowWidth ), ChatFormat.GRAY ) ); } - for( TextComponent[] row : table.getRows() ) + for( Component[] row : table.getRows() ) { - StringTextComponent line = new StringTextComponent( "" ); + TextComponent line = new TextComponent( "" ); for( int i = 0; i < columns - 1; i++ ) { line.append( row[i] ); - TextComponent padding = getPadding( row[i], maxWidths[i] ); + Component padding = getPadding( row[i], maxWidths[i] ); if( padding != null ) line.append( padding ); line.append( SEPARATOR ); } @@ -112,7 +112,7 @@ public interface TableFormatter if( table.getAdditional() > 0 ) { - writeLine( rowId++, coloured( translate( "commands.computercraft.generic.additional_rows", table.getAdditional() ), TextFormat.AQUA ) ); + writeLine( rowId++, coloured( translate( "commands.computercraft.generic.additional_rows", table.getAdditional() ), ChatFormat.AQUA ) ); } return rowId - table.getId(); diff --git a/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java b/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java index fc02a69e4..4d95c0a29 100644 --- a/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java +++ b/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java @@ -6,6 +6,7 @@ package dan200.computercraft.shared.common; +import dan200.computercraft.shared.util.NamedBlockEntityType; import net.minecraft.block.Block; import net.minecraft.block.BlockEntityProvider; import net.minecraft.block.BlockState; @@ -26,10 +27,11 @@ public abstract class BlockGeneric extends Block implements BlockEntityProvider { private final BlockEntityType type; - public BlockGeneric( Settings settings, BlockEntityType type ) + public BlockGeneric( Settings settings, NamedBlockEntityType type ) { super( settings ); this.type = type; + type.setBlock( this ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java index 4757f3e53..db3c55380 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java @@ -9,9 +9,9 @@ package dan200.computercraft.shared.computer.blocks; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerState; import dan200.computercraft.shared.computer.items.ComputerItemFactory; +import dan200.computercraft.shared.util.NamedBlockEntityType; import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntityType; import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemStack; import net.minecraft.state.StateFactory; @@ -28,7 +28,7 @@ public class BlockComputer extends BlockComputerBase public static final EnumProperty STATE = EnumProperty.create( "state", ComputerState.class ); public static final DirectionProperty FACING = Properties.FACING_HORIZONTAL; - public BlockComputer( Settings settings, ComputerFamily family, BlockEntityType type ) + public BlockComputer( Settings settings, ComputerFamily family, NamedBlockEntityType type ) { super( settings, family, type ); setDefaultState( getDefaultState() @@ -40,7 +40,7 @@ public class BlockComputer extends BlockComputerBase @Override protected void appendProperties( StateFactory.Builder builder ) { - builder.with( FACING, STATE ); + builder.add( FACING, STATE ); } @Nullable diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java index 4e90a8da7..518bcdfd9 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java @@ -13,9 +13,9 @@ import dan200.computercraft.shared.common.IBundledRedstoneBlock; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.items.IComputerItem; +import dan200.computercraft.shared.util.NamedBlockEntityType; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; @@ -35,7 +35,7 @@ public abstract class BlockComputerBase extends Bloc private final ComputerFamily family; - protected BlockComputerBase( Settings settings, ComputerFamily family, BlockEntityType type ) + protected BlockComputerBase( Settings settings, ComputerFamily family, NamedBlockEntityType type ) { super( settings, type ); this.family = family; diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java index e0c3c333e..b92844091 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java @@ -13,13 +13,13 @@ import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.util.NamedBlockEntityType; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.CommandOutput; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; -import net.minecraft.text.TranslatableTextComponent; import net.minecraft.util.Identifier; import net.minecraft.util.math.Vec2f; import net.minecraft.util.math.Vec3d; @@ -54,7 +54,7 @@ public class TileCommandComputer extends TileComputer } @Override - public void sendMessage( TextComponent textComponent ) + public void sendMessage( Component textComponent ) { output.put( output.size() + 1, textComponent.getText() ); } @@ -104,7 +104,7 @@ public class TileCommandComputer extends TileComputer return new ServerCommandSource( receiver, new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ), Vec2f.ZERO, (ServerWorld) getWorld(), 2, - name, new StringTextComponent( name ), + name, new TextComponent( name ), getWorld().getServer(), null ); } @@ -123,12 +123,12 @@ public class TileCommandComputer extends TileComputer MinecraftServer server = player.getServer(); if( server == null || !server.areCommandBlocksEnabled() ) { - player.addChatMessage( new TranslatableTextComponent( "advMode.notEnabled" ), true ); + player.addChatMessage( new TranslatableComponent( "advMode.notEnabled" ), true ); return false; } else if( !player.isCreativeLevelTwoOp() ) { - player.addChatMessage( new TranslatableTextComponent( "advMode.notAllowed" ), true ); + player.addChatMessage( new TranslatableComponent( "advMode.notAllowed" ), true ); return false; } else 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 1b04eab58..d7d380c2e 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java @@ -28,8 +28,8 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.nbt.CompoundTag; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; import net.minecraft.util.Hand; import net.minecraft.util.Nameable; import net.minecraft.util.Tickable; @@ -439,9 +439,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT @Nonnull @Override - public TextComponent getName() + public Component getName() { - return hasCustomName() ? new StringTextComponent( m_label ) : getCachedState().getBlock().getTextComponent(); + return hasCustomName() ? new TextComponent( m_label ) : getCachedState().getBlock().getTextComponent(); } @Override @@ -452,8 +452,8 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT @Nullable @Override - public TextComponent getCustomName() + public Component getCustomName() { - return hasCustomName() ? new StringTextComponent( m_label ) : null; + return hasCustomName() ? new TextComponent( m_label ) : null; } } diff --git a/src/main/java/dan200/computercraft/shared/computer/core/ComputerState.java b/src/main/java/dan200/computercraft/shared/computer/core/ComputerState.java index 85f818ebe..a5800094e 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ComputerState.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ComputerState.java @@ -6,11 +6,11 @@ package dan200.computercraft.shared.computer.core; -import net.minecraft.util.StringRepresentable; +import net.minecraft.util.SnakeCaseIdentifiable; import javax.annotation.Nonnull; -public enum ComputerState implements StringRepresentable +public enum ComputerState implements SnakeCaseIdentifiable { OFF( "off" ), ON( "on" ), @@ -25,7 +25,7 @@ public enum ComputerState implements StringRepresentable @Nonnull @Override - public String asString() + public String toSnakeCase() { return name; } diff --git a/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerViewComputer.java b/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerViewComputer.java index 0f714dc0f..b28a7bea2 100644 --- a/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerViewComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerViewComputer.java @@ -10,8 +10,8 @@ import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.computer.core.*; import net.minecraft.container.Container; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.server.MinecraftServer; -import net.minecraft.text.TranslatableTextComponent; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -53,12 +53,12 @@ public class ContainerViewComputer extends Container implements IContainerComput MinecraftServer server = player.getServer(); if( server == null || !server.areCommandBlocksEnabled() ) { - player.addChatMessage( new TranslatableTextComponent( "advMode.notEnabled" ), false ); + player.addChatMessage( new TranslatableComponent( "advMode.notEnabled" ), false ); return false; } else if( !player.isCreativeLevelTwoOp() ) { - player.addChatMessage( new TranslatableTextComponent( "advMode.notAllowed" ), false ); + player.addChatMessage( new TranslatableComponent( "advMode.notAllowed" ), false ); return false; } } diff --git a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java index 11af62c11..3411b4760 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java @@ -9,7 +9,7 @@ package dan200.computercraft.shared.computer.items; import dan200.computercraft.shared.computer.blocks.BlockComputer; import dan200.computercraft.shared.computer.core.ComputerFamily; import net.minecraft.item.ItemStack; -import net.minecraft.text.StringTextComponent; +import net.minecraft.network.chat.TextComponent; import javax.annotation.Nonnull; @@ -24,7 +24,7 @@ public class ItemComputer extends ItemComputerBase { ItemStack result = new ItemStack( this ); if( id >= 0 ) result.getOrCreateTag().putInt( NBT_ID, id ); - if( label != null ) result.setDisplayName( new StringTextComponent( label ) ); + if( label != null ) result.setDisplayName( new TextComponent( label ) ); return result; } diff --git a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java index 155afb352..273647416 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java @@ -12,13 +12,13 @@ import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.media.IMedia; import dan200.computercraft.shared.computer.blocks.BlockComputerBase; import dan200.computercraft.shared.computer.core.ComputerFamily; +import net.minecraft.ChatFormat; import net.minecraft.client.item.TooltipContext; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; -import net.minecraft.text.TextFormat; -import net.minecraft.text.TranslatableTextComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.world.World; import javax.annotation.Nonnull; @@ -36,15 +36,15 @@ public abstract class ItemComputerBase extends BlockItem implements IComputerIte } @Override - public void buildTooltip( @Nonnull ItemStack stack, @Nullable World world, @Nonnull List list, @Nonnull TooltipContext options ) + public void buildTooltip( @Nonnull ItemStack stack, @Nullable World world, @Nonnull List list, @Nonnull TooltipContext options ) { if( options.isAdvanced() ) { int id = getComputerID( stack ); if( id >= 0 ) { - list.add( new TranslatableTextComponent( "gui.computercraft.tooltip.computer_id", id ) - .applyFormat( TextFormat.GRAY ) ); + list.add( new TranslatableComponent( "gui.computercraft.tooltip.computer_id", id ) + .applyFormat( ChatFormat.GRAY ) ); } } } @@ -68,7 +68,7 @@ public abstract class ItemComputerBase extends BlockItem implements IComputerIte { if( label != null ) { - stack.setDisplayName( new StringTextComponent( label ) ); + stack.setDisplayName( new TextComponent( label ) ); } else { diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemDisk.java b/src/main/java/dan200/computercraft/shared/media/items/ItemDisk.java index 521d6436a..10dcb24d3 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemDisk.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemDisk.java @@ -12,15 +12,15 @@ import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.media.IMedia; import dan200.computercraft.shared.common.IColouredItem; import dan200.computercraft.shared.util.Colour; +import net.minecraft.ChatFormat; import net.minecraft.client.item.TooltipContext; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; -import net.minecraft.text.TextFormat; -import net.minecraft.text.TranslatableTextComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.util.DefaultedList; import net.minecraft.world.World; @@ -58,15 +58,15 @@ public class ItemDisk extends Item implements IMedia, IColouredItem } @Override - public void buildTooltip( ItemStack stack, @Nullable World world, List list, TooltipContext options ) + public void buildTooltip( ItemStack stack, @Nullable World world, List list, TooltipContext options ) { if( options.isAdvanced() ) { int id = getDiskID( stack ); if( id >= 0 ) { - list.add( new TranslatableTextComponent( "gui.computercraft.tooltip.disk_id", id ) - .applyFormat( TextFormat.GRAY ) ); + list.add( new TranslatableComponent( "gui.computercraft.tooltip.disk_id", id ) + .applyFormat( ChatFormat.GRAY ) ); } } } @@ -82,7 +82,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem { if( label != null ) { - stack.setDisplayName( new StringTextComponent( label ) ); + stack.setDisplayName( new TextComponent( label ) ); } else { diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java b/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java index a66792539..cba9d1aa6 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java @@ -13,8 +13,8 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; @@ -50,10 +50,10 @@ public class ItemPrintout extends Item } @Override - public void buildTooltip( @Nonnull ItemStack stack, World world, List list, TooltipContext options ) + public void buildTooltip( @Nonnull ItemStack stack, World world, List list, TooltipContext options ) { String title = getTitle( stack ); - if( title != null && !title.isEmpty() ) list.add( new StringTextComponent( title ) ); + if( title != null && !title.isEmpty() ) list.add( new TextComponent( title ) ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java b/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java index 71d28f1bc..c2b84fba4 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java @@ -17,8 +17,8 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; import net.minecraft.util.DefaultedList; import net.minecraft.world.World; @@ -44,10 +44,10 @@ public class ItemTreasureDisk extends Item implements IMedia } @Override - public void buildTooltip( ItemStack stack, @Nullable World world, List list, TooltipContext context ) + public void buildTooltip( ItemStack stack, @Nullable World world, List list, TooltipContext context ) { String label = getTitle( stack ); - if( !label.isEmpty() ) list.add( new StringTextComponent( label ) ); + if( !label.isEmpty() ) list.add( new TextComponent( label ) ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java b/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java index 5f58f2338..d76e0b299 100644 --- a/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java +++ b/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java @@ -14,10 +14,10 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import net.fabricmc.api.EnvType; import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; import net.fabricmc.fabric.api.network.PacketContext; import net.fabricmc.fabric.api.network.ServerSidePacketRegistry; -import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.packet.CustomPayloadS2CPacket; diff --git a/src/main/java/dan200/computercraft/shared/network/client/ChatTableClientMessage.java b/src/main/java/dan200/computercraft/shared/network/client/ChatTableClientMessage.java index d99c7a083..bd0817f50 100644 --- a/src/main/java/dan200/computercraft/shared/network/client/ChatTableClientMessage.java +++ b/src/main/java/dan200/computercraft/shared/network/client/ChatTableClientMessage.java @@ -12,7 +12,7 @@ import dan200.computercraft.shared.network.NetworkMessage; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.network.PacketContext; -import net.minecraft.text.TextComponent; +import net.minecraft.network.chat.Component; import net.minecraft.util.PacketByteBuf; import javax.annotation.Nonnull; @@ -39,13 +39,13 @@ public class ChatTableClientMessage implements NetworkMessage buf.writeBoolean( table.getHeaders() != null ); if( table.getHeaders() != null ) { - for( TextComponent header : table.getHeaders() ) buf.writeTextComponent( header ); + for( Component header : table.getHeaders() ) buf.writeTextComponent( header ); } buf.writeVarInt( table.getRows().size() ); - for( TextComponent[] row : table.getRows() ) + for( Component[] row : table.getRows() ) { - for( TextComponent column : row ) buf.writeTextComponent( column ); + for( Component column : row ) buf.writeTextComponent( column ); } buf.writeVarInt( table.getAdditional() ); @@ -59,7 +59,7 @@ public class ChatTableClientMessage implements NetworkMessage TableBuilder table; if( buf.readBoolean() ) { - TextComponent[] headers = new TextComponent[columns]; + Component[] headers = new Component[columns]; for( int i = 0; i < columns; i++ ) headers[i] = buf.readTextComponent(); table = new TableBuilder( id, headers ); } @@ -71,7 +71,7 @@ public class ChatTableClientMessage implements NetworkMessage int rows = buf.readVarInt(); for( int i = 0; i < rows; i++ ) { - TextComponent[] row = new TextComponent[columns]; + Component[] row = new Component[columns]; for( int j = 0; j < columns; j++ ) row[j] = buf.readTextComponent(); table.row( row ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/BlockDiskDrive.java b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/BlockDiskDrive.java index 8825d5151..18946c288 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/BlockDiskDrive.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/BlockDiskDrive.java @@ -39,7 +39,7 @@ public class BlockDiskDrive extends BlockGeneric @Override protected void appendProperties( StateFactory.Builder properties ) { - properties.with( FACING, STATE ); + properties.add( FACING, STATE ); } @Nullable diff --git a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDriveState.java b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDriveState.java index 80c6a0328..38c170d38 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDriveState.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDriveState.java @@ -6,9 +6,9 @@ package dan200.computercraft.shared.peripheral.diskdrive; -import net.minecraft.util.StringRepresentable; +import net.minecraft.util.SnakeCaseIdentifiable; -public enum DiskDriveState implements StringRepresentable +public enum DiskDriveState implements SnakeCaseIdentifiable { EMPTY( "empty" ), FULL( "full" ), @@ -23,7 +23,7 @@ public enum DiskDriveState implements StringRepresentable @Override - public String asString() + public String toSnakeCase() { return name; } 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 be871eb75..ea636823a 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java @@ -26,8 +26,9 @@ import net.minecraft.entity.ItemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; import net.minecraft.sound.SoundEvent; -import net.minecraft.text.TextComponent; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import net.minecraft.util.Nameable; @@ -59,7 +60,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory String mountPath; } - TextComponent customName; + Component customName; private final Map m_computers = new HashMap<>(); @@ -542,14 +543,14 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory @Nullable @Override - public TextComponent getCustomName() + public Component getCustomName() { return customName; } @Nonnull @Override - public TextComponent getName() + public Component getName() { return customName != null ? customName : getCachedState().getBlock().getTextComponent(); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockCable.java index 5449f14a2..49e13e08f 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockCable.java @@ -18,8 +18,8 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.EntityContext; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.VerticalEntityPosition; import net.minecraft.fluid.FluidState; import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemStack; @@ -75,7 +75,7 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock @Override protected void appendProperties( StateFactory.Builder builder ) { - builder.with( MODEM, CABLE, NORTH, SOUTH, EAST, WEST, UP, DOWN, WATERLOGGED ); + builder.add( MODEM, CABLE, NORTH, SOUTH, EAST, WEST, UP, DOWN, WATERLOGGED ); } public static boolean canConnectIn( BlockState state, Direction direction ) @@ -92,7 +92,7 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock @Override @Deprecated - public VoxelShape getOutlineShape( BlockState state, BlockView world, BlockPos pos, VerticalEntityPosition position ) + public VoxelShape getOutlineShape( BlockState state, BlockView world, BlockPos pos, EntityContext position ) { return CableShapes.getShape( state ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockWiredModemFull.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockWiredModemFull.java index 85b636093..d290a08d0 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockWiredModemFull.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockWiredModemFull.java @@ -29,6 +29,6 @@ public class BlockWiredModemFull extends BlockGeneric @Override protected void appendProperties( StateFactory.Builder builder ) { - builder.with( MODEM_ON, PERIPHERAL_ON ); + builder.add( MODEM_ON, PERIPHERAL_ON ); } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableModemVariant.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableModemVariant.java index d4539bd36..e320a605a 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableModemVariant.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableModemVariant.java @@ -6,12 +6,12 @@ package dan200.computercraft.shared.peripheral.modem.wired; -import net.minecraft.util.StringRepresentable; +import net.minecraft.util.SnakeCaseIdentifiable; import net.minecraft.util.math.Direction; import javax.annotation.Nonnull; -public enum CableModemVariant implements StringRepresentable +public enum CableModemVariant implements SnakeCaseIdentifiable { None( "none", null ), DownOff( "down_off", Direction.DOWN ), @@ -65,7 +65,7 @@ public enum CableModemVariant implements StringRepresentable @Nonnull @Override - public String asString() + public String toSnakeCase() { return name; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/ItemBlockCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/ItemBlockCable.java index 0639f0e72..cc48eac6a 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/ItemBlockCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/ItemBlockCable.java @@ -9,11 +9,7 @@ package dan200.computercraft.shared.peripheral.modem.wired; import dan200.computercraft.ComputerCraft; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.item.ItemStack; -import net.minecraft.item.BlockItem; +import net.minecraft.item.*; import net.minecraft.sound.BlockSoundGroup; import net.minecraft.sound.SoundCategory; import net.minecraft.util.ActionResult; 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 19a4ad6ec..01cd25017 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 @@ -24,7 +24,7 @@ import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; -import net.minecraft.text.TranslatableTextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import net.minecraft.util.hit.BlockHitResult; @@ -238,12 +238,12 @@ public class TileCable extends TileGeneric implements IPeripheralTile { if( oldName != null ) { - player.addChatMessage( new TranslatableTextComponent( "chat.computercraft.wired_modem.peripheral_disconnected", + player.addChatMessage( new TranslatableComponent( "chat.computercraft.wired_modem.peripheral_disconnected", CommandCopy.createCopyText( oldName ) ), false ); } if( newName != null ) { - player.addChatMessage( new TranslatableTextComponent( "chat.computercraft.wired_modem.peripheral_connected", + player.addChatMessage( new TranslatableComponent( "chat.computercraft.wired_modem.peripheral_connected", CommandCopy.createCopyText( newName ) ), false ); } } 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 e4b597422..e909cfa8f 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 @@ -22,8 +22,8 @@ import dan200.computercraft.shared.util.TickScheduler; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundTag; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TranslatableTextComponent; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import net.minecraft.util.hit.BlockHitResult; @@ -194,14 +194,14 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile List names = new ArrayList<>( peripherals ); names.sort( Comparator.naturalOrder() ); - StringTextComponent base = new StringTextComponent( "" ); + TextComponent base = new TextComponent( "" ); for( int i = 0; i < names.size(); i++ ) { if( i > 0 ) base.append( ", " ); base.append( CommandCopy.createCopyText( names.get( i ) ) ); } - player.addChatMessage( new TranslatableTextComponent( kind, base ), false ); + player.addChatMessage( new TranslatableComponent( kind, base ), false ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/BlockWirelessModem.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/BlockWirelessModem.java index e6790bdec..ee21d44d4 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/BlockWirelessModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/BlockWirelessModem.java @@ -8,11 +8,11 @@ package dan200.computercraft.shared.peripheral.modem.wireless; import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.peripheral.modem.ModemShapes; +import dan200.computercraft.shared.util.NamedBlockEntityType; import dan200.computercraft.shared.util.WaterloggableBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.entity.VerticalEntityPosition; +import net.minecraft.entity.EntityContext; import net.minecraft.fluid.FluidState; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateFactory; @@ -34,7 +34,7 @@ public class BlockWirelessModem extends BlockGeneric implements WaterloggableBlo public static final DirectionProperty FACING = Properties.FACING; public static final BooleanProperty ON = BooleanProperty.create( "on" ); - public BlockWirelessModem( Settings settings, BlockEntityType type ) + public BlockWirelessModem( Settings settings, NamedBlockEntityType type ) { super( settings, type ); setDefaultState( getStateFactory().getDefaultState() @@ -46,13 +46,13 @@ public class BlockWirelessModem extends BlockGeneric implements WaterloggableBlo @Override protected void appendProperties( StateFactory.Builder builder ) { - builder.with( FACING, ON, WATERLOGGED ); + builder.add( FACING, ON, WATERLOGGED ); } @Nonnull @Override @Deprecated - public VoxelShape getOutlineShape( BlockState blockState, BlockView world, BlockPos pos, VerticalEntityPosition position ) + public VoxelShape getOutlineShape( BlockState blockState, BlockView world, BlockPos pos, EntityContext position ) { return ModemShapes.getBounds( blockState.get( FACING ) ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java index 83bd1c467..c914eb391 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java @@ -8,11 +8,11 @@ package dan200.computercraft.shared.peripheral.monitor; import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.common.TileGeneric; +import dan200.computercraft.shared.util.NamedBlockEntityType; import net.minecraft.block.Block; import net.minecraft.block.BlockRenderLayer; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemStack; @@ -35,7 +35,7 @@ public class BlockMonitor extends BlockGeneric static final EnumProperty STATE = EnumProperty.create( "state", MonitorEdgeState.class ); - public BlockMonitor( Settings settings, BlockEntityType type ) + public BlockMonitor( Settings settings, NamedBlockEntityType type ) { super( settings, type ); setDefaultState( getStateFactory().getDefaultState() @@ -53,7 +53,7 @@ public class BlockMonitor extends BlockGeneric @Override protected void appendProperties( StateFactory.Builder builder ) { - builder.with( ORIENTATION, FACING, STATE ); + builder.add( ORIENTATION, FACING, STATE ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorEdgeState.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorEdgeState.java index 68a007139..d71ee72e5 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorEdgeState.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorEdgeState.java @@ -6,13 +6,13 @@ package dan200.computercraft.shared.peripheral.monitor; -import net.minecraft.util.StringRepresentable; +import net.minecraft.util.SnakeCaseIdentifiable; import javax.annotation.Nonnull; import static dan200.computercraft.shared.peripheral.monitor.MonitorEdgeState.Flags.*; -public enum MonitorEdgeState implements StringRepresentable +public enum MonitorEdgeState implements SnakeCaseIdentifiable { NONE( "none", 0 ), @@ -60,7 +60,7 @@ public enum MonitorEdgeState implements StringRepresentable @Nonnull @Override - public String asString() + public String toSnakeCase() { return name; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/printer/BlockPrinter.java b/src/main/java/dan200/computercraft/shared/peripheral/printer/BlockPrinter.java index 522828191..b9365c445 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/printer/BlockPrinter.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/printer/BlockPrinter.java @@ -42,7 +42,7 @@ public class BlockPrinter extends BlockGeneric protected void appendProperties( StateFactory.Builder properties ) { super.appendProperties( properties ); - properties.with( FACING, TOP, BOTTOM ); + properties.add( FACING, TOP, BOTTOM ); } @Nullable 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 29ffa2038..f73efb78a 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java @@ -22,7 +22,8 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.nbt.CompoundTag; -import net.minecraft.text.TextComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; import net.minecraft.util.*; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; @@ -51,7 +52,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent private static final int[] TOP_SLOTS = new int[] { 1, 2, 3, 4, 5, 6 }; private static final int[] SIDE_SLOTS = new int[] { 0 }; - TextComponent customName; + Component customName; private final DefaultedList m_inventory = DefaultedList.create( INVENTORY_SIZE, ItemStack.EMPTY ); private final ItemStorage m_itemHandlerAll = ItemStorage.wrap( this ); @@ -528,14 +529,14 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent @Nullable @Override - public TextComponent getCustomName() + public Component getCustomName() { return customName; } @Nonnull @Override - public TextComponent getName() + public Component getName() { return customName != null ? customName : getCachedState().getBlock().getTextComponent(); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/speaker/BlockSpeaker.java b/src/main/java/dan200/computercraft/shared/peripheral/speaker/BlockSpeaker.java index 9094596ef..6721a6e66 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/speaker/BlockSpeaker.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/speaker/BlockSpeaker.java @@ -31,7 +31,7 @@ public class BlockSpeaker extends BlockGeneric @Override protected void appendProperties( StateFactory.Builder properties ) { - properties.with( FACING ); + properties.add( FACING ); } @Nullable diff --git a/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java index 38c6d16a6..f85e6188f 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java @@ -106,7 +106,7 @@ public abstract class SpeakerPeripheral implements IPeripheral Instrument instrument = null; for( Instrument testInstrument : Instrument.values() ) { - if( testInstrument.asString().equalsIgnoreCase( name ) ) + if( testInstrument.toSnakeCase().equalsIgnoreCase( name ) ) { instrument = testInstrument; break; 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 67a804430..cbf065081 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java @@ -25,6 +25,7 @@ import dan200.computercraft.shared.pocket.apis.PocketAPI; import dan200.computercraft.shared.pocket.core.PocketServerComputer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.ChatFormat; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; @@ -34,10 +35,9 @@ import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemPropertyGetter; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; -import net.minecraft.text.TextFormat; -import net.minecraft.text.TranslatableTextComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.util.*; import net.minecraft.world.World; @@ -68,7 +68,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I { ItemStack result = new ItemStack( this ); if( id >= 0 ) result.getOrCreateTag().putInt( NBT_ID, id ); - if( label != null ) result.setDisplayName( new StringTextComponent( label ) ); + if( label != null ) result.setDisplayName( new TextComponent( label ) ); if( upgrade != null ) result.getOrCreateTag().putString( NBT_UPGRADE, upgrade.getUpgradeID().toString() ); if( colour != -1 ) result.getOrCreateTag().putInt( NBT_COLOUR, colour ); return result; @@ -161,14 +161,14 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I @Nonnull @Override - public TextComponent getTranslatedNameTrimmed( @Nonnull ItemStack stack ) + public Component getTranslatedNameTrimmed( @Nonnull ItemStack stack ) { String baseString = getTranslationKey( stack ); IPocketUpgrade upgrade = getUpgrade( stack ); if( upgrade != null ) { - return new TranslatableTextComponent( baseString + ".upgraded", - new TranslatableTextComponent( upgrade.getUnlocalisedAdjective() ) + return new TranslatableComponent( baseString + ".upgraded", + new TranslatableComponent( upgrade.getUnlocalisedAdjective() ) ); } else @@ -179,15 +179,15 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I @Override - public void buildTooltip( ItemStack stack, @Nullable World world, List list, TooltipContext flag ) + public void buildTooltip( ItemStack stack, @Nullable World world, List list, TooltipContext flag ) { if( flag.isAdvanced() ) { int id = getComputerID( stack ); if( id >= 0 ) { - list.add( new TranslatableTextComponent( "gui.computercraft.tooltip.computer_id", id ) - .applyFormat( TextFormat.GRAY ) ); + list.add( new TranslatableComponent( "gui.computercraft.tooltip.computer_id", id ) + .applyFormat( ChatFormat.GRAY ) ); } } } @@ -297,7 +297,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I { if( label != null ) { - stack.setDisplayName( new StringTextComponent( label ) ); + stack.setDisplayName( new TextComponent( label ) ); } else { diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java index 0daccefa1..aee10a89f 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java @@ -13,14 +13,14 @@ import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.turtle.core.TurtleBrain; import dan200.computercraft.shared.turtle.items.ITurtleItem; import dan200.computercraft.shared.turtle.items.TurtleItemFactory; +import dan200.computercraft.shared.util.NamedBlockEntityType; import dan200.computercraft.shared.util.WaterloggableBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.entity.EntityContext; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.VerticalEntityPosition; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.fluid.FluidState; import net.minecraft.item.ItemPlacementContext; @@ -50,7 +50,7 @@ public class BlockTurtle extends BlockComputerBase implements Waterl 0.875, 0.875, 0.875 ); - public BlockTurtle( Settings settings, ComputerFamily family, BlockEntityType type ) + public BlockTurtle( Settings settings, ComputerFamily family, NamedBlockEntityType type ) { super( settings, family, type ); setDefaultState( getStateFactory().getDefaultState() @@ -62,7 +62,7 @@ public class BlockTurtle extends BlockComputerBase implements Waterl @Override protected void appendProperties( StateFactory.Builder builder ) { - builder.with( FACING, WATERLOGGED ); + builder.add( FACING, WATERLOGGED ); } @Nonnull @@ -76,7 +76,7 @@ public class BlockTurtle extends BlockComputerBase implements Waterl @Nonnull @Override @Deprecated - public VoxelShape getOutlineShape( BlockState state, BlockView world, BlockPos pos, VerticalEntityPosition position ) + public VoxelShape getOutlineShape( BlockState state, BlockView world, BlockPos pos, EntityContext position ) { BlockEntity tile = world.getBlockEntity( pos ); Vec3d offset = tile instanceof TileTurtle ? ((TileTurtle) tile).getRenderOffset( 1.0f ) : Vec3d.ZERO; diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java index 9f4dd41c0..4138aeba0 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java @@ -60,7 +60,7 @@ public class TurtleCompareCommand implements ITurtleCommand { for( ItemStack drop : drops ) { - if( drop.getItem() == lookAtBlock.getItem() ) + if( drop.getItem() == lookAtBlock.asItem() ) { lookAtStack = drop; break; diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java index 9971f83cd..726423bd6 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java @@ -22,7 +22,7 @@ import net.minecraft.block.entity.SignBlockEntity; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.item.*; -import net.minecraft.text.StringTextComponent; +import net.minecraft.network.chat.TextComponent; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; @@ -228,10 +228,10 @@ public class TurtlePlaceCommand implements ITurtleCommand // Place on the entity boolean placed = false; - ActionResult cancelResult = null; // ForgeHooks.onInteractEntityAt( turtlePlayer, hitEntity, hitPos, Hand.MAIN ); + ActionResult cancelResult = null; // ForgeHooks.onInteractEntityAt( turtlePlayer, hitEntity, hitPos, Hand.MAIN_HAND); if( cancelResult == null ) { - cancelResult = hitEntity.interactAt( turtlePlayer, hitPos, Hand.MAIN ); + cancelResult = hitEntity.interactAt( turtlePlayer, hitPos, Hand.MAIN_HAND ); } if( cancelResult == ActionResult.SUCCESS ) @@ -241,20 +241,20 @@ public class TurtlePlaceCommand implements ITurtleCommand else { // See PlayerEntity.interactOn - // cancelResult = ForgeHooks.onInteractEntity( turtlePlayer, hitEntity, Hand.MAIN ); + // cancelResult = ForgeHooks.onInteractEntity( turtlePlayer, hitEntity, Hand.MAIN_HAND); if( cancelResult == ActionResult.SUCCESS ) { placed = true; } else if( cancelResult == null ) { - if( hitEntity.interact( turtlePlayer, Hand.MAIN ) ) + if( hitEntity.interact( turtlePlayer, Hand.MAIN_HAND ) ) { placed = true; } else if( hitEntity instanceof LivingEntity ) { - placed = stackCopy.interactWithEntity( turtlePlayer, (LivingEntity) hitEntity, Hand.MAIN ); + placed = stackCopy.interactWithEntity( turtlePlayer, (LivingEntity) hitEntity, Hand.MAIN_HAND ); if( placed ) turtlePlayer.loadInventory( stackCopy ); } } @@ -336,7 +336,7 @@ public class TurtlePlaceCommand implements ITurtleCommand } // Check if there's something suitable to place onto - ItemUsageContext context = new ItemUsageContext( turtlePlayer, Hand.MAIN, new BlockHitResult( new Vec3d( hitX, hitY, hitZ ), side, position, false ) ); + ItemUsageContext context = new ItemUsageContext( turtlePlayer, Hand.MAIN_HAND, new BlockHitResult( new Vec3d( hitX, hitY, hitZ ), side, position, false ) ); if( !canDeployOnBlock( new ItemPlacementContext( context ), turtle, turtlePlayer, position, side, allowReplace, outErrorMessage ) ) { return stack; @@ -354,7 +354,7 @@ public class TurtlePlaceCommand implements ITurtleCommand PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock( turtlePlayer, Hand.MAIN, position, side, new Vec3d( hitX, hitY, hitZ ) ); if( !event.isCanceled() ) */ { - /* if( item.onItemUseFirst( turtlePlayer, turtle.getWorld(), position, side, hitX, hitY, hitZ, Hand.MAIN ) == ActionResult.SUCCESS ) + /* if( item.onItemUseFirst( turtlePlayer, turtle.getWorld(), position, side, hitX, hitY, hitZ, Hand.MAIN_HAND) == ActionResult.SUCCESS ) { placed = true; turtlePlayer.loadInventory( stackCopy ); @@ -370,14 +370,14 @@ public class TurtlePlaceCommand implements ITurtleCommand if( !placed && (item instanceof BucketItem || item instanceof BoatItem || item instanceof LilyPadItem || item instanceof GlassBottleItem) ) { - ActionResult actionResult = null; // ForgeHooks.onItemRightClick( turtlePlayer, Hand.MAIN ); + ActionResult actionResult = null; // ForgeHooks.onItemRightClick( turtlePlayer, Hand.MAIN_HAND); if( actionResult == ActionResult.SUCCESS ) { placed = true; } else if( actionResult == null ) { - TypedActionResult result = stackCopy.use( turtle.getWorld(), turtlePlayer, Hand.MAIN ); + TypedActionResult result = stackCopy.use( turtle.getWorld(), turtlePlayer, Hand.MAIN_HAND ); if( result.getResult() == ActionResult.SUCCESS && !ItemStack.areEqual( stack, result.getValue() ) ) { placed = true; @@ -409,16 +409,16 @@ public class TurtlePlaceCommand implements ITurtleCommand { if( split[i - firstLine].length() > 15 ) { - signTile.text[i] = new StringTextComponent( split[i - firstLine].substring( 0, 15 ) ); + signTile.text[i] = new TextComponent( split[i - firstLine].substring( 0, 15 ) ); } else { - signTile.text[i] = new StringTextComponent( split[i - firstLine] ); + signTile.text[i] = new TextComponent( split[i - firstLine] ); } } else { - signTile.text[i] = new StringTextComponent( "" ); + signTile.text[i] = new TextComponent( "" ); } } signTile.markDirty(); diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtle.java index df517b8b0..19d35f567 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtle.java @@ -16,9 +16,9 @@ import dan200.computercraft.shared.turtle.blocks.BlockTurtle; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextComponent; -import net.minecraft.text.TranslatableTextComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.util.DefaultedList; import net.minecraft.util.Identifier; @@ -37,7 +37,7 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem { // Build the stack ItemStack stack = new ItemStack( this ); - if( label != null ) stack.setDisplayName( new StringTextComponent( label ) ); + if( label != null ) stack.setDisplayName( new TextComponent( label ) ); if( id >= 0 ) stack.getOrCreateTag().putInt( NBT_ID, id ); IColouredItem.setColourBasic( stack, colour ); if( fuelLevel > 0 ) stack.getOrCreateTag().putInt( NBT_FUEL, fuelLevel ); @@ -74,33 +74,33 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem @Nonnull @Override - public TextComponent getTranslatedNameTrimmed( @Nonnull ItemStack stack ) + public Component getTranslatedNameTrimmed( @Nonnull ItemStack stack ) { String baseString = getTranslationKey( stack ); ITurtleUpgrade left = getUpgrade( stack, TurtleSide.Left ); ITurtleUpgrade right = getUpgrade( stack, TurtleSide.Right ); if( left != null && right != null ) { - return new TranslatableTextComponent( baseString + ".upgraded_twice", - new TranslatableTextComponent( right.getUnlocalisedAdjective() ), - new TranslatableTextComponent( left.getUnlocalisedAdjective() ) + return new TranslatableComponent( baseString + ".upgraded_twice", + new TranslatableComponent( right.getUnlocalisedAdjective() ), + new TranslatableComponent( left.getUnlocalisedAdjective() ) ); } else if( left != null ) { - return new TranslatableTextComponent( baseString + ".upgraded", - new TranslatableTextComponent( left.getUnlocalisedAdjective() ) + return new TranslatableComponent( baseString + ".upgraded", + new TranslatableComponent( left.getUnlocalisedAdjective() ) ); } else if( right != null ) { - return new TranslatableTextComponent( baseString + ".upgraded", - new TranslatableTextComponent( right.getUnlocalisedAdjective() ) + return new TranslatableComponent( baseString + ".upgraded", + new TranslatableComponent( right.getUnlocalisedAdjective() ) ); } else { - return new TranslatableTextComponent( baseString ); + return new TranslatableComponent( baseString ); } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java index e47255504..4925bb659 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java @@ -130,7 +130,7 @@ public class TurtleTool extends AbstractTurtleUpgrade Entity hitEntity = hit.getKey(); // Fire several events to ensure we have permissions. - if( AttackEntityCallback.EVENT.invoker().interact( turtlePlayer, world, Hand.MAIN, hitEntity, null ) == ActionResult.FAIL + if( AttackEntityCallback.EVENT.invoker().interact( turtlePlayer, world, Hand.MAIN_HAND, hitEntity, null ) == ActionResult.FAIL || !hitEntity.canPlayerAttack() ) { return TurtleCommandResult.failure( "Nothing to attack here" ); diff --git a/src/main/java/dan200/computercraft/shared/util/ItemStorage.java b/src/main/java/dan200/computercraft/shared/util/ItemStorage.java index 0f99c4289..d6f03d5ef 100644 --- a/src/main/java/dan200/computercraft/shared/util/ItemStorage.java +++ b/src/main/java/dan200/computercraft/shared/util/ItemStorage.java @@ -6,7 +6,6 @@ package dan200.computercraft.shared.util; -import dan200.computercraft.ComputerCraft; import net.minecraft.inventory.Inventory; import net.minecraft.inventory.SidedInventory; import net.minecraft.item.ItemStack; diff --git a/src/main/java/dan200/computercraft/shared/util/NamedBlockEntityType.java b/src/main/java/dan200/computercraft/shared/util/NamedBlockEntityType.java index 95979406a..f2d7dadeb 100644 --- a/src/main/java/dan200/computercraft/shared/util/NamedBlockEntityType.java +++ b/src/main/java/dan200/computercraft/shared/util/NamedBlockEntityType.java @@ -10,6 +10,7 @@ import com.mojang.datafixers.DataFixUtils; import com.mojang.datafixers.types.Type; import dan200.computercraft.ComputerCraft; import net.minecraft.SharedConstants; +import net.minecraft.block.Block; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.datafixers.Schemas; @@ -17,16 +18,20 @@ import net.minecraft.datafixers.TypeReferences; import net.minecraft.util.Identifier; import net.minecraft.util.registry.MutableRegistry; +import javax.annotation.Nonnull; +import java.util.Collections; +import java.util.Objects; import java.util.function.Function; import java.util.function.Supplier; -public class NamedBlockEntityType extends BlockEntityType +public final class NamedBlockEntityType extends BlockEntityType { private final Identifier identifier; + private Block block; private NamedBlockEntityType( Identifier identifier, Supplier supplier ) { - super( supplier, getDatafixer( identifier ) ); + super( supplier, Collections.emptySet(), getDatafixer( identifier ) ); this.identifier = identifier; } @@ -45,6 +50,18 @@ public class NamedBlockEntityType extends BlockEntityType return identifier; } + @Override + public boolean method_20526( Block block ) + { + return block == this.block; + } + + public void setBlock( @Nonnull Block block ) + { + if( this.block != null ) throw new IllegalStateException( "Cannot override block" ); + this.block = Objects.requireNonNull( block, "block cannot be null" ); + } + public void register( MutableRegistry> registry ) { registry.add( getId(), this ); @@ -66,14 +83,14 @@ public class NamedBlockEntityType extends BlockEntityType } } - private static class FixedPointSupplier implements Supplier + private static final class FixedPointSupplier implements Supplier { final NamedBlockEntityType factory; private final Function, ? extends T> builder; private FixedPointSupplier( Identifier identifier, Function, ? extends T> builder ) { - this.factory = create( identifier, this ); + factory = create( identifier, this ); this.builder = builder; } diff --git a/src/main/java/dan200/computercraft/shared/util/RecordUtil.java b/src/main/java/dan200/computercraft/shared/util/RecordUtil.java index 0e36d2fb8..7fc3ab85d 100644 --- a/src/main/java/dan200/computercraft/shared/util/RecordUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/RecordUtil.java @@ -12,8 +12,8 @@ import dan200.computercraft.shared.network.client.PlayRecordClientMessage; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.MusicDiscItem; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.sound.SoundEvent; -import net.minecraft.text.TranslatableTextComponent; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -35,6 +35,6 @@ public final class RecordUtil Item item = recordStack.getItem(); if( !(item instanceof MusicDiscItem) ) return null; - return new TranslatableTextComponent( item.getTranslationKey() + ".desc" ).getString(); + return new TranslatableComponent( item.getTranslationKey() + ".desc" ).getString(); } } diff --git a/src/test/java/dan200/computercraft/core/filesystem/ResourceMountTest.java b/src/test/java/dan200/computercraft/core/filesystem/ResourceMountTest.java index 78af4f31d..1910b7be8 100644 --- a/src/test/java/dan200/computercraft/core/filesystem/ResourceMountTest.java +++ b/src/test/java/dan200/computercraft/core/filesystem/ResourceMountTest.java @@ -29,7 +29,7 @@ public class ResourceMountTest @BeforeEach public void before() { - ReloadableResourceManagerImpl manager = new ReloadableResourceManagerImpl( ResourceType.DATA, null ); + ReloadableResourceManagerImpl manager = new ReloadableResourceManagerImpl( ResourceType.SERVER_DATA, null ); manager.addPack( new DirectoryResourcePack( new File( "src/main/resources" ) ) ); mount = new ResourceMount( "computercraft", "lua/rom", manager );