1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-04 15:43:00 +00:00

Update to Minecraft 1.21

API Changes:

 - Minecraft had updated ModelResourceLocation to no longer inherit from
   ResourceLocation.

   To allow referencing both already baked models
   (ModelResourceLocation) and loading new models (via ResourceLocation)
   in turtle model loadders, we add a new "ModelLocation" class, that
   acts as a union between the two.

   I'm not entirely convinced by the design here, so might end up
   changing again before a stable release.o

 - Merge IMedia.getAudioTitle and IMedia.getAudio into a single
   IMedia.getAudio method, which now returns a JukeboxSong rather than a
   SoundEvent.

Other update notes:
 - Minecraft had rewritten how buffers are managed again. This is a
   fairly minor change for us (vertex -> addVertex, normal -> setNormal,
   etc...), with the exception that you can no longer use
   MultiBufferSource.immediate with the tesselator.

   I've replaced this with GuiGraphics.bufferSource, which appears to be
   fine, but worth keeping an eye on in case there's any odd render
   state issues.

 - Crafting now uses a CraftingInput (a list of items) rather than a
   CraftingContainer, which allows us to simplify turtle crafting code.
This commit is contained in:
Jonathan Coates
2024-06-22 16:19:59 +01:00
parent bb933d0100
commit 4b102f16b3
292 changed files with 665 additions and 655 deletions

View File

