From 6f868849ab2f264508e12c184cc56f2632aaf5bc Mon Sep 17 00:00:00 2001 From: SquidDev Date: Wed, 16 Sep 2020 21:27:59 +0100 Subject: [PATCH] Use tags to check if something is a dye We half did this already, just needed to change a couple of checks. Closes #541. --- .../shared/peripheral/printer/ContainerPrinter.java | 3 +-- .../shared/peripheral/printer/TilePrinter.java | 10 +++++----- .../dan200/computercraft/shared/util/ColourUtils.java | 2 ++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java b/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java index 9f0666645..8ab37fef9 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java @@ -13,7 +13,6 @@ import net.minecraft.inventory.Inventory; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Slot; -import net.minecraft.item.DyeItem; import net.minecraft.item.ItemStack; import net.minecraft.util.IIntArray; import net.minecraft.util.IntArray; @@ -95,7 +94,7 @@ public ItemStack transferStackInSlot( @Nonnull PlayerEntity player, int index ) else { // Transfer from inventory to printer - if( stack.getItem() instanceof DyeItem ) + if( TilePrinter.isInk( stack ) ) { if( !mergeItemStack( stack, 0, 1, false ) ) return ItemStack.EMPTY; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java b/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java index ac560c8b4..f704c2484 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java @@ -300,9 +300,9 @@ void setPageTitle( String title ) } } - private static boolean isInk( @Nonnull ItemStack stack ) + static boolean isInk( @Nonnull ItemStack stack ) { - return stack.getItem() instanceof DyeItem; + return ColourUtils.getStackColour( stack ) != null; } private static boolean isPaper( @Nonnull ItemStack stack ) @@ -321,7 +321,8 @@ private boolean canInputPage() private boolean inputPage() { ItemStack inkStack = m_inventory.get( 0 ); - if( !isInk( inkStack ) ) return false; + DyeColor dye = ColourUtils.getStackColour( inkStack ); + if( dye == null ) return false; for( int i = 1; i < 7; i++ ) { @@ -329,8 +330,7 @@ private boolean inputPage() if( paperStack.isEmpty() || !isPaper( paperStack ) ) continue; // Setup the new page - DyeColor dye = ColourUtils.getStackColour( inkStack ); - m_page.setTextColour( dye != null ? dye.getId() : 15 ); + m_page.setTextColour( dye.getId() ); m_page.clear(); if( paperStack.getItem() instanceof ItemPrintout ) diff --git a/src/main/java/dan200/computercraft/shared/util/ColourUtils.java b/src/main/java/dan200/computercraft/shared/util/ColourUtils.java index 3c776d1bd..7a595f3c2 100644 --- a/src/main/java/dan200/computercraft/shared/util/ColourUtils.java +++ b/src/main/java/dan200/computercraft/shared/util/ColourUtils.java @@ -40,6 +40,8 @@ private ColourUtils() {} public static DyeColor getStackColour( ItemStack stack ) { + if( stack.isEmpty() ) return null; + for( int i = 0; i < DYES.length; i++ ) { Tag dye = DYES[i];