1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-07-04 02:52:56 +00:00

Remove PrintoutItem.getType

Kinda surprised this is still around! Not sure why I kept it post
the-flattening really, it's been redundant for a while.
This commit is contained in:
Jonathan Coates 2025-03-09 11:46:36 +00:00
parent b97634b717
commit 749b3df227
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
7 changed files with 14 additions and 26 deletions

View File

@ -12,6 +12,7 @@ import dan200.computercraft.client.pocket.ClientPocketComputers;
import dan200.computercraft.client.render.text.FixedWidthFontRenderer; import dan200.computercraft.client.render.text.FixedWidthFontRenderer;
import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.core.util.Colour; import dan200.computercraft.core.util.Colour;
import dan200.computercraft.shared.ModRegistry;
import dan200.computercraft.shared.lectern.CustomLecternBlockEntity; import dan200.computercraft.shared.lectern.CustomLecternBlockEntity;
import dan200.computercraft.shared.media.items.PrintoutItem; import dan200.computercraft.shared.media.items.PrintoutItem;
import dan200.computercraft.shared.pocket.items.PocketComputerItem; import dan200.computercraft.shared.pocket.items.PocketComputerItem;
@ -57,9 +58,9 @@ public class CustomLecternRenderer implements BlockEntityRenderer<CustomLecternB
poseStack.translate(0, -0.125f, 0); poseStack.translate(0, -0.125f, 0);
var item = lectern.getItem(); var item = lectern.getItem();
if (item.getItem() instanceof PrintoutItem printout) { if (item.getItem() instanceof PrintoutItem) {
var vertexConsumer = LecternPrintoutModel.MATERIAL.buffer(buffer, RenderType::entitySolid); var vertexConsumer = LecternPrintoutModel.MATERIAL.buffer(buffer, RenderType::entitySolid);
if (printout.getType() == PrintoutItem.Type.BOOK) { if (item.is(ModRegistry.Items.PRINTED_BOOK.get())) {
printoutModel.renderBook(poseStack, vertexConsumer, packedLight, packedOverlay); printoutModel.renderBook(poseStack, vertexConsumer, packedLight, packedOverlay);
} else { } else {
printoutModel.renderPages(poseStack, vertexConsumer, packedLight, packedOverlay, PrintoutItem.getPageCount(item)); printoutModel.renderPages(poseStack, vertexConsumer, packedLight, packedOverlay, PrintoutItem.getPageCount(item));

View File

@ -6,6 +6,7 @@ package dan200.computercraft.client.render;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import dan200.computercraft.shared.ModRegistry;
import dan200.computercraft.shared.media.items.PrintoutItem; import dan200.computercraft.shared.media.items.PrintoutItem;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
@ -51,7 +52,7 @@ public final class PrintoutItemRenderer extends ItemMapLikeRenderer {
private static void drawPrintout(PoseStack transform, MultiBufferSource render, ItemStack stack, int light) { private static void drawPrintout(PoseStack transform, MultiBufferSource render, ItemStack stack, int light) {
var pages = PrintoutItem.getPageCount(stack); var pages = PrintoutItem.getPageCount(stack);
var book = ((PrintoutItem) stack.getItem()).getType() == PrintoutItem.Type.BOOK; var book = stack.is(ModRegistry.Items.PRINTED_BOOK.get());
double width = LINE_MAX_LENGTH * FONT_WIDTH + X_TEXT_MARGIN * 2; double width = LINE_MAX_LENGTH * FONT_WIDTH + X_TEXT_MARGIN * 2;
double height = LINES_PER_PAGE * FONT_HEIGHT + Y_TEXT_MARGIN * 2; double height = LINES_PER_PAGE * FONT_HEIGHT + Y_TEXT_MARGIN * 2;

View File

@ -264,11 +264,11 @@ public final class ModRegistry {
REGISTRY.register("treasure_disk", () -> new TreasureDiskItem(properties().stacksTo(1))); REGISTRY.register("treasure_disk", () -> new TreasureDiskItem(properties().stacksTo(1)));
public static final RegistryEntry<PrintoutItem> PRINTED_PAGE = REGISTRY.register("printed_page", public static final RegistryEntry<PrintoutItem> PRINTED_PAGE = REGISTRY.register("printed_page",
() -> new PrintoutItem(properties().stacksTo(1), PrintoutItem.Type.PAGE)); () -> new PrintoutItem(properties().stacksTo(1)));
public static final RegistryEntry<PrintoutItem> PRINTED_PAGES = REGISTRY.register("printed_pages", public static final RegistryEntry<PrintoutItem> PRINTED_PAGES = REGISTRY.register("printed_pages",
() -> new PrintoutItem(properties().stacksTo(1), PrintoutItem.Type.PAGES)); () -> new PrintoutItem(properties().stacksTo(1)));
public static final RegistryEntry<PrintoutItem> PRINTED_BOOK = REGISTRY.register("printed_book", public static final RegistryEntry<PrintoutItem> PRINTED_BOOK = REGISTRY.register("printed_book",
() -> new PrintoutItem(properties().stacksTo(1), PrintoutItem.Type.BOOK)); () -> new PrintoutItem(properties().stacksTo(1)));
public static final RegistryEntry<BlockItem> SPEAKER = ofBlock(Blocks.SPEAKER, BlockItem::new); public static final RegistryEntry<BlockItem> SPEAKER = ofBlock(Blocks.SPEAKER, BlockItem::new);
public static final RegistryEntry<BlockItem> DISK_DRIVE = ofBlock(Blocks.DISK_DRIVE, BlockItem::new); public static final RegistryEntry<BlockItem> DISK_DRIVE = ofBlock(Blocks.DISK_DRIVE, BlockItem::new);

View File

@ -33,17 +33,8 @@ public class PrintoutItem extends Item {
public static final int LINE_MAX_LENGTH = 25; public static final int LINE_MAX_LENGTH = 25;
public static final int MAX_PAGES = 16; public static final int MAX_PAGES = 16;
public enum Type { public PrintoutItem(Properties settings) {
PAGE,
PAGES,
BOOK
}
private final Type type;
public PrintoutItem(Properties settings, Type type) {
super(settings); super(settings);
this.type = type;
} }
@Override @Override
@ -103,10 +94,6 @@ public class PrintoutItem extends Item {
return ModRegistry.Items.PRINTED_BOOK.get().createFromTitleAndText(title, text, colours); return ModRegistry.Items.PRINTED_BOOK.get().createFromTitleAndText(title, text, colours);
} }
public Type getType() {
return type;
}
public static String getTitle(ItemStack stack) { public static String getTitle(ItemStack stack) {
var nbt = stack.getTag(); var nbt = stack.getTag();
return nbt != null && nbt.contains(NBT_TITLE) ? nbt.getString(NBT_TITLE) : ""; return nbt != null && nbt.contains(NBT_TITLE) ? nbt.getString(NBT_TITLE) : "";

View File

@ -58,7 +58,7 @@ public final class PrintoutRecipe extends CustomRecipe {
for (var x = 0; x < inventory.getWidth(); x++) { for (var x = 0; x < inventory.getWidth(); x++) {
var stack = inventory.getItem(x + y * inventory.getWidth()); var stack = inventory.getItem(x + y * inventory.getWidth());
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
if (stack.getItem() instanceof PrintoutItem printout && printout.getType() != PrintoutItem.Type.BOOK) { if (!stack.is(ModRegistry.Items.PRINTED_BOOK.get())) {
if (printouts == null) printouts = new ItemStack[9]; if (printouts == null) printouts = new ItemStack[9];
printouts[numPrintouts] = stack; printouts[numPrintouts] = stack;
numPages += PrintoutItem.getPageCount(stack); numPages += PrintoutItem.getPageCount(stack);

View File

@ -5,6 +5,7 @@
package dan200.computercraft.shared.peripheral.printer; package dan200.computercraft.shared.peripheral.printer;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.shared.ModRegistry;
import dan200.computercraft.shared.common.AbstractContainerBlockEntity; import dan200.computercraft.shared.common.AbstractContainerBlockEntity;
import dan200.computercraft.shared.computer.terminal.NetworkedTerminal; import dan200.computercraft.shared.computer.terminal.NetworkedTerminal;
import dan200.computercraft.shared.container.BasicWorldlyContainer; import dan200.computercraft.shared.container.BasicWorldlyContainer;
@ -159,9 +160,7 @@ public final class PrinterBlockEntity extends AbstractContainerBlockEntity imple
} }
static boolean isPaper(ItemStack stack) { static boolean isPaper(ItemStack stack) {
var item = stack.getItem(); return stack.is(Items.PAPER) || stack.is(ModRegistry.Items.PRINTED_PAGE.get());
return item == Items.PAPER
|| (item instanceof PrintoutItem printout && printout.getType() == PrintoutItem.Type.PAGE);
} }
private boolean canInputPage() { private boolean canInputPage() {

View File

@ -439,14 +439,14 @@ class Turtle_Test {
object : object :
BasicItemDetailProvider<PrintoutItem>("printout", PrintoutItem::class.java) { BasicItemDetailProvider<PrintoutItem>("printout", PrintoutItem::class.java) {
override fun provideDetails(data: MutableMap<in String, Any>, stack: ItemStack, item: PrintoutItem) { override fun provideDetails(data: MutableMap<in String, Any>, stack: ItemStack, item: PrintoutItem) {
data["type"] = item.type.toString().lowercase() data["pages"] = PrintoutItem.getPageCount(stack)
} }
}, },
) )
} }
thenOnComputer { thenOnComputer {
val details = getTurtleItemDetail(detailed = true) val details = getTurtleItemDetail(detailed = true)
assertEquals(mapOf("type" to "page"), details["printout"]) { assertEquals(mapOf("pages" to 1), details["printout"]) {
"Printout information is returned (whole map is $details)" "Printout information is returned (whole map is $details)"
} }
} }