mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-07-06 12:02:52 +00:00
Make the main mod non-null by default
This was actually much more work than I thought it would be. Tests pass, but I'm sure there's some regressions in here.
This commit is contained in:
parent
34c7fcf750
commit
b36b96e0bc
@ -152,7 +152,9 @@ configurations {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
minecraft("net.minecraftforge:forge:$mcVersion-${libs.versions.forge.get()}")
|
minecraft("net.minecraftforge:forge:$mcVersion-${libs.versions.forge.get()}")
|
||||||
annotationProcessor("org.spongepowered:mixin:0.8.5:processor")
|
annotationProcessor("org.spongepowered:mixin:0.8.5-SQUID:processor")
|
||||||
|
|
||||||
|
errorprone(project(":lints"))
|
||||||
|
|
||||||
compileOnly(libs.jetbrainsAnnotations)
|
compileOnly(libs.jetbrainsAnnotations)
|
||||||
annotationProcessorEverywhere(libs.autoService)
|
annotationProcessorEverywhere(libs.autoService)
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
import net.ltgt.gradle.errorprone.CheckSeverity
|
|
||||||
import net.ltgt.gradle.errorprone.errorprone
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
java
|
|
||||||
id("net.ltgt.errorprone")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
val libs = project.extensions.getByType<VersionCatalogsExtension>().named("libs")
|
|
||||||
errorprone(libs.findLibrary("errorProne-core").get())
|
|
||||||
errorprone(libs.findLibrary("nullAway").get())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure default JavaCompile tasks with our arguments.
|
|
||||||
sourceSets.all {
|
|
||||||
tasks.named(compileJavaTaskName, JavaCompile::class.java) {
|
|
||||||
options.errorprone {
|
|
||||||
check("InvalidBlockTag", CheckSeverity.OFF) // Broken by @cc.xyz
|
|
||||||
check("InvalidParam", CheckSeverity.OFF) // Broken by records.
|
|
||||||
check("InlineMeSuggester", CheckSeverity.OFF) // Minecraft uses @Deprecated liberally
|
|
||||||
// Too many false positives right now. Maybe we need an indirection for it later on.
|
|
||||||
check("ReferenceEquality",CheckSeverity.OFF)
|
|
||||||
check("UnusedVariable", CheckSeverity.OFF) // Too many false positives with records.
|
|
||||||
check("OperatorPrecedence", CheckSeverity.OFF) // For now.
|
|
||||||
check("AlreadyChecked", CheckSeverity.OFF) // Seems to be broken?
|
|
||||||
check("NonOverridingEquals", CheckSeverity.OFF) // Peripheral.equals makes this hard to avoid
|
|
||||||
check("FutureReturnValueIgnored", CheckSeverity.OFF) // Too many false positives with Netty
|
|
||||||
|
|
||||||
check("NullAway", CheckSeverity.ERROR)
|
|
||||||
option("NullAway:AnnotatedPackages", listOf("dan200.computercraft").joinToString(","))
|
|
||||||
option("NullAway:ExcludedFieldAnnotations", listOf("org.spongepowered.asm.mixin.Shadow").joinToString(","))
|
|
||||||
option("NullAway:CastToNonNullMethod", "dan200.computercraft.core.util.Nullability.assertNonNull")
|
|
||||||
option("NullAway:CheckOptionalEmptiness")
|
|
||||||
option("NullAway:AcknowledgeRestrictiveAnnotations")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.compileTestJava {
|
|
||||||
options.errorprone {
|
|
||||||
check("NullAway", CheckSeverity.OFF)
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,7 +7,6 @@ import cc.tweaked.gradle.MinecraftConfigurations
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("cc-tweaked.java-convention")
|
id("cc-tweaked.java-convention")
|
||||||
id("cc-tweaked.errorprone")
|
|
||||||
id("net.minecraftforge.gradle")
|
id("net.minecraftforge.gradle")
|
||||||
id("org.parchmentmc.librarian.forgegradle")
|
id("org.parchmentmc.librarian.forgegradle")
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ import cc.tweaked.gradle.CCTweakedPlugin
|
|||||||
import cc.tweaked.gradle.LicenseHeader
|
import cc.tweaked.gradle.LicenseHeader
|
||||||
import com.diffplug.gradle.spotless.FormatExtension
|
import com.diffplug.gradle.spotless.FormatExtension
|
||||||
import com.diffplug.spotless.LineEnding
|
import com.diffplug.spotless.LineEnding
|
||||||
|
import net.ltgt.gradle.errorprone.CheckSeverity
|
||||||
|
import net.ltgt.gradle.errorprone.errorprone
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
@ -10,6 +12,7 @@ plugins {
|
|||||||
jacoco
|
jacoco
|
||||||
checkstyle
|
checkstyle
|
||||||
id("com.diffplug.spotless")
|
id("com.diffplug.spotless")
|
||||||
|
id("net.ltgt.errorprone")
|
||||||
}
|
}
|
||||||
|
|
||||||
val modVersion: String by extra
|
val modVersion: String by extra
|
||||||
@ -43,6 +46,8 @@ repositories {
|
|||||||
includeGroup("commoble.morered")
|
includeGroup("commoble.morered")
|
||||||
includeGroup("maven.modrinth")
|
includeGroup("maven.modrinth")
|
||||||
includeGroup("mezz.jei")
|
includeGroup("mezz.jei")
|
||||||
|
// Until https://github.com/SpongePowered/Mixin/pull/593 is merged
|
||||||
|
includeModule("org.spongepowered", "mixin")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,6 +55,9 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
val libs = project.extensions.getByType<VersionCatalogsExtension>().named("libs")
|
val libs = project.extensions.getByType<VersionCatalogsExtension>().named("libs")
|
||||||
checkstyle(libs.findLibrary("checkstyle").get())
|
checkstyle(libs.findLibrary("checkstyle").get())
|
||||||
|
|
||||||
|
errorprone(libs.findLibrary("errorProne-core").get())
|
||||||
|
errorprone(libs.findLibrary("nullAway").get())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure default JavaCompile tasks with our arguments.
|
// Configure default JavaCompile tasks with our arguments.
|
||||||
@ -57,9 +65,36 @@ sourceSets.all {
|
|||||||
tasks.named(compileJavaTaskName, JavaCompile::class.java) {
|
tasks.named(compileJavaTaskName, JavaCompile::class.java) {
|
||||||
// Processing just gives us "No processor claimed any of these annotations", so skip that!
|
// Processing just gives us "No processor claimed any of these annotations", so skip that!
|
||||||
options.compilerArgs.addAll(listOf("-Xlint", "-Xlint:-processing"))
|
options.compilerArgs.addAll(listOf("-Xlint", "-Xlint:-processing"))
|
||||||
|
|
||||||
|
options.errorprone {
|
||||||
|
check("InvalidBlockTag", CheckSeverity.OFF) // Broken by @cc.xyz
|
||||||
|
check("InvalidParam", CheckSeverity.OFF) // Broken by records.
|
||||||
|
check("InlineMeSuggester", CheckSeverity.OFF) // Minecraft uses @Deprecated liberally
|
||||||
|
// Too many false positives right now. Maybe we need an indirection for it later on.
|
||||||
|
check("ReferenceEquality", CheckSeverity.OFF)
|
||||||
|
check("UnusedVariable", CheckSeverity.OFF) // Too many false positives with records.
|
||||||
|
check("OperatorPrecedence", CheckSeverity.OFF) // For now.
|
||||||
|
check("AlreadyChecked", CheckSeverity.OFF) // Seems to be broken?
|
||||||
|
check("NonOverridingEquals", CheckSeverity.OFF) // Peripheral.equals makes this hard to avoid
|
||||||
|
check("FutureReturnValueIgnored", CheckSeverity.OFF) // Too many false positives with Netty
|
||||||
|
|
||||||
|
check("NullAway", CheckSeverity.ERROR)
|
||||||
|
option("NullAway:AnnotatedPackages", listOf("dan200.computercraft").joinToString(","))
|
||||||
|
option("NullAway:ExcludedFieldAnnotations", listOf("org.spongepowered.asm.mixin.Shadow").joinToString(","))
|
||||||
|
option("NullAway:CastToNonNullMethod", "dan200.computercraft.core.util.Nullability.assertNonNull")
|
||||||
|
option("NullAway:CheckOptionalEmptiness")
|
||||||
|
option("NullAway:AcknowledgeRestrictiveAnnotations")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.compileTestJava {
|
||||||
|
options.errorprone {
|
||||||
|
check("NullAway", CheckSeverity.OFF)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
tasks.withType(JavaCompile::class.java).configureEach {
|
tasks.withType(JavaCompile::class.java).configureEach {
|
||||||
options.encoding = "UTF-8"
|
options.encoding = "UTF-8"
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import cc.tweaked.gradle.MinecraftConfigurations
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("cc-tweaked.java-convention")
|
id("cc-tweaked.java-convention")
|
||||||
id("cc-tweaked.errorprone")
|
|
||||||
id("org.spongepowered.gradle.vanilla")
|
id("org.spongepowered.gradle.vanilla")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ public interface ITurtleAccess {
|
|||||||
* @return The upgrade-specific data.
|
* @return The upgrade-specific data.
|
||||||
* @see #updateUpgradeNBTData(TurtleSide)
|
* @see #updateUpgradeNBTData(TurtleSide)
|
||||||
*/
|
*/
|
||||||
CompoundTag getUpgradeNBTData(@Nullable TurtleSide side);
|
CompoundTag getUpgradeNBTData(TurtleSide side);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the
|
* Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("cc-tweaked.java-convention")
|
id("cc-tweaked.java-convention")
|
||||||
id("cc-tweaked.publishing")
|
id("cc-tweaked.publishing")
|
||||||
id("cc-tweaked.errorprone")
|
|
||||||
id("cc-tweaked")
|
id("cc-tweaked")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ plugins {
|
|||||||
id("cc-tweaked.kotlin-convention")
|
id("cc-tweaked.kotlin-convention")
|
||||||
id("cc-tweaked.java-convention")
|
id("cc-tweaked.java-convention")
|
||||||
id("cc-tweaked.publishing")
|
id("cc-tweaked.publishing")
|
||||||
id("cc-tweaked.errorprone")
|
|
||||||
id("cc-tweaked")
|
id("cc-tweaked")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
34
projects/lints/build.gradle.kts
Normal file
34
projects/lints/build.gradle.kts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
plugins {
|
||||||
|
id("cc-tweaked.kotlin-convention")
|
||||||
|
id("cc-tweaked.java-convention")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven("https://maven.minecraftforge.net") {
|
||||||
|
content {
|
||||||
|
includeGroup("net.minecraftforge")
|
||||||
|
includeGroup("cpw.mods")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(libs.kotlin.stdlib)
|
||||||
|
implementation(libs.errorProne.api)
|
||||||
|
implementation(libs.nullAway)
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.test {
|
||||||
|
jvmArgs(
|
||||||
|
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
|
||||||
|
"--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
|
||||||
|
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
|
||||||
|
"--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
|
||||||
|
"--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
|
||||||
|
"--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
|
||||||
|
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
|
||||||
|
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
|
||||||
|
"--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
|
||||||
|
"--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
package cc.tweaked.linter
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet
|
||||||
|
import com.google.common.collect.ImmutableSetMultimap
|
||||||
|
import com.uber.nullaway.LibraryModels
|
||||||
|
import com.uber.nullaway.LibraryModels.MethodRef.methodRef
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends NullAway's model of Minecraft's code with a couple of extra annotations.
|
||||||
|
*/
|
||||||
|
class MinecraftLibraryModel : LibraryModels {
|
||||||
|
override fun failIfNullParameters(): ImmutableSetMultimap<LibraryModels.MethodRef, Int> = ImmutableSetMultimap.of()
|
||||||
|
override fun explicitlyNullableParameters(): ImmutableSetMultimap<LibraryModels.MethodRef, Int> =
|
||||||
|
ImmutableSetMultimap.of()
|
||||||
|
|
||||||
|
override fun nonNullParameters(): ImmutableSetMultimap<LibraryModels.MethodRef, Int> = ImmutableSetMultimap.of()
|
||||||
|
override fun nullImpliesTrueParameters(): ImmutableSetMultimap<LibraryModels.MethodRef, Int> =
|
||||||
|
ImmutableSetMultimap.of()
|
||||||
|
|
||||||
|
override fun nullImpliesFalseParameters(): ImmutableSetMultimap<LibraryModels.MethodRef, Int> =
|
||||||
|
ImmutableSetMultimap.of()
|
||||||
|
|
||||||
|
override fun nullImpliesNullParameters(): ImmutableSetMultimap<LibraryModels.MethodRef, Int> =
|
||||||
|
ImmutableSetMultimap.of()
|
||||||
|
|
||||||
|
override fun castToNonNullMethods(): ImmutableSetMultimap<LibraryModels.MethodRef, Int> = ImmutableSetMultimap.of()
|
||||||
|
override fun nullableReturns(): ImmutableSet<LibraryModels.MethodRef> = ImmutableSet.of()
|
||||||
|
|
||||||
|
override fun nonNullReturns(): ImmutableSet<LibraryModels.MethodRef> = ImmutableSet.of(
|
||||||
|
// Reasoning about nullability of BlockEntity.getLevel() is awkward. For now, assume it's non-null.
|
||||||
|
methodRef("net.minecraft.world.level.block.entity.BlockEntity", "getLevel()"),
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
cc.tweaked.linter.MinecraftLibraryModel
|
@ -24,6 +24,7 @@ include(":forge-stubs")
|
|||||||
include(":common-api")
|
include(":common-api")
|
||||||
include(":forge-api")
|
include(":forge-api")
|
||||||
|
|
||||||
|
include(":lints")
|
||||||
include(":web")
|
include(":web")
|
||||||
|
|
||||||
for (project in rootProject.children) {
|
for (project in rootProject.children) {
|
||||||
|
@ -51,7 +51,7 @@ import net.minecraftforge.fluids.FluidStack;
|
|||||||
import net.minecraftforge.fml.ModList;
|
import net.minecraftforge.fml.ModList;
|
||||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -64,9 +64,9 @@ public final class ComputerCraftAPIImpl implements ComputerCraftAPIForgeService
|
|||||||
private final DetailRegistry<BlockReference> blockDetails = new DetailRegistryImpl<>(BlockData::fillBasic);
|
private final DetailRegistry<BlockReference> blockDetails = new DetailRegistryImpl<>(BlockData::fillBasic);
|
||||||
private final DetailRegistry<FluidStack> fluidStackDetails = new DetailRegistryImpl<>(FluidData::fillBasic);
|
private final DetailRegistry<FluidStack> fluidStackDetails = new DetailRegistryImpl<>(FluidData::fillBasic);
|
||||||
|
|
||||||
private String version;
|
private @Nullable String version;
|
||||||
|
|
||||||
public static InputStream getResourceFile(MinecraftServer server, String domain, String subPath) {
|
public static @Nullable InputStream getResourceFile(MinecraftServer server, String domain, String subPath) {
|
||||||
var manager = server.getResourceManager();
|
var manager = server.getResourceManager();
|
||||||
var resource = manager.getResource(new ResourceLocation(domain, subPath)).orElse(null);
|
var resource = manager.getResource(new ResourceLocation(domain, subPath)).orElse(null);
|
||||||
if (resource == null) return null;
|
if (resource == null) return null;
|
||||||
@ -77,7 +77,6 @@ public final class ComputerCraftAPIImpl implements ComputerCraftAPIForgeService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public String getInstalledVersion() {
|
public String getInstalledVersion() {
|
||||||
if (version != null) return version;
|
if (version != null) return version;
|
||||||
@ -87,71 +86,75 @@ public final class ComputerCraftAPIImpl implements ComputerCraftAPIForgeService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int createUniqueNumberedSaveDir(@Nonnull Level world, @Nonnull String parentSubPath) {
|
public int createUniqueNumberedSaveDir(Level world, String parentSubPath) {
|
||||||
return ServerContext.get(world.getServer()).getNextId(parentSubPath);
|
var server = world.getServer();
|
||||||
|
if (server == null) throw new IllegalArgumentException("Cannot find server from provided level");
|
||||||
|
return ServerContext.get(server).getNextId(parentSubPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IWritableMount createSaveDirMount(@Nonnull Level world, @Nonnull String subPath, long capacity) {
|
public @Nullable IWritableMount createSaveDirMount(Level world, String subPath, long capacity) {
|
||||||
|
var server = world.getServer();
|
||||||
|
if (server == null) throw new IllegalArgumentException("Cannot find server from provided level");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new FileMount(new File(ServerContext.get(world.getServer()).storageDir().toFile(), subPath), capacity);
|
return new FileMount(new File(ServerContext.get(server).storageDir().toFile(), subPath), capacity);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMount createResourceMount(@Nonnull String domain, @Nonnull String subPath) {
|
public @Nullable IMount createResourceMount(String domain, String subPath) {
|
||||||
var manager = ServerLifecycleHooks.getCurrentServer().getResourceManager();
|
var manager = ServerLifecycleHooks.getCurrentServer().getResourceManager();
|
||||||
var mount = ResourceMount.get(domain, subPath, manager);
|
var mount = ResourceMount.get(domain, subPath, manager);
|
||||||
return mount.exists("") ? mount : null;
|
return mount.exists("") ? mount : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerPeripheralProvider(@Nonnull IPeripheralProvider provider) {
|
public void registerPeripheralProvider(IPeripheralProvider provider) {
|
||||||
Peripherals.register(provider);
|
Peripherals.register(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerGenericSource(@Nonnull GenericSource source) {
|
public void registerGenericSource(GenericSource source) {
|
||||||
GenericMethod.register(source);
|
GenericMethod.register(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerGenericCapability(@Nonnull Capability<?> capability) {
|
public void registerGenericCapability(Capability<?> capability) {
|
||||||
GenericPeripheralProvider.addCapability(capability);
|
GenericPeripheralProvider.addCapability(capability);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerBundledRedstoneProvider(@Nonnull IBundledRedstoneProvider provider) {
|
public void registerBundledRedstoneProvider(IBundledRedstoneProvider provider) {
|
||||||
BundledRedstone.register(provider);
|
BundledRedstone.register(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBundledRedstoneOutput(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side) {
|
public int getBundledRedstoneOutput(Level world, BlockPos pos, Direction side) {
|
||||||
return BundledRedstone.getDefaultOutput(world, pos, side);
|
return BundledRedstone.getDefaultOutput(world, pos, side);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerMediaProvider(@Nonnull IMediaProvider provider) {
|
public void registerMediaProvider(IMediaProvider provider) {
|
||||||
MediaProviders.register(provider);
|
MediaProviders.register(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public IPacketNetwork getWirelessNetwork() {
|
public IPacketNetwork getWirelessNetwork() {
|
||||||
return WirelessNetwork.getUniversal();
|
return WirelessNetwork.getUniversal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerAPIFactory(@Nonnull ILuaAPIFactory factory) {
|
public void registerAPIFactory(ILuaAPIFactory factory) {
|
||||||
ApiFactories.register(factory);
|
ApiFactories.register(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> void registerDetailProvider(@Nonnull Class<T> type, @Nonnull IDetailProvider<T> provider) {
|
public <T> void registerDetailProvider(Class<T> type, IDetailProvider<T> provider) {
|
||||||
if (type == ItemStack.class) {
|
if (type == ItemStack.class) {
|
||||||
itemStackDetails.addProvider((IDetailProvider<ItemStack>) provider);
|
itemStackDetails.addProvider((IDetailProvider<ItemStack>) provider);
|
||||||
} else if (type == BlockReference.class) {
|
} else if (type == BlockReference.class) {
|
||||||
@ -163,21 +166,19 @@ public final class ComputerCraftAPIImpl implements ComputerCraftAPIForgeService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public IWiredNode createWiredNodeForElement(@Nonnull IWiredElement element) {
|
public IWiredNode createWiredNodeForElement(IWiredElement element) {
|
||||||
return new WiredNode(element);
|
return new WiredNode(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public LazyOptional<IWiredElement> getWiredElementAt(@Nonnull BlockGetter world, @Nonnull BlockPos pos, @Nonnull Direction side) {
|
public LazyOptional<IWiredElement> getWiredElementAt(BlockGetter world, BlockPos pos, Direction side) {
|
||||||
var tile = world.getBlockEntity(pos);
|
var tile = world.getBlockEntity(pos);
|
||||||
return tile == null ? LazyOptional.empty() : tile.getCapability(CAPABILITY_WIRED_ELEMENT, side);
|
return tile == null ? LazyOptional.empty() : tile.getCapability(CAPABILITY_WIRED_ELEMENT, side);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerRefuelHandler(@Nonnull TurtleRefuelHandler handler) {
|
public void registerRefuelHandler(TurtleRefuelHandler handler) {
|
||||||
TurtleRefuelHandlers.register(handler);
|
TurtleRefuelHandlers.register(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,12 +12,11 @@ import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
|
|||||||
import dan200.computercraft.client.turtle.TurtleUpgradeModellers;
|
import dan200.computercraft.client.turtle.TurtleUpgradeModellers;
|
||||||
import dan200.computercraft.impl.client.ComputerCraftAPIClientService;
|
import dan200.computercraft.impl.client.ComputerCraftAPIClientService;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
@AutoService(ComputerCraftAPIClientService.class)
|
@AutoService(ComputerCraftAPIClientService.class)
|
||||||
public final class ComputerCraftAPIClientImpl implements ComputerCraftAPIClientService {
|
public final class ComputerCraftAPIClientImpl implements ComputerCraftAPIClientService {
|
||||||
@Override
|
@Override
|
||||||
public <T extends ITurtleUpgrade> void registerTurtleUpgradeModeller(@Nonnull TurtleUpgradeSerialiser<T> serialiser, @Nonnull TurtleUpgradeModeller<T> modeller) {
|
public <T extends ITurtleUpgrade> void registerTurtleUpgradeModeller(TurtleUpgradeSerialiser<T> serialiser, TurtleUpgradeModeller<T> modeller) {
|
||||||
TurtleUpgradeModellers.register(serialiser, modeller);
|
TurtleUpgradeModellers.register(serialiser, modeller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ import net.minecraft.world.entity.player.Inventory;
|
|||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -37,13 +36,15 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static dan200.computercraft.core.util.Nullability.assertNonNull;
|
||||||
|
|
||||||
public abstract class ComputerScreenBase<T extends ContainerComputerBase> extends AbstractContainerScreen<T> {
|
public abstract class ComputerScreenBase<T extends ContainerComputerBase> extends AbstractContainerScreen<T> {
|
||||||
private static final Component OK = Component.translatable("gui.ok");
|
private static final Component OK = Component.translatable("gui.ok");
|
||||||
private static final Component NO_RESPONSE_TITLE = Component.translatable("gui.computercraft.upload.no_response");
|
private static final Component NO_RESPONSE_TITLE = Component.translatable("gui.computercraft.upload.no_response");
|
||||||
private static final Component NO_RESPONSE_MSG = Component.translatable("gui.computercraft.upload.no_response.msg",
|
private static final Component NO_RESPONSE_MSG = Component.translatable("gui.computercraft.upload.no_response.msg",
|
||||||
Component.literal("import").withStyle(ChatFormatting.DARK_GRAY));
|
Component.literal("import").withStyle(ChatFormatting.DARK_GRAY));
|
||||||
|
|
||||||
protected WidgetTerminal terminal;
|
protected @Nullable WidgetTerminal terminal;
|
||||||
protected Terminal terminalData;
|
protected Terminal terminalData;
|
||||||
protected final ComputerFamily family;
|
protected final ComputerFamily family;
|
||||||
protected final InputHandler input;
|
protected final InputHandler input;
|
||||||
@ -64,6 +65,11 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
|||||||
|
|
||||||
protected abstract WidgetTerminal createTerminal();
|
protected abstract WidgetTerminal createTerminal();
|
||||||
|
|
||||||
|
protected final WidgetTerminal getTerminal() {
|
||||||
|
if (terminal == null) throw new IllegalStateException("Screen has not been initialised yet");
|
||||||
|
return terminal;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
super.init();
|
super.init();
|
||||||
@ -83,7 +89,7 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
|||||||
@Override
|
@Override
|
||||||
public void containerTick() {
|
public void containerTick() {
|
||||||
super.containerTick();
|
super.containerTick();
|
||||||
terminal.update();
|
getTerminal().update();
|
||||||
|
|
||||||
if (uploadNagDeadline != Long.MAX_VALUE && Util.getNanos() >= uploadNagDeadline) {
|
if (uploadNagDeadline != Long.MAX_VALUE && Util.getNanos() >= uploadNagDeadline) {
|
||||||
new ItemToast(minecraft, displayStack, NO_RESPONSE_TITLE, NO_RESPONSE_MSG, ItemToast.TRANSFER_NO_RESPONSE_TOKEN)
|
new ItemToast(minecraft, displayStack, NO_RESPONSE_TITLE, NO_RESPONSE_MSG, ItemToast.TRANSFER_NO_RESPONSE_TOKEN)
|
||||||
@ -104,7 +110,7 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(@Nonnull PoseStack stack, int mouseX, int mouseY, float partialTicks) {
|
public void render(PoseStack stack, int mouseX, int mouseY, float partialTicks) {
|
||||||
renderBackground(stack);
|
renderBackground(stack);
|
||||||
super.render(stack, mouseX, mouseY, partialTicks);
|
super.render(stack, mouseX, mouseY, partialTicks);
|
||||||
renderTooltip(stack, mouseX, mouseY);
|
renderTooltip(stack, mouseX, mouseY);
|
||||||
@ -127,12 +133,12 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderLabels(@Nonnull PoseStack transform, int mouseX, int mouseY) {
|
protected void renderLabels(PoseStack transform, int mouseX, int mouseY) {
|
||||||
// Skip rendering labels.
|
// Skip rendering labels.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFilesDrop(@Nonnull List<Path> files) {
|
public void onFilesDrop(List<Path> files) {
|
||||||
if (files.isEmpty()) return;
|
if (files.isEmpty()) return;
|
||||||
|
|
||||||
if (!menu.isOn()) {
|
if (!menu.isOn()) {
|
||||||
@ -193,7 +199,7 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case CONSUMED -> uploadNagDeadline = Long.MAX_VALUE;
|
case CONSUMED -> uploadNagDeadline = Long.MAX_VALUE;
|
||||||
case ERROR -> alert(UploadResult.FAILED_TITLE, message);
|
case ERROR -> alert(UploadResult.FAILED_TITLE, assertNonNull(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,8 +13,6 @@ import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
|
|||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
import static dan200.computercraft.client.render.ComputerBorderRenderer.BORDER;
|
import static dan200.computercraft.client.render.ComputerBorderRenderer.BORDER;
|
||||||
import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP;
|
import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP;
|
||||||
|
|
||||||
@ -32,8 +30,9 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Computer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderBg(@Nonnull PoseStack stack, float partialTicks, int mouseX, int mouseY) {
|
public void renderBg(PoseStack stack, float partialTicks, int mouseX, int mouseY) {
|
||||||
// Draw a border around the terminal
|
// Draw a border around the terminal
|
||||||
|
var terminal = getTerminal();
|
||||||
ComputerBorderRenderer.render(
|
ComputerBorderRenderer.render(
|
||||||
stack.last().pose(), ComputerBorderRenderer.getTexture(family), terminal.x, terminal.y, getBlitOffset(),
|
stack.last().pose(), ComputerBorderRenderer.getTexture(family), terminal.x, terminal.y, getBlitOffset(),
|
||||||
FULL_BRIGHT_LIGHTMAP, terminal.getWidth(), terminal.getHeight()
|
FULL_BRIGHT_LIGHTMAP, terminal.getWidth(), terminal.getHeight()
|
||||||
|
@ -13,7 +13,6 @@ import net.minecraft.network.chat.Component;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class GuiDiskDrive extends AbstractContainerScreen<ContainerDiskDrive> {
|
public class GuiDiskDrive extends AbstractContainerScreen<ContainerDiskDrive> {
|
||||||
private static final ResourceLocation BACKGROUND = new ResourceLocation("computercraft", "textures/gui/disk_drive.png");
|
private static final ResourceLocation BACKGROUND = new ResourceLocation("computercraft", "textures/gui/disk_drive.png");
|
||||||
@ -23,14 +22,14 @@ public class GuiDiskDrive extends AbstractContainerScreen<ContainerDiskDrive> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderBg(@Nonnull PoseStack transform, float partialTicks, int mouseX, int mouseY) {
|
protected void renderBg(PoseStack transform, float partialTicks, int mouseX, int mouseY) {
|
||||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
RenderSystem.setShaderTexture(0, BACKGROUND);
|
RenderSystem.setShaderTexture(0, BACKGROUND);
|
||||||
blit(transform, leftPos, topPos, 0, 0, imageWidth, imageHeight);
|
blit(transform, leftPos, topPos, 0, 0, imageWidth, imageHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(@Nonnull PoseStack transform, int mouseX, int mouseY, float partialTicks) {
|
public void render(PoseStack transform, int mouseX, int mouseY, float partialTicks) {
|
||||||
renderBackground(transform);
|
renderBackground(transform);
|
||||||
super.render(transform, mouseX, mouseY, partialTicks);
|
super.render(transform, mouseX, mouseY, partialTicks);
|
||||||
renderTooltip(transform, mouseX, mouseY);
|
renderTooltip(transform, mouseX, mouseY);
|
||||||
|
@ -13,7 +13,6 @@ import net.minecraft.network.chat.Component;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class GuiPrinter extends AbstractContainerScreen<ContainerPrinter> {
|
public class GuiPrinter extends AbstractContainerScreen<ContainerPrinter> {
|
||||||
private static final ResourceLocation BACKGROUND = new ResourceLocation("computercraft", "textures/gui/printer.png");
|
private static final ResourceLocation BACKGROUND = new ResourceLocation("computercraft", "textures/gui/printer.png");
|
||||||
@ -23,7 +22,7 @@ public class GuiPrinter extends AbstractContainerScreen<ContainerPrinter> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderBg(@Nonnull PoseStack transform, float partialTicks, int mouseX, int mouseY) {
|
protected void renderBg(PoseStack transform, float partialTicks, int mouseX, int mouseY) {
|
||||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
RenderSystem.setShaderTexture(0, BACKGROUND);
|
RenderSystem.setShaderTexture(0, BACKGROUND);
|
||||||
blit(transform, leftPos, topPos, 0, 0, imageWidth, imageHeight);
|
blit(transform, leftPos, topPos, 0, 0, imageWidth, imageHeight);
|
||||||
@ -32,7 +31,7 @@ public class GuiPrinter extends AbstractContainerScreen<ContainerPrinter> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(@Nonnull PoseStack stack, int mouseX, int mouseY, float partialTicks) {
|
public void render(PoseStack stack, int mouseX, int mouseY, float partialTicks) {
|
||||||
renderBackground(stack);
|
renderBackground(stack);
|
||||||
super.render(stack, mouseX, mouseY, partialTicks);
|
super.render(stack, mouseX, mouseY, partialTicks);
|
||||||
renderTooltip(stack, mouseX, mouseY);
|
renderTooltip(stack, mouseX, mouseY);
|
||||||
|
@ -17,8 +17,6 @@ import net.minecraft.network.chat.Component;
|
|||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
||||||
import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP;
|
import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP;
|
||||||
|
|
||||||
@ -83,7 +81,7 @@ public class GuiPrintout extends AbstractContainerScreen<ContainerHeldItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderBg(@Nonnull PoseStack transform, float partialTicks, int mouseX, int mouseY) {
|
protected void renderBg(PoseStack transform, float partialTicks, int mouseX, int mouseY) {
|
||||||
// Draw the printout
|
// Draw the printout
|
||||||
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
|
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
RenderSystem.enableDepthTest();
|
RenderSystem.enableDepthTest();
|
||||||
@ -95,7 +93,7 @@ public class GuiPrintout extends AbstractContainerScreen<ContainerHeldItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(@Nonnull PoseStack stack, int mouseX, int mouseY, float partialTicks) {
|
public void render(PoseStack stack, int mouseX, int mouseY, float partialTicks) {
|
||||||
// We must take the background further back in order to not overlap with our printed pages.
|
// We must take the background further back in order to not overlap with our printed pages.
|
||||||
setBlitOffset(getBlitOffset() - 1);
|
setBlitOffset(getBlitOffset() - 1);
|
||||||
renderBackground(stack);
|
renderBackground(stack);
|
||||||
@ -105,7 +103,7 @@ public class GuiPrintout extends AbstractContainerScreen<ContainerHeldItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderLabels(@Nonnull PoseStack transform, int mouseX, int mouseY) {
|
protected void renderLabels(PoseStack transform, int mouseX, int mouseY) {
|
||||||
// Skip rendering labels.
|
// Skip rendering labels.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,6 @@ import net.minecraft.network.chat.Component;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
import static dan200.computercraft.shared.turtle.inventory.ContainerTurtle.*;
|
import static dan200.computercraft.shared.turtle.inventory.ContainerTurtle.*;
|
||||||
|
|
||||||
public class GuiTurtle extends ComputerScreenBase<ContainerTurtle> {
|
public class GuiTurtle extends ComputerScreenBase<ContainerTurtle> {
|
||||||
@ -44,7 +42,7 @@ public class GuiTurtle extends ComputerScreenBase<ContainerTurtle> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderBg(@Nonnull PoseStack transform, float partialTicks, int mouseX, int mouseY) {
|
protected void renderBg(PoseStack transform, float partialTicks, int mouseX, int mouseY) {
|
||||||
var advanced = family == ComputerFamily.ADVANCED;
|
var advanced = family == ComputerFamily.ADVANCED;
|
||||||
RenderSystem.setShaderTexture(0, advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL);
|
RenderSystem.setShaderTexture(0, advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL);
|
||||||
blit(transform, leftPos + ComputerSidebar.WIDTH, topPos, 0, 0, TEX_WIDTH, TEX_HEIGHT);
|
blit(transform, leftPos + ComputerSidebar.WIDTH, topPos, 0, 0, TEX_WIDTH, TEX_HEIGHT);
|
||||||
|
@ -14,7 +14,6 @@ import net.minecraft.network.chat.Component;
|
|||||||
import net.minecraft.util.FormattedCharSequence;
|
import net.minecraft.util.FormattedCharSequence;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,15 +67,13 @@ public class ItemToast implements Toast {
|
|||||||
return MARGIN * 2 + LINE_SPACING + message.size() * LINE_SPACING;
|
return MARGIN * 2 + LINE_SPACING + message.size() * LINE_SPACING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Object getToken() {
|
public Object getToken() {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Visibility render(@Nonnull PoseStack transform, @Nonnull ToastComponent component, long time) {
|
public Visibility render(PoseStack transform, ToastComponent component, long time) {
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
|
|
||||||
firstDisplay = time;
|
firstDisplay = time;
|
||||||
|
@ -16,12 +16,14 @@ import net.minecraft.network.chat.Component;
|
|||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static dan200.computercraft.core.util.Nullability.assertNonNull;
|
||||||
|
|
||||||
public class NoTermComputerScreen<T extends ContainerComputerBase> extends Screen implements MenuAccess<T> {
|
public class NoTermComputerScreen<T extends ContainerComputerBase> extends Screen implements MenuAccess<T> {
|
||||||
private final T menu;
|
private final T menu;
|
||||||
private final Terminal terminalData;
|
private final Terminal terminalData;
|
||||||
private WidgetTerminal terminal;
|
private @Nullable WidgetTerminal terminal;
|
||||||
|
|
||||||
public NoTermComputerScreen(T menu, Inventory player, Component title) {
|
public NoTermComputerScreen(T menu, Inventory player, Component title) {
|
||||||
super(title);
|
super(title);
|
||||||
@ -29,7 +31,6 @@ public class NoTermComputerScreen<T extends ContainerComputerBase> extends Scree
|
|||||||
terminalData = menu.getTerminal();
|
terminalData = menu.getTerminal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public T getMenu() {
|
public T getMenu() {
|
||||||
return menu;
|
return menu;
|
||||||
@ -62,7 +63,7 @@ public class NoTermComputerScreen<T extends ContainerComputerBase> extends Scree
|
|||||||
@Override
|
@Override
|
||||||
public final void tick() {
|
public final void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
terminal.update();
|
assertNonNull(terminal).update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -93,7 +94,7 @@ public class NoTermComputerScreen<T extends ContainerComputerBase> extends Scree
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(@Nonnull PoseStack transform, int mouseX, int mouseY, float partialTicks) {
|
public void render(PoseStack transform, int mouseX, int mouseY, float partialTicks) {
|
||||||
super.render(transform, mouseX, mouseY, partialTicks);
|
super.render(transform, mouseX, mouseY, partialTicks);
|
||||||
|
|
||||||
var font = minecraft.font;
|
var font = minecraft.font;
|
||||||
|
@ -15,9 +15,11 @@ import net.minecraft.client.gui.screens.Screen;
|
|||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static dan200.computercraft.core.util.Nullability.assertNonNull;
|
||||||
|
|
||||||
public final class OptionScreen extends Screen {
|
public final class OptionScreen extends Screen {
|
||||||
private static final ResourceLocation BACKGROUND = new ResourceLocation("computercraft", "textures/gui/blank_screen.png");
|
private static final ResourceLocation BACKGROUND = new ResourceLocation("computercraft", "textures/gui/blank_screen.png");
|
||||||
|
|
||||||
@ -32,7 +34,7 @@ public final class OptionScreen extends Screen {
|
|||||||
private int innerWidth;
|
private int innerWidth;
|
||||||
private int innerHeight;
|
private int innerHeight;
|
||||||
|
|
||||||
private MultiLineLabel messageRenderer;
|
private @Nullable MultiLineLabel messageRenderer;
|
||||||
private final Component message;
|
private final Component message;
|
||||||
private final List<AbstractWidget> buttons;
|
private final List<AbstractWidget> buttons;
|
||||||
private final Runnable exit;
|
private final Runnable exit;
|
||||||
@ -81,7 +83,7 @@ public final class OptionScreen extends Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(@Nonnull PoseStack transform, int mouseX, int mouseY, float partialTicks) {
|
public void render(PoseStack transform, int mouseX, int mouseY, float partialTicks) {
|
||||||
renderBackground(transform);
|
renderBackground(transform);
|
||||||
|
|
||||||
// Render the actual texture.
|
// Render the actual texture.
|
||||||
@ -93,7 +95,7 @@ public final class OptionScreen extends Screen {
|
|||||||
);
|
);
|
||||||
blit(transform, x, y + innerHeight - PADDING, 0, 256 - PADDING, innerWidth, PADDING);
|
blit(transform, x, y + innerHeight - PADDING, 0, 256 - PADDING, innerWidth, PADDING);
|
||||||
|
|
||||||
messageRenderer.renderLeftAlignedNoShadow(transform, x + PADDING, y + PADDING, FONT_HEIGHT, 0x404040);
|
assertNonNull(messageRenderer).renderLeftAlignedNoShadow(transform, x + PADDING, y + PADDING, FONT_HEIGHT, 0x404040);
|
||||||
super.render(transform, mouseX, mouseY, partialTicks);
|
super.render(transform, mouseX, mouseY, partialTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +112,6 @@ public final class OptionScreen extends Screen {
|
|||||||
for (var widget : buttons) widget.active = false;
|
for (var widget : buttons) widget.active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public Screen getOriginalScreen() {
|
public Screen getOriginalScreen() {
|
||||||
return originalScreen;
|
return originalScreen;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import net.minecraft.client.gui.screens.Screen;
|
|||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.IntSupplier;
|
import java.util.function.IntSupplier;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@ -61,7 +60,7 @@ public class DynamicImageButton extends Button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderButton(@Nonnull PoseStack stack, int mouseX, int mouseY, float partialTicks) {
|
public void renderButton(PoseStack stack, int mouseX, int mouseY, float partialTicks) {
|
||||||
RenderSystem.setShaderTexture(0, texture);
|
RenderSystem.setShaderTexture(0, texture);
|
||||||
RenderSystem.disableDepthTest();
|
RenderSystem.disableDepthTest();
|
||||||
|
|
||||||
@ -74,7 +73,6 @@ public class DynamicImageButton extends Button {
|
|||||||
if (isHovered) renderToolTip(stack, mouseX, mouseY);
|
if (isHovered) renderToolTip(stack, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Component getMessage() {
|
public Component getMessage() {
|
||||||
var tooltip = this.tooltip.get();
|
var tooltip = this.tooltip.get();
|
||||||
@ -82,7 +80,7 @@ public class DynamicImageButton extends Button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderToolTip(@Nonnull PoseStack stack, int mouseX, int mouseY) {
|
public void renderToolTip(PoseStack stack, int mouseX, int mouseY) {
|
||||||
var tooltip = this.tooltip.get();
|
var tooltip = this.tooltip.get();
|
||||||
if (!tooltip.isEmpty()) {
|
if (!tooltip.isEmpty()) {
|
||||||
screen.renderComponentTooltip(stack, tooltip, mouseX, mouseY);
|
screen.renderComponentTooltip(stack, tooltip, mouseX, mouseY);
|
||||||
|
@ -19,7 +19,6 @@ import net.minecraft.client.renderer.MultiBufferSource;
|
|||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import static dan200.computercraft.client.render.ComputerBorderRenderer.MARGIN;
|
import static dan200.computercraft.client.render.ComputerBorderRenderer.MARGIN;
|
||||||
@ -29,8 +28,8 @@ import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.FON
|
|||||||
public class WidgetTerminal extends AbstractWidget {
|
public class WidgetTerminal extends AbstractWidget {
|
||||||
private static final float TERMINATE_TIME = 0.5f;
|
private static final float TERMINATE_TIME = 0.5f;
|
||||||
|
|
||||||
private final @Nonnull Terminal terminal;
|
private final Terminal terminal;
|
||||||
private final @Nonnull InputHandler computer;
|
private final InputHandler computer;
|
||||||
|
|
||||||
// The positions of the actual terminal
|
// The positions of the actual terminal
|
||||||
private final int innerX;
|
private final int innerX;
|
||||||
@ -48,7 +47,7 @@ public class WidgetTerminal extends AbstractWidget {
|
|||||||
|
|
||||||
private final BitSet keysDown = new BitSet(256);
|
private final BitSet keysDown = new BitSet(256);
|
||||||
|
|
||||||
public WidgetTerminal(@Nonnull Terminal terminal, @Nonnull InputHandler computer, int x, int y) {
|
public WidgetTerminal(Terminal terminal, InputHandler computer, int x, int y) {
|
||||||
super(x, y, terminal.getWidth() * FONT_WIDTH + MARGIN * 2, terminal.getHeight() * FONT_HEIGHT + MARGIN * 2, Component.empty());
|
super(x, y, terminal.getWidth() * FONT_WIDTH + MARGIN * 2, terminal.getHeight() * FONT_HEIGHT + MARGIN * 2, Component.empty());
|
||||||
|
|
||||||
this.terminal = terminal;
|
this.terminal = terminal;
|
||||||
@ -264,7 +263,7 @@ public class WidgetTerminal extends AbstractWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(@Nonnull PoseStack transform, int mouseX, int mouseY, float partialTicks) {
|
public void render(PoseStack transform, int mouseX, int mouseY, float partialTicks) {
|
||||||
if (!visible) return;
|
if (!visible) return;
|
||||||
|
|
||||||
var bufferSource = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
|
var bufferSource = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
|
||||||
@ -279,7 +278,7 @@ public class WidgetTerminal extends AbstractWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateNarration(@Nonnull NarrationElementOutput output) {
|
public void updateNarration(NarrationElementOutput output) {
|
||||||
// I'm not sure what the right option is here.
|
// I'm not sure what the right option is here.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import net.minecraft.resources.ResourceLocation;
|
|||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,7 +97,7 @@ public abstract class AbstractClientNetworkContext implements ClientNetworkConte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void handleUploadResult(int containerId, UploadResult result, Component errorMessage) {
|
public final void handleUploadResult(int containerId, UploadResult result, @Nullable Component errorMessage) {
|
||||||
var minecraft = Minecraft.getInstance();
|
var minecraft = Minecraft.getInstance();
|
||||||
|
|
||||||
var screen = OptionScreen.unwrap(minecraft.screen);
|
var screen = OptionScreen.unwrap(minecraft.screen);
|
||||||
|
@ -14,8 +14,6 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
|||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps {@link ServerComputer#getInstanceID()} to locals {@link PocketComputerData}.
|
* Maps {@link ServerComputer#getInstanceID()} to locals {@link PocketComputerData}.
|
||||||
* <p>
|
* <p>
|
||||||
@ -42,14 +40,12 @@ public final class ClientPocketComputers {
|
|||||||
* @param advanced Whether this computer has an advanced terminal.
|
* @param advanced Whether this computer has an advanced terminal.
|
||||||
* @return The pocket computer data.
|
* @return The pocket computer data.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
public static PocketComputerData get(int instanceId, boolean advanced) {
|
public static PocketComputerData get(int instanceId, boolean advanced) {
|
||||||
var computer = instances.get(instanceId);
|
var computer = instances.get(instanceId);
|
||||||
if (computer == null) instances.put(instanceId, computer = new PocketComputerData(advanced));
|
if (computer == null) instances.put(instanceId, computer = new PocketComputerData(advanced));
|
||||||
return computer;
|
return computer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public static PocketComputerData get(ItemStack stack) {
|
public static PocketComputerData get(ItemStack stack) {
|
||||||
var family = stack.getItem() instanceof ItemComputer computer ? computer.getFamily() : ComputerFamily.NORMAL;
|
var family = stack.getItem() instanceof ItemComputer computer ? computer.getFamily() : ComputerFamily.NORMAL;
|
||||||
return get(ItemPocketComputer.getInstanceID(stack), family != ComputerFamily.NORMAL);
|
return get(ItemPocketComputer.getInstanceID(stack), family != ComputerFamily.NORMAL);
|
||||||
|
@ -12,8 +12,6 @@ import dan200.computercraft.shared.computer.terminal.NetworkedTerminal;
|
|||||||
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||||
import dan200.computercraft.shared.pocket.core.PocketServerComputer;
|
import dan200.computercraft.shared.pocket.core.PocketServerComputer;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clientside data about a pocket computer.
|
* Clientside data about a pocket computer.
|
||||||
* <p>
|
* <p>
|
||||||
@ -37,7 +35,6 @@ public class PocketComputerData {
|
|||||||
return state != ComputerState.OFF ? lightColour : -1;
|
return state != ComputerState.OFF ? lightColour : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public Terminal getTerminal() {
|
public Terminal getTerminal() {
|
||||||
return terminal;
|
return terminal;
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,6 @@ import net.minecraft.client.renderer.MultiBufferSource;
|
|||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class ComputerBorderRenderer {
|
public class ComputerBorderRenderer {
|
||||||
public static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation(ComputerCraft.MOD_ID, "textures/gui/corners_normal.png");
|
public static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation(ComputerCraft.MOD_ID, "textures/gui/corners_normal.png");
|
||||||
public static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation(ComputerCraft.MOD_ID, "textures/gui/corners_advanced.png");
|
public static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation(ComputerCraft.MOD_ID, "textures/gui/corners_advanced.png");
|
||||||
@ -61,8 +59,7 @@ public class ComputerBorderRenderer {
|
|||||||
this.b = b;
|
this.b = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
public static ResourceLocation getTexture(ComputerFamily family) {
|
||||||
public static ResourceLocation getTexture(@Nonnull ComputerFamily family) {
|
|
||||||
return switch (family) {
|
return switch (family) {
|
||||||
case NORMAL -> BACKGROUND_NORMAL;
|
case NORMAL -> BACKGROUND_NORMAL;
|
||||||
case ADVANCED -> BACKGROUND_ADVANCED;
|
case ADVANCED -> BACKGROUND_ADVANCED;
|
||||||
|
@ -36,7 +36,7 @@ public class MonitorTextureBufferShader extends ShaderInstance {
|
|||||||
private final int monitorData;
|
private final int monitorData;
|
||||||
private int uniformBuffer = 0;
|
private int uniformBuffer = 0;
|
||||||
|
|
||||||
private final Uniform cursorBlink;
|
private final @Nullable Uniform cursorBlink;
|
||||||
|
|
||||||
public MonitorTextureBufferShader(ResourceProvider provider, ResourceLocation location, VertexFormat format) throws IOException {
|
public MonitorTextureBufferShader(ResourceProvider provider, ResourceLocation location, VertexFormat format) throws IOException {
|
||||||
super(provider, location, format);
|
super(provider, location, format);
|
||||||
|
@ -16,15 +16,16 @@ import net.minecraft.client.renderer.ShaderInstance;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.packs.resources.ResourceManager;
|
import net.minecraft.server.packs.resources.ResourceManager;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class RenderTypes {
|
public class RenderTypes {
|
||||||
public static final int FULL_BRIGHT_LIGHTMAP = (0xF << 4) | (0xF << 20);
|
public static final int FULL_BRIGHT_LIGHTMAP = (0xF << 4) | (0xF << 20);
|
||||||
|
|
||||||
private static MonitorTextureBufferShader monitorTboShader;
|
private static @Nullable MonitorTextureBufferShader monitorTboShader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders a fullbright terminal.
|
* Renders a fullbright terminal.
|
||||||
@ -49,15 +50,13 @@ public class RenderTypes {
|
|||||||
*/
|
*/
|
||||||
public static final RenderType PRINTOUT_BACKGROUND = RenderType.text(new ResourceLocation("computercraft", "textures/gui/printout.png"));
|
public static final RenderType PRINTOUT_BACKGROUND = RenderType.text(new ResourceLocation("computercraft", "textures/gui/printout.png"));
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
static MonitorTextureBufferShader getMonitorTextureBufferShader() {
|
static MonitorTextureBufferShader getMonitorTextureBufferShader() {
|
||||||
if (monitorTboShader == null) throw new NullPointerException("MonitorTboShader has not been registered");
|
if (monitorTboShader == null) throw new NullPointerException("MonitorTboShader has not been registered");
|
||||||
return monitorTboShader;
|
return monitorTboShader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
static ShaderInstance getTerminalShader() {
|
static ShaderInstance getTerminalShader() {
|
||||||
return GameRenderer.getRendertypeTextShader();
|
return Objects.requireNonNull(GameRenderer.getRendertypeTextShader(), "Text shader has not been registered");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerShaders(ResourceManager resources, BiConsumer<ShaderInstance, Consumer<ShaderInstance>> load) throws IOException {
|
public static void registerShaders(ResourceManager resources, BiConsumer<ShaderInstance, Consumer<ShaderInstance>> load) throws IOException {
|
||||||
|
@ -21,6 +21,7 @@ import dan200.computercraft.client.render.text.DirectFixedWidthFontRenderer;
|
|||||||
import dan200.computercraft.client.render.text.FixedWidthFontRenderer;
|
import dan200.computercraft.client.render.text.FixedWidthFontRenderer;
|
||||||
import dan200.computercraft.client.util.DirectBuffers;
|
import dan200.computercraft.client.util.DirectBuffers;
|
||||||
import dan200.computercraft.client.util.DirectVertexBuffer;
|
import dan200.computercraft.client.util.DirectVertexBuffer;
|
||||||
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
import dan200.computercraft.shared.integration.ShaderMod;
|
import dan200.computercraft.shared.integration.ShaderMod;
|
||||||
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
|
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
|
||||||
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
||||||
@ -34,12 +35,13 @@ import org.lwjgl.opengl.GL11;
|
|||||||
import org.lwjgl.opengl.GL20;
|
import org.lwjgl.opengl.GL20;
|
||||||
import org.lwjgl.opengl.GL31;
|
import org.lwjgl.opengl.GL31;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.FONT_HEIGHT;
|
import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.FONT_WIDTH;
|
import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
|
import static dan200.computercraft.core.util.Nullability.assertNonNull;
|
||||||
|
|
||||||
public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonitor> {
|
public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonitor> {
|
||||||
/**
|
/**
|
||||||
@ -50,13 +52,13 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
|||||||
|
|
||||||
private static final Matrix3f IDENTITY_NORMAL = Util.make(new Matrix3f(), Matrix3f::setIdentity);
|
private static final Matrix3f IDENTITY_NORMAL = Util.make(new Matrix3f(), Matrix3f::setIdentity);
|
||||||
|
|
||||||
private static ByteBuffer backingBuffer;
|
private static @Nullable ByteBuffer backingBuffer;
|
||||||
|
|
||||||
public TileEntityMonitorRenderer(BlockEntityRendererProvider.Context context) {
|
public TileEntityMonitorRenderer(BlockEntityRendererProvider.Context context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(@Nonnull TileMonitor monitor, float partialTicks, @Nonnull PoseStack transform, @Nonnull MultiBufferSource bufferSource, int lightmapCoord, int overlayLight) {
|
public void render(TileMonitor monitor, float partialTicks, PoseStack transform, MultiBufferSource bufferSource, int lightmapCoord, int overlayLight) {
|
||||||
// Render from the origin monitor
|
// Render from the origin monitor
|
||||||
var originTerminal = monitor.getClientMonitor();
|
var originTerminal = monitor.getClientMonitor();
|
||||||
|
|
||||||
@ -114,7 +116,7 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
|||||||
|
|
||||||
var matrix = transform.last().pose();
|
var matrix = transform.last().pose();
|
||||||
|
|
||||||
renderTerminal(matrix, originTerminal, (float) (MARGIN / xScale), (float) (MARGIN / yScale));
|
renderTerminal(matrix, originTerminal, terminal, (float) (MARGIN / xScale), (float) (MARGIN / yScale));
|
||||||
|
|
||||||
transform.popPose();
|
transform.popPose();
|
||||||
} else {
|
} else {
|
||||||
@ -128,8 +130,7 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
|||||||
transform.popPose();
|
transform.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void renderTerminal(Matrix4f matrix, ClientMonitor monitor, float xMargin, float yMargin) {
|
private static void renderTerminal(Matrix4f matrix, ClientMonitor monitor, Terminal terminal, float xMargin, float yMargin) {
|
||||||
var terminal = monitor.getTerminal();
|
|
||||||
int width = terminal.getWidth(), height = terminal.getHeight();
|
int width = terminal.getWidth(), height = terminal.getHeight();
|
||||||
int pixelWidth = width * FONT_WIDTH, pixelHeight = height * FONT_HEIGHT;
|
int pixelWidth = width * FONT_WIDTH, pixelHeight = height * FONT_HEIGHT;
|
||||||
|
|
||||||
@ -167,8 +168,8 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
|||||||
RenderTypes.MONITOR_TBO.end(buffer, 0, 0, 0);
|
RenderTypes.MONITOR_TBO.end(buffer, 0, 0, 0);
|
||||||
}
|
}
|
||||||
case VBO -> {
|
case VBO -> {
|
||||||
var backgroundBuffer = monitor.backgroundBuffer;
|
var backgroundBuffer = assertNonNull(monitor.backgroundBuffer);
|
||||||
var foregroundBuffer = monitor.foregroundBuffer;
|
var foregroundBuffer = assertNonNull(monitor.foregroundBuffer);
|
||||||
if (redraw) {
|
if (redraw) {
|
||||||
var size = DirectFixedWidthFontRenderer.getVertexCount(terminal);
|
var size = DirectFixedWidthFontRenderer.getVertexCount(terminal);
|
||||||
|
|
||||||
@ -236,7 +237,6 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
|||||||
builder.vertex(matrix, x, y, 0).uv(x, y).endVertex();
|
builder.vertex(matrix, x, y, 0).uv(x, y).endVertex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
private static ByteBuffer getBuffer(int capacity) {
|
private static ByteBuffer getBuffer(int capacity) {
|
||||||
|
|
||||||
var buffer = backingBuffer;
|
var buffer = backingBuffer;
|
||||||
|
@ -30,7 +30,7 @@ import net.minecraft.util.RandomSource;
|
|||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
import net.minecraft.world.phys.HitResult;
|
import net.minecraft.world.phys.HitResult;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle> {
|
public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle> {
|
||||||
@ -54,14 +54,14 @@ public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceLocation getTurtleOverlayModel(ResourceLocation overlay, boolean christmas) {
|
public static @Nullable ResourceLocation getTurtleOverlayModel(@Nullable ResourceLocation overlay, boolean christmas) {
|
||||||
if (overlay != null) return overlay;
|
if (overlay != null) return overlay;
|
||||||
if (christmas) return ELF_OVERLAY_MODEL;
|
if (christmas) return ELF_OVERLAY_MODEL;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(@Nonnull TileTurtle turtle, float partialTicks, @Nonnull PoseStack transform, @Nonnull MultiBufferSource buffers, int lightmapCoord, int overlayLight) {
|
public void render(TileTurtle turtle, float partialTicks, PoseStack transform, MultiBufferSource buffers, int lightmapCoord, int overlayLight) {
|
||||||
// Render the label
|
// Render the label
|
||||||
var label = turtle.getLabel();
|
var label = turtle.getLabel();
|
||||||
var hit = renderer.cameraHitResult;
|
var hit = renderer.cameraHitResult;
|
||||||
@ -119,7 +119,7 @@ public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
|
|||||||
transform.popPose();
|
transform.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderUpgrade(@Nonnull PoseStack transform, @Nonnull VertexConsumer renderer, int lightmapCoord, int overlayLight, TileTurtle turtle, TurtleSide side, float f) {
|
private void renderUpgrade(PoseStack transform, VertexConsumer renderer, int lightmapCoord, int overlayLight, TileTurtle turtle, TurtleSide side, float f) {
|
||||||
var upgrade = turtle.getUpgrade(side);
|
var upgrade = turtle.getUpgrade(side);
|
||||||
if (upgrade == null) return;
|
if (upgrade == null) return;
|
||||||
transform.pushPose();
|
transform.pushPose();
|
||||||
@ -137,12 +137,12 @@ public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
|
|||||||
transform.popPose();
|
transform.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderModel(@Nonnull PoseStack transform, @Nonnull VertexConsumer renderer, int lightmapCoord, int overlayLight, ResourceLocation modelLocation, int[] tints) {
|
private void renderModel(PoseStack transform, VertexConsumer renderer, int lightmapCoord, int overlayLight, ResourceLocation modelLocation, @Nullable int[] tints) {
|
||||||
var modelManager = Minecraft.getInstance().getItemRenderer().getItemModelShaper().getModelManager();
|
var modelManager = Minecraft.getInstance().getItemRenderer().getItemModelShaper().getModelManager();
|
||||||
renderModel(transform, renderer, lightmapCoord, overlayLight, modelManager.getModel(modelLocation), tints);
|
renderModel(transform, renderer, lightmapCoord, overlayLight, modelManager.getModel(modelLocation), tints);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderModel(@Nonnull PoseStack transform, @Nonnull VertexConsumer renderer, int lightmapCoord, int overlayLight, BakedModel model, int[] tints) {
|
private void renderModel(PoseStack transform, VertexConsumer renderer, int lightmapCoord, int overlayLight, BakedModel model, @Nullable int[] tints) {
|
||||||
random.setSeed(0);
|
random.setSeed(0);
|
||||||
renderQuads(transform, renderer, lightmapCoord, overlayLight, model.getQuads(null, null, random), tints);
|
renderQuads(transform, renderer, lightmapCoord, overlayLight, model.getQuads(null, null, random), tints);
|
||||||
for (var facing : DirectionUtil.FACINGS) {
|
for (var facing : DirectionUtil.FACINGS) {
|
||||||
@ -150,7 +150,7 @@ public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void renderQuads(@Nonnull PoseStack transform, @Nonnull VertexConsumer buffer, int lightmapCoord, int overlayLight, List<BakedQuad> quads, int[] tints) {
|
private static void renderQuads(PoseStack transform, VertexConsumer buffer, int lightmapCoord, int overlayLight, List<BakedQuad> quads, @Nullable int[] tints) {
|
||||||
var matrix = transform.last();
|
var matrix = transform.last();
|
||||||
|
|
||||||
for (var bakedquad : quads) {
|
for (var bakedquad : quads) {
|
||||||
|
@ -19,7 +19,6 @@ import net.minecraftforge.client.model.geometry.IGeometryBakingContext;
|
|||||||
import net.minecraftforge.client.model.geometry.IGeometryLoader;
|
import net.minecraftforge.client.model.geometry.IGeometryLoader;
|
||||||
import net.minecraftforge.client.model.geometry.IUnbakedGeometry;
|
import net.minecraftforge.client.model.geometry.IUnbakedGeometry;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -33,9 +32,8 @@ public final class TurtleModelLoader implements IGeometryLoader<TurtleModelLoade
|
|||||||
private TurtleModelLoader() {
|
private TurtleModelLoader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Unbaked read(@Nonnull JsonObject modelContents, @Nonnull JsonDeserializationContext deserializationContext) {
|
public Unbaked read(JsonObject modelContents, JsonDeserializationContext deserializationContext) {
|
||||||
var model = new ResourceLocation(GsonHelper.getAsString(modelContents, "model"));
|
var model = new ResourceLocation(GsonHelper.getAsString(modelContents, "model"));
|
||||||
return new Unbaked(model);
|
return new Unbaked(model);
|
||||||
}
|
}
|
||||||
@ -57,10 +55,13 @@ public final class TurtleModelLoader implements IGeometryLoader<TurtleModelLoade
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BakedModel bake(IGeometryBakingContext owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState transform, ItemOverrides overrides, ResourceLocation modelLocation) {
|
public BakedModel bake(IGeometryBakingContext owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState transform, ItemOverrides overrides, ResourceLocation modelLocation) {
|
||||||
return new TurtleModel(
|
var mainModel = bakery.bake(family, transform, spriteGetter);
|
||||||
bakery.bake(family, transform, spriteGetter),
|
if (mainModel == null) throw new NullPointerException(family + " failed to bake");
|
||||||
bakery.bake(COLOUR_TURTLE_MODEL, transform, spriteGetter)
|
|
||||||
);
|
var colourModel = bakery.bake(COLOUR_TURTLE_MODEL, transform, spriteGetter);
|
||||||
|
if (colourModel == null) throw new NullPointerException(COLOUR_TURTLE_MODEL + " failed to bake");
|
||||||
|
|
||||||
|
return new TurtleModel(mainModel, colourModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ import dan200.computercraft.core.terminal.TextBuffer;
|
|||||||
import dan200.computercraft.core.util.Colour;
|
import dan200.computercraft.core.util.Colour;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.*;
|
import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.*;
|
||||||
@ -65,7 +64,7 @@ public final class DirectFixedWidthFontRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void drawBackground(
|
private static void drawBackground(
|
||||||
@Nonnull QuadEmitter emitter, float x, float y, @Nonnull TextBuffer backgroundColour, @Nonnull Palette palette,
|
QuadEmitter emitter, float x, float y, TextBuffer backgroundColour, Palette palette,
|
||||||
float leftMarginSize, float rightMarginSize, float height
|
float leftMarginSize, float rightMarginSize, float height
|
||||||
) {
|
) {
|
||||||
if (leftMarginSize > 0) {
|
if (leftMarginSize > 0) {
|
||||||
@ -96,7 +95,7 @@ public final class DirectFixedWidthFontRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawString(@Nonnull QuadEmitter emitter, float x, float y, @Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nonnull Palette palette) {
|
public static void drawString(QuadEmitter emitter, float x, float y, TextBuffer text, TextBuffer textColour, Palette palette) {
|
||||||
for (var i = 0; i < text.length(); i++) {
|
for (var i = 0; i < text.length(); i++) {
|
||||||
var colour = palette.getRenderColours(getColour(textColour.charAt(i), Colour.BLACK));
|
var colour = palette.getRenderColours(getColour(textColour.charAt(i), Colour.BLACK));
|
||||||
|
|
||||||
@ -107,7 +106,7 @@ public final class DirectFixedWidthFontRenderer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawTerminalForeground(@Nonnull QuadEmitter emitter, float x, float y, @Nonnull Terminal terminal) {
|
public static void drawTerminalForeground(QuadEmitter emitter, float x, float y, Terminal terminal) {
|
||||||
var palette = terminal.getPalette();
|
var palette = terminal.getPalette();
|
||||||
var height = terminal.getHeight();
|
var height = terminal.getHeight();
|
||||||
|
|
||||||
@ -122,7 +121,7 @@ public final class DirectFixedWidthFontRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void drawTerminalBackground(
|
public static void drawTerminalBackground(
|
||||||
@Nonnull QuadEmitter emitter, float x, float y, @Nonnull Terminal terminal,
|
QuadEmitter emitter, float x, float y, Terminal terminal,
|
||||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||||
) {
|
) {
|
||||||
var palette = terminal.getPalette();
|
var palette = terminal.getPalette();
|
||||||
@ -149,7 +148,7 @@ public final class DirectFixedWidthFontRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawCursor(@Nonnull QuadEmitter emitter, float x, float y, @Nonnull Terminal terminal) {
|
public static void drawCursor(QuadEmitter emitter, float x, float y, Terminal terminal) {
|
||||||
if (isCursorVisible(terminal)) {
|
if (isCursorVisible(terminal)) {
|
||||||
var colour = terminal.getPalette().getRenderColours(15 - terminal.getTextColour());
|
var colour = terminal.getPalette().getRenderColours(15 - terminal.getTextColour());
|
||||||
drawChar(emitter, x + terminal.getCursorX() * FONT_WIDTH, y + terminal.getCursorY() * FONT_HEIGHT, '_', colour);
|
drawChar(emitter, x + terminal.getCursorX() * FONT_WIDTH, y + terminal.getCursorY() * FONT_HEIGHT, '_', colour);
|
||||||
|
@ -16,8 +16,6 @@ import dan200.computercraft.core.terminal.TextBuffer;
|
|||||||
import dan200.computercraft.core.util.Colour;
|
import dan200.computercraft.core.util.Colour;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP;
|
import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,7 +86,7 @@ public final class FixedWidthFontRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void drawBackground(
|
private static void drawBackground(
|
||||||
@Nonnull QuadEmitter emitter, float x, float y, @Nonnull TextBuffer backgroundColour, @Nonnull Palette palette,
|
QuadEmitter emitter, float x, float y, TextBuffer backgroundColour, Palette palette,
|
||||||
float leftMarginSize, float rightMarginSize, float height, int light
|
float leftMarginSize, float rightMarginSize, float height, int light
|
||||||
) {
|
) {
|
||||||
if (leftMarginSize > 0) {
|
if (leftMarginSize > 0) {
|
||||||
@ -119,7 +117,7 @@ public final class FixedWidthFontRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawString(@Nonnull QuadEmitter emitter, float x, float y, @Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nonnull Palette palette, int light) {
|
public static void drawString(QuadEmitter emitter, float x, float y, TextBuffer text, TextBuffer textColour, Palette palette, int light) {
|
||||||
for (var i = 0; i < text.length(); i++) {
|
for (var i = 0; i < text.length(); i++) {
|
||||||
var colour = palette.getRenderColours(getColour(textColour.charAt(i), Colour.BLACK));
|
var colour = palette.getRenderColours(getColour(textColour.charAt(i), Colour.BLACK));
|
||||||
|
|
||||||
@ -130,7 +128,7 @@ public final class FixedWidthFontRenderer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawTerminalForeground(@Nonnull QuadEmitter emitter, float x, float y, @Nonnull Terminal terminal) {
|
public static void drawTerminalForeground(QuadEmitter emitter, float x, float y, Terminal terminal) {
|
||||||
var palette = terminal.getPalette();
|
var palette = terminal.getPalette();
|
||||||
var height = terminal.getHeight();
|
var height = terminal.getHeight();
|
||||||
|
|
||||||
@ -145,7 +143,7 @@ public final class FixedWidthFontRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void drawTerminalBackground(
|
public static void drawTerminalBackground(
|
||||||
@Nonnull QuadEmitter emitter, float x, float y, @Nonnull Terminal terminal,
|
QuadEmitter emitter, float x, float y, Terminal terminal,
|
||||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||||
) {
|
) {
|
||||||
var palette = terminal.getPalette();
|
var palette = terminal.getPalette();
|
||||||
@ -180,7 +178,7 @@ public final class FixedWidthFontRenderer {
|
|||||||
return cursorX >= 0 && cursorX < terminal.getWidth() && cursorY >= 0 && cursorY < terminal.getHeight();
|
return cursorX >= 0 && cursorX < terminal.getWidth() && cursorY >= 0 && cursorY < terminal.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawCursor(@Nonnull QuadEmitter emitter, float x, float y, @Nonnull Terminal terminal) {
|
public static void drawCursor(QuadEmitter emitter, float x, float y, Terminal terminal) {
|
||||||
if (isCursorVisible(terminal) && FrameInfo.getGlobalCursorBlink()) {
|
if (isCursorVisible(terminal) && FrameInfo.getGlobalCursorBlink()) {
|
||||||
var colour = terminal.getPalette().getRenderColours(15 - terminal.getTextColour());
|
var colour = terminal.getPalette().getRenderColours(15 - terminal.getTextColour());
|
||||||
drawChar(emitter, x + terminal.getCursorX() * FONT_WIDTH, y + terminal.getCursorY() * FONT_HEIGHT, '_', colour, FULL_BRIGHT_LIGHTMAP);
|
drawChar(emitter, x + terminal.getCursorX() * FONT_WIDTH, y + terminal.getCursorY() * FONT_HEIGHT, '_', colour, FULL_BRIGHT_LIGHTMAP);
|
||||||
@ -188,7 +186,7 @@ public final class FixedWidthFontRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void drawTerminal(
|
public static void drawTerminal(
|
||||||
@Nonnull QuadEmitter emitter, float x, float y, @Nonnull Terminal terminal,
|
QuadEmitter emitter, float x, float y, Terminal terminal,
|
||||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||||
) {
|
) {
|
||||||
drawTerminalBackground(
|
drawTerminalBackground(
|
||||||
@ -208,7 +206,7 @@ public final class FixedWidthFontRenderer {
|
|||||||
emitter.poseMatrix().load(transformBackup);
|
emitter.poseMatrix().load(transformBackup);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawEmptyTerminal(@Nonnull QuadEmitter emitter, float x, float y, float width, float height) {
|
public static void drawEmptyTerminal(QuadEmitter emitter, float x, float y, float width, float height) {
|
||||||
drawQuad(emitter, x, y, 0, width, height, BLACK, FULL_BRIGHT_LIGHTMAP);
|
drawQuad(emitter, x, y, 0, width, height, BLACK, FULL_BRIGHT_LIGHTMAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import net.minecraft.client.sounds.AudioStream;
|
|||||||
import net.minecraft.client.sounds.SoundEngine;
|
import net.minecraft.client.sounds.SoundEngine;
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.sound.sampled.AudioFormat;
|
import javax.sound.sampled.AudioFormat;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -55,7 +54,7 @@ class DfpwmStream implements AudioStream {
|
|||||||
DfpwmStream() {
|
DfpwmStream() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void push(@Nonnull ByteBuf input) {
|
void push(ByteBuf input) {
|
||||||
var readable = input.readableBytes();
|
var readable = input.readableBytes();
|
||||||
var output = ByteBuffer.allocate(readable * 8).order(ByteOrder.nativeOrder());
|
var output = ByteBuffer.allocate(readable * 8).order(ByteOrder.nativeOrder());
|
||||||
|
|
||||||
@ -101,13 +100,12 @@ class DfpwmStream implements AudioStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public AudioFormat getFormat() {
|
public AudioFormat getFormat() {
|
||||||
return MONO_8;
|
return MONO_8;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public synchronized ByteBuffer read(int capacity) {
|
public synchronized ByteBuffer read(int capacity) {
|
||||||
var result = BufferUtils.createByteBuffer(capacity);
|
var result = BufferUtils.createByteBuffer(capacity);
|
||||||
|
@ -12,14 +12,16 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An instance of a speaker, which is either playing a {@link DfpwmStream} stream or a normal sound.
|
* An instance of a speaker, which is either playing a {@link DfpwmStream} stream or a normal sound.
|
||||||
*/
|
*/
|
||||||
public class SpeakerInstance {
|
public class SpeakerInstance {
|
||||||
public static final ResourceLocation DFPWM_STREAM = new ResourceLocation(ComputerCraft.MOD_ID, "speaker.dfpwm_fake_audio_should_not_be_played");
|
public static final ResourceLocation DFPWM_STREAM = new ResourceLocation(ComputerCraft.MOD_ID, "speaker.dfpwm_fake_audio_should_not_be_played");
|
||||||
|
|
||||||
private DfpwmStream currentStream;
|
private @Nullable DfpwmStream currentStream;
|
||||||
private SpeakerSound sound;
|
private @Nullable SpeakerSound sound;
|
||||||
|
|
||||||
SpeakerInstance() {
|
SpeakerInstance() {
|
||||||
}
|
}
|
||||||
@ -30,7 +32,7 @@ public class SpeakerInstance {
|
|||||||
var stream = currentStream;
|
var stream = currentStream;
|
||||||
if (stream == null) stream = currentStream = new DfpwmStream();
|
if (stream == null) stream = currentStream = new DfpwmStream();
|
||||||
var exhausted = stream.isEmpty();
|
var exhausted = stream.isEmpty();
|
||||||
currentStream.push(buffer);
|
stream.push(buffer);
|
||||||
|
|
||||||
// If we've got nothing left in the buffer, enqueue an additional one just in case.
|
// If we've got nothing left in the buffer, enqueue an additional one just in case.
|
||||||
if (exhausted && sound != null && sound.stream == stream && stream.channel != null && stream.executor != null) {
|
if (exhausted && sound != null && sound.stream == stream && stream.channel != null && stream.executor != null) {
|
||||||
|
@ -16,17 +16,18 @@ import net.minecraft.resources.ResourceLocation;
|
|||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class SpeakerSound extends AbstractSoundInstance implements TickableSoundInstance {
|
public class SpeakerSound extends AbstractSoundInstance implements TickableSoundInstance {
|
||||||
|
@Nullable
|
||||||
DfpwmStream stream;
|
DfpwmStream stream;
|
||||||
|
|
||||||
private Entity entity;
|
private @Nullable Entity entity;
|
||||||
|
|
||||||
private boolean stopped = false;
|
private boolean stopped = false;
|
||||||
|
|
||||||
SpeakerSound(ResourceLocation sound, DfpwmStream stream, SpeakerPosition position, float volume, float pitch) {
|
SpeakerSound(ResourceLocation sound, @Nullable DfpwmStream stream, SpeakerPosition position, float volume, float pitch) {
|
||||||
super(sound, SoundSource.RECORDS, SoundInstance.createUnseededRandom());
|
super(sound, SoundSource.RECORDS, SoundInstance.createUnseededRandom());
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
@ -60,13 +61,12 @@ public class SpeakerSound extends AbstractSoundInstance implements TickableSound
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<AudioStream> getStream(@Nonnull SoundBufferLibrary soundBuffers, @Nonnull Sound sound, boolean looping) {
|
public CompletableFuture<AudioStream> getStream(SoundBufferLibrary soundBuffers, Sound sound, boolean looping) {
|
||||||
return stream != null ? CompletableFuture.completedFuture(stream) : super.getStream(soundBuffers, sound, looping);
|
return stream != null ? CompletableFuture.completedFuture(stream) : super.getStream(soundBuffers, sound, looping);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AudioStream getStream() {
|
public @Nullable AudioStream getStream() {
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,6 @@ import dan200.computercraft.shared.turtle.upgrades.TurtleModem;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class TurtleModemModeller implements TurtleUpgradeModeller<TurtleModem> {
|
public class TurtleModemModeller implements TurtleUpgradeModeller<TurtleModem> {
|
||||||
private final ResourceLocation leftOffModel;
|
private final ResourceLocation leftOffModel;
|
||||||
private final ResourceLocation rightOffModel;
|
private final ResourceLocation rightOffModel;
|
||||||
@ -36,9 +34,8 @@ public class TurtleModemModeller implements TurtleUpgradeModeller<TurtleModem> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public TransformedModel getModel(@Nonnull TurtleModem upgrade, @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side) {
|
public TransformedModel getModel(TurtleModem upgrade, @Nullable ITurtleAccess turtle, TurtleSide side) {
|
||||||
var active = false;
|
var active = false;
|
||||||
if (turtle != null) {
|
if (turtle != null) {
|
||||||
var turtleNBT = turtle.getUpgradeNBTData(side);
|
var turtleNBT = turtle.getUpgradeNBTData(side);
|
||||||
|
@ -16,7 +16,6 @@ import dan200.computercraft.shared.TurtleUpgrades;
|
|||||||
import dan200.computercraft.shared.UpgradeManager;
|
import dan200.computercraft.shared.UpgradeManager;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
@ -39,7 +38,7 @@ public final class TurtleUpgradeModellers {
|
|||||||
private TurtleUpgradeModellers() {
|
private TurtleUpgradeModellers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends ITurtleUpgrade> void register(@Nonnull TurtleUpgradeSerialiser<T> serialiser, @Nonnull TurtleUpgradeModeller<T> modeller) {
|
public static <T extends ITurtleUpgrade> void register(TurtleUpgradeSerialiser<T> serialiser, TurtleUpgradeModeller<T> modeller) {
|
||||||
synchronized (turtleModels) {
|
synchronized (turtleModels) {
|
||||||
if (turtleModels.containsKey(serialiser)) {
|
if (turtleModels.containsKey(serialiser)) {
|
||||||
throw new IllegalStateException("Modeller already registered for serialiser");
|
throw new IllegalStateException("Modeller already registered for serialiser");
|
||||||
@ -49,7 +48,7 @@ public final class TurtleUpgradeModellers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransformedModel getModel(@Nonnull ITurtleUpgrade upgrade, @Nullable ITurtleAccess access, @Nonnull TurtleSide side) {
|
public static TransformedModel getModel(ITurtleUpgrade upgrade, @Nullable ITurtleAccess access, TurtleSide side) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
var modeller = (TurtleUpgradeModeller<ITurtleUpgrade>) modelCache.computeIfAbsent(upgrade, TurtleUpgradeModellers::getModeller);
|
var modeller = (TurtleUpgradeModeller<ITurtleUpgrade>) modelCache.computeIfAbsent(upgrade, TurtleUpgradeModellers::getModeller);
|
||||||
return modeller.getModel(upgrade, access, side);
|
return modeller.getModel(upgrade, access, side);
|
||||||
|
@ -35,7 +35,6 @@ import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePrope
|
|||||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||||
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
|
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@ -47,7 +46,6 @@ class LootTableGenerator extends LootTableProvider {
|
|||||||
super(generator);
|
super(generator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> getTables() {
|
public List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> getTables() {
|
||||||
return List.of(
|
return List.of(
|
||||||
@ -57,7 +55,7 @@ class LootTableGenerator extends LootTableProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validate(Map<ResourceLocation, LootTable> map, @Nonnull ValidationContext validationtracker) {
|
protected void validate(Map<ResourceLocation, LootTable> map, ValidationContext validationtracker) {
|
||||||
map.forEach((id, table) -> LootTables.validate(validationtracker, id, table));
|
map.forEach((id, table) -> LootTables.validate(validationtracker, id, table));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ import net.minecraft.resources.ResourceLocation;
|
|||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -56,7 +55,7 @@ public class ModelProvider implements DataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(@Nonnull CachedOutput output) {
|
public void run(CachedOutput output) {
|
||||||
Map<Block, BlockStateGenerator> blockStates = new HashMap<>();
|
Map<Block, BlockStateGenerator> blockStates = new HashMap<>();
|
||||||
Consumer<BlockStateGenerator> addBlockState = generator -> {
|
Consumer<BlockStateGenerator> addBlockState = generator -> {
|
||||||
var block = generator.getBlock();
|
var block = generator.getBlock();
|
||||||
@ -102,7 +101,6 @@ public class ModelProvider implements DataProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Block State Definitions";
|
return "Block State Definitions";
|
||||||
|
@ -11,7 +11,6 @@ import dan200.computercraft.api.pocket.PocketUpgradeSerialiser;
|
|||||||
import net.minecraft.data.DataGenerator;
|
import net.minecraft.data.DataGenerator;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static dan200.computercraft.shared.ModRegistry.Items;
|
import static dan200.computercraft.shared.ModRegistry.Items;
|
||||||
@ -23,14 +22,13 @@ class PocketUpgradeGenerator extends PocketUpgradeDataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addUpgrades(@Nonnull Consumer<Upgrade<PocketUpgradeSerialiser<?>>> addUpgrade) {
|
protected void addUpgrades(Consumer<Upgrade<PocketUpgradeSerialiser<?>>> addUpgrade) {
|
||||||
addUpgrade.accept(simpleWithCustomItem(id("speaker"), PocketUpgradeSerialisers.SPEAKER.get(), Items.SPEAKER.get()));
|
addUpgrade.accept(simpleWithCustomItem(id("speaker"), PocketUpgradeSerialisers.SPEAKER.get(), Items.SPEAKER.get()));
|
||||||
simpleWithCustomItem(id("wireless_modem_normal"), PocketUpgradeSerialisers.WIRELESS_MODEM_NORMAL.get(), Items.WIRELESS_MODEM_NORMAL.get()).add(addUpgrade);
|
simpleWithCustomItem(id("wireless_modem_normal"), PocketUpgradeSerialisers.WIRELESS_MODEM_NORMAL.get(), Items.WIRELESS_MODEM_NORMAL.get()).add(addUpgrade);
|
||||||
simpleWithCustomItem(id("wireless_modem_advanced"), PocketUpgradeSerialisers.WIRELESS_MODEM_ADVANCED.get(), Items.WIRELESS_MODEM_ADVANCED.get()).add(addUpgrade);
|
simpleWithCustomItem(id("wireless_modem_advanced"), PocketUpgradeSerialisers.WIRELESS_MODEM_ADVANCED.get(), Items.WIRELESS_MODEM_ADVANCED.get()).add(addUpgrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private static ResourceLocation id(String id) {
|
||||||
private static ResourceLocation id(@Nonnull String id) {
|
|
||||||
return new ResourceLocation(ComputerCraft.MOD_ID, id);
|
return new ResourceLocation(ComputerCraft.MOD_ID, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.data;
|
package dan200.computercraft.data;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
@ -243,7 +242,7 @@ public class PrettyJsonWriter extends JsonWriter {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// We've run out of room, so write each value on separate lines.
|
// We've run out of room, so write each value on separate lines.
|
||||||
var indentStr = Strings.repeat(" ", indent);
|
var indentStr = " ".repeat(indent);
|
||||||
writer.append("\n ").append(indentStr);
|
writer.append("\n ").append(indentStr);
|
||||||
|
|
||||||
var comma = false;
|
var comma = false;
|
||||||
|
@ -38,7 +38,6 @@ import net.minecraft.world.item.crafting.SimpleRecipeSerializer;
|
|||||||
import net.minecraft.world.level.ItemLike;
|
import net.minecraft.world.level.ItemLike;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@ -58,7 +57,7 @@ class RecipeGenerator extends RecipeProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void buildCraftingRecipes(@Nonnull Consumer<FinishedRecipe> add) {
|
protected void buildCraftingRecipes(Consumer<FinishedRecipe> add) {
|
||||||
basicRecipes(add);
|
basicRecipes(add);
|
||||||
diskColours(add);
|
diskColours(add);
|
||||||
pocketUpgrades(add);
|
pocketUpgrades(add);
|
||||||
@ -76,7 +75,7 @@ class RecipeGenerator extends RecipeProvider {
|
|||||||
*
|
*
|
||||||
* @param add The callback to add recipes.
|
* @param add The callback to add recipes.
|
||||||
*/
|
*/
|
||||||
private void diskColours(@Nonnull Consumer<FinishedRecipe> add) {
|
private void diskColours(Consumer<FinishedRecipe> add) {
|
||||||
for (var colour : Colour.VALUES) {
|
for (var colour : Colour.VALUES) {
|
||||||
ShapelessRecipeBuilder
|
ShapelessRecipeBuilder
|
||||||
.shapeless(ModRegistry.Items.DISK.get())
|
.shapeless(ModRegistry.Items.DISK.get())
|
||||||
@ -98,7 +97,7 @@ class RecipeGenerator extends RecipeProvider {
|
|||||||
*
|
*
|
||||||
* @param add The callback to add recipes.
|
* @param add The callback to add recipes.
|
||||||
*/
|
*/
|
||||||
private void turtleUpgrades(@Nonnull Consumer<FinishedRecipe> add) {
|
private void turtleUpgrades(Consumer<FinishedRecipe> add) {
|
||||||
for (var family : ComputerFamily.values()) {
|
for (var family : ComputerFamily.values()) {
|
||||||
var base = TurtleItemFactory.create(-1, null, -1, family, null, null, 0, null);
|
var base = TurtleItemFactory.create(-1, null, -1, family, null, null, 0, null);
|
||||||
if (base.isEmpty()) continue;
|
if (base.isEmpty()) continue;
|
||||||
@ -130,7 +129,7 @@ class RecipeGenerator extends RecipeProvider {
|
|||||||
*
|
*
|
||||||
* @param add The callback to add recipes.
|
* @param add The callback to add recipes.
|
||||||
*/
|
*/
|
||||||
private void pocketUpgrades(@Nonnull Consumer<FinishedRecipe> add) {
|
private void pocketUpgrades(Consumer<FinishedRecipe> add) {
|
||||||
for (var family : ComputerFamily.values()) {
|
for (var family : ComputerFamily.values()) {
|
||||||
var base = PocketComputerItemFactory.create(-1, null, -1, family, null);
|
var base = PocketComputerItemFactory.create(-1, null, -1, family, null);
|
||||||
if (base.isEmpty()) continue;
|
if (base.isEmpty()) continue;
|
||||||
@ -158,7 +157,7 @@ class RecipeGenerator extends RecipeProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void basicRecipes(@Nonnull Consumer<FinishedRecipe> add) {
|
private void basicRecipes(Consumer<FinishedRecipe> add) {
|
||||||
ShapedRecipeBuilder
|
ShapedRecipeBuilder
|
||||||
.shaped(ModRegistry.Items.CABLE.get(), 6)
|
.shaped(ModRegistry.Items.CABLE.get(), 6)
|
||||||
.pattern(" # ")
|
.pattern(" # ")
|
||||||
|
@ -12,7 +12,6 @@ import net.minecraft.resources.ResourceLocation;
|
|||||||
import net.minecraft.util.GsonHelper;
|
import net.minecraft.util.GsonHelper;
|
||||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -65,18 +64,16 @@ final class RecipeWrapper implements Consumer<FinishedRecipe> {
|
|||||||
FinishedRecipe recipe, RecipeSerializer<?> serializer, List<Consumer<JsonObject>> extend
|
FinishedRecipe recipe, RecipeSerializer<?> serializer, List<Consumer<JsonObject>> extend
|
||||||
) implements FinishedRecipe {
|
) implements FinishedRecipe {
|
||||||
@Override
|
@Override
|
||||||
public void serializeRecipeData(@Nonnull JsonObject jsonObject) {
|
public void serializeRecipeData(JsonObject jsonObject) {
|
||||||
recipe.serializeRecipeData(jsonObject);
|
recipe.serializeRecipeData(jsonObject);
|
||||||
for (var extender : extend) extender.accept(jsonObject);
|
for (var extender : extend) extender.accept(jsonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getId() {
|
public ResourceLocation getId() {
|
||||||
return recipe.getId();
|
return recipe.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public RecipeSerializer<?> getType() {
|
public RecipeSerializer<?> getType() {
|
||||||
return serializer;
|
return serializer;
|
||||||
|
@ -12,7 +12,6 @@ import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
|
|||||||
import net.minecraft.data.DataGenerator;
|
import net.minecraft.data.DataGenerator;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static dan200.computercraft.shared.ModRegistry.Items;
|
import static dan200.computercraft.shared.ModRegistry.Items;
|
||||||
@ -24,7 +23,7 @@ class TurtleUpgradeGenerator extends TurtleUpgradeDataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addUpgrades(@Nonnull Consumer<Upgrade<TurtleUpgradeSerialiser<?>>> addUpgrade) {
|
protected void addUpgrades(Consumer<Upgrade<TurtleUpgradeSerialiser<?>>> addUpgrade) {
|
||||||
simpleWithCustomItem(id("speaker"), TurtleSerialisers.SPEAKER.get(), Items.SPEAKER.get()).add(addUpgrade);
|
simpleWithCustomItem(id("speaker"), TurtleSerialisers.SPEAKER.get(), Items.SPEAKER.get()).add(addUpgrade);
|
||||||
simpleWithCustomItem(vanilla("crafting_table"), TurtleSerialisers.WORKBENCH.get(), net.minecraft.world.item.Items.CRAFTING_TABLE).add(addUpgrade);
|
simpleWithCustomItem(vanilla("crafting_table"), TurtleSerialisers.WORKBENCH.get(), net.minecraft.world.item.Items.CRAFTING_TABLE).add(addUpgrade);
|
||||||
simpleWithCustomItem(id("wireless_modem_normal"), TurtleSerialisers.WIRELESS_MODEM_NORMAL.get(), Items.WIRELESS_MODEM_NORMAL.get()).add(addUpgrade);
|
simpleWithCustomItem(id("wireless_modem_normal"), TurtleSerialisers.WIRELESS_MODEM_NORMAL.get(), Items.WIRELESS_MODEM_NORMAL.get()).add(addUpgrade);
|
||||||
@ -37,13 +36,11 @@ class TurtleUpgradeGenerator extends TurtleUpgradeDataProvider {
|
|||||||
tool(vanilla("diamond_sword"), net.minecraft.world.item.Items.DIAMOND_SWORD).breakable(Blocks.TURTLE_SWORD_BREAKABLE).damageMultiplier(9.0f).add(addUpgrade);
|
tool(vanilla("diamond_sword"), net.minecraft.world.item.Items.DIAMOND_SWORD).breakable(Blocks.TURTLE_SWORD_BREAKABLE).damageMultiplier(9.0f).add(addUpgrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private static ResourceLocation id(String id) {
|
||||||
private static ResourceLocation id(@Nonnull String id) {
|
|
||||||
return new ResourceLocation(ComputerCraft.MOD_ID, id);
|
return new ResourceLocation(ComputerCraft.MOD_ID, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private static ResourceLocation vanilla(String id) {
|
||||||
private static ResourceLocation vanilla(@Nonnull String id) {
|
|
||||||
// Naughty, please don't do this. Mostly here for some semblance of backwards compatibility.
|
// Naughty, please don't do this. Mostly here for some semblance of backwards compatibility.
|
||||||
return new ResourceLocation("minecraft", id);
|
return new ResourceLocation("minecraft", id);
|
||||||
}
|
}
|
||||||
|
22
src/main/java/dan200/computercraft/package-info.java
Normal file
22
src/main/java/dan200/computercraft/package-info.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ComputerCraft's core Lua runtime and APIs.
|
||||||
|
* <p>
|
||||||
|
* This is not considered part of the stable API, and so should not be consumed by other Minecraft mods. However,
|
||||||
|
* emulators or other CC-tooling may find this useful.
|
||||||
|
*/
|
||||||
|
@DefaultQualifier(value = NonNull.class, locations = {
|
||||||
|
TypeUseLocation.RETURN,
|
||||||
|
TypeUseLocation.PARAMETER,
|
||||||
|
TypeUseLocation.FIELD,
|
||||||
|
})
|
||||||
|
package dan200.computercraft;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
import org.checkerframework.framework.qual.TypeUseLocation;
|
@ -12,7 +12,6 @@ import net.minecraft.core.BlockPos;
|
|||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -22,12 +21,12 @@ public final class BundledRedstone {
|
|||||||
private BundledRedstone() {
|
private BundledRedstone() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void register(@Nonnull IBundledRedstoneProvider provider) {
|
public static synchronized void register(IBundledRedstoneProvider provider) {
|
||||||
Objects.requireNonNull(provider, "provider cannot be null");
|
Objects.requireNonNull(provider, "provider cannot be null");
|
||||||
if (!providers.contains(provider)) providers.add(provider);
|
if (!providers.contains(provider)) providers.add(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDefaultOutput(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side) {
|
public static int getDefaultOutput(Level world, BlockPos pos, Direction side) {
|
||||||
return world.isInWorldBounds(pos) ? DefaultBundledRedstoneProvider.getDefaultBundledRedstoneOutput(world, pos, side) : -1;
|
return world.isInWorldBounds(pos) ? DefaultBundledRedstoneProvider.getDefaultBundledRedstoneOutput(world, pos, side) : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import dan200.computercraft.api.media.IMedia;
|
|||||||
import dan200.computercraft.api.media.IMediaProvider;
|
import dan200.computercraft.api.media.IMediaProvider;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -21,12 +21,12 @@ public final class MediaProviders {
|
|||||||
private MediaProviders() {
|
private MediaProviders() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void register(@Nonnull IMediaProvider provider) {
|
public static synchronized void register(IMediaProvider provider) {
|
||||||
Objects.requireNonNull(provider, "provider cannot be null");
|
Objects.requireNonNull(provider, "provider cannot be null");
|
||||||
providers.add(provider);
|
providers.add(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMedia get(@Nonnull ItemStack stack) {
|
public static @Nullable IMedia get(ItemStack stack) {
|
||||||
if (stack.isEmpty()) return null;
|
if (stack.isEmpty()) return null;
|
||||||
|
|
||||||
// Try the handlers in order:
|
// Try the handlers in order:
|
||||||
|
@ -15,7 +15,6 @@ import net.minecraft.core.Direction;
|
|||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraftforge.common.util.NonNullConsumer;
|
import net.minecraftforge.common.util.NonNullConsumer;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
@ -29,7 +28,7 @@ public final class Peripherals {
|
|||||||
private Peripherals() {
|
private Peripherals() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void register(@Nonnull IPeripheralProvider provider) {
|
public static synchronized void register(IPeripheralProvider provider) {
|
||||||
Objects.requireNonNull(provider, "provider cannot be null");
|
Objects.requireNonNull(provider, "provider cannot be null");
|
||||||
providers.add(provider);
|
providers.add(provider);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import net.minecraft.world.item.ItemStack;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -42,7 +41,7 @@ public class UpgradeManager<R extends UpgradeSerialiser<? extends T>, T extends
|
|||||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
||||||
|
|
||||||
public record UpgradeWrapper<R extends UpgradeSerialiser<? extends T>, T extends IUpgradeBase>(
|
public record UpgradeWrapper<R extends UpgradeSerialiser<? extends T>, T extends IUpgradeBase>(
|
||||||
@Nonnull String id, @Nonnull T upgrade, @Nonnull R serialiser, @Nonnull String modId
|
String id, T upgrade, R serialiser, String modId
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +51,7 @@ public class UpgradeManager<R extends UpgradeSerialiser<? extends T>, T extends
|
|||||||
private Map<String, UpgradeWrapper<R, T>> current = Collections.emptyMap();
|
private Map<String, UpgradeWrapper<R, T>> current = Collections.emptyMap();
|
||||||
private Map<T, UpgradeWrapper<R, T>> currentWrappers = Collections.emptyMap();
|
private Map<T, UpgradeWrapper<R, T>> currentWrappers = Collections.emptyMap();
|
||||||
|
|
||||||
public UpgradeManager(@Nonnull String kind, @Nonnull String path, @Nonnull ResourceKey<Registry<R>> registry) {
|
public UpgradeManager(String kind, String path, ResourceKey<Registry<R>> registry) {
|
||||||
super(GSON, path);
|
super(GSON, path);
|
||||||
this.kind = kind;
|
this.kind = kind;
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
@ -65,18 +64,18 @@ public class UpgradeManager<R extends UpgradeSerialiser<? extends T>, T extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public UpgradeWrapper<R, T> getWrapper(@Nonnull T upgrade) {
|
public UpgradeWrapper<R, T> getWrapper(T upgrade) {
|
||||||
return currentWrappers.get(upgrade);
|
return currentWrappers.get(upgrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getOwner(@Nonnull T upgrade) {
|
public String getOwner(T upgrade) {
|
||||||
var wrapper = currentWrappers.get(upgrade);
|
var wrapper = currentWrappers.get(upgrade);
|
||||||
return wrapper != null ? wrapper.modId() : null;
|
return wrapper != null ? wrapper.modId() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public T get(@Nonnull ItemStack stack) {
|
public T get(ItemStack stack) {
|
||||||
if (stack.isEmpty()) return null;
|
if (stack.isEmpty()) return null;
|
||||||
|
|
||||||
for (var wrapper : current.values()) {
|
for (var wrapper : current.values()) {
|
||||||
@ -89,18 +88,16 @@ public class UpgradeManager<R extends UpgradeSerialiser<? extends T>, T extends
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public Collection<T> getUpgrades() {
|
public Collection<T> getUpgrades() {
|
||||||
return currentWrappers.keySet();
|
return currentWrappers.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public Map<String, UpgradeWrapper<R, T>> getUpgradeWrappers() {
|
public Map<String, UpgradeWrapper<R, T>> getUpgradeWrappers() {
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void apply(@Nonnull Map<ResourceLocation, JsonElement> upgrades, @Nonnull ResourceManager manager, @Nonnull ProfilerFiller profiler) {
|
protected void apply(Map<ResourceLocation, JsonElement> upgrades, ResourceManager manager, ProfilerFiller profiler) {
|
||||||
Map<String, UpgradeWrapper<R, T>> newUpgrades = new HashMap<>();
|
Map<String, UpgradeWrapper<R, T>> newUpgrades = new HashMap<>();
|
||||||
for (var element : upgrades.entrySet()) {
|
for (var element : upgrades.entrySet()) {
|
||||||
try {
|
try {
|
||||||
@ -136,7 +133,7 @@ public class UpgradeManager<R extends UpgradeSerialiser<? extends T>, T extends
|
|||||||
current.put(result.id(), result);
|
current.put(result.id(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadFromNetwork(@Nonnull Map<String, UpgradeWrapper<R, T>> newUpgrades) {
|
public void loadFromNetwork(Map<String, UpgradeWrapper<R, T>> newUpgrades) {
|
||||||
current = Collections.unmodifiableMap(newUpgrades);
|
current = Collections.unmodifiableMap(newUpgrades);
|
||||||
currentWrappers = newUpgrades.values().stream().collect(Collectors.toUnmodifiableMap(UpgradeWrapper::upgrade, x -> x));
|
currentWrappers = newUpgrades.values().stream().collect(Collectors.toUnmodifiableMap(UpgradeWrapper::upgrade, x -> x));
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import net.minecraft.commands.CommandSourceStack;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket;
|
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.MenuProvider;
|
import net.minecraft.world.MenuProvider;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
@ -33,7 +32,7 @@ import net.minecraft.world.inventory.AbstractContainerMenu;
|
|||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -150,11 +149,9 @@ public final class CommandComputerCraft {
|
|||||||
.arg("computer", oneComputer())
|
.arg("computer", oneComputer())
|
||||||
.executes(context -> {
|
.executes(context -> {
|
||||||
var computer = getComputerArgument(context, "computer");
|
var computer = getComputerArgument(context, "computer");
|
||||||
Level world = computer.getLevel();
|
var world = computer.getLevel();
|
||||||
var pos = computer.getPosition();
|
var pos = computer.getPosition();
|
||||||
|
|
||||||
if (world == null || pos == null) throw TP_NOT_THERE.create();
|
|
||||||
|
|
||||||
var entity = context.getSource().getEntityOrException();
|
var entity = context.getSource().getEntityOrException();
|
||||||
if (!(entity instanceof ServerPlayer player)) throw TP_NOT_PLAYER.create();
|
if (!(entity instanceof ServerPlayer player)) throw TP_NOT_PLAYER.create();
|
||||||
|
|
||||||
@ -164,7 +161,7 @@ public final class CommandComputerCraft {
|
|||||||
EnumSet.noneOf(ClientboundPlayerPositionPacket.RelativeArgument.class)
|
EnumSet.noneOf(ClientboundPlayerPositionPacket.RelativeArgument.class)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
player.teleportTo((ServerLevel) world,
|
player.teleportTo(world,
|
||||||
pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0
|
pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -198,15 +195,13 @@ public final class CommandComputerCraft {
|
|||||||
var player = context.getSource().getPlayerOrException();
|
var player = context.getSource().getPlayerOrException();
|
||||||
var computer = getComputerArgument(context, "computer");
|
var computer = getComputerArgument(context, "computer");
|
||||||
new ComputerContainerData(computer, ItemStack.EMPTY).open(player, new MenuProvider() {
|
new ComputerContainerData(computer, ItemStack.EMPTY).open(player, new MenuProvider() {
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Component getDisplayName() {
|
public Component getDisplayName() {
|
||||||
return Component.translatable("gui.computercraft.view_computer");
|
return Component.translatable("gui.computercraft.view_computer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractContainerMenu createMenu(int id, @Nonnull Inventory player, @Nonnull Player entity) {
|
public AbstractContainerMenu createMenu(int id, Inventory player, Player entity) {
|
||||||
return new ContainerViewComputer(id, player, computer);
|
return new ContainerViewComputer(id, player, computer);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -251,7 +246,7 @@ public final class CommandComputerCraft {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Component linkComputer(CommandSourceStack source, ServerComputer serverComputer, int computerId) {
|
private static Component linkComputer(CommandSourceStack source, @Nullable ServerComputer serverComputer, int computerId) {
|
||||||
var out = Component.literal("");
|
var out = Component.literal("");
|
||||||
|
|
||||||
// Append the computer instance
|
// Append the computer instance
|
||||||
@ -305,7 +300,7 @@ public final class CommandComputerCraft {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Component linkStorage(CommandSourceStack source, int id) {
|
private static @Nullable Component linkStorage(CommandSourceStack source, int id) {
|
||||||
var file = new File(ServerContext.get(source.getServer()).storageDir().toFile(), "computer/" + id);
|
var file = new File(ServerContext.get(source.getServer()).storageDir().toFile(), "computer/" + id);
|
||||||
if (!file.isDirectory()) return null;
|
if (!file.isDirectory()) return null;
|
||||||
|
|
||||||
@ -316,7 +311,6 @@ public final class CommandComputerCraft {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
private static BasicComputerMetricsObserver getMetricsInstance(CommandSourceStack source) {
|
private static BasicComputerMetricsObserver getMetricsInstance(CommandSourceStack source) {
|
||||||
var entity = source.getEntity();
|
var entity = source.getEntity();
|
||||||
return ServerContext.get(source.getServer()).metrics().getMetricsInstance(entity instanceof Player ? entity.getUUID() : SYSTEM_UUID);
|
return ServerContext.get(source.getServer()).metrics().getMetricsInstance(entity instanceof Player ? entity.getUUID() : SYSTEM_UUID);
|
||||||
|
@ -21,7 +21,6 @@ import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
|||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -145,19 +144,18 @@ public final class ComputersArgumentType implements ArgumentType<ComputersArgume
|
|||||||
|
|
||||||
public static class Info implements ArgumentTypeInfo<ComputersArgumentType, Template> {
|
public static class Info implements ArgumentTypeInfo<ComputersArgumentType, Template> {
|
||||||
@Override
|
@Override
|
||||||
public void serializeToNetwork(@Nonnull ComputersArgumentType.Template arg, @Nonnull FriendlyByteBuf buf) {
|
public void serializeToNetwork(ComputersArgumentType.Template arg, FriendlyByteBuf buf) {
|
||||||
buf.writeBoolean(arg.requireSome());
|
buf.writeBoolean(arg.requireSome());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ComputersArgumentType.Template deserializeFromNetwork(@Nonnull FriendlyByteBuf buf) {
|
public ComputersArgumentType.Template deserializeFromNetwork(FriendlyByteBuf buf) {
|
||||||
var requiresSome = buf.readBoolean();
|
var requiresSome = buf.readBoolean();
|
||||||
return new ComputersArgumentType.Template(this, requiresSome);
|
return new ComputersArgumentType.Template(this, requiresSome);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serializeToJson(@Nonnull ComputersArgumentType.Template arg, @Nonnull JsonObject json) {
|
public void serializeToJson(ComputersArgumentType.Template arg, JsonObject json) {
|
||||||
json.addProperty("requireSome", arg.requireSome);
|
json.addProperty("requireSome", arg.requireSome);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ import net.minecraft.network.FriendlyByteBuf;
|
|||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -114,29 +113,27 @@ public final class RepeatArgumentType<T, U> implements ArgumentType<List<T>> {
|
|||||||
|
|
||||||
public static class Info implements ArgumentTypeInfo<RepeatArgumentType<?, ?>, Template> {
|
public static class Info implements ArgumentTypeInfo<RepeatArgumentType<?, ?>, Template> {
|
||||||
@Override
|
@Override
|
||||||
public void serializeToNetwork(@Nonnull RepeatArgumentType.Template arg, @Nonnull FriendlyByteBuf buf) {
|
public void serializeToNetwork(RepeatArgumentType.Template arg, FriendlyByteBuf buf) {
|
||||||
buf.writeBoolean(arg.flatten);
|
buf.writeBoolean(arg.flatten);
|
||||||
ArgumentUtils.serializeToNetwork(buf, arg.child);
|
ArgumentUtils.serializeToNetwork(buf, arg.child);
|
||||||
buf.writeComponent(ArgumentUtils.getMessage(arg.some));
|
buf.writeComponent(ArgumentUtils.getMessage(arg.some));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public RepeatArgumentType.Template deserializeFromNetwork(@Nonnull FriendlyByteBuf buf) {
|
public RepeatArgumentType.Template deserializeFromNetwork(FriendlyByteBuf buf) {
|
||||||
var isList = buf.readBoolean();
|
var isList = buf.readBoolean();
|
||||||
var child = ArgumentUtils.deserialize(buf);
|
var child = ArgumentUtils.deserialize(buf);
|
||||||
var message = buf.readComponent();
|
var message = buf.readComponent();
|
||||||
return new RepeatArgumentType.Template(this, child, isList, new SimpleCommandExceptionType(message));
|
return new RepeatArgumentType.Template(this, child, isList, new SimpleCommandExceptionType(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public RepeatArgumentType.Template unpack(RepeatArgumentType<?, ?> argumentType) {
|
public RepeatArgumentType.Template unpack(RepeatArgumentType<?, ?> argumentType) {
|
||||||
return new RepeatArgumentType.Template(this, ArgumentTypeInfos.unpack(argumentType.child), argumentType.flatten, argumentType.some);
|
return new RepeatArgumentType.Template(this, ArgumentTypeInfos.unpack(argumentType.child), argumentType.flatten, argumentType.some);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serializeToJson(@Nonnull RepeatArgumentType.Template arg, @Nonnull JsonObject json) {
|
public void serializeToJson(RepeatArgumentType.Template arg, JsonObject json) {
|
||||||
json.addProperty("flatten", arg.flatten);
|
json.addProperty("flatten", arg.flatten);
|
||||||
json.add("child", ArgumentUtils.serializeToJson(arg.child));
|
json.add("child", ArgumentUtils.serializeToJson(arg.child));
|
||||||
json.addProperty("error", Component.Serializer.toJson(ArgumentUtils.getMessage(arg.some)));
|
json.addProperty("error", Component.Serializer.toJson(ArgumentUtils.getMessage(arg.some)));
|
||||||
@ -146,7 +143,6 @@ public final class RepeatArgumentType<T, U> implements ArgumentType<List<T>> {
|
|||||||
public record Template(
|
public record Template(
|
||||||
Info info, ArgumentTypeInfo.Template<?> child, boolean flatten, SimpleCommandExceptionType some
|
Info info, ArgumentTypeInfo.Template<?> child, boolean flatten, SimpleCommandExceptionType some
|
||||||
) implements ArgumentTypeInfo.Template<RepeatArgumentType<?, ?>> {
|
) implements ArgumentTypeInfo.Template<RepeatArgumentType<?, ?>> {
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public RepeatArgumentType<?, ?> instantiate(@NotNull CommandBuildContext commandBuildContext) {
|
public RepeatArgumentType<?, ?> instantiate(@NotNull CommandBuildContext commandBuildContext) {
|
||||||
@ -154,7 +150,6 @@ public final class RepeatArgumentType<T, U> implements ArgumentType<List<T>> {
|
|||||||
return flatten ? RepeatArgumentType.someFlat((ArgumentType) child, some()) : RepeatArgumentType.some(child, some());
|
return flatten ? RepeatArgumentType.someFlat((ArgumentType) child, some()) : RepeatArgumentType.some(child, some());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentTypeInfo<RepeatArgumentType<?, ?>, ?> type() {
|
public ArgumentTypeInfo<RepeatArgumentType<?, ?>, ?> type() {
|
||||||
return info;
|
return info;
|
||||||
|
@ -14,6 +14,7 @@ import com.mojang.brigadier.tree.CommandNode;
|
|||||||
import dan200.computercraft.shared.command.arguments.RepeatArgumentType;
|
import dan200.computercraft.shared.command.arguments.RepeatArgumentType;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -31,7 +32,7 @@ import static dan200.computercraft.shared.command.builder.HelpingArgumentBuilder
|
|||||||
*/
|
*/
|
||||||
public class CommandBuilder<S> implements CommandNodeBuilder<S, Command<S>> {
|
public class CommandBuilder<S> implements CommandNodeBuilder<S, Command<S>> {
|
||||||
private final List<ArgumentBuilder<S, ?>> args = new ArrayList<>();
|
private final List<ArgumentBuilder<S, ?>> args = new ArrayList<>();
|
||||||
private Predicate<S> requires;
|
private @Nullable Predicate<S> requires;
|
||||||
|
|
||||||
public static CommandBuilder<CommandSourceStack> args() {
|
public static CommandBuilder<CommandSourceStack> args() {
|
||||||
return new CommandBuilder<>();
|
return new CommandBuilder<>();
|
||||||
|
@ -16,10 +16,11 @@ import net.minecraft.commands.CommandSourceStack;
|
|||||||
import net.minecraft.network.chat.ClickEvent;
|
import net.minecraft.network.chat.ClickEvent;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import static dan200.computercraft.core.util.Nullability.assertNonNull;
|
||||||
import static dan200.computercraft.shared.command.text.ChatHelpers.coloured;
|
import static dan200.computercraft.shared.command.text.ChatHelpers.coloured;
|
||||||
import static dan200.computercraft.shared.command.text.ChatHelpers.translate;
|
import static dan200.computercraft.shared.command.text.ChatHelpers.translate;
|
||||||
|
|
||||||
@ -71,7 +72,7 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder<Command
|
|||||||
return buildImpl(getLiteral().replace('-', '_'), getLiteral());
|
return buildImpl(getLiteral().replace('-', '_'), getLiteral());
|
||||||
}
|
}
|
||||||
|
|
||||||
private LiteralCommandNode<CommandSourceStack> build(@Nonnull String id, @Nonnull String command) {
|
private LiteralCommandNode<CommandSourceStack> build(String id, String command) {
|
||||||
return buildImpl(id + "." + getLiteral().replace('-', '_'), command + " " + getLiteral());
|
return buildImpl(id + "." + getLiteral().replace('-', '_'), command + " " + getLiteral());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +121,7 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder<Command
|
|||||||
private static final class HelpCommand implements Command<CommandSourceStack> {
|
private static final class HelpCommand implements Command<CommandSourceStack> {
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String command;
|
private final String command;
|
||||||
|
@Nullable
|
||||||
LiteralCommandNode<CommandSourceStack> node;
|
LiteralCommandNode<CommandSourceStack> node;
|
||||||
|
|
||||||
private HelpCommand(String id, String command) {
|
private HelpCommand(String id, String command) {
|
||||||
@ -129,7 +131,7 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder<Command
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int run(CommandContext<CommandSourceStack> context) {
|
public int run(CommandContext<CommandSourceStack> context) {
|
||||||
context.getSource().sendSuccess(getHelp(context, node, id, command), false);
|
context.getSource().sendSuccess(getHelp(context, assertNonNull(node), id, command), false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,7 +149,7 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder<Command
|
|||||||
var dispatcher = context.getSource().getServer().getCommands().getDispatcher();
|
var dispatcher = context.getSource().getServer().getCommands().getDispatcher();
|
||||||
CommandNode<CommandSourceStack> temp = new LiteralCommandNode<>("_", null, x -> true, null, null, false);
|
CommandNode<CommandSourceStack> temp = new LiteralCommandNode<>("_", null, x -> true, null, null, false);
|
||||||
temp.addChild(node);
|
temp.addChild(node);
|
||||||
var usage = dispatcher.getSmartUsage(temp, context.getSource()).get(node).substring(node.getName().length());
|
var usage = assertNonNull(dispatcher.getSmartUsage(temp, context.getSource()).get(node)).substring(node.getName().length());
|
||||||
|
|
||||||
var output = Component.literal("")
|
var output = Component.literal("")
|
||||||
.append(coloured("/" + command + usage, HEADER))
|
.append(coloured("/" + command + usage, HEADER))
|
||||||
|
@ -12,6 +12,8 @@ import net.minecraft.network.chat.Component;
|
|||||||
import net.minecraft.network.chat.HoverEvent;
|
import net.minecraft.network.chat.HoverEvent;
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Various helpers for building chat messages.
|
* Various helpers for building chat messages.
|
||||||
*/
|
*/
|
||||||
@ -21,7 +23,7 @@ public final class ChatHelpers {
|
|||||||
private ChatHelpers() {
|
private ChatHelpers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MutableComponent coloured(String text, ChatFormatting colour) {
|
public static MutableComponent coloured(@Nullable String text, ChatFormatting colour) {
|
||||||
return Component.literal(text == null ? "" : text).withStyle(colour);
|
return Component.literal(text == null ? "" : text).withStyle(colour);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,15 +32,15 @@ public final class ChatHelpers {
|
|||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MutableComponent text(String text) {
|
public static MutableComponent text(@Nullable String text) {
|
||||||
return Component.literal(text == null ? "" : text);
|
return Component.literal(text == null ? "" : text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MutableComponent translate(String text) {
|
public static MutableComponent translate(@Nullable String text) {
|
||||||
return Component.translatable(text == null ? "" : text);
|
return Component.translatable(text == null ? "" : text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MutableComponent translate(String text, Object... args) {
|
public static MutableComponent translate(@Nullable String text, Object... args) {
|
||||||
return Component.translatable(text == null ? "" : text, args);
|
return Component.translatable(text == null ? "" : text, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +52,7 @@ public final class ChatHelpers {
|
|||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MutableComponent position(BlockPos pos) {
|
public static MutableComponent position(@Nullable BlockPos pos) {
|
||||||
if (pos == null) return translate("commands.computercraft.generic.no_position");
|
if (pos == null) return translate("commands.computercraft.generic.no_position");
|
||||||
return translate("commands.computercraft.generic.position", pos.getX(), pos.getY(), pos.getZ());
|
return translate("commands.computercraft.generic.position", pos.getX(), pos.getY(), pos.getZ());
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared.command.text;
|
package dan200.computercraft.shared.command.text;
|
||||||
|
|
||||||
|
import dan200.computercraft.core.util.Nullability;
|
||||||
import dan200.computercraft.shared.command.CommandUtils;
|
import dan200.computercraft.shared.command.CommandUtils;
|
||||||
import dan200.computercraft.shared.network.client.ChatTableClientMessage;
|
import dan200.computercraft.shared.network.client.ChatTableClientMessage;
|
||||||
import dan200.computercraft.shared.platform.PlatformHelper;
|
import dan200.computercraft.shared.platform.PlatformHelper;
|
||||||
@ -12,7 +13,6 @@ import net.minecraft.commands.CommandSourceStack;
|
|||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -20,22 +20,22 @@ import java.util.List;
|
|||||||
public class TableBuilder {
|
public class TableBuilder {
|
||||||
private final String id;
|
private final String id;
|
||||||
private int columns = -1;
|
private int columns = -1;
|
||||||
private final Component[] headers;
|
private final @Nullable Component[] headers;
|
||||||
private final ArrayList<Component[]> rows = new ArrayList<>();
|
private final ArrayList<Component[]> rows = new ArrayList<>();
|
||||||
private int additional;
|
private int additional;
|
||||||
|
|
||||||
public TableBuilder(@Nonnull String id, @Nonnull Component... headers) {
|
public TableBuilder(String id, Component... headers) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.headers = headers;
|
this.headers = headers;
|
||||||
columns = headers.length;
|
columns = headers.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TableBuilder(@Nonnull String id) {
|
public TableBuilder(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
headers = null;
|
headers = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TableBuilder(@Nonnull String id, @Nonnull String... headers) {
|
public TableBuilder(String id, String... headers) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.headers = new Component[headers.length];
|
this.headers = new Component[headers.length];
|
||||||
columns = headers.length;
|
columns = headers.length;
|
||||||
@ -43,7 +43,7 @@ public class TableBuilder {
|
|||||||
for (var i = 0; i < headers.length; i++) this.headers[i] = ChatHelpers.header(headers[i]);
|
for (var i = 0; i < headers.length; i++) this.headers[i] = ChatHelpers.header(headers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void row(@Nonnull Component... row) {
|
public void row(Component... row) {
|
||||||
if (columns == -1) columns = row.length;
|
if (columns == -1) columns = row.length;
|
||||||
if (row.length != columns) throw new IllegalArgumentException("Row is the incorrect length");
|
if (row.length != columns) throw new IllegalArgumentException("Row is the incorrect length");
|
||||||
rows.add(row);
|
rows.add(row);
|
||||||
@ -78,7 +78,6 @@ public class TableBuilder {
|
|||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public List<Component[]> getRows() {
|
public List<Component[]> getRows() {
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
@ -106,7 +105,8 @@ public class TableBuilder {
|
|||||||
public void display(CommandSourceStack source) {
|
public void display(CommandSourceStack source) {
|
||||||
if (CommandUtils.isPlayer(source)) {
|
if (CommandUtils.isPlayer(source)) {
|
||||||
trim(18);
|
trim(18);
|
||||||
PlatformHelper.get().sendToPlayer(new ChatTableClientMessage(this), (ServerPlayer) source.getEntity());
|
var player = (ServerPlayer) Nullability.assertNonNull(source.getEntity());
|
||||||
|
PlatformHelper.get().sendToPlayer(new ChatTableClientMessage(this), player);
|
||||||
} else {
|
} else {
|
||||||
trim(100);
|
trim(100);
|
||||||
new ServerTableFormatter(source).display(this);
|
new ServerTableFormatter(source).display(this);
|
||||||
|
@ -22,7 +22,6 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
|
|||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public abstract class BlockGeneric extends BaseEntityBlock {
|
public abstract class BlockGeneric extends BaseEntityBlock {
|
||||||
@ -35,7 +34,7 @@ public abstract class BlockGeneric extends BaseEntityBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public final void onRemove(@Nonnull BlockState block, @Nonnull Level world, @Nonnull BlockPos pos, BlockState replace, boolean bool) {
|
public final void onRemove(BlockState block, Level world, BlockPos pos, BlockState replace, boolean bool) {
|
||||||
if (block.getBlock() == replace.getBlock()) return;
|
if (block.getBlock() == replace.getBlock()) return;
|
||||||
|
|
||||||
var tile = world.getBlockEntity(pos);
|
var tile = world.getBlockEntity(pos);
|
||||||
@ -44,17 +43,16 @@ public abstract class BlockGeneric extends BaseEntityBlock {
|
|||||||
if (tile instanceof TileGeneric generic) generic.destroy();
|
if (tile instanceof TileGeneric generic) generic.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public final InteractionResult use(@Nonnull BlockState state, Level world, @Nonnull BlockPos pos, @Nonnull Player player, @Nonnull InteractionHand hand, @Nonnull BlockHitResult hit) {
|
public final InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
|
||||||
var tile = world.getBlockEntity(pos);
|
var tile = world.getBlockEntity(pos);
|
||||||
return tile instanceof TileGeneric generic ? generic.onActivate(player, hand, hit) : InteractionResult.PASS;
|
return tile instanceof TileGeneric generic ? generic.onActivate(player, hand, hit) : InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public final void neighborChanged(@Nonnull BlockState state, Level world, @Nonnull BlockPos pos, @Nonnull Block neighbourBlock, @Nonnull BlockPos neighbourPos, boolean isMoving) {
|
public final void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighbourBlock, BlockPos neighbourPos, boolean isMoving) {
|
||||||
var tile = world.getBlockEntity(pos);
|
var tile = world.getBlockEntity(pos);
|
||||||
if (tile instanceof TileGeneric generic) generic.onNeighbourChange(neighbourPos);
|
if (tile instanceof TileGeneric generic) generic.onNeighbourChange(neighbourPos);
|
||||||
}
|
}
|
||||||
@ -67,21 +65,20 @@ public abstract class BlockGeneric extends BaseEntityBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void tick(@Nonnull BlockState state, ServerLevel world, @Nonnull BlockPos pos, @Nonnull RandomSource rand) {
|
public void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource rand) {
|
||||||
var te = world.getBlockEntity(pos);
|
var te = world.getBlockEntity(pos);
|
||||||
if (te instanceof TileGeneric generic) generic.blockTick();
|
if (te instanceof TileGeneric generic) generic.blockTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BlockEntity newBlockEntity(@Nonnull BlockPos pos, @Nonnull BlockState state) {
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||||
return type.get().create(pos, state);
|
return type.get().create(pos, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public RenderShape getRenderShape(@Nonnull BlockState state) {
|
public RenderShape getRenderShape(BlockState state) {
|
||||||
return RenderShape.MODEL;
|
return RenderShape.MODEL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,15 +15,13 @@ import net.minecraft.world.item.crafting.CustomRecipe;
|
|||||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public final class ColourableRecipe extends CustomRecipe {
|
public final class ColourableRecipe extends CustomRecipe {
|
||||||
public ColourableRecipe(ResourceLocation id) {
|
public ColourableRecipe(ResourceLocation id) {
|
||||||
super(id);
|
super(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(@Nonnull CraftingContainer inv, @Nonnull Level world) {
|
public boolean matches(CraftingContainer inv, Level world) {
|
||||||
var hasColourable = false;
|
var hasColourable = false;
|
||||||
var hasDye = false;
|
var hasDye = false;
|
||||||
for (var i = 0; i < inv.getContainerSize(); i++) {
|
for (var i = 0; i < inv.getContainerSize(); i++) {
|
||||||
@ -43,9 +41,8 @@ public final class ColourableRecipe extends CustomRecipe {
|
|||||||
return hasColourable && hasDye;
|
return hasColourable && hasDye;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack assemble(@Nonnull CraftingContainer inv) {
|
public ItemStack assemble(CraftingContainer inv) {
|
||||||
var colourable = ItemStack.EMPTY;
|
var colourable = ItemStack.EMPTY;
|
||||||
|
|
||||||
var tracker = new ColourTracker();
|
var tracker = new ColourTracker();
|
||||||
@ -76,7 +73,6 @@ public final class ColourableRecipe extends CustomRecipe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
|
||||||
public RecipeSerializer<?> getSerializer() {
|
public RecipeSerializer<?> getSerializer() {
|
||||||
return ModRegistry.RecipeSerializers.DYEABLE_ITEM.get();
|
return ModRegistry.RecipeSerializers.DYEABLE_ITEM.get();
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ import net.minecraft.world.inventory.AbstractContainerMenu;
|
|||||||
import net.minecraft.world.inventory.MenuType;
|
import net.minecraft.world.inventory.MenuType;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class ContainerHeldItem extends AbstractContainerMenu {
|
public class ContainerHeldItem extends AbstractContainerMenu {
|
||||||
@ -34,19 +33,17 @@ public class ContainerHeldItem extends AbstractContainerMenu {
|
|||||||
return new ContainerHeldItem(ModRegistry.Menus.PRINTOUT.get(), id, inventory.player, data.getHand());
|
return new ContainerHeldItem(ModRegistry.Menus.PRINTOUT.get(), id, inventory.player, data.getHand());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public ItemStack getStack() {
|
public ItemStack getStack() {
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack quickMoveStack(@Nonnull Player player, int slot) {
|
public ItemStack quickMoveStack(Player player, int slot) {
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean stillValid(@Nonnull Player player) {
|
public boolean stillValid(Player player) {
|
||||||
if (!player.isAlive()) return false;
|
if (!player.isAlive()) return false;
|
||||||
|
|
||||||
var stack = player.getItemInHand(hand);
|
var stack = player.getItemInHand(hand);
|
||||||
@ -64,7 +61,6 @@ public class ContainerHeldItem extends AbstractContainerMenu {
|
|||||||
this.hand = hand;
|
this.hand = hand;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Component getDisplayName() {
|
public Component getDisplayName() {
|
||||||
return name;
|
return name;
|
||||||
@ -72,7 +68,7 @@ public class ContainerHeldItem extends AbstractContainerMenu {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public AbstractContainerMenu createMenu(int id, @Nonnull Inventory inventory, @Nonnull Player player) {
|
public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
|
||||||
return new ContainerHeldItem(type, id, player, hand);
|
return new ContainerHeldItem(type, id, player, hand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,10 @@ import net.minecraft.core.BlockPos;
|
|||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider {
|
public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider {
|
||||||
@Override
|
@Override
|
||||||
public int getBundledRedstoneOutput(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side) {
|
public int getBundledRedstoneOutput(Level world, BlockPos pos, Direction side) {
|
||||||
return getDefaultBundledRedstoneOutput(world, pos, side);
|
return getDefaultBundledRedstoneOutput(world, pos, side);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,6 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
|
|||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public abstract class TileGeneric extends BlockEntity {
|
public abstract class TileGeneric extends BlockEntity {
|
||||||
public TileGeneric(BlockEntityType<? extends TileGeneric> type, BlockPos pos, BlockState state) {
|
public TileGeneric(BlockEntityType<? extends TileGeneric> type, BlockPos pos, BlockState state) {
|
||||||
super(type, pos, state);
|
super(type, pos, state);
|
||||||
@ -35,15 +33,14 @@ public abstract class TileGeneric extends BlockEntity {
|
|||||||
getLevel().sendBlockUpdated(pos, state, state, Block.UPDATE_ALL);
|
getLevel().sendBlockUpdated(pos, state, state, Block.UPDATE_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public InteractionResult onActivate(Player player, InteractionHand hand, BlockHitResult hit) {
|
public InteractionResult onActivate(Player player, InteractionHand hand, BlockHitResult hit) {
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNeighbourChange(@Nonnull BlockPos neighbour) {
|
public void onNeighbourChange(BlockPos neighbour) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNeighbourTileEntityChange(@Nonnull BlockPos neighbour) {
|
public void onNeighbourTileEntityChange(BlockPos neighbour) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void blockTick() {
|
protected void blockTick() {
|
||||||
@ -69,6 +66,6 @@ public abstract class TileGeneric extends BlockEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleUpdateTag(@Nonnull CompoundTag tag) {
|
public void handleUpdateTag(CompoundTag tag) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,9 @@ import net.minecraft.core.BlockPos;
|
|||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,9 +243,8 @@ public class CommandAPI implements ILuaAPI {
|
|||||||
return getBlockInfo(level, position);
|
return getBlockInfo(level, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private Level getLevel(Optional<String> id) throws LuaException {
|
||||||
private Level getLevel(@Nonnull Optional<String> id) throws LuaException {
|
var currentLevel = (ServerLevel) computer.getLevel();
|
||||||
var currentLevel = computer.getLevel();
|
|
||||||
if (currentLevel == null) throw new LuaException("No world exists");
|
if (currentLevel == null) throw new LuaException("No world exists");
|
||||||
|
|
||||||
if (!id.isPresent()) return currentLevel;
|
if (!id.isPresent()) return currentLevel;
|
||||||
|
@ -22,7 +22,6 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|||||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class BlockComputer<T extends TileComputer> extends BlockComputerBase<T> {
|
public class BlockComputer<T extends TileComputer> extends BlockComputerBase<T> {
|
||||||
@ -48,21 +47,18 @@ public class BlockComputer<T extends TileComputer> extends BlockComputerBase<T>
|
|||||||
return defaultBlockState().setValue(FACING, placement.getHorizontalDirection().getOpposite());
|
return defaultBlockState().setValue(FACING, placement.getHorizontalDirection().getOpposite());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public BlockState mirror(BlockState state, Mirror mirrorIn) {
|
public BlockState mirror(BlockState state, Mirror mirrorIn) {
|
||||||
return state.rotate(mirrorIn.getRotation(state.getValue(FACING)));
|
return state.rotate(mirrorIn.getRotation(state.getValue(FACING)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public BlockState rotate(BlockState state, Rotation rot) {
|
public BlockState rotate(BlockState state, Rotation rot) {
|
||||||
return state.setValue(FACING, rot.rotate(state.getValue(FACING)));
|
return state.setValue(FACING, rot.rotate(state.getValue(FACING)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
protected ItemStack getItem(TileComputerBase tile) {
|
protected ItemStack getItem(TileComputerBase tile) {
|
||||||
return tile instanceof TileComputer ? ComputerItemFactory.create((TileComputer) tile) : ItemStack.EMPTY;
|
return tile instanceof TileComputer ? ComputerItemFactory.create((TileComputer) tile) : ItemStack.EMPTY;
|
||||||
|
@ -32,7 +32,6 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
|||||||
import net.minecraft.world.phys.HitResult;
|
import net.minecraft.world.phys.HitResult;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public abstract class BlockComputerBase<T extends TileComputerBase> extends BlockGeneric implements IBundledRedstoneBlock {
|
public abstract class BlockComputerBase<T extends TileComputerBase> extends BlockGeneric implements IBundledRedstoneBlock {
|
||||||
@ -50,7 +49,7 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void onPlace(@Nonnull BlockState state, @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState oldState, boolean isMoving) {
|
public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean isMoving) {
|
||||||
super.onPlace(state, world, pos, oldState, isMoving);
|
super.onPlace(state, world, pos, oldState, isMoving);
|
||||||
|
|
||||||
var tile = world.getBlockEntity(pos);
|
var tile = world.getBlockEntity(pos);
|
||||||
@ -59,13 +58,13 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean isSignalSource(@Nonnull BlockState state) {
|
public boolean isSignalSource(BlockState state) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public int getDirectSignal(@Nonnull BlockState state, BlockGetter world, @Nonnull BlockPos pos, @Nonnull Direction incomingSide) {
|
public int getDirectSignal(BlockState state, BlockGetter world, BlockPos pos, Direction incomingSide) {
|
||||||
var entity = world.getBlockEntity(pos);
|
var entity = world.getBlockEntity(pos);
|
||||||
if (!(entity instanceof TileComputerBase computerEntity)) return 0;
|
if (!(entity instanceof TileComputerBase computerEntity)) return 0;
|
||||||
|
|
||||||
@ -76,7 +75,6 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
|||||||
return computer.getRedstoneOutput(localSide);
|
return computer.getRedstoneOutput(localSide);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
protected abstract ItemStack getItem(TileComputerBase tile);
|
protected abstract ItemStack getItem(TileComputerBase tile);
|
||||||
|
|
||||||
public ComputerFamily getFamily() {
|
public ComputerFamily getFamily() {
|
||||||
@ -85,7 +83,7 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public int getSignal(@Nonnull BlockState state, @Nonnull BlockGetter world, @Nonnull BlockPos pos, @Nonnull Direction incomingSide) {
|
public int getSignal(BlockState state, BlockGetter world, BlockPos pos, Direction incomingSide) {
|
||||||
return getDirectSignal(state, world, pos, incomingSide);
|
return getDirectSignal(state, world, pos, incomingSide);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +104,6 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
|||||||
return computer.getBundledRedstoneOutput(localSide);
|
return computer.getBundledRedstoneOutput(localSide);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter world, BlockPos pos, Player player) {
|
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter world, BlockPos pos, Player player) {
|
||||||
var tile = world.getBlockEntity(pos);
|
var tile = world.getBlockEntity(pos);
|
||||||
@ -119,14 +116,14 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playerDestroy(@Nonnull Level world, Player player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable BlockEntity tile, @Nonnull ItemStack tool) {
|
public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity tile, ItemStack tool) {
|
||||||
// Don't drop blocks here - see onBlockHarvested.
|
// Don't drop blocks here - see onBlockHarvested.
|
||||||
player.awardStat(Stats.BLOCK_MINED.get(this));
|
player.awardStat(Stats.BLOCK_MINED.get(this));
|
||||||
player.causeFoodExhaustion(0.005F);
|
player.causeFoodExhaustion(0.005F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playerWillDestroy(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull Player player) {
|
public void playerWillDestroy(Level world, BlockPos pos, BlockState state, Player player) {
|
||||||
if (!(world instanceof ServerLevel serverWorld)) return;
|
if (!(world instanceof ServerLevel serverWorld)) return;
|
||||||
|
|
||||||
// We drop the item here instead of doing it in the harvest method, as we should
|
// We drop the item here instead of doing it in the harvest method, as we should
|
||||||
@ -150,7 +147,7 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPlacedBy(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, @Nonnull ItemStack stack) {
|
public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
|
||||||
super.setPlacedBy(world, pos, state, placer, stack);
|
super.setPlacedBy(world, pos, state, placer, stack);
|
||||||
|
|
||||||
var tile = world.getBlockEntity(pos);
|
var tile = world.getBlockEntity(pos);
|
||||||
@ -171,7 +168,7 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public <U extends BlockEntity> BlockEntityTicker<U> getTicker(@Nonnull Level level, @Nonnull BlockState state, @Nonnull BlockEntityType<U> type) {
|
public <U extends BlockEntity> BlockEntityTicker<U> getTicker(Level level, BlockState state, BlockEntityType<U> type) {
|
||||||
return level.isClientSide ? null : BaseEntityBlock.createTickerHelper(type, this.type.get(), serverTicker);
|
return level.isClientSide ? null : BaseEntityBlock.createTickerHelper(type, this.type.get(), serverTicker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import dan200.computercraft.api.lua.LuaFunction;
|
|||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.core.apis.OSAPI;
|
import dan200.computercraft.core.apis.OSAPI;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +28,6 @@ public class ComputerPeripheral implements IPeripheral {
|
|||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
@ -111,11 +109,10 @@ public class ComputerPeripheral implements IPeripheral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(IPeripheral other) {
|
public boolean equals(@Nullable IPeripheral other) {
|
||||||
return other instanceof ComputerPeripheral computerPeripheral && owner == computerPeripheral.owner;
|
return other instanceof ComputerPeripheral computerPeripheral && owner == computerPeripheral.owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Object getTarget() {
|
public Object getTarget() {
|
||||||
return owner;
|
return owner;
|
||||||
|
@ -7,14 +7,17 @@ package dan200.computercraft.shared.computer.blocks;
|
|||||||
|
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public interface IComputerTile {
|
public interface IComputerTile {
|
||||||
int getComputerID();
|
int getComputerID();
|
||||||
|
|
||||||
void setComputerID(int id);
|
void setComputerID(int id);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
String getLabel();
|
String getLabel();
|
||||||
|
|
||||||
void setLabel(String label);
|
void setLabel(@Nullable String label);
|
||||||
|
|
||||||
ComputerFamily getFamily();
|
ComputerFamily getFamily();
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||||||
import net.minecraft.world.phys.Vec2;
|
import net.minecraft.world.phys.Vec2;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -42,7 +41,7 @@ public class TileCommandComputer extends TileComputer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendSystemMessage(@Nonnull Component textComponent) {
|
public void sendSystemMessage(Component textComponent) {
|
||||||
output.put(output.size() + 1, textComponent.getString());
|
output.put(output.size() + 1, textComponent.getString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,11 +22,10 @@ import net.minecraft.world.inventory.AbstractContainerMenu;
|
|||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class TileComputer extends TileComputerBase {
|
public class TileComputer extends TileComputerBase {
|
||||||
private IPeripheral peripheral;
|
private @Nullable IPeripheral peripheral;
|
||||||
|
|
||||||
public TileComputer(BlockEntityType<? extends TileComputer> type, BlockPos pos, BlockState state, ComputerFamily family) {
|
public TileComputer(BlockEntityType<? extends TileComputer> type, BlockPos pos, BlockState state, ComputerFamily family) {
|
||||||
super(type, pos, state, family);
|
super(type, pos, state, family);
|
||||||
@ -35,12 +34,11 @@ public class TileComputer extends TileComputerBase {
|
|||||||
@Override
|
@Override
|
||||||
protected ServerComputer createComputer(int id) {
|
protected ServerComputer createComputer(int id) {
|
||||||
var family = getFamily();
|
var family = getFamily();
|
||||||
var computer = new ServerComputer(
|
return new ServerComputer(
|
||||||
(ServerLevel) getLevel(), id, label, family,
|
(ServerLevel) getLevel(), getBlockPos(), id, label,
|
||||||
ComputerCraft.computerTermWidth, ComputerCraft.computerTermHeight
|
family, ComputerCraft.computerTermWidth,
|
||||||
|
ComputerCraft.computerTermHeight
|
||||||
);
|
);
|
||||||
computer.setPosition(getBlockPos());
|
|
||||||
return computer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isUsableByPlayer(Player player) {
|
protected boolean isUsableByPlayer(Player player) {
|
||||||
@ -71,7 +69,7 @@ public class TileComputer extends TileComputerBase {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public AbstractContainerMenu createMenu(int id, @Nonnull Inventory inventory, @Nonnull Player player) {
|
public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
|
||||||
return new ComputerMenuWithoutInventory(ModRegistry.Menus.COMPUTER.get(), id, inventory, this::isUsableByPlayer, createServerComputer(), getFamily());
|
return new ComputerMenuWithoutInventory(ModRegistry.Menus.COMPUTER.get(), id, inventory, this::isUsableByPlayer, createServerComputer(), getFamily());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
|
|||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -47,7 +46,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
|
|
||||||
private int instanceID = -1;
|
private int instanceID = -1;
|
||||||
private int computerID = -1;
|
private int computerID = -1;
|
||||||
protected String label = null;
|
protected @Nullable String label = null;
|
||||||
private boolean on = false;
|
private boolean on = false;
|
||||||
boolean startOn = false;
|
boolean startOn = false;
|
||||||
private boolean fresh = false;
|
private boolean fresh = false;
|
||||||
@ -100,7 +99,6 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
return super.isUsable(player) && BaseContainerBlockEntity.canUnlock(player, lockCode, getDisplayName());
|
return super.isUsable(player) && BaseContainerBlockEntity.canUnlock(player, lockCode, getDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionResult onActivate(Player player, InteractionHand hand, BlockHitResult hit) {
|
public InteractionResult onActivate(Player player, InteractionHand hand, BlockHitResult hit) {
|
||||||
var currentItem = player.getItemInHand(hand);
|
var currentItem = player.getItemInHand(hand);
|
||||||
@ -128,12 +126,12 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNeighbourChange(@Nonnull BlockPos neighbour) {
|
public void onNeighbourChange(BlockPos neighbour) {
|
||||||
updateInputAt(neighbour);
|
updateInputAt(neighbour);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNeighbourTileEntityChange(@Nonnull BlockPos neighbour) {
|
public void onNeighbourTileEntityChange(BlockPos neighbour) {
|
||||||
updateInputAt(neighbour);
|
updateInputAt(neighbour);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +172,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
protected abstract void updateBlockState(ComputerState newState);
|
protected abstract void updateBlockState(ComputerState newState);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveAdditional(@Nonnull CompoundTag nbt) {
|
public void saveAdditional(CompoundTag nbt) {
|
||||||
// Save ID, label and power state
|
// Save ID, label and power state
|
||||||
if (computerID >= 0) nbt.putInt(NBT_ID, computerID);
|
if (computerID >= 0) nbt.putInt(NBT_ID, computerID);
|
||||||
if (label != null) nbt.putString(NBT_LABEL, label);
|
if (label != null) nbt.putString(NBT_LABEL, label);
|
||||||
@ -186,7 +184,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(@Nonnull CompoundTag nbt) {
|
public void load(CompoundTag nbt) {
|
||||||
super.load(nbt);
|
super.load(nbt);
|
||||||
|
|
||||||
// Load ID, label and power state
|
// Load ID, label and power state
|
||||||
@ -211,7 +209,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
return localSide;
|
return localSide;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRedstoneInput(@Nonnull ServerComputer computer, Direction dir, BlockPos targetPos) {
|
private void updateRedstoneInput(ServerComputer computer, Direction dir, BlockPos targetPos) {
|
||||||
var offsetSide = dir.getOpposite();
|
var offsetSide = dir.getOpposite();
|
||||||
var localDir = remapToLocalSide(dir);
|
var localDir = remapToLocalSide(dir);
|
||||||
|
|
||||||
@ -219,7 +217,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
computer.setBundledRedstoneInput(localDir, BundledRedstone.getOutput(getLevel(), targetPos, offsetSide));
|
computer.setBundledRedstoneInput(localDir, BundledRedstone.getOutput(getLevel(), targetPos, offsetSide));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshPeripheral(@Nonnull ServerComputer computer, Direction dir) {
|
private void refreshPeripheral(ServerComputer computer, Direction dir) {
|
||||||
invalidSides &= ~(1 << dir.ordinal());
|
invalidSides &= ~(1 << dir.ordinal());
|
||||||
|
|
||||||
var localDir = remapToLocalSide(dir);
|
var localDir = remapToLocalSide(dir);
|
||||||
@ -243,7 +241,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
*
|
*
|
||||||
* @param computer The current computer instance.
|
* @param computer The current computer instance.
|
||||||
*/
|
*/
|
||||||
private void updateInputsImmediately(@Nonnull ServerComputer computer) {
|
private void updateInputsImmediately(ServerComputer computer) {
|
||||||
var pos = getBlockPos();
|
var pos = getBlockPos();
|
||||||
for (var dir : DirectionUtil.FACINGS) {
|
for (var dir : DirectionUtil.FACINGS) {
|
||||||
updateRedstoneInput(computer, dir, pos.relative(dir));
|
updateRedstoneInput(computer, dir, pos.relative(dir));
|
||||||
@ -251,7 +249,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateInputAt(@Nonnull BlockPos neighbour) {
|
private void updateInputAt(BlockPos neighbour) {
|
||||||
var computer = getServerComputer();
|
var computer = getServerComputer();
|
||||||
if (computer == null) return;
|
if (computer == null) return;
|
||||||
|
|
||||||
@ -289,7 +287,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final String getLabel() {
|
public final @Nullable String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +300,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void setLabel(String label) {
|
public final void setLabel(@Nullable String label) {
|
||||||
if (getLevel().isClientSide || Objects.equals(this.label, label)) return;
|
if (getLevel().isClientSide || Objects.equals(this.label, label)) return;
|
||||||
|
|
||||||
this.label = label;
|
this.label = label;
|
||||||
@ -316,13 +314,13 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
return family;
|
return family;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public final ServerComputer createServerComputer() {
|
public final ServerComputer createServerComputer() {
|
||||||
if (getLevel().isClientSide) throw new IllegalStateException("Cannot access server computer on the client.");
|
var server = getLevel().getServer();
|
||||||
|
if (server == null) throw new IllegalStateException("Cannot access server computer on the client.");
|
||||||
|
|
||||||
var changed = false;
|
var changed = false;
|
||||||
|
|
||||||
var computer = ServerContext.get(getLevel().getServer()).registry().get(instanceID);
|
var computer = ServerContext.get(server).registry().get(instanceID);
|
||||||
if (computer == null) {
|
if (computer == null) {
|
||||||
if (computerID < 0) {
|
if (computerID < 0) {
|
||||||
computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(level, IDAssigner.COMPUTER);
|
computerID = ComputerCraftAPI.createUniqueNumberedSaveDir(level, IDAssigner.COMPUTER);
|
||||||
@ -341,18 +339,16 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ServerComputer getServerComputer() {
|
public ServerComputer getServerComputer() {
|
||||||
return getLevel().isClientSide ? null : ServerContext.get(getLevel().getServer()).registry().get(instanceID);
|
return getLevel().isClientSide || getLevel().getServer() == null ? null : ServerContext.get(getLevel().getServer()).registry().get(instanceID);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Networking stuff
|
// Networking stuff
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final ClientboundBlockEntityDataPacket getUpdatePacket() {
|
public final ClientboundBlockEntityDataPacket getUpdatePacket() {
|
||||||
return ClientboundBlockEntityDataPacket.create(this);
|
return ClientboundBlockEntityDataPacket.create(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag getUpdateTag() {
|
public CompoundTag getUpdateTag() {
|
||||||
// We need this for pick block on the client side.
|
// We need this for pick block on the client side.
|
||||||
@ -363,7 +359,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleUpdateTag(@Nonnull CompoundTag nbt) {
|
public void handleUpdateTag(CompoundTag nbt) {
|
||||||
label = nbt.contains(NBT_LABEL) ? nbt.getString(NBT_LABEL) : null;
|
label = nbt.contains(NBT_LABEL) ? nbt.getString(NBT_LABEL) : null;
|
||||||
computerID = nbt.contains(NBT_ID) ? nbt.getInt(NBT_ID) : -1;
|
computerID = nbt.contains(NBT_ID) ? nbt.getInt(NBT_ID) : -1;
|
||||||
}
|
}
|
||||||
@ -382,7 +378,6 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
copy.instanceID = -1;
|
copy.instanceID = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Component getName() {
|
public Component getName() {
|
||||||
return hasCustomName()
|
return hasCustomName()
|
||||||
@ -401,7 +396,6 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
return hasCustomName() ? Component.literal(label) : null;
|
return hasCustomName() ? Component.literal(label) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Component getDisplayName() {
|
public Component getDisplayName() {
|
||||||
return Nameable.super.getDisplayName();
|
return Nameable.super.getDisplayName();
|
||||||
|
@ -7,8 +7,6 @@ package dan200.computercraft.shared.computer.core;
|
|||||||
|
|
||||||
import net.minecraft.util.StringRepresentable;
|
import net.minecraft.util.StringRepresentable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public enum ComputerState implements StringRepresentable {
|
public enum ComputerState implements StringRepresentable {
|
||||||
OFF("off", ""),
|
OFF("off", ""),
|
||||||
ON("on", "_on"),
|
ON("on", "_on"),
|
||||||
@ -22,7 +20,6 @@ public enum ComputerState implements StringRepresentable {
|
|||||||
this.texture = texture;
|
this.texture = texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public String getSerializedName() {
|
public String getSerializedName() {
|
||||||
return name;
|
return name;
|
||||||
@ -33,7 +30,6 @@ public enum ComputerState implements StringRepresentable {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public String getTexture() {
|
public String getTexture() {
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ import net.minecraft.server.packs.resources.ResourceManager;
|
|||||||
import net.minecraft.server.packs.resources.SimplePreparableReloadListener;
|
import net.minecraft.server.packs.resources.SimplePreparableReloadListener;
|
||||||
import net.minecraft.util.profiling.ProfilerFiller;
|
import net.minecraft.util.profiling.ProfilerFiller;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
@ -108,7 +107,7 @@ public final class ResourceMount implements IMount {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileEntry get(String path) {
|
private @Nullable FileEntry get(String path) {
|
||||||
var lastEntry = root;
|
var lastEntry = root;
|
||||||
var lastIndex = 0;
|
var lastIndex = 0;
|
||||||
|
|
||||||
@ -150,18 +149,18 @@ public final class ResourceMount implements IMount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean exists(@Nonnull String path) {
|
public boolean exists(String path) {
|
||||||
return get(path) != null;
|
return get(path) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDirectory(@Nonnull String path) {
|
public boolean isDirectory(String path) {
|
||||||
var file = get(path);
|
var file = get(path);
|
||||||
return file != null && file.isDirectory();
|
return file != null && file.isDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void list(@Nonnull String path, @Nonnull List<String> contents) throws IOException {
|
public void list(String path, List<String> contents) throws IOException {
|
||||||
var file = get(path);
|
var file = get(path);
|
||||||
if (file == null || !file.isDirectory()) throw new IOException("/" + path + ": Not a directory");
|
if (file == null || !file.isDirectory()) throw new IOException("/" + path + ": Not a directory");
|
||||||
|
|
||||||
@ -169,7 +168,7 @@ public final class ResourceMount implements IMount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getSize(@Nonnull String path) throws IOException {
|
public long getSize(String path) throws IOException {
|
||||||
var file = get(path);
|
var file = get(path);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
if (file.size != -1) return file.size;
|
if (file.size != -1) return file.size;
|
||||||
@ -197,9 +196,8 @@ public final class ResourceMount implements IMount {
|
|||||||
throw new IOException("/" + path + ": No such file");
|
throw new IOException("/" + path + ": No such file");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ReadableByteChannel openForRead(@Nonnull String path) throws IOException {
|
public ReadableByteChannel openForRead(String path) throws IOException {
|
||||||
var file = get(path);
|
var file = get(path);
|
||||||
if (file != null && !file.isDirectory()) {
|
if (file != null && !file.isDirectory()) {
|
||||||
var contents = CONTENTS_CACHE.getIfPresent(file);
|
var contents = CONTENTS_CACHE.getIfPresent(file);
|
||||||
@ -226,6 +224,7 @@ public final class ResourceMount implements IMount {
|
|||||||
|
|
||||||
private static class FileEntry {
|
private static class FileEntry {
|
||||||
final ResourceLocation identifier;
|
final ResourceLocation identifier;
|
||||||
|
@Nullable
|
||||||
Map<String, FileEntry> children;
|
Map<String, FileEntry> children;
|
||||||
long size = -1;
|
long size = -1;
|
||||||
|
|
||||||
@ -243,13 +242,12 @@ public final class ResourceMount implements IMount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link PreparableReloadListener} which reloads any associated mounts and correctly updates the resource manager
|
* A {@link SimplePreparableReloadListener} which reloads any associated mounts and correctly updates the resource manager
|
||||||
* they point to.
|
* they point to.
|
||||||
*/
|
*/
|
||||||
public static final SimplePreparableReloadListener<Void> RELOAD_LISTENER = new SimplePreparableReloadListener<>() {
|
public static final SimplePreparableReloadListener<Void> RELOAD_LISTENER = new SimplePreparableReloadListener<>() {
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
protected Void prepare(@Nonnull ResourceManager manager, @Nonnull ProfilerFiller profiler) {
|
protected Void prepare(ResourceManager manager, ProfilerFiller profiler) {
|
||||||
profiler.push("Reloading ComputerCraft mounts");
|
profiler.push("Reloading ComputerCraft mounts");
|
||||||
try {
|
try {
|
||||||
for (var mount : MOUNT_CACHE.values()) mount.load(manager);
|
for (var mount : MOUNT_CACHE.values()) mount.load(manager);
|
||||||
@ -261,7 +259,7 @@ public final class ResourceMount implements IMount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void apply(@Nonnull Void result, @Nonnull ResourceManager manager, @Nonnull ProfilerFiller profiler) {
|
protected void apply(Void result, ResourceManager manager, ProfilerFiller profiler) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import net.minecraft.core.BlockPos;
|
|||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@ -45,8 +46,11 @@ public class ServerComputer implements InputHandler, ComputerEnvironment {
|
|||||||
private boolean changedLastFrame;
|
private boolean changedLastFrame;
|
||||||
private int ticksSincePing;
|
private int ticksSincePing;
|
||||||
|
|
||||||
public ServerComputer(ServerLevel level, int computerID, String label, ComputerFamily family, int terminalWidth, int terminalHeight) {
|
public ServerComputer(
|
||||||
|
ServerLevel level, BlockPos position, int computerID, @Nullable String label, ComputerFamily family, int terminalWidth, int terminalHeight
|
||||||
|
) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
|
this.position = position;
|
||||||
this.family = family;
|
this.family = family;
|
||||||
|
|
||||||
var context = ServerContext.get(level.getServer());
|
var context = ServerContext.get(level.getServer());
|
||||||
@ -155,7 +159,7 @@ public class ServerComputer implements InputHandler, ComputerEnvironment {
|
|||||||
return computer.getID();
|
return computer.getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLabel() {
|
public @Nullable String getLabel() {
|
||||||
return computer.getLabel();
|
return computer.getLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +191,7 @@ public class ServerComputer implements InputHandler, ComputerEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void queueEvent(String event, Object[] arguments) {
|
public void queueEvent(String event, @Nullable Object[] arguments) {
|
||||||
// Queue event
|
// Queue event
|
||||||
computer.queueEvent(event, arguments);
|
computer.queueEvent(event, arguments);
|
||||||
}
|
}
|
||||||
@ -212,15 +216,16 @@ public class ServerComputer implements InputHandler, ComputerEnvironment {
|
|||||||
computer.addApi(api);
|
computer.addApi(api);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPeripheral(ComputerSide side, IPeripheral peripheral) {
|
public void setPeripheral(ComputerSide side, @Nullable IPeripheral peripheral) {
|
||||||
computer.getEnvironment().setPeripheral(side, peripheral);
|
computer.getEnvironment().setPeripheral(side, peripheral);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public IPeripheral getPeripheral(ComputerSide side) {
|
public IPeripheral getPeripheral(ComputerSide side) {
|
||||||
return computer.getEnvironment().getPeripheral(side);
|
return computer.getEnvironment().getPeripheral(side);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLabel(String label) {
|
public void setLabel(@Nullable String label) {
|
||||||
computer.setLabel(label);
|
computer.setLabel(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +245,7 @@ public class ServerComputer implements InputHandler, ComputerEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IWritableMount createRootMount() {
|
public @Nullable IWritableMount createRootMount() {
|
||||||
return ComputerCraftAPI.createSaveDirMount(level, "computer/" + computer.getID(), ComputerCraft.computerSpaceLimit);
|
return ComputerCraftAPI.createSaveDirMount(level, "computer/" + computer.getID(), ComputerCraft.computerSpaceLimit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import net.minecraft.server.MinecraftServer;
|
|||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.storage.LevelResource;
|
import net.minecraft.world.level.storage.LevelResource;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -180,23 +179,21 @@ public final class ServerContext {
|
|||||||
|
|
||||||
private record Environment(MinecraftServer server) implements GlobalEnvironment {
|
private record Environment(MinecraftServer server) implements GlobalEnvironment {
|
||||||
@Override
|
@Override
|
||||||
public IMount createResourceMount(String domain, String subPath) {
|
public @Nullable IMount createResourceMount(String domain, String subPath) {
|
||||||
return ComputerCraftAPI.createResourceMount(domain, subPath);
|
return ComputerCraftAPI.createResourceMount(domain, subPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream createResourceFile(String domain, String subPath) {
|
public @Nullable InputStream createResourceFile(String domain, String subPath) {
|
||||||
return ComputerCraftAPIImpl.getResourceFile(server, domain, subPath);
|
return ComputerCraftAPIImpl.getResourceFile(server, domain, subPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public String getHostString() {
|
public String getHostString() {
|
||||||
var version = SharedConstants.getCurrentVersion().getName();
|
var version = SharedConstants.getCurrentVersion().getName();
|
||||||
return String.format("ComputerCraft %s (Minecraft %s)", ComputerCraftAPI.getInstalledVersion(), version);
|
return String.format("ComputerCraft %s (Minecraft %s)", ComputerCraftAPI.getInstalledVersion(), version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public String getUserAgent() {
|
public String getUserAgent() {
|
||||||
return ComputerCraft.MOD_ID + "/" + ComputerCraftAPI.getInstalledVersion();
|
return ComputerCraft.MOD_ID + "/" + ComputerCraftAPI.getInstalledVersion();
|
||||||
|
@ -14,7 +14,6 @@ import net.minecraft.world.entity.player.Player;
|
|||||||
import net.minecraft.world.inventory.MenuType;
|
import net.minecraft.world.inventory.MenuType;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,9 +39,8 @@ public class ComputerMenuWithoutInventory extends ContainerComputerBase {
|
|||||||
for (var i = 0; i < 9; i++) addSlot(new InvisibleSlot(player, i));
|
for (var i = 0; i < 9; i++) addSlot(new InvisibleSlot(player, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack quickMoveStack(@Nonnull Player player, int slot) {
|
public ItemStack quickMoveStack(Player player, int slot) {
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import net.minecraft.world.inventory.MenuType;
|
|||||||
import net.minecraft.world.inventory.SimpleContainerData;
|
import net.minecraft.world.inventory.SimpleContainerData;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@ -51,15 +50,14 @@ public abstract class ContainerComputerBase extends AbstractContainerMenu implem
|
|||||||
this.computer = computer;
|
this.computer = computer;
|
||||||
input = computer == null ? null : new ServerInputState<>(this);
|
input = computer == null ? null : new ServerInputState<>(this);
|
||||||
terminal = containerData == null ? null : containerData.terminal().create();
|
terminal = containerData == null ? null : containerData.terminal().create();
|
||||||
displayStack = containerData == null ? null : containerData.displayStack();
|
displayStack = containerData == null ? ItemStack.EMPTY : containerData.displayStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean stillValid(@Nonnull Player player) {
|
public boolean stillValid(Player player) {
|
||||||
return canUse.test(player);
|
return canUse.test(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public ComputerFamily getFamily() {
|
public ComputerFamily getFamily() {
|
||||||
return family;
|
return family;
|
||||||
}
|
}
|
||||||
@ -98,7 +96,7 @@ public abstract class ContainerComputerBase extends AbstractContainerMenu implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removed(@Nonnull Player player) {
|
public void removed(Player player) {
|
||||||
super.removed(player);
|
super.removed(player);
|
||||||
if (input != null) input.close();
|
if (input != null) input.close();
|
||||||
}
|
}
|
||||||
@ -108,7 +106,6 @@ public abstract class ContainerComputerBase extends AbstractContainerMenu implem
|
|||||||
*
|
*
|
||||||
* @return The current stack.
|
* @return The current stack.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
public ItemStack getDisplayStack() {
|
public ItemStack getDisplayStack() {
|
||||||
return displayStack;
|
return displayStack;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import dan200.computercraft.shared.network.container.ComputerContainerData;
|
|||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class ContainerViewComputer extends ComputerMenuWithoutInventory {
|
public class ContainerViewComputer extends ComputerMenuWithoutInventory {
|
||||||
public ContainerViewComputer(int id, Inventory player, ServerComputer computer) {
|
public ContainerViewComputer(int id, Inventory player, ServerComputer computer) {
|
||||||
@ -25,7 +24,7 @@ public class ContainerViewComputer extends ComputerMenuWithoutInventory {
|
|||||||
super(ModRegistry.Menus.VIEW_COMPUTER.get(), id, player, data);
|
super(ModRegistry.Menus.VIEW_COMPUTER.get(), id, player, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean canInteractWith(@Nonnull ServerComputer computer, @Nonnull Player player) {
|
private static boolean canInteractWith(ServerComputer computer, Player player) {
|
||||||
// If this computer no longer exists then discard it.
|
// If this computer no longer exists then discard it.
|
||||||
if (ServerContext.get(computer.getLevel().getServer()).registry().get(computer.getInstanceID()) != computer) {
|
if (ServerContext.get(computer.getLevel().getServer()).registry().get(computer.getInstanceID()) != computer) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -10,19 +10,17 @@ import dan200.computercraft.shared.computer.blocks.TileComputer;
|
|||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public final class ComputerItemFactory {
|
public final class ComputerItemFactory {
|
||||||
private ComputerItemFactory() {
|
private ComputerItemFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public static ItemStack create(TileComputer tile) {
|
public static ItemStack create(TileComputer tile) {
|
||||||
return create(tile.getComputerID(), tile.getLabel(), tile.getFamily());
|
return create(tile.getComputerID(), tile.getLabel(), tile.getFamily());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
public static ItemStack create(int id, @Nullable String label, ComputerFamily family) {
|
||||||
public static ItemStack create(int id, String label, ComputerFamily family) {
|
|
||||||
return switch (family) {
|
return switch (family) {
|
||||||
case NORMAL -> ModRegistry.Items.COMPUTER_NORMAL.get().create(id, label);
|
case NORMAL -> ModRegistry.Items.COMPUTER_NORMAL.get().create(id, label);
|
||||||
case ADVANCED -> ModRegistry.Items.COMPUTER_ADVANCED.get().create(id, label);
|
case ADVANCED -> ModRegistry.Items.COMPUTER_ADVANCED.get().create(id, label);
|
||||||
|
@ -8,21 +8,21 @@ package dan200.computercraft.shared.computer.items;
|
|||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public interface IComputerItem {
|
public interface IComputerItem {
|
||||||
String NBT_ID = "ComputerId";
|
String NBT_ID = "ComputerId";
|
||||||
|
|
||||||
default int getComputerID(@Nonnull ItemStack stack) {
|
default int getComputerID(ItemStack stack) {
|
||||||
var nbt = stack.getTag();
|
var nbt = stack.getTag();
|
||||||
return nbt != null && nbt.contains(NBT_ID) ? nbt.getInt(NBT_ID) : -1;
|
return nbt != null && nbt.contains(NBT_ID) ? nbt.getInt(NBT_ID) : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
default String getLabel(@Nonnull ItemStack stack) {
|
default @Nullable String getLabel(ItemStack stack) {
|
||||||
return stack.hasCustomHoverName() ? stack.getHoverName().getString() : null;
|
return stack.hasCustomHoverName() ? stack.getHoverName().getString() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComputerFamily getFamily();
|
ComputerFamily getFamily();
|
||||||
|
|
||||||
ItemStack withFamily(@Nonnull ItemStack stack, @Nonnull ComputerFamily family);
|
ItemStack withFamily(ItemStack stack, ComputerFamily family);
|
||||||
}
|
}
|
||||||
|
@ -10,14 +10,14 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
|
|||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class ItemComputer extends ItemComputerBase {
|
public class ItemComputer extends ItemComputerBase {
|
||||||
public ItemComputer(BlockComputer<?> block, Properties settings) {
|
public ItemComputer(BlockComputer<?> block, Properties settings) {
|
||||||
super(block, settings);
|
super(block, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack create(int id, String label) {
|
public ItemStack create(int id, @Nullable String label) {
|
||||||
var result = new ItemStack(this);
|
var result = new ItemStack(this);
|
||||||
if (id >= 0) result.getOrCreateTag().putInt(NBT_ID, id);
|
if (id >= 0) result.getOrCreateTag().putInt(NBT_ID, id);
|
||||||
if (label != null) result.setHoverName(Component.literal(label));
|
if (label != null) result.setHoverName(Component.literal(label));
|
||||||
@ -25,7 +25,7 @@ public class ItemComputer extends ItemComputerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack withFamily(@Nonnull ItemStack stack, @Nonnull ComputerFamily family) {
|
public ItemStack withFamily(ItemStack stack, ComputerFamily family) {
|
||||||
var result = ComputerItemFactory.create(getComputerID(stack), null, family);
|
var result = ComputerItemFactory.create(getComputerID(stack), null, family);
|
||||||
if (stack.hasCustomHoverName()) result.setHoverName(stack.getHoverName());
|
if (stack.hasCustomHoverName()) result.setHoverName(stack.getHoverName());
|
||||||
return result;
|
return result;
|
||||||
|
@ -18,7 +18,6 @@ import net.minecraft.world.item.ItemStack;
|
|||||||
import net.minecraft.world.item.TooltipFlag;
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ public abstract class ItemComputerBase extends BlockItem implements IComputerIte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendHoverText(@Nonnull ItemStack stack, @Nullable Level world, @Nonnull List<Component> list, @Nonnull TooltipFlag options) {
|
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> list, TooltipFlag options) {
|
||||||
if (options.isAdvanced() || getLabel(stack) == null) {
|
if (options.isAdvanced() || getLabel(stack) == null) {
|
||||||
var id = getComputerID(stack);
|
var id = getComputerID(stack);
|
||||||
if (id >= 0) {
|
if (id >= 0) {
|
||||||
@ -42,7 +41,7 @@ public abstract class ItemComputerBase extends BlockItem implements IComputerIte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLabel(@Nonnull ItemStack stack) {
|
public @Nullable String getLabel(ItemStack stack) {
|
||||||
return IComputerItem.super.getLabel(stack);
|
return IComputerItem.super.getLabel(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ public abstract class ItemComputerBase extends BlockItem implements IComputerIte
|
|||||||
// IMedia implementation
|
// IMedia implementation
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setLabel(@Nonnull ItemStack stack, String label) {
|
public boolean setLabel(ItemStack stack, @Nullable String label) {
|
||||||
if (label != null) {
|
if (label != null) {
|
||||||
stack.setHoverName(Component.literal(label));
|
stack.setHoverName(Component.literal(label));
|
||||||
} else {
|
} else {
|
||||||
@ -64,7 +63,7 @@ public abstract class ItemComputerBase extends BlockItem implements IComputerIte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMount createDataMount(@Nonnull ItemStack stack, @Nonnull Level world) {
|
public @Nullable IMount createDataMount(ItemStack stack, Level world) {
|
||||||
var family = getFamily();
|
var family = getFamily();
|
||||||
if (family != ComputerFamily.COMMAND) {
|
if (family != ComputerFamily.COMMAND) {
|
||||||
var id = getComputerID(stack);
|
var id = getComputerID(stack);
|
||||||
|
@ -11,7 +11,6 @@ import dan200.computercraft.shared.computer.upload.FileUpload;
|
|||||||
import dan200.computercraft.shared.network.server.ComputerServerMessage;
|
import dan200.computercraft.shared.network.server.ComputerServerMessage;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -29,7 +28,7 @@ public interface ServerInputHandler extends InputHandler {
|
|||||||
* @param uploadId The unique ID of this upload.
|
* @param uploadId The unique ID of this upload.
|
||||||
* @param files The files to upload.
|
* @param files The files to upload.
|
||||||
*/
|
*/
|
||||||
void startUpload(@Nonnull UUID uploadId, @Nonnull List<FileUpload> files);
|
void startUpload(UUID uploadId, List<FileUpload> files);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append more data to partially uploaded files.
|
* Append more data to partially uploaded files.
|
||||||
@ -37,7 +36,7 @@ public interface ServerInputHandler extends InputHandler {
|
|||||||
* @param uploadId The unique ID of this upload.
|
* @param uploadId The unique ID of this upload.
|
||||||
* @param slices Additional parts of file data to upload.
|
* @param slices Additional parts of file data to upload.
|
||||||
*/
|
*/
|
||||||
void continueUpload(@Nonnull UUID uploadId, @Nonnull List<FileSlice> slices);
|
void continueUpload(UUID uploadId, List<FileSlice> slices);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finish off an upload. This either writes the uploaded files or informs the user that files will be overwritten.
|
* Finish off an upload. This either writes the uploaded files or informs the user that files will be overwritten.
|
||||||
@ -45,5 +44,5 @@ public interface ServerInputHandler extends InputHandler {
|
|||||||
* @param uploader The player uploading files.
|
* @param uploader The player uploading files.
|
||||||
* @param uploadId The unique ID of this upload.
|
* @param uploadId The unique ID of this upload.
|
||||||
*/
|
*/
|
||||||
void finishUpload(@Nonnull ServerPlayer uploader, @Nonnull UUID uploadId);
|
void finishUpload(ServerPlayer uploader, UUID uploadId);
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,6 @@ import net.minecraft.world.item.crafting.Ingredient;
|
|||||||
import net.minecraft.world.item.crafting.ShapedRecipe;
|
import net.minecraft.world.item.crafting.ShapedRecipe;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a recipe which converts a computer from one form into another.
|
* Represents a recipe which converts a computer from one form into another.
|
||||||
*/
|
*/
|
||||||
@ -27,11 +25,10 @@ public abstract class ComputerConvertRecipe extends ShapedRecipe {
|
|||||||
this.group = group;
|
this.group = group;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
protected abstract ItemStack convert(IComputerItem item, ItemStack stack);
|
||||||
protected abstract ItemStack convert(@Nonnull IComputerItem item, @Nonnull ItemStack stack);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(@Nonnull CraftingContainer inventory, @Nonnull Level world) {
|
public boolean matches(CraftingContainer inventory, Level world) {
|
||||||
if (!super.matches(inventory, world)) return false;
|
if (!super.matches(inventory, world)) return false;
|
||||||
|
|
||||||
for (var i = 0; i < inventory.getContainerSize(); i++) {
|
for (var i = 0; i < inventory.getContainerSize(); i++) {
|
||||||
@ -41,9 +38,8 @@ public abstract class ComputerConvertRecipe extends ShapedRecipe {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack assemble(@Nonnull CraftingContainer inventory) {
|
public ItemStack assemble(CraftingContainer inventory) {
|
||||||
// Find our computer item and convert it.
|
// Find our computer item and convert it.
|
||||||
for (var i = 0; i < inventory.getContainerSize(); i++) {
|
for (var i = 0; i < inventory.getContainerSize(); i++) {
|
||||||
var stack = inventory.getItem(i);
|
var stack = inventory.getItem(i);
|
||||||
@ -53,7 +49,6 @@ public abstract class ComputerConvertRecipe extends ShapedRecipe {
|
|||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public String getGroup() {
|
public String getGroup() {
|
||||||
return group;
|
return group;
|
||||||
|
@ -16,8 +16,6 @@ import net.minecraft.world.item.ItemStack;
|
|||||||
import net.minecraft.world.item.crafting.Ingredient;
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public abstract class ComputerFamilyRecipe extends ComputerConvertRecipe {
|
public abstract class ComputerFamilyRecipe extends ComputerConvertRecipe {
|
||||||
private final ComputerFamily family;
|
private final ComputerFamily family;
|
||||||
|
|
||||||
@ -33,9 +31,8 @@ public abstract class ComputerFamilyRecipe extends ComputerConvertRecipe {
|
|||||||
public abstract static class Serializer<T extends ComputerFamilyRecipe> implements RecipeSerializer<T> {
|
public abstract static class Serializer<T extends ComputerFamilyRecipe> implements RecipeSerializer<T> {
|
||||||
protected abstract T create(ResourceLocation identifier, String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result, ComputerFamily family);
|
protected abstract T create(ResourceLocation identifier, String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result, ComputerFamily family);
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public T fromJson(@Nonnull ResourceLocation identifier, @Nonnull JsonObject json) {
|
public T fromJson(ResourceLocation identifier, JsonObject json) {
|
||||||
var group = GsonHelper.getAsString(json, "group", "");
|
var group = GsonHelper.getAsString(json, "group", "");
|
||||||
var family = RecipeUtil.getFamily(json, "family");
|
var family = RecipeUtil.getFamily(json, "family");
|
||||||
|
|
||||||
@ -45,9 +42,8 @@ public abstract class ComputerFamilyRecipe extends ComputerConvertRecipe {
|
|||||||
return create(identifier, group, template.width(), template.height(), template.ingredients(), result, family);
|
return create(identifier, group, template.width(), template.height(), template.ingredients(), result, family);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public T fromNetwork(@Nonnull ResourceLocation identifier, @Nonnull FriendlyByteBuf buf) {
|
public T fromNetwork(ResourceLocation identifier, FriendlyByteBuf buf) {
|
||||||
var width = buf.readVarInt();
|
var width = buf.readVarInt();
|
||||||
var height = buf.readVarInt();
|
var height = buf.readVarInt();
|
||||||
var group = buf.readUtf(Short.MAX_VALUE);
|
var group = buf.readUtf(Short.MAX_VALUE);
|
||||||
@ -61,7 +57,7 @@ public abstract class ComputerFamilyRecipe extends ComputerConvertRecipe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toNetwork(@Nonnull FriendlyByteBuf buf, @Nonnull T recipe) {
|
public void toNetwork(FriendlyByteBuf buf, T recipe) {
|
||||||
buf.writeVarInt(recipe.getWidth());
|
buf.writeVarInt(recipe.getWidth());
|
||||||
buf.writeVarInt(recipe.getHeight());
|
buf.writeVarInt(recipe.getHeight());
|
||||||
buf.writeUtf(recipe.getGroup());
|
buf.writeUtf(recipe.getGroup());
|
||||||
|
@ -14,20 +14,16 @@ import net.minecraft.world.item.ItemStack;
|
|||||||
import net.minecraft.world.item.crafting.Ingredient;
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public final class ComputerUpgradeRecipe extends ComputerFamilyRecipe {
|
public final class ComputerUpgradeRecipe extends ComputerFamilyRecipe {
|
||||||
private ComputerUpgradeRecipe(ResourceLocation identifier, String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result, ComputerFamily family) {
|
private ComputerUpgradeRecipe(ResourceLocation identifier, String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result, ComputerFamily family) {
|
||||||
super(identifier, group, width, height, ingredients, result, family);
|
super(identifier, group, width, height, ingredients, result, family);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
protected ItemStack convert(@Nonnull IComputerItem item, @Nonnull ItemStack stack) {
|
protected ItemStack convert(IComputerItem item, ItemStack stack) {
|
||||||
return item.withFamily(stack, getFamily());
|
return item.withFamily(stack, getFamily());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public RecipeSerializer<?> getSerializer() {
|
public RecipeSerializer<?> getSerializer() {
|
||||||
return ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get();
|
return ModRegistry.RecipeSerializers.COMPUTER_UPGRADE.get();
|
||||||
|
@ -37,7 +37,7 @@ public class TerminalState {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private final ByteBuf buffer;
|
private final ByteBuf buffer;
|
||||||
|
|
||||||
private ByteBuf compressed;
|
private @Nullable ByteBuf compressed;
|
||||||
|
|
||||||
public TerminalState(@Nullable NetworkedTerminal terminal) {
|
public TerminalState(@Nullable NetworkedTerminal terminal) {
|
||||||
this(terminal, true);
|
this(terminal, true);
|
||||||
|
@ -7,7 +7,6 @@ package dan200.computercraft.shared.computer.upload;
|
|||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@ -29,12 +28,10 @@ public class FileUpload {
|
|||||||
this.checksum = checksum;
|
this.checksum = checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public ByteBuffer getBytes() {
|
public ByteBuffer getBytes() {
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
@ -43,7 +40,6 @@ public class FileUpload {
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public byte[] getChecksum() {
|
public byte[] getChecksum() {
|
||||||
return checksum;
|
return checksum;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
|||||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
|
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -33,14 +32,12 @@ public final class BlockNamedEntityLootCondition implements LootItemCondition {
|
|||||||
return tile instanceof Nameable nameable && nameable.hasCustomName();
|
return tile instanceof Nameable nameable && nameable.hasCustomName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Set<LootContextParam<?>> getReferencedContextParams() {
|
public Set<LootContextParam<?>> getReferencedContextParams() {
|
||||||
return Collections.singleton(LootContextParams.BLOCK_ENTITY);
|
return Collections.singleton(LootContextParams.BLOCK_ENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
|
||||||
public LootItemConditionType getType() {
|
public LootItemConditionType getType() {
|
||||||
return ModRegistry.LootItemConditionTypes.BLOCK_NAMED.get();
|
return ModRegistry.LootItemConditionTypes.BLOCK_NAMED.get();
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,6 @@ import net.minecraft.world.level.storage.loot.Serializer;
|
|||||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
|
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public final class ConstantLootConditionSerializer<T extends LootItemCondition> implements Serializer<T> {
|
public final class ConstantLootConditionSerializer<T extends LootItemCondition> implements Serializer<T> {
|
||||||
private final T instance;
|
private final T instance;
|
||||||
|
|
||||||
@ -26,12 +24,11 @@ public final class ConstantLootConditionSerializer<T extends LootItemCondition>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(@Nonnull JsonObject json, @Nonnull T object, @Nonnull JsonSerializationContext context) {
|
public void serialize(JsonObject json, T object, JsonSerializationContext context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public T deserialize(@Nonnull JsonObject json, @Nonnull JsonDeserializationContext context) {
|
public T deserialize(JsonObject json, JsonDeserializationContext context) {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
|||||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
|
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -33,14 +32,12 @@ public final class HasComputerIdLootCondition implements LootItemCondition {
|
|||||||
return tile instanceof IComputerTile computer && computer.getComputerID() >= 0;
|
return tile instanceof IComputerTile computer && computer.getComputerID() >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Set<LootContextParam<?>> getReferencedContextParams() {
|
public Set<LootContextParam<?>> getReferencedContextParams() {
|
||||||
return Collections.singleton(LootContextParams.BLOCK_ENTITY);
|
return Collections.singleton(LootContextParams.BLOCK_ENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
|
||||||
public LootItemConditionType getType() {
|
public LootItemConditionType getType() {
|
||||||
return ModRegistry.LootItemConditionTypes.HAS_ID.get();
|
return ModRegistry.LootItemConditionTypes.HAS_ID.get();
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
|||||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
|
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -33,14 +32,12 @@ public final class PlayerCreativeLootCondition implements LootItemCondition {
|
|||||||
return entity instanceof Player player && player.getAbilities().instabuild;
|
return entity instanceof Player player && player.getAbilities().instabuild;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Set<LootContextParam<?>> getReferencedContextParams() {
|
public Set<LootContextParam<?>> getReferencedContextParams() {
|
||||||
return Collections.singleton(LootContextParams.THIS_ENTITY);
|
return Collections.singleton(LootContextParams.THIS_ENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
|
||||||
public LootItemConditionType getType() {
|
public LootItemConditionType getType() {
|
||||||
return ModRegistry.LootItemConditionTypes.PLAYER_CREATIVE.get();
|
return ModRegistry.LootItemConditionTypes.PLAYER_CREATIVE.get();
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,10 @@ import mezz.jei.api.runtime.IJeiRuntime;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
@JeiPlugin
|
@JeiPlugin
|
||||||
public class JEIComputerCraft implements IModPlugin {
|
public class JEIComputerCraft implements IModPlugin {
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getPluginUid() {
|
public ResourceLocation getPluginUid() {
|
||||||
return new ResourceLocation(ComputerCraft.MOD_ID, "jei");
|
return new ResourceLocation(ComputerCraft.MOD_ID, "jei");
|
||||||
|
@ -16,14 +16,12 @@ import mezz.jei.api.recipe.category.IRecipeCategory;
|
|||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.CraftingRecipe;
|
import net.minecraft.world.item.crafting.CraftingRecipe;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class RecipeResolver implements IRecipeManagerPlugin {
|
class RecipeResolver implements IRecipeManagerPlugin {
|
||||||
private final UpgradeRecipeGenerator<CraftingRecipe> resolver = new UpgradeRecipeGenerator<>(x -> x);
|
private final UpgradeRecipeGenerator<CraftingRecipe> resolver = new UpgradeRecipeGenerator<>(x -> x);
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public <V> List<RecipeType<?>> getRecipeTypes(IFocus<V> focus) {
|
public <V> List<RecipeType<?>> getRecipeTypes(IFocus<V> focus) {
|
||||||
var value = focus.getTypedValue().getIngredient();
|
var value = focus.getTypedValue().getIngredient();
|
||||||
@ -41,9 +39,8 @@ class RecipeResolver implements IRecipeManagerPlugin {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public <T, V> List<T> getRecipes(@Nonnull IRecipeCategory<T> recipeCategory, IFocus<V> focus) {
|
public <T, V> List<T> getRecipes(IRecipeCategory<T> recipeCategory, IFocus<V> focus) {
|
||||||
if (!(focus.getTypedValue().getIngredient() instanceof ItemStack stack) || recipeCategory.getRecipeType() != RecipeTypes.CRAFTING) {
|
if (!(focus.getTypedValue().getIngredient() instanceof ItemStack stack) || recipeCategory.getRecipeType() != RecipeTypes.CRAFTING) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
@ -55,9 +52,8 @@ class RecipeResolver implements IRecipeManagerPlugin {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public <T> List<T> getRecipes(@Nonnull IRecipeCategory<T> recipeCategory) {
|
public <T> List<T> getRecipes(IRecipeCategory<T> recipeCategory) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ import net.minecraft.world.item.TooltipFlag;
|
|||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelReader;
|
import net.minecraft.world.level.LevelReader;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -35,8 +34,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem {
|
|||||||
super(settings);
|
super(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
public static ItemStack createFromIDAndColour(int id, @Nullable String label, int colour) {
|
||||||
public static ItemStack createFromIDAndColour(int id, String label, int colour) {
|
|
||||||
var stack = new ItemStack(ModRegistry.Items.DISK.get());
|
var stack = new ItemStack(ModRegistry.Items.DISK.get());
|
||||||
setDiskID(stack, id);
|
setDiskID(stack, id);
|
||||||
ModRegistry.Items.DISK.get().setLabel(stack, label);
|
ModRegistry.Items.DISK.get().setLabel(stack, label);
|
||||||
@ -45,7 +43,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillItemCategory(@Nonnull CreativeModeTab tabs, @Nonnull NonNullList<ItemStack> list) {
|
public void fillItemCategory(CreativeModeTab tabs, NonNullList<ItemStack> list) {
|
||||||
if (!allowedIn(tabs)) return;
|
if (!allowedIn(tabs)) return;
|
||||||
for (var colour = 0; colour < 16; colour++) {
|
for (var colour = 0; colour < 16; colour++) {
|
||||||
list.add(createFromIDAndColour(-1, null, Colour.VALUES[colour].getHex()));
|
list.add(createFromIDAndColour(-1, null, Colour.VALUES[colour].getHex()));
|
||||||
@ -53,7 +51,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendHoverText(@Nonnull ItemStack stack, @Nullable Level world, @Nonnull List<Component> list, TooltipFlag options) {
|
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> list, TooltipFlag options) {
|
||||||
if (options.isAdvanced()) {
|
if (options.isAdvanced()) {
|
||||||
var id = getDiskID(stack);
|
var id = getDiskID(stack);
|
||||||
if (id >= 0) {
|
if (id >= 0) {
|
||||||
@ -69,12 +67,12 @@ public class ItemDisk extends Item implements IMedia, IColouredItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLabel(@Nonnull ItemStack stack) {
|
public @Nullable String getLabel(ItemStack stack) {
|
||||||
return stack.hasCustomHoverName() ? stack.getHoverName().getString() : null;
|
return stack.hasCustomHoverName() ? stack.getHoverName().getString() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setLabel(@Nonnull ItemStack stack, String label) {
|
public boolean setLabel(ItemStack stack, @Nullable String label) {
|
||||||
if (label != null) {
|
if (label != null) {
|
||||||
stack.setHoverName(Component.literal(label));
|
stack.setHoverName(Component.literal(label));
|
||||||
} else {
|
} else {
|
||||||
@ -84,7 +82,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMount createDataMount(@Nonnull ItemStack stack, @Nonnull Level world) {
|
public @Nullable IMount createDataMount(ItemStack stack, Level world) {
|
||||||
var diskID = getDiskID(stack);
|
var diskID = getDiskID(stack);
|
||||||
if (diskID < 0) {
|
if (diskID < 0) {
|
||||||
diskID = ComputerCraftAPI.createUniqueNumberedSaveDir(world, "disk");
|
diskID = ComputerCraftAPI.createUniqueNumberedSaveDir(world, "disk");
|
||||||
@ -93,17 +91,17 @@ public class ItemDisk extends Item implements IMedia, IColouredItem {
|
|||||||
return ComputerCraftAPI.createSaveDirMount(world, "disk/" + diskID, ComputerCraft.floppySpaceLimit);
|
return ComputerCraftAPI.createSaveDirMount(world, "disk/" + diskID, ComputerCraft.floppySpaceLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDiskID(@Nonnull ItemStack stack) {
|
public static int getDiskID(ItemStack stack) {
|
||||||
var nbt = stack.getTag();
|
var nbt = stack.getTag();
|
||||||
return nbt != null && nbt.contains(NBT_ID) ? nbt.getInt(NBT_ID) : -1;
|
return nbt != null && nbt.contains(NBT_ID) ? nbt.getInt(NBT_ID) : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setDiskID(@Nonnull ItemStack stack, int id) {
|
private static void setDiskID(ItemStack stack, int id) {
|
||||||
if (id >= 0) stack.getOrCreateTag().putInt(NBT_ID, id);
|
if (id >= 0) stack.getOrCreateTag().putInt(NBT_ID, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getColour(@Nonnull ItemStack stack) {
|
public int getColour(ItemStack stack) {
|
||||||
var colour = IColouredItem.getColourBasic(stack);
|
var colour = IColouredItem.getColourBasic(stack);
|
||||||
return colour == -1 ? Colour.WHITE.getHex() : colour;
|
return colour == -1 ? Colour.WHITE.getHex() : colour;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import net.minecraft.world.item.ItemStack;
|
|||||||
import net.minecraft.world.item.TooltipFlag;
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ItemPrintout extends Item {
|
public class ItemPrintout extends Item {
|
||||||
@ -45,14 +45,13 @@ public class ItemPrintout extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendHoverText(@Nonnull ItemStack stack, Level world, @Nonnull List<Component> list, @Nonnull TooltipFlag options) {
|
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> list, TooltipFlag options) {
|
||||||
var title = getTitle(stack);
|
var title = getTitle(stack);
|
||||||
if (title != null && !title.isEmpty()) list.add(Component.literal(title));
|
if (title != null && !title.isEmpty()) list.add(Component.literal(title));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionResultHolder<ItemStack> use(Level world, @Nonnull Player player, @Nonnull InteractionHand hand) {
|
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||||
if (!world.isClientSide) {
|
if (!world.isClientSide) {
|
||||||
new HeldItemContainerData(hand)
|
new HeldItemContainerData(hand)
|
||||||
.open(player, new ContainerHeldItem.Factory(ModRegistry.Menus.PRINTOUT.get(), player.getItemInHand(hand), hand));
|
.open(player, new ContainerHeldItem.Factory(ModRegistry.Menus.PRINTOUT.get(), player.getItemInHand(hand), hand));
|
||||||
@ -60,8 +59,7 @@ public class ItemPrintout extends Item {
|
|||||||
return new InteractionResultHolder<>(InteractionResult.SUCCESS, player.getItemInHand(hand));
|
return new InteractionResultHolder<>(InteractionResult.SUCCESS, player.getItemInHand(hand));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private ItemStack createFromTitleAndText(@Nullable String title, @Nullable String[] text, @Nullable String[] colours) {
|
||||||
private ItemStack createFromTitleAndText(String title, String[] text, String[] colours) {
|
|
||||||
var stack = new ItemStack(this);
|
var stack = new ItemStack(this);
|
||||||
|
|
||||||
// Build NBT
|
// Build NBT
|
||||||
@ -84,18 +82,15 @@ public class ItemPrintout extends Item {
|
|||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
public static ItemStack createSingleFromTitleAndText(@Nullable String title, @Nullable String[] text, @Nullable String[] colours) {
|
||||||
public static ItemStack createSingleFromTitleAndText(String title, String[] text, String[] colours) {
|
|
||||||
return ModRegistry.Items.PRINTED_PAGE.get().createFromTitleAndText(title, text, colours);
|
return ModRegistry.Items.PRINTED_PAGE.get().createFromTitleAndText(title, text, colours);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
public static ItemStack createMultipleFromTitleAndText(@Nullable String title, @Nullable String[] text, @Nullable String[] colours) {
|
||||||
public static ItemStack createMultipleFromTitleAndText(String title, String[] text, String[] colours) {
|
|
||||||
return ModRegistry.Items.PRINTED_PAGES.get().createFromTitleAndText(title, text, colours);
|
return ModRegistry.Items.PRINTED_PAGES.get().createFromTitleAndText(title, text, colours);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
public static ItemStack createBookFromTitleAndText(@Nullable String title, @Nullable String[] text, @Nullable String[] colours) {
|
||||||
public static ItemStack createBookFromTitleAndText(String title, String[] text, String[] colours) {
|
|
||||||
return ModRegistry.Items.PRINTED_BOOK.get().createFromTitleAndText(title, text, colours);
|
return ModRegistry.Items.PRINTED_BOOK.get().createFromTitleAndText(title, text, colours);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,25 +98,25 @@ public class ItemPrintout extends Item {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTitle(@Nonnull ItemStack stack) {
|
public static String getTitle(ItemStack stack) {
|
||||||
var nbt = stack.getTag();
|
var nbt = stack.getTag();
|
||||||
return nbt != null && nbt.contains(NBT_TITLE) ? nbt.getString(NBT_TITLE) : null;
|
return nbt != null && nbt.contains(NBT_TITLE) ? nbt.getString(NBT_TITLE) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPageCount(@Nonnull ItemStack stack) {
|
public static int getPageCount(ItemStack stack) {
|
||||||
var nbt = stack.getTag();
|
var nbt = stack.getTag();
|
||||||
return nbt != null && nbt.contains(NBT_PAGES) ? nbt.getInt(NBT_PAGES) : 1;
|
return nbt != null && nbt.contains(NBT_PAGES) ? nbt.getInt(NBT_PAGES) : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getText(@Nonnull ItemStack stack) {
|
public static String[] getText(ItemStack stack) {
|
||||||
return getLines(stack, NBT_LINE_TEXT);
|
return getLines(stack, NBT_LINE_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getColours(@Nonnull ItemStack stack) {
|
public static String[] getColours(ItemStack stack) {
|
||||||
return getLines(stack, NBT_LINE_COLOUR);
|
return getLines(stack, NBT_LINE_COLOUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] getLines(@Nonnull ItemStack stack, String prefix) {
|
private static String[] getLines(ItemStack stack, String prefix) {
|
||||||
var nbt = stack.getTag();
|
var nbt = stack.getTag();
|
||||||
var numLines = getPageCount(stack) * LINES_PER_PAGE;
|
var numLines = getPageCount(stack) * LINES_PER_PAGE;
|
||||||
var lines = new String[numLines];
|
var lines = new String[numLines];
|
||||||
|
@ -22,7 +22,6 @@ import net.minecraft.world.item.TooltipFlag;
|
|||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelReader;
|
import net.minecraft.world.level.LevelReader;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -37,27 +36,27 @@ public class ItemTreasureDisk extends Item implements IMedia {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillItemCategory(@Nonnull CreativeModeTab group, @Nonnull NonNullList<ItemStack> stacks) {
|
public void fillItemCategory(CreativeModeTab group, NonNullList<ItemStack> stacks) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendHoverText(@Nonnull ItemStack stack, @Nullable Level world, @Nonnull List<Component> list, @Nonnull TooltipFlag tooltipOptions) {
|
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> list, TooltipFlag tooltipOptions) {
|
||||||
var label = getTitle(stack);
|
var label = getTitle(stack);
|
||||||
if (!label.isEmpty()) list.add(Component.literal(label));
|
if (!label.isEmpty()) list.add(Component.literal(label));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doesSneakBypassUse(@Nonnull ItemStack stack, LevelReader world, BlockPos pos, Player player) {
|
public boolean doesSneakBypassUse(ItemStack stack, LevelReader world, BlockPos pos, Player player) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLabel(@Nonnull ItemStack stack) {
|
public String getLabel(ItemStack stack) {
|
||||||
return getTitle(stack);
|
return getTitle(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMount createDataMount(@Nonnull ItemStack stack, @Nonnull Level world) {
|
public @Nullable IMount createDataMount(ItemStack stack, Level world) {
|
||||||
var rootTreasure = getTreasureMount();
|
var rootTreasure = getTreasureMount();
|
||||||
if (rootTreasure == null) return null;
|
if (rootTreasure == null) return null;
|
||||||
|
|
||||||
@ -93,23 +92,21 @@ public class ItemTreasureDisk extends Item implements IMedia {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IMount getTreasureMount() {
|
private static @Nullable IMount getTreasureMount() {
|
||||||
return ComputerCraftAPI.createResourceMount("computercraft", "lua/treasure");
|
return ComputerCraftAPI.createResourceMount("computercraft", "lua/treasure");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private static String getTitle(ItemStack stack) {
|
||||||
private static String getTitle(@Nonnull ItemStack stack) {
|
|
||||||
var nbt = stack.getTag();
|
var nbt = stack.getTag();
|
||||||
return nbt != null && nbt.contains(NBT_TITLE) ? nbt.getString(NBT_TITLE) : "'missingno' by how did you get this anyway?";
|
return nbt != null && nbt.contains(NBT_TITLE) ? nbt.getString(NBT_TITLE) : "'missingno' by how did you get this anyway?";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private static String getSubPath(ItemStack stack) {
|
||||||
private static String getSubPath(@Nonnull ItemStack stack) {
|
|
||||||
var nbt = stack.getTag();
|
var nbt = stack.getTag();
|
||||||
return nbt != null && nbt.contains(NBT_SUB_PATH) ? nbt.getString(NBT_SUB_PATH) : "dan200/alongtimeago";
|
return nbt != null && nbt.contains(NBT_SUB_PATH) ? nbt.getString(NBT_SUB_PATH) : "dan200/alongtimeago";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getColour(@Nonnull ItemStack stack) {
|
public static int getColour(ItemStack stack) {
|
||||||
var nbt = stack.getTag();
|
var nbt = stack.getTag();
|
||||||
return nbt != null && nbt.contains(NBT_COLOUR) ? nbt.getInt(NBT_COLOUR) : Colour.BLUE.getHex();
|
return nbt != null && nbt.contains(NBT_COLOUR) ? nbt.getInt(NBT_COLOUR) : Colour.BLUE.getHex();
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import net.minecraft.sounds.SoundEvent;
|
|||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.RecordItem;
|
import net.minecraft.world.item.RecordItem;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of IMedia for ItemRecords.
|
* An implementation of IMedia for ItemRecords.
|
||||||
@ -23,12 +23,12 @@ public final class RecordMedia implements IMedia {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLabel(@Nonnull ItemStack stack) {
|
public @Nullable String getLabel(ItemStack stack) {
|
||||||
return getAudioTitle(stack);
|
return getAudioTitle(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAudioTitle(@Nonnull ItemStack stack) {
|
public @Nullable String getAudioTitle(ItemStack stack) {
|
||||||
var item = stack.getItem();
|
var item = stack.getItem();
|
||||||
if (!(item instanceof RecordItem)) return null;
|
if (!(item instanceof RecordItem)) return null;
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ public final class RecordMedia implements IMedia {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SoundEvent getAudio(@Nonnull ItemStack stack) {
|
public @Nullable SoundEvent getAudio(ItemStack stack) {
|
||||||
var item = stack.getItem();
|
var item = stack.getItem();
|
||||||
if (!(item instanceof RecordItem)) return null;
|
if (!(item instanceof RecordItem)) return null;
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user