@@ -10,6 +10,7 @@ import dan200.computercraft.client.model.turtle.TurtleModelLoader;
import dan200.computercraft.client.turtle.TurtleUpgradeModellers;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
@@ -33,7 +34,7 @@ public final class ForgeClientRegistry {
@SubscribeEvent
public static void registerModelLoaders(ModelEvent.RegisterGeometryLoaders event) {
event.register(new ResourceLocation(ComputerCraftAPI.MOD_ID, "turtle"), TurtleModelLoader.INSTANCE);
event.register(ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "turtle"), TurtleModelLoader.INSTANCE);
}
/**
@@ -56,7 +57,7 @@ public final class ForgeClientRegistry {
@SubscribeEvent
public static void registerModels(ModelEvent.RegisterAdditional event) {
gatherModellers();
ClientRegistry.registerExtraModels(event::register);
ClientRegistry.registerExtraModels(x -> event.register(ModelResourceLocation.standalone(x)));
}
@SubscribeEvent

View File

@@ -35,7 +35,7 @@ public final class FoiledModel extends BakedModelWrapper<BakedModel> {
@Override
public List<RenderType> getRenderTypes(ItemStack itemStack, boolean fabulous) {
return new ConsList<>(fabulous ? RenderType.glintDirect() : RenderType.glint(), super.getRenderTypes(itemStack, fabulous));
return new ConsList<>(fabulous ? RenderType.glintTranslucent() : RenderType.glint(), super.getRenderTypes(itemStack, fabulous));
}
@Override

View File

@@ -28,7 +28,7 @@ import java.util.function.Function;
* {@link TurtleModel}.
*/
public final class TurtleModelLoader implements IGeometryLoader<TurtleModelLoader.Unbaked> {
private static final ResourceLocation COLOUR_TURTLE_MODEL = new ResourceLocation(ComputerCraftAPI.MOD_ID, "block/turtle_colour");
private static final ResourceLocation COLOUR_TURTLE_MODEL = ResourceLocation.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "block/turtle_colour");
public static final TurtleModelLoader INSTANCE = new TurtleModelLoader();
@@ -37,7 +37,7 @@ public final class TurtleModelLoader implements IGeometryLoader<TurtleModelLoade
@Override
public Unbaked read(JsonObject modelContents, JsonDeserializationContext deserializationContext) {
var model = new ResourceLocation(GsonHelper.getAsString(modelContents, "model"));
var model = ResourceLocation.parse(GsonHelper.getAsString(modelContents, "model"));
return new Unbaked(model);
}
@@ -49,7 +49,7 @@ public final class TurtleModelLoader implements IGeometryLoader<TurtleModelLoade
}
@Override
public BakedModel bake(IGeometryBakingContext owner, ModelBaker bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState transform, ItemOverrides overrides, ResourceLocation modelLocation) {
public BakedModel bake(IGeometryBakingContext owner, ModelBaker bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState transform, ItemOverrides overrides) {
var mainModel = bakery.bake(family, transform, spriteGetter);
if (mainModel == null) throw new NullPointerException(family + " failed to bake");

View File

@@ -8,14 +8,12 @@ import com.google.auto.service.AutoService;
import com.mojang.blaze3d.vertex.PoseStack;
import dan200.computercraft.client.model.FoiledModel;
import dan200.computercraft.client.render.ModelRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.core.BlockPos;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.client.model.data.ModelData;
@@ -29,8 +27,13 @@ public class ClientPlatformHelperImpl implements ClientPlatformHelper {
private static final Direction[] directions = Arrays.copyOf(Direction.values(), 7);
@Override
public BakedModel getModel(ModelManager manager, ResourceLocation location) {
return manager.getModel(location);
public BakedModel getModel(ModelManager manager, ResourceLocation resourceLocation) {
return manager.getModel(ModelResourceLocation.standalone(resourceLocation));
}
@Override
public BakedModel getModel(ModelManager manager, ModelResourceLocation modelLocation, @Nullable ResourceLocation resourceLocation) {
return manager.getModel(modelLocation);
}
@Override
@@ -49,9 +52,4 @@ public class ClientPlatformHelperImpl implements ClientPlatformHelper {
}
}
}
@Override
public void playStreamingMusic(BlockPos pos, @Nullable SoundEvent sound) {
Minecraft.getInstance().levelRenderer.playStreamingMusic(sound, pos, null);
}
}

View File

@@ -1,12 +0,0 @@
{
"type": "computercraft:printout",
"category": "redstone",
"ingredients": [{"tag": "c:leathers"}, {"tag": "c:strings"}],
"min_printouts": 1,
"printout": [
{"item": "computercraft:printed_page"},
{"item": "computercraft:printed_pages"},
{"item": "minecraft:paper"}
],
"result": {"count": 1, "id": "computercraft:printed_book"}
}

View File

@@ -15,6 +15,7 @@ import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.PeripheralCapability;
import dan200.computercraft.impl.Peripherals;
import dan200.computercraft.shared.config.ConfigFile;
import dan200.computercraft.shared.container.ListContainer;
import dan200.computercraft.shared.network.container.ContainerData;
import dan200.computercraft.shared.util.InventoryUtil;
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
@@ -36,12 +37,12 @@ import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.level.Level;
@@ -49,7 +50,6 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.neoforged.bus.api.Event;
import net.neoforged.neoforge.capabilities.BlockCapability;
import net.neoforged.neoforge.capabilities.BlockCapabilityCache;
import net.neoforged.neoforge.capabilities.Capabilities;
@@ -187,7 +187,7 @@ public class PlatformHelperImpl implements PlatformHelper {
}
@Override
public List<ItemStack> getRecipeRemainingItems(ServerPlayer player, Recipe<CraftingContainer> recipe, CraftingContainer container) {
public List<ItemStack> getRecipeRemainingItems(ServerPlayer player, Recipe<CraftingInput> recipe, CraftingInput container) {
CommonHooks.setCraftingPlayer(player);
var result = recipe.getRemainingItems(container);
CommonHooks.setCraftingPlayer(null);
@@ -195,8 +195,8 @@ public class PlatformHelperImpl implements PlatformHelper {
}
@Override
public void onItemCrafted(ServerPlayer player, CraftingContainer container, ItemStack stack) {
EventHooks.firePlayerCraftingEvent(player, stack, container);
public void onItemCrafted(ServerPlayer player, CraftingInput container, ItemStack stack) {
EventHooks.firePlayerCraftingEvent(player, stack, new ListContainer(container.items()));
}
@Override
@@ -239,18 +239,18 @@ public class PlatformHelperImpl implements PlatformHelper {
if (event.isCanceled()) return event.getCancellationResult();
var context = new UseOnContext(player, InteractionHand.MAIN_HAND, hit);
if (event.getUseItem() != Event.Result.DENY) {
if (!event.getUseItem().isFalse()) {
var result = stack.onItemUseFirst(context);
if (result != InteractionResult.PASS) return result;
}
var block = level.getBlockState(hit.getBlockPos());
if (event.getUseBlock() != Event.Result.DENY && !block.isAir() && canUseBlock.test(block)) {
if (!event.getUseBlock().isFalse() && !block.isAir() && canUseBlock.test(block)) {
var useResult = block.useItemOn(stack, level, player, InteractionHand.MAIN_HAND, hit);
if (useResult.consumesAction()) return useResult.result();
}
return event.getUseItem() == Event.Result.DENY ? InteractionResult.PASS : stack.useOn(context);
return event.getUseItem().isFalse() ? InteractionResult.PASS : stack.useOn(context);
}
private record RegistrationHelperImpl<R>(DeferredRegister<R> registry) implements RegistrationHelper<R> {

View File

@@ -26,7 +26,7 @@ CC: Tweaked is a fork of ComputerCraft, adding programmable computers, turtles a
[[dependencies.computercraft]]
modId="neoforge"
type="required"
versionRange="[${neoVersion},20.7)"
versionRange="[${neoVersion},21.1)"
ordering="NONE"
side="BOTH"