1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2026-01-07 12:49:04 +00:00

Update to 1.21.11

90% just ResourceLocation → Identifier. Also:
 - StandaloneModel now needs to detect which atlas to use, as the block
   and item atlases are different.

 - MultiLineLabel now always draws in white with a drop shadow, so we go
   back to manual word-wrapping for now.
This commit is contained in:
Jonathan Coates
2025-12-17 11:32:27 +00:00
parent 1ad20eea05
commit a072b116fa
151 changed files with 677 additions and 616 deletions

View File

@@ -15,4 +15,4 @@ isUnstable=true
modVersion=1.116.2
# Minecraft properties: We want to configure this here so we can read it in settings.gradle
mcVersion=1.21.10
mcVersion=1.21.11

View File

@@ -7,20 +7,20 @@
# Minecraft
# MC version is specified in gradle.properties, as we need that in settings.gradle.
# Remember to update corresponding versions in fabric.mod.json/neoforge.mods.toml
fabric-api = "0.137.0+1.21.10"
fabric-loader = "0.17.3"
neoForge = "21.10.46-beta"
fabric-api = "0.140.0+1.21.11"
fabric-loader = "0.18.3"
neoForge = "21.11.8-beta"
neoMergeTool = "2.0.0"
mixin = "0.8.5"
parchment = "2025.10.12"
parchmentMc = "1.21.10"
yarn = "1.21.10+build.2"
yarn = "1.21.11+build.1"
# Core dependencies (these versions are tied to the version Minecraft uses)
fastutil = "8.5.15"
guava = "33.3.1-jre"
netty = "4.1.118.Final"
slf4j = "2.0.16"
fastutil = "8.5.18"
guava = "33.5.0-jre"
netty = "4.2.7.Final"
slf4j = "2.0.17"
# Core dependencies (independent of Minecraft)
asm = "9.9"
@@ -69,7 +69,7 @@ illuaminate = "0.1.0-83-g1131f68"
lwjgl = "3.3.6"
minotaur = "2.8.7"
modDevGradle = "2.0.122"
nullAway = "0.12.11"
nullAway = "0.12.14"
shadow = "9.2.2"
spotless = "8.0.0"
teavm = "0.13.0-SQUID.2"
@@ -182,7 +182,7 @@ kotlin = ["kotlin-stdlib", "kotlin-coroutines"]
# Minecraft
externalMods-common = ["iris-forge", "jei-api", "nightConfig-core", "nightConfig-toml"]
externalMods-forge-compile = ["moreRed", "iris-forge", "jei-api"]
externalMods-forge-runtime = ["jei-forge"]
externalMods-forge-runtime = []
externalMods-fabric-compile = ["fabricPermissions", "iris-fabric", "jei-api", "rei-api", "rei-builtin"]
externalMods-fabric-runtime = []

View File

@@ -10,7 +10,6 @@ import com.mojang.blaze3d.vertex.SheetedDecalTextureGenerator;
import com.mojang.blaze3d.vertex.VertexConsumer;
import dan200.computercraft.api.client.turtle.TurtleUpgradeModel;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.SubmitNodeCollector;
import net.minecraft.client.renderer.block.model.BakedQuad;
@@ -19,17 +18,19 @@ import net.minecraft.client.renderer.item.BlockModelWrapper;
import net.minecraft.client.renderer.item.ItemModel;
import net.minecraft.client.renderer.item.ItemModelResolver;
import net.minecraft.client.renderer.item.ItemStackRenderState;
import net.minecraft.client.renderer.rendertype.RenderType;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.ModelBaker;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ResolvedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.ARGB;
import net.minecraft.world.entity.ItemOwner;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.jspecify.annotations.Nullable;
import java.util.List;
@@ -46,7 +47,7 @@ public final class StandaloneModel {
private final boolean useBlockLight;
private final TextureAtlasSprite particleIcon;
private final RenderType renderType;
private final Supplier<Vector3f[]> extents;
private final Supplier<Vector3fc[]> extents;
/**
* Construct a new {@link StandaloneModel}.
@@ -71,7 +72,7 @@ public final class StandaloneModel {
* @param baker The model baker.
* @return The baked {@link StandaloneModel}.
*/
public static StandaloneModel of(ResourceLocation model, ModelBaker baker) {
public static StandaloneModel of(Identifier model, ModelBaker baker) {
return of(baker.getModel(model), baker);
}
@@ -105,14 +106,36 @@ public final class StandaloneModel {
private static StandaloneModel ofUncached(ResolvedModel model, ModelBaker baker) {
var slots = model.getTopTextureSlots();
var quads = model.bakeTopGeometry(slots, baker, BlockModelRotation.IDENTITY).getAll();
return new StandaloneModel(
model.bakeTopGeometry(slots, baker, BlockModelRotation.X0_Y0).getAll(),
quads,
model.getTopGuiLight().lightLikeBlock(),
model.resolveParticleSprite(slots, baker),
Sheets.translucentItemSheet()
detectRenderType(quads)
);
}
private static RenderType detectRenderType(List<BakedQuad> list) {
if (list.isEmpty()) return Sheets.translucentItemSheet();
var atlas = list.getFirst().sprite().atlasLocation();
var mismatchedAtlas = list.stream()
.map(x -> x.sprite().atlasLocation())
.filter(x -> !x.equals(atlas)).findFirst().orElse(null);
if (mismatchedAtlas != null) {
throw new IllegalStateException("Multiple atlases used in model, expected " + atlas + ", but also got " + mismatchedAtlas);
}
if (atlas.equals(TextureAtlas.LOCATION_ITEMS)) {
return Sheets.translucentItemSheet();
} else if (atlas.equals(TextureAtlas.LOCATION_BLOCKS)) {
return Sheets.translucentBlockItemSheet();
} else {
throw new IllegalArgumentException("Atlas " + atlas + " can't be used for models");
}
}
/**
* Set up an {@link ItemStackRenderState.LayerRenderState} to render this model.
*

View File

@@ -16,7 +16,7 @@ import net.minecraft.client.renderer.item.BlockModelWrapper;
import net.minecraft.client.renderer.item.ItemModelResolver;
import net.minecraft.client.renderer.item.ItemStackRenderState;
import net.minecraft.client.resources.model.ModelBaker;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
/**
* A {@link TurtleUpgradeModel} that renders a basic model.
@@ -24,10 +24,10 @@ import net.minecraft.resources.ResourceLocation;
* This is the {@link TurtleUpgradeModel} equivalent of {@link BlockModelWrapper}.
*/
public final class BasicUpgradeModel implements TurtleUpgradeModel {
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "sided");
public static final Identifier ID = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "sided");
public static final MapCodec<? extends TurtleUpgradeModel.Unbaked> CODEC = RecordCodecBuilder.<Unbaked>mapCodec(instance -> instance.group(
ResourceLocation.CODEC.fieldOf("left").forGetter(Unbaked::left),
ResourceLocation.CODEC.fieldOf("right").forGetter(Unbaked::right)
Identifier.CODEC.fieldOf("left").forGetter(Unbaked::left),
Identifier.CODEC.fieldOf("right").forGetter(Unbaked::right)
).apply(instance, Unbaked::new));
private final StandaloneModel left;
@@ -45,7 +45,7 @@ public final class BasicUpgradeModel implements TurtleUpgradeModel {
* @param right The model when equipped on the right.
* @return The unbaked turtle upgrade model.
*/
public static TurtleUpgradeModel.Unbaked unbaked(ResourceLocation left, ResourceLocation right) {
public static TurtleUpgradeModel.Unbaked unbaked(Identifier left, Identifier right) {
return new Unbaked(left, right);
}
@@ -67,7 +67,7 @@ public final class BasicUpgradeModel implements TurtleUpgradeModel {
getModel(side).setupItemLayer(layer);
}
private record Unbaked(ResourceLocation left, ResourceLocation right) implements TurtleUpgradeModel.Unbaked {
private record Unbaked(Identifier left, Identifier right) implements TurtleUpgradeModel.Unbaked {
@Override
public MapCodec<? extends TurtleUpgradeModel.Unbaked> type() {
return CODEC;

View File

@@ -20,14 +20,14 @@ import net.minecraft.client.renderer.item.TrackingItemStackRenderState;
import net.minecraft.client.renderer.special.SpecialModelRenderer;
import net.minecraft.client.resources.model.ModelBaker;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.jspecify.annotations.Nullable;
import java.util.Set;
import java.util.function.Consumer;
/**
* A sic {@link TurtleUpgradeModel} that renders the upgrade's {@linkplain ITurtleUpgrade#getUpgradeItem(DataComponentPatch)
@@ -40,7 +40,7 @@ public final class ItemUpgradeModel implements TurtleUpgradeModel {
private static final TurtleUpgradeModel.Unbaked UNBAKED = new Unbaked();
private static final TurtleUpgradeModel INSTANCE = new ItemUpgradeModel();
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item");
public static final Identifier ID = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item");
public static final MapCodec<TurtleUpgradeModel.Unbaked> CODEC = MapCodec.unit(UNBAKED);
private static final TransformedRenderer LEFT = computeRenderer(TurtleSide.LEFT);
@@ -120,7 +120,7 @@ public final class ItemUpgradeModel implements TurtleUpgradeModel {
}
@Override
public void getExtents(Set<Vector3f> set) {
public void getExtents(Consumer<Vector3fc> set) {
}
@Override

View File

@@ -5,7 +5,7 @@
package dan200.computercraft.api.client.turtle;
import com.mojang.serialization.MapCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
/**
* A functional interface to register a {@link TurtleUpgradeModel}.
@@ -21,5 +21,5 @@ public interface RegisterTurtleUpgradeModel {
* @param id The id used for this type of upgrade model.
* @param model The codec used to read/decode an upgrade model.
*/
void register(ResourceLocation id, MapCodec<? extends TurtleUpgradeModel.Unbaked> model);
void register(Identifier id, MapCodec<? extends TurtleUpgradeModel.Unbaked> model);
}

View File

@@ -16,7 +16,6 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.upgrades.UpgradeData;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.Util;
import net.minecraft.client.renderer.block.model.ItemTransform;
import net.minecraft.client.renderer.item.ItemModelResolver;
import net.minecraft.client.renderer.item.ItemStackRenderState;
@@ -24,7 +23,8 @@ import net.minecraft.client.renderer.item.SelectItemModel;
import net.minecraft.client.resources.model.MissingBlockModel;
import net.minecraft.client.resources.model.ModelBaker;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.Util;
import org.jspecify.annotations.Nullable;
import java.util.*;
@@ -39,7 +39,7 @@ import java.util.stream.Collectors;
* @param <T> The type of value to switch on.
*/
public final class SelectUpgradeModel<T> implements TurtleUpgradeModel {
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "select");
public static final Identifier ID = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "select");
public static final MapCodec<? extends TurtleUpgradeModel.Unbaked> CODEC = RecordCodecBuilder.<Unbaked<?>>mapCodec(instance -> instance.group(
Cases.CODEC.forGetter(Unbaked::cases),
TurtleUpgradeModel.CODEC.optionalFieldOf("fallback").forGetter(Unbaked::fallback)

View File

@@ -5,7 +5,7 @@
package dan200.computercraft.api;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.InteractionHand;
@@ -60,7 +60,7 @@ public class ComputerCraftTags {
public static final TagKey<Item> DYEABLE = make("dyeable");
private static TagKey<Item> make(String name) {
return TagKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name));
return TagKey.create(Registries.ITEM, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name));
}
}
@@ -105,7 +105,7 @@ public class ComputerCraftTags {
public static final TagKey<Block> TURTLE_CAN_USE = make("turtle_can_use");
private static TagKey<Block> make(String name) {
return TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name));
return TagKey.create(Registries.BLOCK, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name));
}
}
}

View File

@@ -5,6 +5,8 @@
package dan200.computercraft.api.component;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.permissions.LevelBasedPermissionSet;
import net.minecraft.server.permissions.PermissionSet;
import org.jetbrains.annotations.ApiStatus;
/**
@@ -13,12 +15,12 @@ import org.jetbrains.annotations.ApiStatus;
@ApiStatus.NonExtendable
public interface AdminComputer {
/**
* The permission level that this computer can operate at.
* The permissions that this computer has.
*
* @return The permission level for this computer.
* @see CommandSourceStack#hasPermission(int)
* @return The permissions for this computer.
* @see CommandSourceStack#permissions()
*/
default int permissionLevel() {
return 2;
default PermissionSet permissions() {
return LevelBasedPermissionSet.GAMEMASTER;
}
}

View File

@@ -5,6 +5,7 @@
package dan200.computercraft.api.detail;
import dan200.computercraft.impl.ComputerCraftAPIService;
import net.minecraft.core.HolderLookup;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
@@ -15,8 +16,8 @@ public class VanillaDetailRegistries {
/**
* Provides details for {@link ItemStack}s.
* <p>
* This instance's {@link DetailRegistry#getBasicDetails(Object)} is thread safe (assuming the stack is immutable)
* and may be called from the computer thread.
* This instance's {@link DetailRegistry#getBasicDetails(HolderLookup.Provider, Object)} is thread safe (assuming
* the stack is immutable) and may be called from the computer thread.
* <p>
* This does not have special handling for {@linkplain ItemStack#isEmpty() empty item stacks}, and so the returned
* details will be an empty stack of air. Callers should generally check for empty stacks before calling this.
@@ -26,8 +27,8 @@ public class VanillaDetailRegistries {
/**
* Provides details for {@link BlockReference}, a reference to a {@link Block} in the world.
* <p>
* This instance's {@link DetailRegistry#getBasicDetails(Object)} is thread safe and may be called from the computer
* thread.
* This instance's {@link DetailRegistry#getBasicDetails(HolderLookup.Provider, Object)} is thread safe and may be
* called from the computer thread.
*/
public static final DetailRegistry<BlockReference> BLOCK_IN_WORLD = ComputerCraftAPIService.get().getBlockInWorldDetailRegistry();
}

View File

@@ -36,7 +36,7 @@
* <h2>Example: Returning details from methods</h2>
* Here we define a {@code getHeldItem()} method for pocket computers which finds the currently held item of the player
* and returns it to the user using {@link dan200.computercraft.api.detail.VanillaDetailRegistries#ITEM_STACK} and
* {@link dan200.computercraft.api.detail.DetailRegistry#getDetails(java.lang.Object)}.
* {@link dan200.computercraft.api.detail.DetailRegistry#getDetails(net.minecraft.core.HolderLookup.Provider, Object)}.
*
* {@snippet class=com.example.examplemod.ExamplePocketPeripheral region=details}
*

View File

@@ -10,8 +10,8 @@ import dan200.computercraft.api.upgrades.UpgradeBase;
import dan200.computercraft.api.upgrades.UpgradeType;
import dan200.computercraft.impl.ComputerCraftAPIService;
import net.minecraft.core.Registry;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import org.jspecify.annotations.Nullable;
@@ -25,7 +25,7 @@ import org.jspecify.annotations.Nullable;
* the upgrade registered internally.
*/
public interface IPocketUpgrade extends UpgradeBase {
ResourceKey<Registry<IPocketUpgrade>> REGISTRY = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_upgrade"));
ResourceKey<Registry<IPocketUpgrade>> REGISTRY = ResourceKey.createRegistryKey(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_upgrade"));
/**
* The registry key for pocket upgrade types.

View File

@@ -13,8 +13,8 @@ import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistrySetBuilder.PatchedRegistries;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import org.jspecify.annotations.Nullable;
@@ -86,17 +86,17 @@ public interface ITurtleUpgrade extends UpgradeBase {
/**
* The registry in which turtle upgrades are stored.
*/
ResourceKey<Registry<ITurtleUpgrade>> REGISTRY = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle_upgrade"));
ResourceKey<Registry<ITurtleUpgrade>> REGISTRY = ResourceKey.createRegistryKey(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle_upgrade"));
/**
* Create a {@link ResourceKey} for a turtle upgrade given a {@link ResourceLocation}.
* Create a {@link ResourceKey} for a turtle upgrade given a {@link Identifier}.
* <p>
* This should only be called from within data generation code. Do not hard code references to your upgrades!
*
* @param id The id of the turtle upgrade.
* @return The upgrade registry key.
*/
static ResourceKey<ITurtleUpgrade> createKey(ResourceLocation id) {
static ResourceKey<ITurtleUpgrade> createKey(Identifier id) {
return ResourceKey.create(REGISTRY, id);
}

View File

@@ -11,8 +11,8 @@ import dan200.computercraft.impl.upgrades.TurtleToolSpec;
import net.minecraft.core.component.DataComponents;
import net.minecraft.data.worldgen.BootstrapContext;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.Item;
@@ -42,11 +42,11 @@ public final class TurtleToolBuilder {
private TurtleToolBuilder(ResourceKey<ITurtleUpgrade> id, Item item) {
this.id = id;
adjective = Component.translatable(UpgradeBase.getDefaultAdjective(id.location()));
adjective = Component.translatable(UpgradeBase.getDefaultAdjective(id.identifier()));
this.item = item;
}
public static TurtleToolBuilder tool(ResourceLocation id, Item item) {
public static TurtleToolBuilder tool(Identifier id, Item item) {
return new TurtleToolBuilder(ITurtleUpgrade.createKey(id), item);
}

View File

@@ -9,10 +9,10 @@ import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import net.minecraft.Util;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.Util;
import net.minecraft.world.item.ItemStack;
/**
@@ -113,7 +113,7 @@ public interface UpgradeBase {
* @return The generated adjective.
* @see #getAdjective()
*/
static String getDefaultAdjective(ResourceLocation id) {
static String getDefaultAdjective(Identifier id) {
return Util.makeDescriptionId("upgrade", id) + ".adjective";
}
}

View File

@@ -11,6 +11,12 @@ plugins {
id("cc-tweaked.publishing")
}
sourceSets.client {
java {
exclude("dan200/computercraft/client/integration/jei")
}
}
minecraft {
accessWideners(
"src/main/resources/computercraft.accesswidener",

View File

@@ -44,7 +44,7 @@ import net.minecraft.client.resources.model.MissingBlockModel;
import net.minecraft.client.resources.model.ModelBaker;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ResolvableModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
@@ -71,13 +71,13 @@ public final class ClientRegistry {
private ClientRegistry() {
}
private static final Map<ResourceLocation, ModelKey<StandaloneModel>> models = new ConcurrentHashMap<>();
private static final Map<Identifier, ModelKey<StandaloneModel>> models = new ConcurrentHashMap<>();
public static ModelKey<StandaloneModel> getModel(ResourceLocation model) {
public static ModelKey<StandaloneModel> getModel(Identifier model) {
return models.computeIfAbsent(model, m -> ClientPlatformHelper.get().createModelKey(m::toString));
}
public static StandaloneModel getModel(ModelManager manager, ResourceLocation modelId) {
public static StandaloneModel getModel(ModelManager manager, Identifier modelId) {
var model = getModel(modelId).get(manager);
if (model != null) return model;
@@ -115,7 +115,7 @@ public final class ClientRegistry {
register.register(SelectUpgradeModel.ID, SelectUpgradeModel.CODEC);
}
private static final ResourceLocation[] EXTRA_MODELS = {
private static final Identifier[] EXTRA_MODELS = {
TurtleOverlay.ELF_MODEL,
TurtleBlockEntityRenderer.NORMAL_TURTLE_MODEL,
TurtleBlockEntityRenderer.ADVANCED_TURTLE_MODEL,
@@ -132,8 +132,8 @@ public final class ClientRegistry {
* @see #registerExtraModels(RegisterExtraModels, ExtraModels)
*/
public record ExtraModels(
Map<ResourceLocation, TurtleOverlay.Unbaked> turtleOverlays,
Map<ResourceLocation, TurtleUpgradeModel.Unbaked> turtleUpgrades
Map<Identifier, TurtleOverlay.Unbaked> turtleOverlays,
Map<Identifier, TurtleUpgradeModel.Unbaked> turtleUpgrades
) {
}
@@ -183,20 +183,20 @@ public final class ClientRegistry {
TurtleUpgradeModelManager.loader().register(register, models.turtleUpgrades());
}
public static void registerItemModels(BiConsumer<ResourceLocation, MapCodec<? extends ItemModel.Unbaked>> register) {
public static void registerItemModels(BiConsumer<Identifier, MapCodec<? extends ItemModel.Unbaked>> register) {
register.accept(TurtleOverlayModel.ID, TurtleOverlayModel.CODEC);
register.accept(dan200.computercraft.client.item.model.TurtleUpgradeModel.ID, dan200.computercraft.client.item.model.TurtleUpgradeModel.CODEC);
}
public static void registerItemColours(BiConsumer<ResourceLocation, MapCodec<? extends ItemTintSource>> register) {
public static void registerItemColours(BiConsumer<Identifier, MapCodec<? extends ItemTintSource>> register) {
register.accept(PocketComputerLight.ID, PocketComputerLight.CODEC);
}
public static void registerSelectItemProperties(BiConsumer<ResourceLocation, SelectItemModelProperty.Type<?, ?>> register) {
public static void registerSelectItemProperties(BiConsumer<Identifier, SelectItemModelProperty.Type<?, ?>> register) {
register.accept(PocketComputerStateProperty.ID, PocketComputerStateProperty.TYPE);
}
public static void registerConditionalItemProperties(BiConsumer<ResourceLocation, MapCodec<? extends ConditionalItemModelProperty>> register) {
public static void registerConditionalItemProperties(BiConsumer<Identifier, MapCodec<? extends ConditionalItemModelProperty>> register) {
register.accept(TurtleShowElfOverlay.ID, TurtleShowElfOverlay.CODEC);
}
@@ -214,7 +214,7 @@ public final class ClientRegistry {
register.register(PrintoutScreen.PrintoutRenderState.class, PrintoutScreen.PrintoutPictureRenderer::new);
}
public static void registerDebugScreenEntries(BiConsumer<ResourceLocation, DebugScreenEntry> register) {
public static void registerDebugScreenEntries(BiConsumer<Identifier, DebugScreenEntry> register) {
register.accept(LookingAtBlockEntityDebugEntry.ID, LookingAtBlockEntityDebugEntry.create());
}
}

View File

@@ -13,7 +13,7 @@ import net.minecraft.client.resources.model.ModelBaker;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ResolvableModel;
import net.minecraft.resources.FileToIdConverter;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.packs.resources.ResourceManager;
import java.util.Map;
@@ -25,7 +25,7 @@ import java.util.function.BiFunction;
/**
* A manager for loading custom models. This is responsible for {@linkplain #load(ResourceManager, Executor) loading
* models from resource packs}, {@linkplain #register(ClientRegistry.RegisterExtraModels, Map) registering them as
* extra models}, and then {@linkplain #get(ModelManager, ResourceLocation) looking them up}.
* extra models}, and then {@linkplain #get(ModelManager, Identifier) looking them up}.
*
* @param <U> The type of unbaked model.
* @param <T> The type of baked model.
@@ -39,7 +39,7 @@ public class CustomModelManager<U extends ResolvableModel, T> {
private final ModelKey<T> missingModelKey;
private final U missingModel;
private final Map<ResourceLocation, ModelKey<T>> modelKeys = new ConcurrentHashMap<>();
private final Map<Identifier, ModelKey<T>> modelKeys = new ConcurrentHashMap<>();
public CustomModelManager(String kind, FileToIdConverter lister, Codec<U> codec, BiFunction<U, ModelBaker, T> bake, U missingModel) {
this.kind = kind;
@@ -51,7 +51,7 @@ public class CustomModelManager<U extends ResolvableModel, T> {
this.missingModel = missingModel;
}
private ModelKey<T> getModelKey(ResourceLocation id) {
private ModelKey<T> getModelKey(Identifier id) {
return modelKeys.computeIfAbsent(id, o -> ClientPlatformHelper.get().createModelKey(() -> kind + " " + o));
}
@@ -62,7 +62,7 @@ public class CustomModelManager<U extends ResolvableModel, T> {
* @param executor The executor to schedule work on.
* @return The map of unbaked models.
*/
public CompletableFuture<Map<ResourceLocation, U>> load(ResourceManager resources, Executor executor) {
public CompletableFuture<Map<Identifier, U>> load(ResourceManager resources, Executor executor) {
return ResourceUtils.load(resources, executor, kind, lister, JsonOps.INSTANCE, codec);
}
@@ -72,7 +72,7 @@ public class CustomModelManager<U extends ResolvableModel, T> {
* @param register The callback to register models with.
* @param models The models to register.
*/
public void register(ClientRegistry.RegisterExtraModels register, Map<ResourceLocation, U> models) {
public void register(ClientRegistry.RegisterExtraModels register, Map<Identifier, U> models) {
models.forEach((id, model) -> register.register(getModelKey(id), model, bake));
register.register(missingModelKey, missingModel, bake);
}
@@ -84,7 +84,7 @@ public class CustomModelManager<U extends ResolvableModel, T> {
* @param id The model id.
* @return The loaded model.
*/
public T get(ModelManager modelManager, ResourceLocation id) {
public T get(ModelManager modelManager, Identifier id) {
var model = getModelKey(id).get(modelManager);
if (model != null) return model;

View File

@@ -9,7 +9,6 @@ import dan200.computercraft.client.gui.widgets.DynamicImageButton;
import dan200.computercraft.client.gui.widgets.TerminalWidget;
import dan200.computercraft.client.network.ClientNetworking;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.core.util.Nullability;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.InputHandler;
import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu;
@@ -18,14 +17,13 @@ import dan200.computercraft.shared.computer.upload.UploadResult;
import dan200.computercraft.shared.config.Config;
import dan200.computercraft.shared.network.server.UploadFileMessage;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.input.KeyEvent;
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Util;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack;
import org.jspecify.annotations.Nullable;
@@ -100,8 +98,8 @@ public abstract class AbstractComputerScreen<T extends AbstractComputerMenu> ext
getTerminal().update();
if (uploadNagDeadline != Long.MAX_VALUE && Util.getNanos() >= uploadNagDeadline) {
new ItemToast(minecraft(), displayStack, NO_RESPONSE_TITLE, NO_RESPONSE_MSG, ItemToast.TRANSFER_NO_RESPONSE_TOKEN)
.showOrReplace(minecraft().getToastManager());
new ItemToast(minecraft, displayStack, NO_RESPONSE_TITLE, NO_RESPONSE_MSG, ItemToast.TRANSFER_NO_RESPONSE_TOKEN)
.showOrReplace(minecraft.getToastManager());
uploadNagDeadline = Long.MAX_VALUE;
}
}
@@ -235,13 +233,8 @@ public abstract class AbstractComputerScreen<T extends AbstractComputerMenu> ext
}
private void alert(Component title, Component message) {
OptionScreen.show(minecraft(), title, message,
List.of(OptionScreen.newButton(OK, b -> minecraft().setScreen(this))),
() -> minecraft().setScreen(this)
OptionScreen.show(minecraft, this, title, message,
List.of(OptionScreen.newButton(OK, b -> minecraft.setScreen(this)))
);
}
private Minecraft minecraft() {
return Nullability.assertNonNull(minecraft);
}
}

View File

@@ -9,14 +9,14 @@ import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.player.Inventory;
/**
* The GUI for disk drives.
*/
public class DiskDriveScreen extends AbstractContainerScreen<DiskDriveMenu> {
private static final ResourceLocation BACKGROUND = ResourceLocation.fromNamespaceAndPath("computercraft", "textures/gui/disk_drive.png");
private static final Identifier BACKGROUND = Identifier.fromNamespaceAndPath("computercraft", "textures/gui/disk_drive.png");
public DiskDriveScreen(DiskDriveMenu container, Inventory player, Component title) {
super(container, player, title);

View File

@@ -7,7 +7,7 @@ package dan200.computercraft.client.gui;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.client.render.ComputerBorderRenderer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jspecify.annotations.Nullable;
import java.util.Objects;
@@ -31,16 +31,16 @@ public final class GuiSprites {
private static ButtonTextures button(String name) {
return new ButtonTextures(
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "buttons/" + name),
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "buttons/" + name + "_hover")
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "buttons/" + name),
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "buttons/" + name + "_hover")
);
}
private static ComputerTextures computer(String name, boolean pocket, boolean sidebar) {
return new ComputerTextures(
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "gui/border_" + name),
pocket ? ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "gui/pocket_bottom_" + name) : null,
sidebar ? ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "gui/sidebar_" + name) : null
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "gui/border_" + name),
pocket ? Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "gui/pocket_bottom_" + name) : null,
sidebar ? Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "gui/sidebar_" + name) : null
);
}
@@ -64,8 +64,8 @@ public final class GuiSprites {
* @param normal The normal texture for the button.
* @param active The texture for the button when it is active (hovered or focused).
*/
public record ButtonTextures(ResourceLocation normal, ResourceLocation active) {
public ResourceLocation get(boolean isActive) {
public record ButtonTextures(Identifier normal, Identifier active) {
public Identifier get(boolean isActive) {
return isActive ? active : normal;
}
}
@@ -79,11 +79,11 @@ public final class GuiSprites {
* @see ComputerBorderRenderer
*/
public record ComputerTextures(
ResourceLocation border,
@Nullable ResourceLocation pocketBottom,
@Nullable ResourceLocation sidebar
Identifier border,
@Nullable Identifier pocketBottom,
@Nullable Identifier sidebar
) {
public Stream<ResourceLocation> textures() {
public Stream<Identifier> textures() {
return Stream.of(border, pocketBottom, sidebar).filter(Objects::nonNull);
}
}

View File

@@ -11,7 +11,7 @@ import net.minecraft.client.gui.components.toasts.Toast;
import net.minecraft.client.gui.components.toasts.ToastManager;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.item.ItemStack;
@@ -21,7 +21,7 @@ import java.util.List;
* A {@link Toast} implementation which displays an arbitrary message along with an optional {@link ItemStack}.
*/
public class ItemToast implements Toast {
private static final ResourceLocation TEXTURE = ResourceLocation.withDefaultNamespace("toast/recipe");
private static final Identifier TEXTURE = Identifier.withDefaultNamespace("toast/recipe");
public static final Object TRANSFER_NO_RESPONSE_TOKEN = new Object();
private static final long DISPLAY_TIME = 7000L;

View File

@@ -14,7 +14,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.debug.DebugEntryLookingAtBlock;
import net.minecraft.client.gui.components.debug.DebugScreenDisplayer;
import net.minecraft.client.gui.components.debug.DebugScreenEntry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
@@ -35,7 +35,7 @@ import java.util.function.BiConsumer;
* @see DebugEntryLookingAtBlock
*/
public final class LookingAtBlockEntityDebugEntry implements DebugScreenEntry {
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "looking_at_block_entity");
public static final Identifier ID = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "looking_at_block_entity");
private final Map<BlockEntityType<?>, BiConsumer<List<String>, BlockEntity>> blockEntityEmitters = new HashMap<>();
@@ -90,7 +90,7 @@ public final class LookingAtBlockEntityDebugEntry implements DebugScreenEntry {
private static void addTurtleUpgrade(List<String> out, TurtleBlockEntity turtle, TurtleSide side) {
var upgrade = turtle.getAccess().getUpgradeWithData(side);
if (upgrade != null) out.add(String.format("Upgrade[%s]: %s", side, upgrade.holder().key().location()));
if (upgrade != null) out.add(String.format("Upgrade[%s]: %s", side, upgrade.holder().key().identifier()));
}
}

View File

@@ -6,10 +6,8 @@ package dan200.computercraft.client.gui;
import dan200.computercraft.client.gui.widgets.TerminalWidget;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.core.util.Nullability;
import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.ScrollWheelHandler;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
@@ -51,8 +49,8 @@ public class NoTermComputerScreen<T extends AbstractComputerMenu> extends Screen
protected void init() {
// First ensure we're still grabbing the mouse, so the user can look around. Then reset bits of state that
// grabbing unsets.
minecraft().mouseHandler.grabMouse();
minecraft().screen = this;
minecraft.mouseHandler.grabMouse();
minecraft.screen = this;
KeyMapping.releaseAll();
super.init();
@@ -72,7 +70,7 @@ public class NoTermComputerScreen<T extends AbstractComputerMenu> extends Screen
@Override
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
var direction = scrollHandler.onMouseScroll(scrollX, scrollY);
var inventory = Objects.requireNonNull(minecraft().player).getInventory();
var inventory = Objects.requireNonNull(minecraft.player).getInventory();
inventory.setSelectedSlot(ScrollWheelHandler.getNextScrollWheelSelection(
direction.y == 0 ? -direction.x : direction.y, inventory.getSelectedSlot(), Inventory.getSelectionSize()
));
@@ -82,7 +80,7 @@ public class NoTermComputerScreen<T extends AbstractComputerMenu> extends Screen
@Override
public void onClose() {
Objects.requireNonNull(minecraft().player).closeContainer();
Objects.requireNonNull(minecraft.player).closeContainer();
super.onClose();
}
@@ -105,7 +103,7 @@ public class NoTermComputerScreen<T extends AbstractComputerMenu> extends Screen
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
super.render(graphics, mouseX, mouseY, partialTicks);
var font = minecraft().font;
var font = minecraft.font;
var lines = font.split(Component.translatable("gui.computercraft.pocket_computer_overlay"), (int) (width * 0.8));
var y = 10;
for (var line : lines) {
@@ -118,8 +116,4 @@ public class NoTermComputerScreen<T extends AbstractComputerMenu> extends Screen
public void renderBackground(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
// Skip rendering the background.
}
private Minecraft minecraft() {
return Nullability.assertNonNull(minecraft);
}
}

View File

@@ -8,24 +8,24 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.MultiLineLabel;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.ARGB;
import net.minecraft.util.FormattedCharSequence;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.Nullable;
import java.util.List;
import static dan200.computercraft.core.util.Nullability.assertNonNull;
/**
* A screen which displays a series of buttons (such as a yes/no prompt).
* <p>
* When closed, it returns to the previous screen.
*/
public final class OptionScreen extends Screen {
private static final ResourceLocation BACKGROUND = ResourceLocation.fromNamespaceAndPath("computercraft", "textures/gui/blank_screen.png");
private static final Identifier BACKGROUND = Identifier.fromNamespaceAndPath("computercraft", "textures/gui/blank_screen.png");
public static final int BUTTON_WIDTH = 100;
public static final int BUTTON_HEIGHT = 20;
@@ -38,26 +38,25 @@ public final class OptionScreen extends Screen {
private int innerWidth;
private int innerHeight;
private @Nullable MultiLineLabel messageRenderer;
private final Component message;
private List<FormattedCharSequence> messageLines = List.of();
private final List<AbstractWidget> buttons;
private final Runnable exit;
private final Screen originalScreen;
private OptionScreen(Component title, Component message, List<AbstractWidget> buttons, Runnable exit, Screen originalScreen) {
private OptionScreen(Component title, Component message, List<AbstractWidget> buttons, Screen originalScreen) {
super(title);
this.message = message;
this.buttons = buttons;
this.exit = exit;
this.originalScreen = originalScreen;
}
public static void show(Minecraft minecraft, Component title, Component message, List<AbstractWidget> buttons, Runnable exit) {
minecraft.setScreen(new OptionScreen(title, message, buttons, exit, unwrap(minecraft.screen)));
public static void show(Minecraft minecraft, Screen originalScreen, Component title, Component message, List<AbstractWidget> buttons) {
minecraft.setScreen(new OptionScreen(title, message, buttons, unwrap(originalScreen)));
}
public static Screen unwrap(Screen screen) {
@Contract("!null -> !null")
public static @Nullable Screen unwrap(@Nullable Screen screen) {
return screen instanceof OptionScreen option ? option.getOriginalScreen() : screen;
}
@@ -68,9 +67,9 @@ public final class OptionScreen extends Screen {
var buttonWidth = BUTTON_WIDTH * buttons.size() + PADDING * (buttons.size() - 1);
var innerWidth = this.innerWidth = Math.max(256, buttonWidth + PADDING * 2);
messageRenderer = MultiLineLabel.create(font, message, innerWidth - PADDING * 2);
messageLines = font.split(message, innerWidth - PADDING * 2);
var textHeight = messageRenderer.getLineCount() * FONT_HEIGHT + PADDING * 2;
var textHeight = messageLines.size() * FONT_HEIGHT + PADDING * 2;
innerHeight = textHeight + (buttons.isEmpty() ? 0 : buttons.get(0).getHeight()) + PADDING;
x = (width - innerWidth) / 2;
@@ -96,13 +95,18 @@ public final class OptionScreen extends Screen {
);
graphics.blit(RenderPipelines.GUI_TEXTURED, BACKGROUND, x, y + innerHeight - PADDING, 0, 256 - PADDING, innerWidth, PADDING, 256, 256);
assertNonNull(messageRenderer).render(graphics, MultiLineLabel.Align.LEFT, +PADDING, y + PADDING, FONT_HEIGHT, false, 0x404040);
var textY = this.y + PADDING;
for (var line : messageLines) {
graphics.drawString(font, line, x, textY, ARGB.opaque(0x404040), false);
textY += FONT_HEIGHT;
}
super.render(graphics, mouseX, mouseY, partialTicks);
}
@Override
public void onClose() {
exit.run();
minecraft.setScreen(originalScreen);
}
public static AbstractWidget newButton(Component component, Button.OnPress clicked) {

View File

@@ -9,14 +9,14 @@ import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.player.Inventory;
/**
* The GUI for printers.
*/
public class PrinterScreen extends AbstractContainerScreen<PrinterMenu> {
private static final ResourceLocation BACKGROUND = ResourceLocation.fromNamespaceAndPath("computercraft", "textures/gui/printer.png");
private static final Identifier BACKGROUND = Identifier.fromNamespaceAndPath("computercraft", "textures/gui/printer.png");
public PrinterScreen(PrinterMenu container, Inventory player, Component title) {
super(container, player, title);

View File

@@ -14,7 +14,7 @@ import dan200.computercraft.shared.turtle.inventory.TurtleMenu;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.player.Inventory;
import static dan200.computercraft.shared.turtle.inventory.TurtleMenu.*;
@@ -23,11 +23,11 @@ import static dan200.computercraft.shared.turtle.inventory.TurtleMenu.*;
* The GUI for turtles.
*/
public class TurtleScreen extends AbstractComputerScreen<TurtleMenu> {
private static final ResourceLocation BACKGROUND_NORMAL = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "textures/gui/turtle_normal.png");
private static final ResourceLocation BACKGROUND_ADVANCED = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "textures/gui/turtle_advanced.png");
private static final Identifier BACKGROUND_NORMAL = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "textures/gui/turtle_normal.png");
private static final Identifier BACKGROUND_ADVANCED = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "textures/gui/turtle_advanced.png");
private static final ResourceLocation SELECTED_NORMAL = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle_normal_selected_slot");
private static final ResourceLocation SELECTED_ADVANCED = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle_advanced_selected_slot");
private static final Identifier SELECTED_NORMAL = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle_normal_selected_slot");
private static final Identifier SELECTED_ADVANCED = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle_advanced_selected_slot");
private static final int TEX_WIDTH = 278;
private static final int TEX_HEIGHT = 217;

View File

@@ -11,7 +11,7 @@ import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jspecify.annotations.Nullable;
import java.util.function.Supplier;
@@ -21,11 +21,11 @@ import java.util.function.Supplier;
* dynamically.
*/
public class DynamicImageButton extends Button {
private final Boolean2ObjectFunction<ResourceLocation> texture;
private final Supplier<HintedMessage> message;
private final Boolean2ObjectFunction<Identifier> texture;
private final Supplier<HintedMessage> messageSupplier;
public DynamicImageButton(
int x, int y, int width, int height, Boolean2ObjectFunction<ResourceLocation> texture, OnPress onPress,
int x, int y, int width, int height, Boolean2ObjectFunction<Identifier> texture, OnPress onPress,
HintedMessage message
) {
this(x, y, width, height, texture, onPress, () -> message);
@@ -33,17 +33,17 @@ public class DynamicImageButton extends Button {
public DynamicImageButton(
int x, int y, int width, int height,
Boolean2ObjectFunction<ResourceLocation> texture,
Boolean2ObjectFunction<Identifier> texture,
OnPress onPress, Supplier<HintedMessage> message
) {
super(x, y, width, height, Component.empty(), onPress, DEFAULT_NARRATION);
this.texture = texture;
this.message = message;
this.messageSupplier = message;
}
@Override
public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
var message = this.message.get();
public void renderContents(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
var message = messageSupplier.get();
setMessage(message.message());
setTooltip(message.tooltip());

View File

@@ -5,6 +5,8 @@
package dan200.computercraft.client.gui.widgets;
import com.mojang.blaze3d.pipeline.RenderPipeline;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.textures.FilterMode;
import com.mojang.blaze3d.vertex.VertexConsumer;
import dan200.computercraft.client.gui.KeyConverter;
import dan200.computercraft.client.render.text.FixedWidthFontRenderer;
@@ -268,7 +270,10 @@ public class TerminalWidget extends AbstractWidget {
var scissor = graphics.scissorStack.peek();
var terminalPose = new Matrix3x2f(graphics.pose());
var terminalTextures = TextureSetup.singleTextureWithLightmap(graphics.minecraft.getTextureManager().getTexture(FixedWidthFontRenderer.FONT).getTextureView());
var terminalTextures = TextureSetup.singleTextureWithLightmap(
graphics.minecraft.getTextureManager().getTexture(FixedWidthFontRenderer.FONT).getTextureView(),
RenderSystem.getSamplerCache().getClampToEdge(FilterMode.NEAREST)
);
graphics.guiRenderState.submitGuiElement(new TerminalBackgroundRenderState(
innerX, innerY, terminal, terminalPose, terminalTextures,

View File

@@ -21,7 +21,7 @@ import mezz.jei.api.registration.ISubtypeRegistration;
import mezz.jei.api.runtime.IJeiRuntime;
import net.minecraft.client.Minecraft;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.DyedItemColor;
@@ -30,8 +30,8 @@ import java.util.List;
@JeiPlugin
public class JEIComputerCraft implements IModPlugin {
@Override
public ResourceLocation getPluginUid() {
return ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "jei");
public Identifier getPluginUid() {
return Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "jei");
}
@Override
@@ -63,7 +63,7 @@ public class JEIComputerCraft implements IModPlugin {
// Hide all upgrade recipes
var category = registry.createRecipeLookup(RecipeTypes.CRAFTING);
category.get().forEach(wrapper -> {
if (RecipeModHelpers.shouldRemoveRecipe(wrapper.id().location())) {
if (RecipeModHelpers.shouldRemoveRecipe(wrapper.id().identifier())) {
registry.hideRecipes(RecipeTypes.CRAFTING, List.of(wrapper));
}
});
@@ -78,9 +78,9 @@ public class JEIComputerCraft implements IModPlugin {
// Add left and right upgrades to the identifier
var left = TurtleItem.getUpgradeWithData(stack, TurtleSide.LEFT);
var right = TurtleItem.getUpgradeWithData(stack, TurtleSide.RIGHT);
if (left != null) name.append(left.holder().key().location());
if (left != null) name.append(left.holder().key().identifier());
if (left != null && right != null) name.append('|');
if (right != null) name.append(right.holder().key().location());
if (right != null) name.append(right.holder().key().identifier());
return name.toString();
};
@@ -94,9 +94,9 @@ public class JEIComputerCraft implements IModPlugin {
// Add the upgrade to the identifier
var back = PocketComputerItem.getUpgradeWithData(stack, PocketSide.BACK);
var bottom = PocketComputerItem.getUpgradeWithData(stack, PocketSide.BOTTOM);
if (back != null) name.append(back.holder().key().location());
if (back != null) name.append(back.holder().key().identifier());
if (back != null && bottom != null) name.append('|');
if (bottom != null) name.append(bottom.holder().key().location());
if (bottom != null) name.append(bottom.holder().key().identifier());
return name.toString();
};

View File

@@ -13,7 +13,7 @@ import mezz.jei.api.recipe.advanced.ISimpleRecipeManagerPlugin;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.*;
import net.minecraft.world.item.crafting.display.RecipeDisplay;
@@ -31,7 +31,7 @@ class RecipeResolver implements ISimpleRecipeManagerPlugin<RecipeHolder<Crafting
RecipeResolver(HolderLookup.Provider registries) {
resolver = new UpgradeRecipeGenerator<>(x -> new RecipeHolder<>(
ResourceKey.create(Registries.RECIPE, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "upgrade_" + nextId++)),
ResourceKey.create(Registries.RECIPE, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "upgrade_" + nextId++)),
new CraftingWrapper(x)
), registries);
}

View File

@@ -11,7 +11,7 @@ import dan200.computercraft.client.pocket.ClientPocketComputers;
import dan200.computercraft.client.pocket.PocketComputerData;
import net.minecraft.client.color.item.ItemTintSource;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.ARGB;
import net.minecraft.util.ExtraCodecs;
import net.minecraft.world.entity.LivingEntity;
@@ -25,7 +25,7 @@ import org.jspecify.annotations.Nullable;
* @param defaultColour The default colour, if the light is not currently on.
*/
public record PocketComputerLight(int defaultColour) implements ItemTintSource {
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_light");
public static final Identifier ID = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_light");
public static final MapCodec<PocketComputerLight> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
ExtraCodecs.RGB_COLOR_CODEC.fieldOf("default").forGetter(PocketComputerLight::defaultColour)
).apply(instance, PocketComputerLight::new));

View File

@@ -16,7 +16,7 @@ import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.item.ItemModel;
import net.minecraft.client.renderer.item.ItemModelResolver;
import net.minecraft.client.renderer.item.ItemStackRenderState;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.ItemOwner;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
@@ -29,9 +29,9 @@ import org.jspecify.annotations.Nullable;
* @see TurtleOverlay#model()
*/
public record TurtleOverlayModel(ItemTransforms transforms) implements ItemModel {
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle/overlay");
public static final Identifier ID = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle/overlay");
public static final MapCodec<Unbaked> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
ResourceLocation.CODEC.fieldOf("transforms").forGetter(Unbaked::base)
Identifier.CODEC.fieldOf("transforms").forGetter(Unbaked::base)
).apply(instance, Unbaked::new));
@Override
@@ -47,7 +47,7 @@ public record TurtleOverlayModel(ItemTransforms transforms) implements ItemModel
layer.setTransform(transforms().getTransform(context));
}
public record Unbaked(ResourceLocation base) implements ItemModel.Unbaked {
public record Unbaked(Identifier base) implements ItemModel.Unbaked {
@Override
public MapCodec<Unbaked> type() {
return CODEC;

View File

@@ -16,7 +16,7 @@ import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.item.ItemModel;
import net.minecraft.client.renderer.item.ItemModelResolver;
import net.minecraft.client.renderer.item.ItemStackRenderState;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.ItemOwner;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
@@ -29,10 +29,10 @@ import org.jspecify.annotations.Nullable;
* @param base The base model. Only used to provide item transforms.
*/
public record TurtleUpgradeModel(TurtleSide side, ItemTransforms base) implements ItemModel {
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle/upgrade");
public static final Identifier ID = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle/upgrade");
public static final MapCodec<Unbaked> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
TurtleSide.CODEC.fieldOf("side").forGetter(Unbaked::side),
ResourceLocation.CODEC.fieldOf("transforms").forGetter(Unbaked::base)
Identifier.CODEC.fieldOf("transforms").forGetter(Unbaked::base)
).apply(instance, Unbaked::new));
@Override
@@ -44,7 +44,7 @@ public record TurtleUpgradeModel(TurtleSide side, ItemTransforms base) implement
.renderForItem(upgrade, side, state, resolver, base.getTransform(context), seed);
}
public record Unbaked(TurtleSide side, ResourceLocation base) implements ItemModel.Unbaked {
public record Unbaked(TurtleSide side, Identifier base) implements ItemModel.Unbaked {
@Override
public MapCodec<Unbaked> type() {
return CODEC;

View File

@@ -11,7 +11,7 @@ import dan200.computercraft.client.pocket.ClientPocketComputers;
import dan200.computercraft.shared.computer.core.ComputerState;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.item.properties.select.SelectItemModelProperty;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
@@ -21,7 +21,7 @@ import org.jspecify.annotations.Nullable;
* A {@link SelectItemModelProperty} that returns the pocket computer's current state.
*/
public final class PocketComputerStateProperty implements SelectItemModelProperty<ComputerState> {
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_state");
public static final Identifier ID = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_state");
private static final PocketComputerStateProperty INSTANCE = new PocketComputerStateProperty();
public static final MapCodec<PocketComputerStateProperty> CODEC = MapCodec.unit(INSTANCE);
public static final Type<PocketComputerStateProperty, ComputerState> TYPE = Type.create(CODEC, ComputerState.CODEC);

View File

@@ -12,7 +12,7 @@ import dan200.computercraft.shared.turtle.items.TurtleItem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.item.properties.conditional.ConditionalItemModelProperty;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
@@ -25,7 +25,7 @@ import org.jspecify.annotations.Nullable;
* @see TurtleOverlay#showElfOverlay()
*/
public class TurtleShowElfOverlay implements ConditionalItemModelProperty {
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle/show_elf_overlay");
public static final Identifier ID = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle/show_elf_overlay");
private static final TurtleShowElfOverlay INSTANCE = new TurtleShowElfOverlay();
public static final MapCodec<TurtleShowElfOverlay> CODEC = MapCodec.unit(INSTANCE);

View File

@@ -14,8 +14,8 @@ import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.CubeListBuilder;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraft.client.model.geom.builders.MeshDefinition;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.renderer.rendertype.RenderTypes;
import net.minecraft.resources.Identifier;
import net.minecraft.util.Unit;
import static dan200.computercraft.client.model.LecternPrintoutModel.TEXTURE_HEIGHT;
@@ -27,10 +27,10 @@ import static dan200.computercraft.client.model.LecternPrintoutModel.TEXTURE_WID
* @see CustomLecternRenderer
*/
public final class LecternBookModel extends Model<Unit> {
public static final ModelLayerLocation LAYER = new ModelLayerLocation(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "lectern_book"), "main");
public static final ModelLayerLocation LAYER = new ModelLayerLocation(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "lectern_book"), "main");
public LecternBookModel(ModelPart root) {
super(root, RenderType::entitySolid);
super(root, RenderTypes::entitySolid);
}
public static LayerDefinition createLayer() {

View File

@@ -18,13 +18,13 @@ import net.minecraft.client.model.geom.builders.CubeListBuilder;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraft.client.model.geom.builders.MeshDefinition;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.SubmitNodeCollector;
import net.minecraft.client.renderer.rendertype.RenderTypes;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.MaterialSet;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.Unit;
import net.minecraft.world.item.component.DyedItemColor;
@@ -34,13 +34,13 @@ import net.minecraft.world.item.component.DyedItemColor;
* @see CustomLecternRenderer
*/
public class LecternPocketModel extends Model<Unit> {
public static final ModelLayerLocation LAYER = new ModelLayerLocation(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "lectern_pocket"), "main");
public static final ModelLayerLocation LAYER = new ModelLayerLocation(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "lectern_pocket"), "main");
public static final Material MATERIAL_NORMAL = Sheets.BLOCK_ENTITIES_MAPPER.apply(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_normal"));
public static final Material MATERIAL_ADVANCED = Sheets.BLOCK_ENTITIES_MAPPER.apply(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_advanced"));
public static final Material MATERIAL_COLOUR = Sheets.BLOCK_ENTITIES_MAPPER.apply(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_colour"));
public static final Material MATERIAL_FRAME = Sheets.BLOCK_ENTITIES_MAPPER.apply(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_frame"));
public static final Material MATERIAL_LIGHT = Sheets.BLOCK_ENTITIES_MAPPER.apply(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_light"));
public static final Material MATERIAL_NORMAL = Sheets.BLOCK_ENTITIES_MAPPER.apply(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_normal"));
public static final Material MATERIAL_ADVANCED = Sheets.BLOCK_ENTITIES_MAPPER.apply(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_advanced"));
public static final Material MATERIAL_COLOUR = Sheets.BLOCK_ENTITIES_MAPPER.apply(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_colour"));
public static final Material MATERIAL_FRAME = Sheets.BLOCK_ENTITIES_MAPPER.apply(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_frame"));
public static final Material MATERIAL_LIGHT = Sheets.BLOCK_ENTITIES_MAPPER.apply(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_light"));
// The size of the terminal within the model.
public static final float TERM_WIDTH = 12.0f / 32.0f;
@@ -51,7 +51,7 @@ public class LecternPocketModel extends Model<Unit> {
private static final int TEXTURE_HEIGHT = 48 / 2;
public LecternPocketModel(ModelPart root) {
super(root, RenderType::entityCutout);
super(root, RenderTypes::entityCutout);
}
public static LayerDefinition createLayer() {
@@ -81,23 +81,23 @@ public class LecternPocketModel extends Model<Unit> {
) {
if (frameColour != -1) {
collector.submitModel(
this, Unit.INSTANCE, poseStack, MATERIAL_FRAME.renderType(RenderType::entityCutout),
this, Unit.INSTANCE, poseStack, MATERIAL_FRAME.renderType(RenderTypes::entityCutout),
packedLight, OverlayTexture.NO_OVERLAY, -1, materials.get(MATERIAL_FRAME), 0, null
);
collector.submitModel(
this, Unit.INSTANCE, poseStack, MATERIAL_COLOUR.renderType(RenderType::entityCutout),
this, Unit.INSTANCE, poseStack, MATERIAL_COLOUR.renderType(RenderTypes::entityCutout),
packedLight, OverlayTexture.NO_OVERLAY, frameColour, materials.get(MATERIAL_COLOUR), 0, null
);
} else {
var material = family == ComputerFamily.ADVANCED ? MATERIAL_ADVANCED : MATERIAL_NORMAL;
collector.submitModel(
this, Unit.INSTANCE, poseStack, material.renderType(RenderType::entityCutout),
this, Unit.INSTANCE, poseStack, material.renderType(RenderTypes::entityCutout),
packedLight, OverlayTexture.NO_OVERLAY, -1, materials.get(material), 0, null
);
}
collector.submitModel(
this, Unit.INSTANCE, poseStack, MATERIAL_LIGHT.renderType(RenderType::entityCutout),
this, Unit.INSTANCE, poseStack, MATERIAL_LIGHT.renderType(RenderTypes::entityCutout),
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, lightColour, materials.get(MATERIAL_LIGHT), 0, null
);
}

View File

@@ -14,10 +14,10 @@ import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.CubeListBuilder;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraft.client.model.geom.builders.MeshDefinition;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.rendertype.RenderTypes;
import net.minecraft.client.resources.model.Material;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import java.util.List;
@@ -28,9 +28,9 @@ import java.util.List;
* @see CustomLecternRenderer
*/
public final class LecternPrintoutModel extends Model<LecternPrintoutModel.State> {
public static final ModelLayerLocation LAYER = new ModelLayerLocation(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "lectern_printout"), "main");
public static final ModelLayerLocation LAYER = new ModelLayerLocation(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "lectern_printout"), "main");
public static final Material MATERIAL = Sheets.BLOCK_ENTITIES_MAPPER.apply(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "printout"));
public static final Material MATERIAL = Sheets.BLOCK_ENTITIES_MAPPER.apply(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "printout"));
static final int TEXTURE_WIDTH = 32;
static final int TEXTURE_HEIGHT = 32;
@@ -43,7 +43,7 @@ public final class LecternPrintoutModel extends Model<LecternPrintoutModel.State
private final ModelPart[] pages;
public LecternPrintoutModel(ModelPart root) {
super(root, RenderType::entitySolid);
super(root, RenderTypes::entitySolid);
pages = PAGES.stream().map(root::getChild).toArray(ModelPart[]::new);
}

View File

@@ -23,7 +23,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.JukeboxSong;
import net.minecraft.world.level.Level;
@@ -94,7 +94,7 @@ public final class ClientNetworkContextImpl implements ClientNetworkContext {
}
@Override
public void handleSpeakerPlay(UUID source, SpeakerPosition.Message position, ResourceLocation sound, float volume, float pitch) {
public void handleSpeakerPlay(UUID source, SpeakerPosition.Message position, Identifier sound, float volume, float pitch) {
SpeakerManager.getSound(source).playSound(reifyPosition(position), sound, volume, pitch);
}
@@ -116,7 +116,7 @@ public final class ClientNetworkContextImpl implements ClientNetworkContext {
private static SpeakerPosition reifyPosition(SpeakerPosition.Message pos) {
var minecraft = Minecraft.getInstance();
Level level = minecraft.level;
if (level != null && !level.dimension().location().equals(pos.level())) level = null;
if (level != null && !level.dimension().identifier().equals(pos.level())) level = null;
return new SpeakerPosition(
level, pos.position(),

View File

@@ -11,7 +11,7 @@ import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.rendertype.RenderTypes;
import net.minecraft.client.renderer.state.LevelRenderState;
import net.minecraft.util.ARGB;
import net.minecraft.util.CommonColors;
@@ -37,15 +37,15 @@ public final class BlockOutlineRenderer {
public static void render(PoseStack transform, MultiBufferSource bufferSource, Renderer renderer) {
var highContrast = Minecraft.getInstance().options.highContrastBlockOutline().get();
if (highContrast) {
renderer.render(transform, bufferSource.getBuffer(RenderType.secondaryBlockOutline()), 0xff000000);
renderer.render(transform, bufferSource.getBuffer(RenderTypes.secondaryBlockOutline()), 0xff000000, 7f);
}
var colour = highContrast ? CommonColors.HIGH_CONTRAST_DIAMOND : ARGB.color(0x66, CommonColors.BLACK);
renderer.render(transform, bufferSource.getBuffer(RenderType.lines()), colour);
renderer.render(transform, bufferSource.getBuffer(RenderTypes.lines()), colour, Minecraft.getInstance().getWindow().getAppropriateLineWidth());
}
@FunctionalInterface
public interface Renderer {
void render(PoseStack transform, VertexConsumer buffer, int colour);
void render(PoseStack transform, VertexConsumer buffer, int colour, float width);
}
}

View File

@@ -26,7 +26,7 @@ public final class CableHighlightRenderer {
*/
public static BlockOutlineRenderer.@Nullable Renderer drawHighlight(Camera camera, BlockHitResult hit) {
var pos = hit.getBlockPos();
var level = camera.getEntity().level();
var level = camera.entity().level();
var state = level.getBlockState(pos);
@@ -39,11 +39,11 @@ public final class CableHighlightRenderer {
? CableShapes.getModemShape(state)
: CableShapes.getCableShape(state);
var cameraPos = camera.getPosition();
var cameraPos = camera.position();
var xOffset = pos.getX() - cameraPos.x();
var yOffset = pos.getY() - cameraPos.y();
var zOffset = pos.getZ() - cameraPos.z();
return (transform, buffer, colour) -> ShapeRenderer.renderShape(transform, buffer, shape, xOffset, yOffset, zOffset, colour);
return (transform, buffer, colour, width) -> ShapeRenderer.renderShape(transform, buffer, shape, xOffset, yOffset, zOffset, colour, width);
}
}

View File

@@ -19,13 +19,13 @@ import dan200.computercraft.shared.lectern.CustomLecternBlockEntity;
import dan200.computercraft.shared.media.items.PrintoutData;
import dan200.computercraft.shared.media.items.PrintoutItem;
import dan200.computercraft.shared.pocket.items.PocketComputerItem;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.SubmitNodeCollector;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.blockentity.LecternRenderer;
import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState;
import net.minecraft.client.renderer.feature.ModelFeatureRenderer;
import net.minecraft.client.renderer.rendertype.RenderTypes;
import net.minecraft.client.renderer.state.CameraRenderState;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.resources.model.MaterialSet;
@@ -97,13 +97,13 @@ public class CustomLecternRenderer implements BlockEntityRenderer<CustomLecternB
if (state.type == Type.PRINTOUT) {
if (state.isBook) {
collector.submitModel(
bookModel, Unit.INSTANCE, poseStack, LecternPrintoutModel.MATERIAL.renderType(RenderType::entitySolid),
bookModel, Unit.INSTANCE, poseStack, LecternPrintoutModel.MATERIAL.renderType(RenderTypes::entitySolid),
state.lightCoords, OverlayTexture.NO_OVERLAY, -1,
materials.get(LecternPrintoutModel.MATERIAL), 0, null
);
} else {
collector.submitModel(
printoutModel, state.printoutState, poseStack, LecternPrintoutModel.MATERIAL.renderType(RenderType::entitySolid),
printoutModel, state.printoutState, poseStack, LecternPrintoutModel.MATERIAL.renderType(RenderTypes::entitySolid),
state.lightCoords, OverlayTexture.NO_OVERLAY, -1,
materials.get(LecternPrintoutModel.MATERIAL), 0, null
);

View File

@@ -37,14 +37,15 @@ public abstract class ItemMapLikeRenderer {
protected abstract void renderItem(PoseStack transform, SubmitNodeCollector collector, ItemStack stack, int light);
public void renderItemFirstPerson(PoseStack transform, SubmitNodeCollector collector, int lightTexture, InteractionHand hand, float pitch, float equipProgress, float swingProgress, ItemStack stack) {
Player player = Objects.requireNonNull(Minecraft.getInstance().player);
var minecraft = Minecraft.getInstance();
var player = Objects.requireNonNull(minecraft.player);
transform.pushPose();
if (hand == InteractionHand.MAIN_HAND && player.getOffhandItem().isEmpty()) {
renderItemFirstPersonCenter(transform, collector, lightTexture, pitch, equipProgress, swingProgress, stack);
renderItemFirstPersonCenter(minecraft, player, transform, collector, lightTexture, pitch, equipProgress, swingProgress, stack);
} else {
renderItemFirstPersonSide(
transform, collector, lightTexture,
minecraft, player, transform, collector, lightTexture,
hand == InteractionHand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite(),
equipProgress, swingProgress, stack
);
@@ -55,6 +56,8 @@ public abstract class ItemMapLikeRenderer {
/**
* Renders the item to one side of the player.
*
* @param minecraft The current Minecraft client.
* @param player The player holding this item.
* @param transform The matrix transformation stack
* @param collector The buffer to render to
* @param combinedLight The current light level
@@ -64,13 +67,15 @@ public abstract class ItemMapLikeRenderer {
* @param stack The stack to render
* @see ItemInHandRenderer#renderOneHandedMap(PoseStack, SubmitNodeCollector, int, float, HumanoidArm, float, ItemStack)
*/
private void renderItemFirstPersonSide(PoseStack transform, SubmitNodeCollector collector, int combinedLight, HumanoidArm side, float equipProgress, float swingProgress, ItemStack stack) {
var minecraft = Minecraft.getInstance();
private void renderItemFirstPersonSide(
Minecraft minecraft, Player player, PoseStack transform, SubmitNodeCollector collector, int combinedLight,
HumanoidArm side, float equipProgress, float swingProgress, ItemStack stack
) {
var offset = side == HumanoidArm.RIGHT ? 1f : -1f;
transform.translate(offset * 0.125f, -0.125f, 0f);
// If the player is not invisible then render a single arm
if (!minecraft.player.isInvisible()) {
if (!player.isInvisible()) {
transform.pushPose();
transform.mulPose(Axis.ZP.rotationDegrees(offset * 10f));
minecraft.getEntityRenderDispatcher().getItemInHandRenderer().renderPlayerArm(transform, collector, combinedLight, equipProgress, swingProgress, side);
@@ -98,6 +103,8 @@ public abstract class ItemMapLikeRenderer {
/**
* Render an item in the middle of the screen.
*
* @param minecraft The current Minecraft client.
* @param player The player holding this item.
* @param transform The matrix transformation stack
* @param collector The buffer to render to
* @param combinedLight The current light level
@@ -107,8 +114,10 @@ public abstract class ItemMapLikeRenderer {
* @param stack The stack to render
* @see ItemInHandRenderer#renderTwoHandedMap(PoseStack, SubmitNodeCollector, int, float, float, float)
*/
private void renderItemFirstPersonCenter(PoseStack transform, SubmitNodeCollector collector, int combinedLight, float pitch, float equipProgress, float swingProgress, ItemStack stack) {
var minecraft = Minecraft.getInstance();
private void renderItemFirstPersonCenter(
Minecraft minecraft, Player player, PoseStack transform, SubmitNodeCollector collector, int combinedLight,
float pitch, float equipProgress, float swingProgress, ItemStack stack
) {
var renderer = minecraft.getEntityRenderDispatcher().getItemInHandRenderer();
// Setup the appropriate transformations. This is just copied from the
@@ -121,7 +130,7 @@ public abstract class ItemMapLikeRenderer {
var pitchAngle = renderer.calculateMapTilt(pitch);
transform.translate(0, 0.04F + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f);
transform.mulPose(Axis.XP.rotationDegrees(pitchAngle * -85.0f));
if (!minecraft.player.isInvisible()) {
if (!player.isInvisible()) {
transform.pushPose();
transform.mulPose(Axis.YP.rotationDegrees(90.0F));
renderer.renderMapHand(transform, collector, combinedLight, HumanoidArm.RIGHT);

View File

@@ -11,8 +11,9 @@ import dan200.computercraft.core.terminal.Palette;
import dan200.computercraft.core.terminal.TextBuffer;
import dan200.computercraft.shared.media.items.PrintoutData;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.renderer.rendertype.RenderType;
import net.minecraft.client.renderer.rendertype.RenderTypes;
import net.minecraft.resources.Identifier;
import org.joml.Matrix4f;
import java.util.List;
@@ -26,10 +27,10 @@ import static dan200.computercraft.shared.media.items.PrintoutData.LINES_PER_PAG
*/
public final class PrintoutRenderer {
/**
* Printout's background texture. {@link RenderType#text(ResourceLocation)} is a <em>little</em> questionable, but
* Printout's background texture. {@link RenderTypes#text(Identifier)} is a <em>little</em> questionable, but
* it is what maps use, so should behave the same as vanilla in both item frames and in-hand.
*/
public static final RenderType BACKGROUND = RenderType.text(ResourceLocation.fromNamespaceAndPath("computercraft", "textures/gui/printout.png"));
public static final RenderType BACKGROUND = RenderTypes.text(Identifier.fromNamespaceAndPath("computercraft", "textures/gui/printout.png"));
private static final float BG_SIZE = 256.0f;

View File

@@ -7,8 +7,8 @@ package dan200.computercraft.client.render;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.SubmitNodeCollector;
import net.minecraft.client.renderer.rendertype.RenderTypes;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -44,7 +44,7 @@ public class SpriteRenderer {
var v0 = sprite.getV((float) spriteY / spriteHeight);
var v1 = sprite.getV((float) (spriteY + height) / spriteHeight);
submit.submitCustomGeometry(transform, RenderType.text(sprite.atlasLocation()), (t, vertices) -> {
submit.submitCustomGeometry(transform, RenderTypes.text(sprite.atlasLocation()), (t, vertices) -> {
vertices.addVertex(t, x0, y1, z).setColor(colour).setUv(u0, v1).setLight(light);
vertices.addVertex(t, x1, y1, z).setColor(colour).setUv(u1, v1).setLight(light);
vertices.addVertex(t, x1, y0, z).setColor(colour).setUv(u1, v0).setLight(light);

View File

@@ -30,7 +30,7 @@ import net.minecraft.client.renderer.item.ItemStackRenderState;
import net.minecraft.client.renderer.state.CameraRenderState;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.ARGB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
@@ -38,9 +38,9 @@ import net.minecraft.world.phys.Vec3;
import org.jspecify.annotations.Nullable;
public class TurtleBlockEntityRenderer implements BlockEntityRenderer<TurtleBlockEntity, TurtleBlockEntityRenderer.State> {
public static final ResourceLocation NORMAL_TURTLE_MODEL = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_normal");
public static final ResourceLocation ADVANCED_TURTLE_MODEL = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_advanced");
public static final ResourceLocation COLOUR_TURTLE_MODEL = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_colour");
public static final Identifier NORMAL_TURTLE_MODEL = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_normal");
public static final Identifier ADVANCED_TURTLE_MODEL = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_advanced");
public static final Identifier COLOUR_TURTLE_MODEL = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_colour");
private final ItemModelResolver itemModelResolver;

View File

@@ -15,19 +15,20 @@ import dan200.computercraft.client.integration.ShaderMod;
import dan200.computercraft.client.render.text.DirectFixedWidthFontRenderer;
import dan200.computercraft.client.render.text.FixedWidthFontRenderer;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.core.util.Nullability;
import dan200.computercraft.shared.config.Config;
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
import dan200.computercraft.shared.peripheral.monitor.MonitorBlockEntity;
import dan200.computercraft.shared.util.DirectionUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.SubmitNodeCollector;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState;
import net.minecraft.client.renderer.feature.ModelFeatureRenderer;
import net.minecraft.client.renderer.fog.FogRenderer;
import net.minecraft.client.renderer.rendertype.RenderType;
import net.minecraft.client.renderer.state.CameraRenderState;
import net.minecraft.core.Direction;
import net.minecraft.world.phys.AABB;
@@ -194,7 +195,7 @@ public class MonitorBlockEntityRenderer implements BlockEntityRenderer<MonitorBl
// There's not really a good way around this, at least without using a custom render type (which the VBO
// renderer is trying to avoid!). Instead, we just disable fog entirely by setting the fog start to an
// absurdly high value.
var oldFog = RenderSystem.getShaderFog();
var oldFog = Nullability.assertNonNull(RenderSystem.getShaderFog());
RenderSystem.setShaderFog(Minecraft.getInstance().gameRenderer.fogRenderer.getBuffer(FogRenderer.FogMode.NONE));
// Compose the existing model view matrix with our transformation matrix.
@@ -226,12 +227,9 @@ public class MonitorBlockEntityRenderer implements BlockEntityRenderer<MonitorBl
RenderSystem.getModelViewMatrix(),
new Vector4f(1.0F, 1.0F, 1.0F, 1.0F),
new Vector3f(),
RenderSystem.getTextureMatrix(),
RenderSystem.getShaderLineWidth()
new Matrix4f()
);
renderType.setupRenderState();
var autoStorageBuffer = RenderSystem.getSequentialBuffer(renderType.mode());
var indexCount = FixedWidthFontRenderer.TERMINAL_TEXT.mode().indexCount(vertexCount);
var indexBuffer = autoStorageBuffer.getBuffer(indexCount);
@@ -243,7 +241,7 @@ public class MonitorBlockEntityRenderer implements BlockEntityRenderer<MonitorBl
: null;
try (var renderPass = RenderSystem.getDevice().createCommandEncoder().createRenderPass(
() -> "Monitor", colourTarget, OptionalInt.empty(), depthTarget, OptionalDouble.empty()
() -> "Monitor", Nullability.assertNonNull(colourTarget), OptionalInt.empty(), depthTarget, OptionalDouble.empty()
)) {
renderPass.setPipeline(pipeline);
@@ -252,15 +250,15 @@ public class MonitorBlockEntityRenderer implements BlockEntityRenderer<MonitorBl
renderPass.setVertexBuffer(0, renderState.vertexBuffer);
renderPass.setIndexBuffer(indexBuffer, autoStorageBuffer.type());
/*
for (var j = 0; j < 12; j++) {
var gpuTexture = RenderSystem.getShaderTexture(j);
if (gpuTexture != null) renderPass.bindSampler("Sampler" + j, gpuTexture);
if (gpuTexture != null) renderPass.bindTexture("Sampler" + j, gpuTexture);
}
*/
renderPass.drawIndexed(vertexOffset, 0, indexCount, 1);
}
renderType.clearRenderState();
}
@Override

View File

@@ -27,9 +27,9 @@ public final class MonitorHighlightRenderer {
public static BlockOutlineRenderer.@Nullable Renderer drawHighlight(Camera camera, BlockHitResult hit) {
// Preserve normal behaviour when crouching.
if (camera.getEntity().isCrouching()) return null;
if (camera.entity().isCrouching()) return null;
var world = camera.getEntity().level();
var world = camera.entity().level();
var pos = hit.getBlockPos();
if (!(world.getBlockEntity(pos) instanceof MonitorBlockEntity monitor)) return null;
@@ -43,43 +43,45 @@ public final class MonitorHighlightRenderer {
if (monitor.getYIndex() != 0) faces.remove(monitor.getDown().getOpposite());
if (monitor.getYIndex() != monitor.getHeight() - 1) faces.remove(monitor.getDown());
var cameraPos = camera.getPosition();
var cameraPos = camera.position();
var xOffset = pos.getX() - cameraPos.x();
var yOffset = pos.getY() - cameraPos.y();
var zOffset = pos.getZ() - cameraPos.z();
return (transform, buffer, colour) -> {
return (transform, buffer, colour, width) -> {
transform.pushPose();
transform.translate(xOffset, yOffset, zOffset);
draw(buffer, transform.last(), faces, colour);
draw(buffer, transform.last(), faces, colour, width);
transform.popPose();
};
}
private static void draw(VertexConsumer buffer, PoseStack.Pose transform, EnumSet<Direction> faces, int colour) {
private static void draw(VertexConsumer buffer, PoseStack.Pose transform, EnumSet<Direction> faces, int colour, float width) {
// I wish I could think of a better way to do this
if (faces.contains(NORTH) || faces.contains(WEST)) line(buffer, transform, 0, 0, 0, UP, colour);
if (faces.contains(SOUTH) || faces.contains(WEST)) line(buffer, transform, 0, 0, 1, UP, colour);
if (faces.contains(NORTH) || faces.contains(EAST)) line(buffer, transform, 1, 0, 0, UP, colour);
if (faces.contains(SOUTH) || faces.contains(EAST)) line(buffer, transform, 1, 0, 1, UP, colour);
if (faces.contains(NORTH) || faces.contains(DOWN)) line(buffer, transform, 0, 0, 0, EAST, colour);
if (faces.contains(SOUTH) || faces.contains(DOWN)) line(buffer, transform, 0, 0, 1, EAST, colour);
if (faces.contains(NORTH) || faces.contains(UP)) line(buffer, transform, 0, 1, 0, EAST, colour);
if (faces.contains(SOUTH) || faces.contains(UP)) line(buffer, transform, 0, 1, 1, EAST, colour);
if (faces.contains(WEST) || faces.contains(DOWN)) line(buffer, transform, 0, 0, 0, SOUTH, colour);
if (faces.contains(EAST) || faces.contains(DOWN)) line(buffer, transform, 1, 0, 0, SOUTH, colour);
if (faces.contains(WEST) || faces.contains(UP)) line(buffer, transform, 0, 1, 0, SOUTH, colour);
if (faces.contains(EAST) || faces.contains(UP)) line(buffer, transform, 1, 1, 0, SOUTH, colour);
if (faces.contains(NORTH) || faces.contains(WEST)) line(buffer, transform, 0, 0, 0, UP, colour, width);
if (faces.contains(SOUTH) || faces.contains(WEST)) line(buffer, transform, 0, 0, 1, UP, colour, width);
if (faces.contains(NORTH) || faces.contains(EAST)) line(buffer, transform, 1, 0, 0, UP, colour, width);
if (faces.contains(SOUTH) || faces.contains(EAST)) line(buffer, transform, 1, 0, 1, UP, colour, width);
if (faces.contains(NORTH) || faces.contains(DOWN)) line(buffer, transform, 0, 0, 0, EAST, colour, width);
if (faces.contains(SOUTH) || faces.contains(DOWN)) line(buffer, transform, 0, 0, 1, EAST, colour, width);
if (faces.contains(NORTH) || faces.contains(UP)) line(buffer, transform, 0, 1, 0, EAST, colour, width);
if (faces.contains(SOUTH) || faces.contains(UP)) line(buffer, transform, 0, 1, 1, EAST, colour, width);
if (faces.contains(WEST) || faces.contains(DOWN)) line(buffer, transform, 0, 0, 0, SOUTH, colour, width);
if (faces.contains(EAST) || faces.contains(DOWN)) line(buffer, transform, 1, 0, 0, SOUTH, colour, width);
if (faces.contains(WEST) || faces.contains(UP)) line(buffer, transform, 0, 1, 0, SOUTH, colour, width);
if (faces.contains(EAST) || faces.contains(UP)) line(buffer, transform, 1, 1, 0, SOUTH, colour, width);
}
private static void line(VertexConsumer buffer, PoseStack.Pose transform, float x, float y, float z, Direction direction, int colour) {
private static void line(VertexConsumer buffer, PoseStack.Pose transform, float x, float y, float z, Direction direction, int colour, float width) {
buffer
.addVertex(transform, x, y, z)
.setColor(colour)
.setNormal(transform, direction.getStepX(), direction.getStepY(), direction.getStepZ());
.setNormal(transform, direction.getStepX(), direction.getStepY(), direction.getStepZ())
.setLineWidth(width);
buffer
.addVertex(transform, x + direction.getStepX(), y + direction.getStepY(), z + direction.getStepZ())
.setColor(colour)
.setNormal(transform, direction.getStepX(), direction.getStepY(), direction.getStepZ());
.setNormal(transform, direction.getStepX(), direction.getStepY(), direction.getStepZ())
.setLineWidth(width);
}
}

View File

@@ -12,9 +12,10 @@ import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.core.terminal.TextBuffer;
import dan200.computercraft.core.util.Colour;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.SubmitNodeCollector;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.renderer.rendertype.RenderType;
import net.minecraft.client.renderer.rendertype.RenderTypes;
import net.minecraft.resources.Identifier;
import net.minecraft.util.ARGB;
import org.joml.Matrix4f;
import org.joml.Vector3f;
@@ -34,14 +35,14 @@ import org.joml.Vector3f;
* {@link DirectFixedWidthFontRenderer}.
*/
public final class FixedWidthFontRenderer {
public static final ResourceLocation FONT = ResourceLocation.fromNamespaceAndPath("computercraft", "textures/gui/term_font.png");
public static final Identifier FONT = Identifier.fromNamespaceAndPath("computercraft", "textures/gui/term_font.png");
/**
* A render type for terminal text.
*/
public static final RenderType TERMINAL_TEXT = RenderType.text(FONT);
public static final RenderType TERMINAL_TEXT = RenderTypes.text(FONT);
public static final RenderType TERMINAL_TEXT_OFFSET = RenderType.textPolygonOffset(FONT);
public static final RenderType TERMINAL_TEXT_OFFSET = RenderTypes.textPolygonOffset(FONT);
public static final int FONT_HEIGHT = 9;
public static final int FONT_WIDTH = 6;

View File

@@ -112,7 +112,6 @@ class DfpwmStream implements AudioStream {
return MONO_8;
}
@Nullable
@Override
public synchronized ByteBuffer read(int capacity) {
var result = BufferUtils.createByteBuffer(capacity);
@@ -131,8 +130,14 @@ class DfpwmStream implements AudioStream {
result.flip();
// This is naughty, but ensures we're not enqueuing empty buffers when the stream is exhausted.
return result.remaining() == 0 ? null : result;
// This is naughty, as AudioStream.read is marked as non-null. However, Channel.pumpBuffers still assumes it can
// return a null value, and doing this ensures we're not enqueuing empty buffers when the stream is exhausted.
return result.remaining() == 0 ? actuallyANullBuffer() : result;
}
@SuppressWarnings("NullAway")
private static ByteBuffer actuallyANullBuffer() {
return null;
}
@Override

View File

@@ -9,14 +9,14 @@ import dan200.computercraft.core.util.Nullability;
import dan200.computercraft.shared.peripheral.speaker.EncodedAudio;
import dan200.computercraft.shared.peripheral.speaker.SpeakerPosition;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jspecify.annotations.Nullable;
/**
* An instance of a speaker, which is either playing a {@link DfpwmStream} stream or a normal sound.
*/
public class SpeakerInstance {
public static final ResourceLocation DFPWM_STREAM = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "speaker.dfpwm_fake_audio_should_not_be_played");
public static final Identifier DFPWM_STREAM = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "speaker.dfpwm_fake_audio_should_not_be_played");
private @Nullable DfpwmStream currentStream;
private @Nullable SpeakerSound sound;
@@ -72,7 +72,7 @@ public class SpeakerInstance {
}
}
public void playSound(SpeakerPosition position, ResourceLocation location, float volume, float pitch) {
public void playSound(SpeakerPosition position, Identifier location, float volume, float pitch) {
var soundManager = Minecraft.getInstance().getSoundManager();
currentStream = null;

View File

@@ -13,7 +13,7 @@ import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.client.resources.sounds.TickableSoundInstance;
import net.minecraft.client.sounds.AudioStream;
import net.minecraft.client.sounds.SoundBufferLibrary;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity;
import org.jspecify.annotations.Nullable;
@@ -36,7 +36,7 @@ public class SpeakerSound extends AbstractSoundInstance implements TickableSound
private boolean stopped = false;
SpeakerSound(ResourceLocation sound, @Nullable DfpwmStream stream, SpeakerPosition position, float volume, float pitch) {
SpeakerSound(Identifier sound, @Nullable DfpwmStream stream, SpeakerPosition position, float volume, float pitch) {
super(sound, SoundSource.RECORDS, SoundInstance.createUnseededRandom());
setPosition(position);
this.stream = stream;
@@ -76,7 +76,7 @@ public class SpeakerSound extends AbstractSoundInstance implements TickableSound
}
@FabricOverride
public CompletableFuture<AudioStream> getAudioStream(SoundBufferLibrary soundBuffers, ResourceLocation sound, boolean looping) {
public CompletableFuture<AudioStream> getAudioStream(SoundBufferLibrary soundBuffers, Identifier sound, boolean looping) {
return stream != null ? CompletableFuture.completedFuture(stream) : soundBuffers.getStream(sound, looping);
}

View File

@@ -12,7 +12,7 @@ import dan200.computercraft.shared.ModRegistry;
import dan200.computercraft.shared.util.Holiday;
import net.minecraft.client.resources.model.ModelBaker;
import net.minecraft.client.resources.model.ResolvableModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
/**
* A cosmetic overlay on a turtle.
@@ -31,7 +31,7 @@ public record TurtleOverlay(StandaloneModel model, boolean showElfOverlay) {
* The codec used to read/write turtle overlay definitions from resource packs.
*/
public static final Codec<TurtleOverlay.Unbaked> CODEC = RecordCodecBuilder.create(instance -> instance.group(
ResourceLocation.CODEC.fieldOf("model").forGetter(TurtleOverlay.Unbaked::model),
Identifier.CODEC.fieldOf("model").forGetter(TurtleOverlay.Unbaked::model),
Codec.BOOL.optionalFieldOf("show_elf_overlay", false).forGetter(TurtleOverlay.Unbaked::showElfOverlay)
).apply(instance, TurtleOverlay.Unbaked::new));
@@ -40,9 +40,9 @@ public record TurtleOverlay(StandaloneModel model, boolean showElfOverlay) {
*
* @see #showElfOverlay()
*/
public static final ResourceLocation ELF_MODEL = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_elf_overlay");
public static final Identifier ELF_MODEL = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_elf_overlay");
public record Unbaked(ResourceLocation model, boolean showElfOverlay) implements ResolvableModel {
public record Unbaked(Identifier model, boolean showElfOverlay) implements ResolvableModel {
@Override
public void resolveDependencies(Resolver resolver) {
resolver.markDependency(model());

View File

@@ -8,7 +8,7 @@ import dan200.computercraft.client.CustomModelManager;
import net.minecraft.client.resources.model.MissingBlockModel;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.resources.FileToIdConverter;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.Nullable;
@@ -36,7 +36,7 @@ public class TurtleOverlayManager {
* @return The turtle overlay.
*/
@Contract("_, null -> null; _, !null -> !null")
public static @Nullable TurtleOverlay get(ModelManager modelManager, @Nullable ResourceLocation id) {
public static @Nullable TurtleOverlay get(ModelManager modelManager, @Nullable Identifier id) {
return id == null ? null : loader.get(modelManager, id);
}
}

View File

@@ -38,6 +38,6 @@ public final class TurtleUpgradeModelManager {
*/
@Contract("_, null -> null; _, !null -> !null")
public static @Nullable TurtleUpgradeModel get(ModelManager modelManager, Holder.@Nullable Reference<ITurtleUpgrade> upgrade) {
return upgrade == null ? null : loader.get(modelManager, upgrade.key().location());
return upgrade == null ? null : loader.get(modelManager, upgrade.key().identifier());
}
}

View File

@@ -15,7 +15,6 @@ import dan200.computercraft.client.turtle.TurtleOverlay;
import dan200.computercraft.data.client.BlockModelProvider;
import dan200.computercraft.data.client.ItemModelProvider;
import dan200.computercraft.shared.turtle.inventory.UpgradeSlot;
import net.minecraft.Util;
import net.minecraft.client.data.models.BlockModelGenerators;
import net.minecraft.client.data.models.ItemModelGenerators;
import net.minecraft.client.renderer.texture.atlas.SpriteSource;
@@ -28,7 +27,8 @@ import net.minecraft.data.DataProvider;
import net.minecraft.data.PackOutput;
import net.minecraft.data.registries.RegistryPatchGenerator;
import net.minecraft.data.tags.TagsProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.Util;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
@@ -96,7 +96,7 @@ public final class DataProviders {
@SafeVarargs
@SuppressWarnings("varargs")
private static List<SpriteSource> makeSprites(final Stream<ResourceLocation>... files) {
private static List<SpriteSource> makeSprites(final Stream<Identifier>... files) {
return Arrays.stream(files).flatMap(Function.identity()).<SpriteSource>map(x -> new SingleFile(x, Optional.empty())).toList();
}
@@ -105,7 +105,7 @@ public final class DataProviders {
<T extends DataProvider> T add(DataProvider.Factory<T> factory);
<T> void addFromCodec(String name, PackOutput.Target target, String directory, Codec<T> codec, Consumer<BiConsumer<ResourceLocation, T>> output);
<T> void addFromCodec(String name, PackOutput.Target target, String directory, Codec<T> codec, Consumer<BiConsumer<Identifier, T>> output);
TagsProvider<Block> blockTags(Consumer<TagProvider.TagConsumer<Block>> tags);

View File

@@ -288,12 +288,12 @@ public final class LanguageProvider implements DataProvider {
private Stream<String> getExpectedKeys(HolderLookup.Provider registries) {
return Stream.of(
BuiltInRegistries.BLOCK.listElements()
.filter(x -> x.key().location().getNamespace().equals(ComputerCraftAPI.MOD_ID))
.filter(x -> x.key().identifier().getNamespace().equals(ComputerCraftAPI.MOD_ID))
.map(x -> x.value().getDescriptionId())
// Exclude blocks that just reuse vanilla translations, such as the lectern.
.filter(x -> !x.startsWith("block.minecraft.")),
BuiltInRegistries.ITEM.listElements()
.filter(x -> x.key().location().getNamespace().equals(ComputerCraftAPI.MOD_ID))
.filter(x -> x.key().identifier().getNamespace().equals(ComputerCraftAPI.MOD_ID))
.map(x -> x.value().getDescriptionId()),
registries.lookupOrThrow(ITurtleUpgrade.REGISTRY).listElements().flatMap(x -> getTranslationKeys(x.value().getAdjective())),
registries.lookupOrThrow(IPocketUpgrade.REGISTRY).listElements().flatMap(x -> getTranslationKeys(x.value().getAdjective())),

View File

@@ -11,7 +11,8 @@ import dan200.computercraft.shared.data.HasComputerIdLootCondition;
import dan200.computercraft.shared.data.PlayerCreativeLootCondition;
import dan200.computercraft.shared.peripheral.modem.wired.CableBlock;
import dan200.computercraft.shared.peripheral.modem.wired.CableModemVariant;
import net.minecraft.advancements.critereon.StatePropertiesPredicate;
import net.minecraft.advancements.criterion.StatePropertiesPredicate;
import net.minecraft.core.component.DataComponents;
import net.minecraft.data.loot.LootTableProvider.SubProviderEntry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.Items;
@@ -21,7 +22,6 @@ import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer;
import net.minecraft.world.level.storage.loot.functions.CopyComponentsFunction;
import net.minecraft.world.level.storage.loot.functions.CopyNameFunction;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.level.storage.loot.predicates.AnyOfCondition;
@@ -93,7 +93,10 @@ class LootTableProvider {
private static void namedBlockDrop(BiConsumer<ResourceKey<LootTable>, LootTable.Builder> add, Supplier<? extends Block> wrapper) {
blockDrop(
add, wrapper,
LootItem.lootTableItem(wrapper.get()).apply(CopyNameFunction.copyName(new CopyNameFunction.Source(LootContextParams.BLOCK_ENTITY))),
LootItem.lootTableItem(wrapper.get()).apply(
CopyComponentsFunction.copyComponentsFromBlockEntity(LootContextParams.BLOCK_ENTITY)
.include(DataComponents.CUSTOM_NAME)
),
ExplosionCondition.survivesExplosion()
);
}

View File

@@ -9,8 +9,8 @@ import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
import net.minecraft.data.worldgen.BootstrapContext;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import static dan200.computercraft.shared.ModRegistry.Items;
@@ -23,6 +23,6 @@ class PocketUpgradeProvider {
}
private static ResourceKey<IPocketUpgrade> id(String id) {
return ResourceKey.create(IPocketUpgrade.REGISTRY, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, id));
return ResourceKey.create(IPocketUpgrade.REGISTRY, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, id));
}
}

View File

@@ -30,8 +30,8 @@ import dan200.computercraft.shared.util.ColourUtils;
import dan200.computercraft.shared.util.DataComponentUtil;
import dan200.computercraft.shared.util.RegistryHelper;
import net.minecraft.advancements.Criterion;
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.criterion.InventoryChangeTrigger;
import net.minecraft.advancements.criterion.ItemPredicate;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponents;
@@ -40,8 +40,8 @@ import net.minecraft.core.registries.Registries;
import net.minecraft.data.PackOutput;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.DyeColor;
@@ -96,7 +96,7 @@ final class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider {
.group("computercraft:disk")
.unlockedBy("has_drive", has(ModRegistry.Items.DISK_DRIVE.get()))
.build(d -> new DiskRecipe(d.properties(), d.ingredients()))
.save(output, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "disk"));
.save(output, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "disk"));
}
private static List<TurtleItem> turtleItems() {
@@ -121,7 +121,7 @@ final class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider {
.build(ImpostorShapedRecipe::new)
.save(
output,
name.withSuffix(String.format("/%s/%s", upgradeHolder.key().location().getNamespace(), upgradeHolder.key().location().getPath()))
name.withSuffix(String.format("/%s/%s", upgradeHolder.key().identifier().getNamespace(), upgradeHolder.key().identifier().getPath()))
);
});
}
@@ -150,7 +150,7 @@ final class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider {
.build(ImpostorShapedRecipe::new)
.save(
output,
name.withSuffix(String.format("/%s/%s", upgradeHolder.key().location().getNamespace(), upgradeHolder.key().location().getPath()))
name.withSuffix(String.format("/%s/%s", upgradeHolder.key().identifier().getNamespace(), upgradeHolder.key().identifier().getPath()))
);
});
}
@@ -177,7 +177,7 @@ final class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider {
);
}
private void turtleOverlay(ResourceLocation overlay, Consumer<ShapelessSpecBuilder> build) {
private void turtleOverlay(Identifier overlay, Consumer<ShapelessSpecBuilder> build) {
for (var turtleItem : turtleItems()) {
var name = RegistryHelper.getKeyOrThrow(BuiltInRegistries.ITEM, turtleItem);
@@ -234,7 +234,7 @@ final class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider {
.define('C', ModRegistry.Items.COMPUTER_NORMAL.get())
.unlockedBy("has_components", inventoryTrigger(itemPredicate(ModRegistry.Items.COMPUTER_NORMAL.get()), itemPredicate(ingredients.goldIngot())))
.build(x -> new TransformShapedRecipe(x, List.of(new CopyComponents(ModRegistry.Items.COMPUTER_NORMAL.get()))))
.save(output, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "computer_advanced_upgrade"));
.save(output, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "computer_advanced_upgrade"));
shaped(RecipeCategory.REDSTONE, ModRegistry.Items.COMPUTER_COMMAND.get())
.pattern("###")
@@ -277,7 +277,7 @@ final class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider {
.define('B', ingredients.goldBlock())
.unlockedBy("has_components", inventoryTrigger(itemPredicate(ModRegistry.Items.TURTLE_NORMAL.get()), itemPredicate(ingredients.goldIngot())))
.build(x -> new TransformShapedRecipe(x, List.of(new CopyComponents(ModRegistry.Items.TURTLE_NORMAL.get()))))
.save(output, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle_advanced_upgrade"));
.save(output, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle_advanced_upgrade"));
shaped(RecipeCategory.REDSTONE, ModRegistry.Items.DISK_DRIVE.get())
.pattern("###")
@@ -336,7 +336,7 @@ final class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider {
.define('C', ModRegistry.Items.POCKET_COMPUTER_NORMAL.get())
.unlockedBy("has_components", inventoryTrigger(itemPredicate(ModRegistry.Items.POCKET_COMPUTER_NORMAL.get()), itemPredicate(ingredients.goldIngot())))
.build(x -> new TransformShapedRecipe(x, List.of(new CopyComponents(ModRegistry.Items.POCKET_COMPUTER_NORMAL.get()))))
.save(output, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_advanced_upgrade"));
.save(output, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_computer_advanced_upgrade"));
shaped(RecipeCategory.REDSTONE, ModRegistry.Items.PRINTER.get())
.pattern("###")
@@ -395,14 +395,14 @@ final class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider {
.requires(ModRegistry.Items.MONITOR_NORMAL.get())
.unlockedBy("has_monitor", has(ModRegistry.Items.MONITOR_NORMAL.get()))
.build()
.save(output, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "skull_cloudy"));
.save(output, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "skull_cloudy"));
customShapeless(RecipeCategory.DECORATIONS, playerHead("dan200", "f3c8d69b-0776-4512-8434-d1b2165909eb"))
.requires(ItemTags.SKULLS)
.requires(ModRegistry.Items.COMPUTER_ADVANCED.get())
.unlockedBy("has_computer", has(ModRegistry.Items.COMPUTER_ADVANCED.get()))
.build()
.save(output, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "skull_dan200"));
.save(output, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "skull_dan200"));
var pages = Ingredient.of(
ModRegistry.Items.PRINTED_PAGE.get(),
@@ -471,7 +471,7 @@ final class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider {
output.accept(recipeKey(key), recipe, null);
}
public static ResourceKey<Recipe<?>> recipeKey(ResourceLocation key) {
public static ResourceKey<Recipe<?>> recipeKey(Identifier key) {
return ResourceKey.create(Registries.RECIPE, key);
}

View File

@@ -14,7 +14,7 @@ import net.minecraft.data.CachedOutput;
import net.minecraft.data.DataProvider;
import net.minecraft.data.PackOutput;
import net.minecraft.data.metadata.PackMetadataGenerator;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.packs.metadata.MetadataSectionType;
import java.util.HashMap;
@@ -88,13 +88,13 @@ final class ResourceMetadataProvider implements DataProvider {
* A builder for a set of {@code mcmeta} files.
*/
private static final class Builder {
private final Map<ResourceLocation, FileMetadata> metadata = new HashMap<>();
private final Map<Identifier, FileMetadata> metadata = new HashMap<>();
FileMetadata texture(ResourceLocation texture) {
FileMetadata texture(Identifier texture) {
return file(texture.withPrefix("textures/").withSuffix(".png"));
}
FileMetadata file(ResourceLocation path) {
FileMetadata file(Identifier path) {
return metadata.computeIfAbsent(path, p -> new FileMetadata());
}
}

View File

@@ -6,7 +6,7 @@ package dan200.computercraft.data;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.client.turtle.TurtleOverlay;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import java.util.function.BiConsumer;
@@ -14,24 +14,24 @@ import java.util.function.BiConsumer;
* Built-in turtle overlays.
*/
final class TurtleOverlays {
public static final ResourceLocation RAINBOW_FLAG = create("rainbow_flag");
public static final ResourceLocation TRANS_FLAG = create("trans_flag");
public static final Identifier RAINBOW_FLAG = create("rainbow_flag");
public static final Identifier TRANS_FLAG = create("trans_flag");
private static ResourceLocation create(String name) {
return ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name);
private static Identifier create(String name) {
return Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name);
}
private TurtleOverlays() {
}
public static void register(BiConsumer<ResourceLocation, TurtleOverlay.Unbaked> registry) {
public static void register(BiConsumer<Identifier, TurtleOverlay.Unbaked> registry) {
registry.accept(RAINBOW_FLAG, new TurtleOverlay.Unbaked(
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_rainbow_overlay"),
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_rainbow_overlay"),
true
));
registry.accept(TRANS_FLAG, new TurtleOverlay.Unbaked(
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_trans_overlay"),
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_trans_overlay"),
true
));
}

View File

@@ -16,8 +16,8 @@ import dan200.computercraft.shared.turtle.upgrades.TurtleCraftingTable;
import dan200.computercraft.shared.turtle.upgrades.TurtleModem;
import dan200.computercraft.shared.turtle.upgrades.TurtleSpeaker;
import net.minecraft.data.worldgen.BootstrapContext;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
@@ -38,12 +38,12 @@ class TurtleUpgradeProvider {
private static final ResourceKey<ITurtleUpgrade> DIAMOND_SWORD = vanilla("diamond_sword");
private static ResourceKey<ITurtleUpgrade> id(String id) {
return ITurtleUpgrade.createKey(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, id));
return ITurtleUpgrade.createKey(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, id));
}
private static ResourceKey<ITurtleUpgrade> vanilla(String id) {
// Naughty, please don't do this. Mostly here for some semblance of backwards compatibility.
return ITurtleUpgrade.createKey(ResourceLocation.fromNamespaceAndPath("minecraft", id));
return ITurtleUpgrade.createKey(Identifier.fromNamespaceAndPath("minecraft", id));
}
public static void register(BootstrapContext<ITurtleUpgrade> upgrades) {
@@ -59,24 +59,24 @@ class TurtleUpgradeProvider {
tool(DIAMOND_SWORD, Items.DIAMOND_SWORD).breakable(ComputerCraftTags.Blocks.TURTLE_SWORD_BREAKABLE).damageMultiplier(9.0f).register(upgrades);
}
public static void addModels(BiConsumer<ResourceLocation, TurtleUpgradeModel.Unbaked> out) {
out.accept(SPEAKER.location(), BasicUpgradeModel.unbaked(
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_speaker_left"),
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_speaker_right")
public static void addModels(BiConsumer<Identifier, TurtleUpgradeModel.Unbaked> out) {
out.accept(SPEAKER.identifier(), BasicUpgradeModel.unbaked(
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_speaker_left"),
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_speaker_right")
));
out.accept(CRAFTING_TABLE.location(), BasicUpgradeModel.unbaked(
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_crafting_table_left"),
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_crafting_table_right")
out.accept(CRAFTING_TABLE.identifier(), BasicUpgradeModel.unbaked(
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_crafting_table_left"),
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_crafting_table_right")
));
out.accept(WIRELESS_MODEM_NORMAL.location(), createModemModel("normal"));
out.accept(WIRELESS_MODEM_ADVANCED.location(), createModemModel("advanced"));
out.accept(WIRELESS_MODEM_NORMAL.identifier(), createModemModel("normal"));
out.accept(WIRELESS_MODEM_ADVANCED.identifier(), createModemModel("advanced"));
out.accept(DIAMOND_AXE.location(), ItemUpgradeModel.unbaked());
out.accept(DIAMOND_PICKAXE.location(), ItemUpgradeModel.unbaked());
out.accept(DIAMOND_HOE.location(), ItemUpgradeModel.unbaked());
out.accept(DIAMOND_SHOVEL.location(), ItemUpgradeModel.unbaked());
out.accept(DIAMOND_SWORD.location(), ItemUpgradeModel.unbaked());
out.accept(DIAMOND_AXE.identifier(), ItemUpgradeModel.unbaked());
out.accept(DIAMOND_PICKAXE.identifier(), ItemUpgradeModel.unbaked());
out.accept(DIAMOND_HOE.identifier(), ItemUpgradeModel.unbaked());
out.accept(DIAMOND_SHOVEL.identifier(), ItemUpgradeModel.unbaked());
out.accept(DIAMOND_SWORD.identifier(), ItemUpgradeModel.unbaked());
}
private static TurtleUpgradeModel.Unbaked createModemModel(String type) {
@@ -89,8 +89,8 @@ class TurtleUpgradeProvider {
private static TurtleUpgradeModel.Unbaked createBaseModemModel(String type, String state) {
return BasicUpgradeModel.unbaked(
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_modem_" + type + "_" + state + "_left"),
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_modem_" + type + "_" + state + "_right")
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_modem_" + type + "_" + state + "_left"),
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_modem_" + type + "_" + state + "_right")
);
}
}

View File

@@ -37,7 +37,7 @@ import net.minecraft.client.renderer.item.EmptyModel;
import net.minecraft.client.renderer.item.properties.conditional.HasComponent;
import net.minecraft.core.Direction;
import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
@@ -60,33 +60,33 @@ public class BlockModelProvider {
private static final TextureSlot BACKPACK = TextureSlot.create("backpack");
private static final ModelTemplate COMPUTER_ON = new ModelTemplate(
Optional.of(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/computer_on")),
Optional.of(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/computer_on")),
Optional.empty(),
TextureSlot.FRONT, TextureSlot.SIDE, TextureSlot.TOP, CURSOR
);
private static final ModelTemplate MONITOR_BASE = new ModelTemplate(
Optional.of(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/monitor_base")),
Optional.of(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/monitor_base")),
Optional.empty(),
TextureSlot.FRONT, TextureSlot.SIDE, TextureSlot.TOP, TextureSlot.BACK
);
private static final ModelTemplate MODEM = new ModelTemplate(
Optional.of(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/modem")),
Optional.of(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/modem")),
Optional.empty(),
TextureSlot.FRONT, TextureSlot.BACK
);
private static final ModelTemplate TURTLE = new ModelTemplate(
Optional.of(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_base")),
Optional.of(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_base")),
Optional.empty(),
TextureSlot.FRONT, TextureSlot.BACK, TextureSlot.TOP, TextureSlot.BOTTOM, LEFT, RIGHT, BACKPACK
);
private static final ModelTemplate TURTLE_UPGRADE_LEFT = new ModelTemplate(
Optional.of(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_upgrade_base_left")),
Optional.of(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_upgrade_base_left")),
Optional.of("_left"),
TextureSlot.TEXTURE
);
private static final ModelTemplate TURTLE_UPGRADE_RIGHT = new ModelTemplate(
Optional.of(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_upgrade_base_right")),
Optional.of(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_upgrade_base_right")),
Optional.of("_left"),
TextureSlot.TEXTURE
);
@@ -186,7 +186,7 @@ public class BlockModelProvider {
);
case ON, BLINKING -> COMPUTER_ON.createWithSuffix(
block, "_" + state.getSerializedName(),
TextureMapping.orientableCube(block).put(CURSOR, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/computer" + state.getTexture())),
TextureMapping.orientableCube(block).put(CURSOR, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/computer" + state.getTexture())),
generators.modelOutput
);
}))
@@ -244,10 +244,10 @@ public class BlockModelProvider {
generators.blockStateOutput.accept(MultiVariantGenerator.dispatch(fullBlock)
.with(createModelDispatch(WiredModemFullBlock.MODEM_ON, WiredModemFullBlock.PERIPHERAL_ON, (on, peripheral) -> {
var suffix = (on ? "_on" : "_off") + (peripheral ? "_peripheral" : "");
var faceTexture = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/wired_modem_face" + (peripheral ? "_peripheral" : "") + (on ? "_on" : ""));
var faceTexture = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/wired_modem_face" + (peripheral ? "_peripheral" : "") + (on ? "_on" : ""));
// TODO: Do this somewhere more elegant!
modemModel(generators, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/wired_modem" + suffix), faceTexture);
modemModel(generators, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/wired_modem" + suffix), faceTexture);
return ModelTemplates.CUBE_ALL.create(
getModelLocation(fullBlock, suffix),
@@ -257,15 +257,15 @@ public class BlockModelProvider {
})));
generators.registerSimpleItemModel(fullBlock, getModelLocation(fullBlock, "_off"));
generators.registerSimpleItemModel(ModRegistry.Items.WIRED_MODEM.get(), ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/wired_modem_off"));
generators.registerSimpleItemModel(ModRegistry.Items.WIRED_MODEM.get(), Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/wired_modem_off"));
}
private static ResourceLocation modemModel(BlockModelGenerators generators, ResourceLocation name, ResourceLocation texture) {
private static Identifier modemModel(BlockModelGenerators generators, Identifier name, Identifier texture) {
return MODEM.create(
name,
new TextureMapping()
.put(TextureSlot.FRONT, texture)
.put(TextureSlot.BACK, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/modem_back")),
.put(TextureSlot.BACK, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/modem_back")),
generators.modelOutput
);
}
@@ -296,7 +296,7 @@ public class BlockModelProvider {
generators.registerSimpleItemModel(block, monitorModel(generators, block, "_item", 15, 4, 0, 32));
}
private static ResourceLocation monitorModel(BlockModelGenerators generators, MonitorBlock block, String corners, int front, int side, int top, int back) {
private static Identifier monitorModel(BlockModelGenerators generators, MonitorBlock block, String corners, int front, int side, int top, int back) {
return MONITOR_BASE.create(
getModelLocation(block, corners),
new TextureMapping()
@@ -312,7 +312,7 @@ public class BlockModelProvider {
var generator = MultiPartGenerator.multiPart(ModRegistry.Blocks.CABLE.get());
// When a cable only has a neighbour in a single direction, we redirect the core to face that direction.
var coreFacing = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/cable_core_facing");
var coreFacing = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/cable_core_facing");
// Up/Down
generator.with(
or(
@@ -342,7 +342,7 @@ public class BlockModelProvider {
);
// Find all other possibilities and emit a "solid" core which doesn't have a facing direction.
var core = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/cable_core_any");
var core = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/cable_core_any");
List<ConditionBuilder> rightAngles = new ArrayList<>();
for (var i = 0; i < DirectionUtil.FACINGS.length; i++) {
for (var j = i; j < DirectionUtil.FACINGS.length; j++) {
@@ -356,7 +356,7 @@ public class BlockModelProvider {
generator.with(or(rightAngles.toArray(new ConditionBuilder[0])), plainVariant(core));
// Then emit the actual cable arms
var arm = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/cable_arm");
var arm = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/cable_arm");
for (var direction : DirectionUtil.FACINGS) {
generator.with(
condition().term(CABLE_DIRECTIONS[direction.ordinal()], true),
@@ -373,7 +373,7 @@ public class BlockModelProvider {
var suffix = (on ? "_on" : "_off") + (peripheral ? "_peripheral" : "");
generator.with(
condition().term(CableBlock.MODEM, CableModemVariant.from(direction, on, peripheral)),
plainVariant(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/wired_modem" + suffix))
plainVariant(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/wired_modem" + suffix))
.with(VariantMutator.X_ROT.withValue(toXAngle(direction)))
.with(VariantMutator.Y_ROT.withValue(toYAngle(direction)))
);
@@ -403,13 +403,13 @@ public class BlockModelProvider {
private static void registerTurtleUpgrade(BlockModelGenerators generators, String name, String texture) {
TURTLE_UPGRADE_LEFT.create(
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name + "_left"),
TextureMapping.defaultTexture(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, texture)),
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name + "_left"),
TextureMapping.defaultTexture(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, texture)),
generators.modelOutput
);
TURTLE_UPGRADE_RIGHT.create(
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name + "_right"),
TextureMapping.defaultTexture(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, texture)),
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name + "_right"),
TextureMapping.defaultTexture(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, texture)),
generators.modelOutput
);
}
@@ -449,7 +449,7 @@ public class BlockModelProvider {
return dispatch;
}
private static <T extends Comparable<T>> PropertyDispatch<MultiVariant> createModelDispatch(Property<T> property, Function<T, ResourceLocation> makeModel) {
private static <T extends Comparable<T>> PropertyDispatch<MultiVariant> createModelDispatch(Property<T> property, Function<T, Identifier> makeModel) {
var variant = PropertyDispatch.initial(property);
for (var value : property.getPossibleValues()) {
variant.select(value, plainVariant(makeModel.apply(value)));
@@ -458,7 +458,7 @@ public class BlockModelProvider {
}
private static <T extends Comparable<T>, U extends Comparable<U>> PropertyDispatch<MultiVariant> createModelDispatch(
Property<T> propertyT, Property<U> propertyU, BiFunction<T, U, ResourceLocation> makeModel
Property<T> propertyT, Property<U> propertyU, BiFunction<T, U, Identifier> makeModel
) {
var variant = PropertyDispatch.initial(propertyT, propertyU);
for (var valueT : propertyT.getPossibleValues()) {

View File

@@ -17,7 +17,7 @@ import net.minecraft.client.renderer.item.BlockModelWrapper;
import net.minecraft.client.renderer.item.ItemModel;
import net.minecraft.client.renderer.item.properties.conditional.HasComponent;
import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.Item;
import java.util.List;
@@ -26,7 +26,7 @@ import java.util.Optional;
import static net.minecraft.client.data.models.model.ModelLocationUtils.getModelLocation;
public final class ItemModelProvider {
private static final ResourceLocation POCKET_COMPUTER_COLOUR = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/pocket_computer_colour");
private static final Identifier POCKET_COMPUTER_COLOUR = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/pocket_computer_colour");
private ItemModelProvider() {
}
@@ -44,21 +44,21 @@ public final class ItemModelProvider {
generators.generateFlatItem(ModRegistry.Items.PRINTED_PAGES.get(), ModelTemplates.FLAT_ITEM);
}
private static void registerPocketComputerModels(ItemModelGenerators generators, ResourceLocation id) {
private static void registerPocketComputerModels(ItemModelGenerators generators, Identifier id) {
createFlatItem(generators, id.withSuffix("_blinking"),
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/pocket_computer_blink"),
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/pocket_computer_blink"),
id,
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/pocket_computer_light")
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/pocket_computer_light")
);
createFlatItem(generators, id.withSuffix("_on"),
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/pocket_computer_on"),
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/pocket_computer_on"),
id,
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/pocket_computer_light")
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/pocket_computer_light")
);
createFlatItem(generators, id,
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/pocket_computer_frame"),
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/pocket_computer_frame"),
id
);
}
@@ -73,7 +73,7 @@ public final class ItemModelProvider {
));
}
private static ItemModel.Unbaked createPocketModel(ResourceLocation id) {
private static ItemModel.Unbaked createPocketModel(Identifier id) {
var tints = List.of(
ItemModelUtils.constantTint(-1),
new Dye(-1),
@@ -90,8 +90,8 @@ public final class ItemModelProvider {
private static void registerDisk(ItemModelGenerators generators, Item item, int colour) {
var model = getModelLocation(item);
createFlatItem(generators, model,
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/disk_frame"),
ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/disk_colour")
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/disk_frame"),
Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "item/disk_colour")
);
generators.itemModelOutput.accept(item, new BlockModelWrapper.Unbaked(model, List.of(
@@ -108,7 +108,7 @@ public final class ItemModelProvider {
* @param textures The textures which make up this model.
* @see net.minecraft.client.renderer.block.model.ItemModelGenerator The parser for this file format.
*/
private static void createFlatItem(ItemModelGenerators generators, ResourceLocation model, ResourceLocation... textures) {
private static void createFlatItem(ItemModelGenerators generators, Identifier model, Identifier... textures) {
if (textures.length > 5) throw new IndexOutOfBoundsException("Too many layers");
if (textures.length == 0) throw new IndexOutOfBoundsException("Must have at least one texture");
if (textures.length == 1) {
@@ -123,7 +123,7 @@ public final class ItemModelProvider {
mapping.put(slot, textures[i]);
}
new ModelTemplate(Optional.of(ResourceLocation.withDefaultNamespace("item/generated")), Optional.empty(), slots)
new ModelTemplate(Optional.of(Identifier.withDefaultNamespace("item/generated")), Optional.empty(), slots)
.create(model, mapping, generators.modelOutput);
}
}

View File

@@ -9,14 +9,14 @@ import dan200.computercraft.shared.recipe.RecipeProperties;
import net.minecraft.advancements.AdvancementRequirements;
import net.minecraft.advancements.AdvancementRewards;
import net.minecraft.advancements.Criterion;
import net.minecraft.advancements.critereon.RecipeUnlockedTrigger;
import net.minecraft.advancements.criterion.RecipeUnlockedTrigger;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.recipes.RecipeBuilder;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
@@ -115,7 +115,7 @@ public abstract class AbstractRecipeBuilder<S extends AbstractRecipeBuilder<S, O
this.criteria = criteria;
}
public void save(RecipeOutput output, ResourceLocation id) {
public void save(RecipeOutput output, Identifier id) {
if (criteria.isEmpty()) throw new IllegalStateException("No way of obtaining recipe " + id);
var key = recipeKey(id);
@@ -133,7 +133,7 @@ public abstract class AbstractRecipeBuilder<S extends AbstractRecipeBuilder<S, O
}
}
protected static ResourceKey<Recipe<?>> recipeKey(ResourceLocation key) {
protected static ResourceKey<Recipe<?>> recipeKey(Identifier key) {
return ResourceKey.create(Registries.RECIPE, key);
}
}

View File

@@ -4,7 +4,7 @@ import com.example.examplemod.ExampleMod;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleToolBuilder;
import net.minecraft.data.worldgen.BootstrapContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.Items;
/**
@@ -16,7 +16,7 @@ public class TurtleToolProvider {
// @start region=body
public static void addUpgrades(BootstrapContext<ITurtleUpgrade> upgrades) {
TurtleToolBuilder
.tool(ResourceLocation.fromNamespaceAndPath(ExampleMod.MOD_ID, "wooden_pickaxe"), Items.WOODEN_PICKAXE)
.tool(Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "wooden_pickaxe"), Items.WOODEN_PICKAXE)
.register(upgrades);
}
// @end region=body

View File

@@ -5,12 +5,12 @@ import com.example.examplemod.ExampleTurtleUpgrade;
import dan200.computercraft.api.client.turtle.ItemUpgradeModel;
import dan200.computercraft.api.client.turtle.TurtleUpgradeModel;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import net.minecraft.Util;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.data.registries.RegistryPatchGenerator;
import net.minecraft.data.worldgen.BootstrapContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.Util;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
@@ -23,7 +23,7 @@ import java.util.function.BiConsumer;
// @start region=body
public class TurtleUpgradeProvider {
// Define our upgrade ids.
private static final ResourceLocation EXAMPLE_TURTLE_UPGRADE = ResourceLocation.fromNamespaceAndPath(ExampleMod.MOD_ID, "example_turtle_upgrade");
private static final Identifier EXAMPLE_TURTLE_UPGRADE = Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "example_turtle_upgrade");
// Register our turtle upgrades.
public static void addUpgrades(BootstrapContext<ITurtleUpgrade> upgrades) {
@@ -38,7 +38,7 @@ public class TurtleUpgradeProvider {
}
// Register our turtle models.
public static void addUpgradeModels(BiConsumer<ResourceLocation, TurtleUpgradeModel.Unbaked> models) {
public static void addUpgradeModels(BiConsumer<Identifier, TurtleUpgradeModel.Unbaked> models) {
models.accept(EXAMPLE_TURTLE_UPGRADE, ItemUpgradeModel.unbaked());
}
}

View File

@@ -3,7 +3,7 @@ package com.example.examplemod.peripheral;
import com.example.examplemod.ExampleMod;
import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.peripheral.GenericPeripheral;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
/**
@@ -17,7 +17,7 @@ import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
public class FurnacePeripheral implements GenericPeripheral {
@Override
public String id() {
return ResourceLocation.fromNamespaceAndPath(ExampleMod.MOD_ID, "furnace").toString();
return Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "furnace").toString();
}
@LuaFunction(mainThread = true)

View File

@@ -34,8 +34,8 @@ import dan200.computercraft.shared.turtle.upgrades.TurtleTool;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
@@ -50,12 +50,12 @@ public abstract class AbstractComputerCraftAPI implements ComputerCraftAPIServic
private final DetailRegistry<ItemStack> itemStackDetails = new DetailRegistryImpl<>(ItemDetails::fillBasic);
private final DetailRegistry<BlockReference> blockDetails = new DetailRegistryImpl<>((m, r, b) -> BlockDetails.fillBasic(m, b));
protected static final ResourceKey<Registry<UpgradeType<? extends ITurtleUpgrade>>> turtleUpgradeRegistryId = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle_upgrade_type"));
protected static final ResourceKey<Registry<UpgradeType<? extends IPocketUpgrade>>> pocketUpgradeRegistryId = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_upgrade_type"));
protected static final ResourceKey<Registry<UpgradeType<? extends ITurtleUpgrade>>> turtleUpgradeRegistryId = ResourceKey.createRegistryKey(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle_upgrade_type"));
protected static final ResourceKey<Registry<UpgradeType<? extends IPocketUpgrade>>> pocketUpgradeRegistryId = ResourceKey.createRegistryKey(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "pocket_upgrade_type"));
public static @Nullable InputStream getResourceFile(MinecraftServer server, String domain, String subPath) {
var manager = server.getResourceManager();
var resource = manager.getResource(ResourceLocation.fromNamespaceAndPath(domain, subPath)).orElse(null);
var resource = manager.getResource(Identifier.fromNamespaceAndPath(domain, subPath)).orElse(null);
if (resource == null) return null;
try {
return resource.open();

View File

@@ -90,7 +90,7 @@ public final class UpgradeManager<T extends UpgradeBase> {
}
public String getOwner(Holder.Reference<T> upgrade) {
var ns = upgrade.key().location().getNamespace();
var ns = upgrade.key().identifier().getNamespace();
return ns.equals("minecraft") ? ComputerCraftAPI.MOD_ID : ns;
// TODO: Would be nice if we could use the registration info here.

View File

@@ -14,8 +14,8 @@ import dan200.computercraft.shared.peripheral.monitor.MonitorWatcher;
import dan200.computercraft.shared.util.DropConsumer;
import dan200.computercraft.shared.util.TickScheduler;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.ServerLevel;
@@ -114,7 +114,7 @@ public final class CommonHooks {
return InteractionResult.PASS;
}
public static final ResourceKey<LootTable> TREASURE_DISK_LOOT = ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "treasure_disk"));
public static final ResourceKey<LootTable> TREASURE_DISK_LOOT = ResourceKey.create(Registries.LOOT_TABLE, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "treasure_disk"));
private static final Set<ResourceKey<LootTable>> TREASURE_DISK_LOOT_TABLES = Set.of(
BuiltInLootTables.SIMPLE_DUNGEON,
@@ -139,8 +139,8 @@ public final class CommonHooks {
.setRolls(ConstantValue.exactly(1));
}
public static void onDatapackReload(BiConsumer<ResourceLocation, PreparableReloadListener> addReload) {
addReload.accept(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "mounts"), ResourceMount.RELOAD_LISTENER);
public static void onDatapackReload(BiConsumer<Identifier, PreparableReloadListener> addReload) {
addReload.accept(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "mounts"), ResourceMount.RELOAD_LISTENER);
}
public static boolean onEntitySpawn(Entity entity) {

View File

@@ -109,8 +109,8 @@ import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.flag.FeatureFlags;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.*;
@@ -149,7 +149,7 @@ public final class ModRegistry {
private static <T extends Block> RegistryEntry<T> register(String name, Function<BlockBehaviour.Properties, T> build, BlockBehaviour.Properties properties) {
return REGISTRY.register(name, () -> {
properties.setId(ResourceKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name)));
properties.setId(ResourceKey.create(Registries.BLOCK, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name)));
return build.apply(properties);
});
}
@@ -285,7 +285,7 @@ public final class ModRegistry {
}
private static <T extends Item> RegistryEntry<T> register(String name, Function<Item.Properties, T> build, Supplier<Item.Properties> properties) {
return REGISTRY.register(name, () -> build.apply(properties.get().setId(ResourceKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name)))));
return REGISTRY.register(name, () -> build.apply(properties.get().setId(ResourceKey.create(Registries.ITEM, Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, name)))));
}
private static <T extends Item> RegistryEntry<T> register(String name, Function<Item.Properties, T> build, Item.Properties properties) {
@@ -396,8 +396,8 @@ public final class ModRegistry {
/**
* The overlay on a turtle.
*/
public static final RegistryEntry<DataComponentType<ResourceLocation>> OVERLAY = register("overlay", b -> b
.persistent(ResourceLocation.CODEC).networkSynchronized(ResourceLocation.STREAM_CODEC).cacheEncoding()
public static final RegistryEntry<DataComponentType<Identifier>> OVERLAY = register("overlay", b -> b
.persistent(Identifier.CODEC).networkSynchronized(Identifier.STREAM_CODEC).cacheEncoding()
);
/**
@@ -773,7 +773,7 @@ public final class ModRegistry {
}
private static boolean isOurUpgrade(Holder.Reference<? extends UpgradeBase> upgrade) {
var namespace = upgrade.key().location().getNamespace();
var namespace = upgrade.key().identifier().getNamespace();
return namespace.equals("minecraft") || namespace.equals(ComputerCraftAPI.MOD_ID);
}
}

View File

@@ -6,6 +6,9 @@ package dan200.computercraft.shared.command;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.permissions.Permission;
import net.minecraft.server.permissions.PermissionLevel;
import net.minecraft.server.permissions.Permissions;
import java.util.function.Predicate;
@@ -28,10 +31,10 @@ public enum UserLevel implements Predicate<CommandSourceStack> {
*/
ANYONE;
public int toLevel() {
public Permission toPermission() {
return switch (this) {
case OP, OWNER_OP -> 2;
case ANYONE -> 0;
case OP, OWNER_OP -> Permissions.COMMANDS_GAMEMASTER;
case ANYONE -> new Permission.HasCommandLevel(PermissionLevel.ALL);
};
}
@@ -39,13 +42,13 @@ public enum UserLevel implements Predicate<CommandSourceStack> {
public boolean test(CommandSourceStack source) {
if (this == ANYONE) return true;
if (this == OWNER_OP && isOwner(source)) return true;
return source.hasPermission(toLevel());
return source.permissions().hasPermission(toPermission());
}
public boolean test(ServerPlayer source) {
if (this == ANYONE) return true;
if (this == OWNER_OP && isOwner(source)) return true;
return source.hasPermissions(toLevel());
return source.permissions().hasPermission(toPermission());
}
public static boolean isOwner(CommandSourceStack source) {
@@ -58,7 +61,7 @@ public enum UserLevel implements Predicate<CommandSourceStack> {
var player = source.getPlayer();
return server.isDedicatedServer()
? source.getEntity() == null && source.hasPermission(4) && source.getTextName().equals("Server")
? source.getEntity() == null && source.permissions().hasPermission(Permissions.COMMANDS_ADMIN) && source.getTextName().equals("Server")
: player != null && server.isSingleplayerOwner(player.nameAndId());
}

View File

@@ -13,7 +13,7 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.computer.core.ServerContext;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.advancements.criterion.MinMaxBounds;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.commands.arguments.UuidArgument;

View File

@@ -17,10 +17,10 @@ import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.gamerules.GameRules;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import org.slf4j.Logger;
@@ -54,12 +54,12 @@ public class CommandAPI implements ILuaAPI {
}
private Object[] doCommand(String command) {
var server = computer.getLevel().getServer();
if (!server.isCommandBlockEnabled()) {
var level = computer.getLevel();
if (!level.isCommandBlockEnabled()) {
return new Object[]{ false, createOutput("Command blocks disabled by server") };
}
var commandManager = server.getCommands();
var commandManager = level.getServer().getCommands();
try {
receiver.clearOutput();
var state = new CommandState();
@@ -281,7 +281,7 @@ public class CommandAPI implements ILuaAPI {
if (id.isEmpty()) return currentLevel;
var dimensionId = ResourceLocation.tryParse(id.get());
var dimensionId = Identifier.tryParse(id.get());
if (dimensionId == null) throw new LuaException("Invalid dimension name");
var level = currentLevel.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, dimensionId));
@@ -297,7 +297,7 @@ public class CommandAPI implements ILuaAPI {
return new CommandSourceStack(receiver,
Vec3.atCenterOf(computer.getPosition()), Vec2.ZERO,
computer.getLevel(), admin.permissionLevel(),
computer.getLevel(), admin.permissions(),
name, Component.literal(name),
computer.getLevel().getServer(), null
);
@@ -334,7 +334,7 @@ public class CommandAPI implements ILuaAPI {
@Override
public boolean shouldInformAdmins() {
return computer.getLevel().getGameRules().getBoolean(GameRules.RULE_COMMANDBLOCKOUTPUT);
return computer.getLevel().getGameRules().get(GameRules.COMMAND_BLOCK_OUTPUT);
}
}
}

View File

@@ -9,11 +9,11 @@ import dan200.computercraft.shared.network.container.ComputerContainerData;
import dan200.computercraft.shared.platform.PlatformHelper;
import dan200.computercraft.shared.platform.RegistryEntry;
import dan200.computercraft.shared.util.BlockEntityHelpers;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.util.RandomSource;
import net.minecraft.util.Util;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
@@ -113,6 +113,7 @@ public abstract class AbstractComputerBlock<T extends AbstractComputerBlockEntit
if (!player.isCrouching() && level.getBlockEntity(pos) instanceof AbstractComputerBlockEntity computer) {
// Regular right click to activate computer
if (!level.isClientSide() && computer.isUsable(player)) {
// TODO(1.21.11): Call BaseContainerBlockEntity.sendChestLockedNotifications
var serverComputer = computer.createServerComputer();
serverComputer.turnOn();

View File

@@ -29,7 +29,6 @@ import net.minecraft.world.LockCode;
import net.minecraft.world.Nameable;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.MenuConstructor;
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
@@ -84,9 +83,9 @@ public abstract class AbstractComputerBlockEntity extends BlockEntity implements
return Container.DEFAULT_DISTANCE_BUFFER;
}
public boolean isUsable(Player player) {
public final boolean isUsable(Player player) {
return getFamily().checkUsable(player)
&& BaseContainerBlockEntity.canUnlock(player, lockCode, getDisplayName())
&& lockCode.canUnlock(player)
&& Container.stillValidBlockEntity(this, player, getInteractRange());
}
@@ -167,7 +166,7 @@ public abstract class AbstractComputerBlockEntity extends BlockEntity implements
protected void loadServer(ValueInput nbt) {
// Load ID, label and power state
computerID = nbt.getIntOr(NBT_ID, -1);
label = nbt.getStringOr(NBT_LABEL, null);
label = nbt.getString(NBT_LABEL).orElse(null);
storageCapacity = nbt.getLongOr(NBT_CAPACITY, -1);
on = startOn = nbt.getBooleanOr(NBT_ON, false);
@@ -411,7 +410,7 @@ public abstract class AbstractComputerBlockEntity extends BlockEntity implements
@Override
public Component getName() {
return hasCustomName()
return !Strings.isNullOrEmpty(label)
? Component.literal(label)
: Component.translatable(getBlockState().getBlock().getDescriptionId());
}
@@ -424,7 +423,7 @@ public abstract class AbstractComputerBlockEntity extends BlockEntity implements
@Nullable
@Override
public Component getCustomName() {
return hasCustomName() ? Component.literal(label) : null;
return !Strings.isNullOrEmpty(label) ? Component.literal(label) : null;
}
@Override

View File

@@ -6,6 +6,8 @@ package dan200.computercraft.shared.computer.core;
import dan200.computercraft.shared.config.Config;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.permissions.Permissions;
import net.minecraft.world.entity.player.Player;
public enum ComputerFamily {
@@ -45,8 +47,7 @@ public enum ComputerFamily {
}
private static boolean checkCommandUsable(Player player) {
var server = player.level().getServer();
if (server == null || !server.isCommandBlockEnabled()) {
if (!(player.level() instanceof ServerLevel level) || !level.isCommandBlockEnabled()) {
player.displayClientMessage(Component.translatable("advMode.notEnabled"), true);
return false;
} else if (!canUseCommandBlock(player)) {
@@ -58,6 +59,6 @@ public enum ComputerFamily {
}
private static boolean canUseCommandBlock(Player player) {
return Config.commandRequireCreative ? player.canUseGameMasterBlocks() : player.hasPermissions(2);
return Config.commandRequireCreative ? player.canUseGameMasterBlocks() : player.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER);
}
}

View File

@@ -7,8 +7,8 @@ package dan200.computercraft.shared.computer.core;
import com.google.common.annotations.VisibleForTesting;
import dan200.computercraft.api.filesystem.FileOperationException;
import dan200.computercraft.core.filesystem.ArchiveMount;
import net.minecraft.ResourceLocationException;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.IdentifierException;
import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.SimplePreparableReloadListener;
@@ -33,14 +33,14 @@ public final class ResourceMount extends ArchiveMount<ResourceMount.FileEntry> {
/**
* Maintain a cache of currently loaded resource mounts. This cache is invalidated when currentManager changes.
*/
private static final Map<ResourceLocation, ResourceMount> MOUNT_CACHE = new HashMap<>(2);
private static final Map<Identifier, ResourceMount> MOUNT_CACHE = new HashMap<>(2);
private final String namespace;
private final String subPath;
private ResourceManager manager;
public static ResourceMount get(String namespace, String subPath, ResourceManager manager) {
var path = ResourceLocation.fromNamespaceAndPath(namespace, subPath);
var path = Identifier.fromNamespaceAndPath(namespace, subPath);
synchronized (MOUNT_CACHE) {
var mount = MOUNT_CACHE.get(path);
if (mount == null) MOUNT_CACHE.put(path, mount = new ResourceMount(namespace, subPath, manager));
@@ -59,7 +59,7 @@ public final class ResourceMount extends ArchiveMount<ResourceMount.FileEntry> {
var hasAny = false;
String existingNamespace = null;
var newRoot = new FileEntry(ResourceLocation.fromNamespaceAndPath(namespace, subPath));
var newRoot = new FileEntry(Identifier.fromNamespaceAndPath(namespace, subPath));
for (var file : manager.listResources(subPath, s -> true).keySet()) {
existingNamespace = file.getNamespace();
@@ -70,7 +70,7 @@ public final class ResourceMount extends ArchiveMount<ResourceMount.FileEntry> {
try {
getOrCreateChild(newRoot, localPath, this::createEntry);
} catch (ResourceLocationException e) {
} catch (IdentifierException e) {
LOG.warn("Cannot create resource location for {} ({})", localPath, e.getMessage());
}
hasAny = true;
@@ -88,7 +88,7 @@ public final class ResourceMount extends ArchiveMount<ResourceMount.FileEntry> {
}
private FileEntry createEntry(String path) {
return new FileEntry(ResourceLocation.fromNamespaceAndPath(namespace, subPath + "/" + path));
return new FileEntry(Identifier.fromNamespaceAndPath(namespace, subPath + "/" + path));
}
@Override
@@ -102,9 +102,9 @@ public final class ResourceMount extends ArchiveMount<ResourceMount.FileEntry> {
}
protected static final class FileEntry extends ArchiveMount.FileEntry<FileEntry> {
final ResourceLocation identifier;
final Identifier identifier;
FileEntry(ResourceLocation identifier) {
FileEntry(Identifier identifier) {
this.identifier = identifier;
}
}

View File

@@ -5,7 +5,7 @@
package dan200.computercraft.shared.integration;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
@@ -32,7 +32,7 @@ public final class ExternalModTags {
public static final TagKey<Block> CREATE_BRITTLE = make("create", "brittle");
private static TagKey<Block> make(String mod, String name) {
return TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath(mod, name));
return TagKey.create(Registries.BLOCK, Identifier.fromNamespaceAndPath(mod, name));
}
}
}

View File

@@ -15,8 +15,8 @@ import dan200.computercraft.shared.util.DataComponentUtil;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import java.util.ArrayList;
@@ -42,7 +42,7 @@ public final class RecipeModHelpers {
* @param id The recipe ID.
* @return Whether it should be removed.
*/
public static boolean shouldRemoveRecipe(ResourceLocation id) {
public static boolean shouldRemoveRecipe(Identifier id) {
if (!id.getNamespace().equals(ComputerCraftAPI.MOD_ID)) return false;
var path = id.getPath();

View File

@@ -11,7 +11,7 @@ import dan200.computercraft.shared.platform.PlatformHelper;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import java.util.*;
@@ -51,7 +51,7 @@ public final class NetworkMessages {
String channel, StreamCodec<RegistryFriendlyByteBuf, T> codec
) {
if (!seenChannel.add(channel)) throw new IllegalArgumentException("Duplicate channel " + channel);
var type = new CustomPacketPayload.Type<T>(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, channel));
var type = new CustomPacketPayload.Type<T>(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, channel));
messages.add(new CustomPacketPayload.TypeAndCodec<>(type, codec));
return type;
}

View File

@@ -13,7 +13,7 @@ import dan200.computercraft.shared.peripheral.speaker.SpeakerPosition;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.JukeboxSong;
import org.jspecify.annotations.Nullable;
@@ -39,7 +39,7 @@ public interface ClientNetworkContext {
void handleSpeakerMove(UUID source, SpeakerPosition.Message position);
void handleSpeakerPlay(UUID source, SpeakerPosition.Message position, ResourceLocation sound, float volume, float pitch);
void handleSpeakerPlay(UUID source, SpeakerPosition.Message position, Identifier sound, float volume, float pitch);
void handleSpeakerStop(UUID source);

View File

@@ -14,7 +14,7 @@ import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import java.util.UUID;
@@ -33,20 +33,20 @@ import java.util.UUID;
public record SpeakerPlayClientMessage(
UUID source,
SpeakerPosition.Message pos,
ResourceLocation sound,
Identifier sound,
float volume,
float pitch
) implements NetworkMessage<ClientNetworkContext> {
public static final StreamCodec<RegistryFriendlyByteBuf, SpeakerPlayClientMessage> STREAM_CODEC = StreamCodec.composite(
UUIDUtil.STREAM_CODEC, SpeakerPlayClientMessage::source,
SpeakerPosition.Message.STREAM_CODEC, SpeakerPlayClientMessage::pos,
ResourceLocation.STREAM_CODEC, SpeakerPlayClientMessage::sound,
Identifier.STREAM_CODEC, SpeakerPlayClientMessage::sound,
ByteBufCodecs.FLOAT, SpeakerPlayClientMessage::volume,
ByteBufCodecs.FLOAT, SpeakerPlayClientMessage::pitch,
SpeakerPlayClientMessage::new
);
public SpeakerPlayClientMessage(UUID source, SpeakerPosition pos, ResourceLocation sound, float volume, float pitch) {
public SpeakerPlayClientMessage(UUID source, SpeakerPosition pos, Identifier sound, float volume, float pitch) {
this(source, pos.asMessage(), sound, volume, pitch);
}

View File

@@ -7,6 +7,7 @@ package dan200.computercraft.shared.peripheral.commandblock;
import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.shared.computer.apis.CommandAPI;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.entity.CommandBlockEntity;
import org.jspecify.annotations.Nullable;
@@ -50,7 +51,7 @@ public class CommandBlockPeripheral implements IPeripheral {
@LuaFunction(mainThread = true)
public final void setCommand(String command) {
commandBlock.getCommandBlock().setCommand(command);
commandBlock.getCommandBlock().onUpdated();
commandBlock.getCommandBlock().onUpdated((ServerLevel) commandBlock.getLevel());
}
/**
@@ -62,7 +63,7 @@ public class CommandBlockPeripheral implements IPeripheral {
*/
@LuaFunction(mainThread = true)
public final Object[] runCommand() {
commandBlock.getCommandBlock().performCommand(commandBlock.getLevel());
commandBlock.getCommandBlock().performCommand((ServerLevel) commandBlock.getLevel());
var result = commandBlock.getCommandBlock().getSuccessCount();
return result > 0 ? new Object[]{ true } : new Object[]{ false, "Command failed" };
}

View File

@@ -5,16 +5,17 @@
package dan200.computercraft.shared.peripheral.modem.wired;
import dan200.computercraft.annotations.ForgeOverride;
import dan200.computercraft.core.util.Nullability;
import dan200.computercraft.shared.ModRegistry;
import dan200.computercraft.shared.peripheral.modem.ModemShapes;
import dan200.computercraft.shared.platform.PlatformHelper;
import dan200.computercraft.shared.util.WaterloggableHelpers;
import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.util.Util;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
@@ -202,7 +203,7 @@ public class CableBlock extends Block implements SimpleWaterloggedBlock, EntityB
}
return level instanceof Level actualLevel
? state.setValue(CONNECTIONS.get(side), doesConnectVisually(state, actualLevel, pos, side))
? state.setValue(Nullability.assertNonNull(CONNECTIONS.get(side)), doesConnectVisually(state, actualLevel, pos, side))
: state;
}

View File

@@ -4,6 +4,7 @@
package dan200.computercraft.shared.peripheral.modem.wired;
import dan200.computercraft.core.util.Nullability;
import dan200.computercraft.shared.ModRegistry;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundSource;
@@ -57,7 +58,7 @@ public abstract class CableBlockItem extends BlockItem {
var side = context.getClickedFace().getOpposite();
var newState = existingState
.setValue(MODEM, CableModemVariant.from(side))
.setValue(CONNECTIONS.get(side), existingState.getValue(CABLE));
.setValue(Nullability.assertNonNull(CONNECTIONS.get(side)), existingState.getValue(CABLE));
if (placeAt(world, pos, newState)) {
stack.shrink(1);
return InteractionResult.SUCCESS;

View File

@@ -4,10 +4,11 @@
package dan200.computercraft.shared.peripheral.modem.wired;
import dan200.computercraft.core.util.Nullability;
import dan200.computercraft.shared.peripheral.modem.ModemShapes;
import dan200.computercraft.shared.util.DirectionUtil;
import net.minecraft.Util;
import net.minecraft.core.Direction;
import net.minecraft.util.Util;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
@@ -39,7 +40,7 @@ public final class CableShapes {
private static int getCableIndex(BlockState state) {
var index = 0;
for (var facing : DirectionUtil.FACINGS) {
if (state.getValue(CONNECTIONS.get(facing))) index |= 1 << facing.ordinal();
if (state.getValue(Nullability.assertNonNull(CONNECTIONS.get(facing)))) index |= 1 << facing.ordinal();
}
return index;
@@ -52,7 +53,7 @@ public final class CableShapes {
shape = SHAPE_CABLE_CORE;
for (var facing : DirectionUtil.FACINGS) {
if ((index & (1 << facing.ordinal())) != 0) {
shape = Shapes.or(shape, SHAPE_CABLE_ARM.get(facing));
shape = Shapes.or(shape, Nullability.assertNonNull(SHAPE_CABLE_ARM.get(facing)));
}
}

View File

@@ -105,7 +105,7 @@ public final class WiredModemLocalPeripheral {
public void read(ValueInput tag, String suffix) {
id = tag.getIntOr(NBT_PERIPHERAL_ID + suffix, -1);
type = tag.getStringOr(NBT_PERIPHERAL_TYPE + suffix, null);
type = tag.getString(NBT_PERIPHERAL_TYPE + suffix).orElse(null);
}
@Nullable

View File

@@ -29,6 +29,7 @@ import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Objects;
import java.util.function.Consumer;
public class MonitorBlockEntity extends BlockEntity {
@@ -521,7 +522,7 @@ public class MonitorBlockEntity extends BlockEntity {
// We attempt to cache the bounding box to save having to do property lookups (and allocations!) on every frame.
// Unfortunately the AABB does depend on quite a lot of state, so we need to add a bunch of extra fields -
// ideally these'd be a single object, but I don't think worth doing until Java has value types.
if (boundingBox != null && getBlockState().equals(bbState) && getBlockPos().equals(bbPos) &&
if (boundingBox != null && Objects.equals(getBlockState(), bbState) && Objects.equals(getBlockPos(), bbPos) &&
xIndex == bbX && yIndex == bbY && width == bbWidth && height == bbHeight) {
return boundingBox;
}

View File

@@ -24,7 +24,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
@@ -74,7 +74,7 @@ public abstract class SpeakerPeripheral implements IPeripheral {
private final Object lock = new Object();
private boolean shouldStop;
private @Nullable PendingSound<ResourceLocation> pendingSound = null;
private @Nullable PendingSound<Identifier> pendingSound = null;
private @Nullable DfpwmState dfpwmState;
public void update() {
@@ -102,7 +102,7 @@ public abstract class SpeakerPeripheral implements IPeripheral {
// dfpwmState will only ever transition from having a buffer to not having a buffer on the main thread (so this
// method), so we don't need to bother locking that.
boolean shouldStop;
PendingSound<ResourceLocation> sound;
PendingSound<Identifier> sound;
DfpwmState dfpwmState;
synchronized (lock) {
sound = pendingSound;
@@ -254,7 +254,7 @@ public abstract class SpeakerPeripheral implements IPeripheral {
var volume = (float) clampVolume(checkFinite(1, volumeA.orElse(1.0)));
var pitch = (float) checkFinite(2, pitchA.orElse(1.0));
var identifier = ResourceLocation.tryParse(name);
var identifier = Identifier.tryParse(name);
if (identifier == null) throw new LuaException("Malformed sound name '" + name + "' ");
// Prevent playing music discs.

View File

@@ -7,7 +7,7 @@ package dan200.computercraft.shared.peripheral.speaker;
import dan200.computercraft.shared.network.codec.MoreStreamCodecs;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
@@ -30,16 +30,16 @@ public record SpeakerPosition(@Nullable Level level, Vec3 position, @Nullable En
public Message asMessage() {
if (level == null) throw new NullPointerException("Cannot send a position without a level");
return new Message(level.dimension().location(), position, entity == null ? OptionalInt.empty() : OptionalInt.of(entity.getId()));
return new Message(level.dimension().identifier(), position, entity == null ? OptionalInt.empty() : OptionalInt.of(entity.getId()));
}
public record Message(
ResourceLocation level,
Identifier level,
Vec3 position,
OptionalInt entity
) {
public static final StreamCodec<FriendlyByteBuf, Message> STREAM_CODEC = StreamCodec.composite(
ResourceLocation.STREAM_CODEC, Message::level,
Identifier.STREAM_CODEC, Message::level,
MoreStreamCodecs.VEC3, Message::position,
MoreStreamCodecs.OPTIONAL_INT, Message::entity,
Message::new

View File

@@ -8,8 +8,8 @@ import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import java.util.function.Supplier;
@@ -25,17 +25,17 @@ public interface RegistryEntry<U> extends Supplier<U> {
*
* @return This registered item.
*/
ResourceLocation id();
Identifier id();
static <T> Codec<RegistryEntry<? extends T>> codec(Registry<T> registry) {
record HolderEntry<T>(ResourceLocation id, Holder<T> holder) implements RegistryEntry<T> {
record HolderEntry<T>(Identifier id, Holder<T> holder) implements RegistryEntry<T> {
@Override
public T get() {
return holder().value();
}
}
return ResourceLocation.CODEC.flatXmap(
return Identifier.CODEC.flatXmap(
id -> registry
.get(ResourceKey.create(registry.key(), id))
.map(x -> DataResult.success(new HolderEntry<>(id, x)))

View File

@@ -14,8 +14,8 @@ import net.minecraft.core.Registry;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.level.storage.loot.functions.LootItemFunction;
@@ -39,7 +39,7 @@ public interface RecipeFunction {
/**
* The registry where {@link RecipeFunction}s are registered.
*/
ResourceKey<Registry<Type<?>>> REGISTRY = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "recipe_function"));
ResourceKey<Registry<Type<?>>> REGISTRY = ResourceKey.createRegistryKey(Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "recipe_function"));
/**
* The codec to read and write {@link RecipeFunction}s with.

View File

@@ -21,7 +21,7 @@ import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractHurtingProjectile;
import net.minecraft.world.entity.projectile.hurtingprojectile.AbstractHurtingProjectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.context.BlockPlaceContext;

View File

@@ -33,7 +33,7 @@ import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.ProblemReporter;
import net.minecraft.world.Container;
@@ -242,7 +242,7 @@ public class TurtleBlockEntity extends AbstractComputerBlockEntity implements Ba
return brain.getColour();
}
public @Nullable ResourceLocation getOverlay() {
public @Nullable Identifier getOverlay() {
return brain.getOverlay();
}
@@ -320,7 +320,7 @@ public class TurtleBlockEntity extends AbstractComputerBlockEntity implements Ba
@Override
public void loadClient(ValueInput nbt) {
super.loadClient(nbt);
label = nbt.getStringOr(NBT_LABEL, null);
label = nbt.getString(NBT_LABEL).orElse(null);
brain.readDescription(nbt);
}

View File

@@ -29,7 +29,7 @@ import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.ExtraCodecs;
@@ -80,7 +80,7 @@ public class TurtleBrain implements TurtleAccessInternal {
private int selectedSlot = 0;
private int fuelLevel = 0;
private int colourHex = -1;
private @Nullable ResourceLocation overlay = null;
private @Nullable Identifier overlay = null;
private TurtleAnimation animation = TurtleAnimation.NONE;
private int animationProgress = 0;
@@ -139,7 +139,7 @@ public class TurtleBrain implements TurtleAccessInternal {
// Read fields
colourHex = nbt.getIntOr(NBT_COLOUR, -1);
fuelLevel = nbt.getIntOr(NBT_FUEL, 0);
overlay = nbt.read(NBT_OVERLAY, ResourceLocation.CODEC).orElse(null);
overlay = nbt.read(NBT_OVERLAY, Identifier.CODEC).orElse(null);
// Read upgrades
setUpgradeDirect(TurtleSide.LEFT, nbt.read(NBT_LEFT_UPGRADE, TurtleUpgrades.instance().upgradeDataCodec()).orElse(null));
@@ -149,7 +149,7 @@ public class TurtleBrain implements TurtleAccessInternal {
private void writeCommon(ValueOutput nbt) {
nbt.putInt(NBT_FUEL, fuelLevel);
if (colourHex != -1) nbt.putInt(NBT_COLOUR, colourHex);
nbt.storeNullable(NBT_OVERLAY, ResourceLocation.CODEC, overlay);
nbt.storeNullable(NBT_OVERLAY, Identifier.CODEC, overlay);
// Write upgrades
nbt.storeNullable(NBT_LEFT_UPGRADE, TurtleUpgrades.instance().upgradeDataCodec(), getUpgradeWithData(TurtleSide.LEFT));
@@ -406,11 +406,11 @@ public class TurtleBrain implements TurtleAccessInternal {
BlockEntityHelpers.updateBlock(owner);
}
public @Nullable ResourceLocation getOverlay() {
public @Nullable Identifier getOverlay() {
return overlay;
}
public void setOverlay(@Nullable ResourceLocation overlay) {
public void setOverlay(@Nullable Identifier overlay) {
if (!Objects.equals(this.overlay, overlay)) {
this.overlay = overlay;
BlockEntityHelpers.updateBlock(owner);
@@ -744,7 +744,7 @@ public class TurtleBrain implements TurtleAccessInternal {
private @Nullable UpgradeData<ITurtleUpgrade> cachedUpgradeData;
public void setUpgrade(@Nullable UpgradeData<ITurtleUpgrade> upgrade) {
private void setUpgrade(@Nullable UpgradeData<ITurtleUpgrade> upgrade) {
if (upgrade == null) {
this.upgrade = null;
data = DataComponentPatch.EMPTY;
@@ -756,7 +756,7 @@ public class TurtleBrain implements TurtleAccessInternal {
}
}
public @Nullable UpgradeData<ITurtleUpgrade> getUpgrade() {
private @Nullable UpgradeData<ITurtleUpgrade> getUpgrade() {
if (upgrade == null) return null;
var cached = cachedUpgradeData;

View File

@@ -8,7 +8,7 @@ import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.impl.TurtleUpgrades;
import net.minecraft.core.HolderLookup;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.Container;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
@@ -20,8 +20,8 @@ import org.jspecify.annotations.Nullable;
* @see TurtleMenu
*/
public class UpgradeSlot extends Slot {
public static final ResourceLocation LEFT_UPGRADE = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "gui/turtle_upgrade_left");
public static final ResourceLocation RIGHT_UPGRADE = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "gui/turtle_upgrade_right");
public static final Identifier LEFT_UPGRADE = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "gui/turtle_upgrade_left");
public static final Identifier RIGHT_UPGRADE = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "gui/turtle_upgrade_right");
private final HolderLookup.Provider registries;
private final TurtleSide side;
@@ -44,7 +44,7 @@ public class UpgradeSlot extends Slot {
@Nullable
@Override
public ResourceLocation getNoItemIcon() {
public Identifier getNoItemIcon() {
return side == TurtleSide.LEFT ? LEFT_UPGRADE : RIGHT_UPGRADE;
}
}

Some files were not shown because too many files have changed in this diff Show More