mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-25 16:36:55 +00:00
Several minor improvements
- Restrict what items can be inserted into printers. They're now closer to brewing stands or furnaces: nothing can go in the output slot, only ink in the ink slot, and only paper in the paper slot. - Fix build.gradle using the wrong version - Trim the width of tables to fit when displaying on the client. Closes #45. Note, our solution isn't perfect, as it will wordwrap too, but it's adaquate for now.
This commit is contained in:
parent
70a226207e
commit
46fa798797
@ -149,7 +149,7 @@ reobfJar.dependsOn proguardMove
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
inputs.property "mcversion", project.version
|
||||
inputs.property "mcversion", mc_version
|
||||
|
||||
def hash = 'none'
|
||||
Set<String> contributors = []
|
||||
@ -170,9 +170,9 @@ processResources {
|
||||
include 'mcmod.info'
|
||||
include 'assets/computercraft/lua/rom/help/credits.txt'
|
||||
|
||||
expand 'version':project.version,
|
||||
'mcversion':project.version,
|
||||
'gitcontributors':contributors.sort(false, String.CASE_INSENSITIVE_ORDER).join('\n')
|
||||
expand 'version': project.version,
|
||||
'mcversion': mc_version,
|
||||
'gitcontributors': contributors.sort(false, String.CASE_INSENSITIVE_ORDER).join('\n')
|
||||
}
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
|
@ -13,12 +13,14 @@ import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiNewChat;
|
||||
import net.minecraft.client.gui.GuiUtilRenderComponents;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class ClientTableFormatter implements TableFormatter
|
||||
{
|
||||
@ -62,7 +64,13 @@ public class ClientTableFormatter implements TableFormatter
|
||||
@Override
|
||||
public void writeLine( int id, ITextComponent component )
|
||||
{
|
||||
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion( component, id );
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
GuiNewChat chat = mc.ingameGUI.getChatGUI();
|
||||
|
||||
// Trim the text if it goes over the allowed length
|
||||
int maxWidth = MathHelper.floor( chat.getChatWidth() / chat.getChatScale() );
|
||||
List<ITextComponent> list = GuiUtilRenderComponents.splitText( component, maxWidth, mc.fontRenderer, false, false );
|
||||
if( !list.isEmpty() ) chat.printChatMessageWithOptionalDeletion( list.get( 0 ), id );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,6 +101,11 @@ public class TableBuilder
|
||||
return additional;
|
||||
}
|
||||
|
||||
public void setAdditional( int additional )
|
||||
{
|
||||
this.additional = additional;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim this table to a given height
|
||||
*
|
||||
@ -110,8 +115,8 @@ public class TableBuilder
|
||||
{
|
||||
if( rows.size() > height )
|
||||
{
|
||||
additional += rows.size() - height;
|
||||
rows.subList( height, rows.size() ).clear();
|
||||
additional += rows.size() - height - 1;
|
||||
rows.subList( height - 1, rows.size() ).clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,8 +74,6 @@ public interface TableFormatter
|
||||
int totalWidth = (columns - 1) * getWidth( SEPARATOR );
|
||||
for( int x : maxWidths ) totalWidth += x;
|
||||
|
||||
// TODO: Limit the widths of some entries if totalWidth > maxWidth
|
||||
|
||||
if( headers != null )
|
||||
{
|
||||
TextComponentString line = new TextComponentString( "" );
|
||||
|
@ -48,6 +48,8 @@ public class ChatTableClientMessage implements NetworkMessage
|
||||
{
|
||||
for( ITextComponent column : row ) buf.writeTextComponent( column );
|
||||
}
|
||||
|
||||
buf.writeVarInt( table.getAdditional() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,6 +76,8 @@ public class ChatTableClientMessage implements NetworkMessage
|
||||
for( int j = 0; j < columns; j++ ) row[j] = NBTUtil.readTextComponent( buf );
|
||||
table.row( row );
|
||||
}
|
||||
|
||||
table.setAdditional( buf.readVarInt() );
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import dan200.computercraft.shared.peripheral.PeripheralType;
|
||||
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
|
||||
import dan200.computercraft.shared.util.DefaultSidedInventory;
|
||||
import dan200.computercraft.shared.util.InventoryUtil;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@ -262,6 +261,23 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int slot, @Nonnull ItemStack stack )
|
||||
{
|
||||
if( slot == 0 )
|
||||
{
|
||||
return isInk( stack );
|
||||
}
|
||||
else if( slot >= topSlots[0] && slot <= topSlots[topSlots.length - 1] )
|
||||
{
|
||||
return isPaper( stack );
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
@ -393,15 +409,15 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInk( @Nonnull ItemStack stack )
|
||||
private static boolean isInk( @Nonnull ItemStack stack )
|
||||
{
|
||||
return (stack.getItem() == Items.DYE);
|
||||
return stack.getItem() == Items.DYE;
|
||||
}
|
||||
|
||||
private boolean isPaper( @Nonnull ItemStack stack )
|
||||
private static boolean isPaper( @Nonnull ItemStack stack )
|
||||
{
|
||||
Item item = stack.getItem();
|
||||
return (item == Items.PAPER || (item instanceof ItemPrintout && ItemPrintout.getType( stack ) == ItemPrintout.Type.Single));
|
||||
return item == Items.PAPER || (item instanceof ItemPrintout && ItemPrintout.getType( stack ) == ItemPrintout.Type.Single);
|
||||
}
|
||||
|
||||
private boolean canInputPage()
|
||||
@ -493,11 +509,14 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
|
||||
ItemStack stack = ItemPrintout.createSingleFromTitleAndText( m_pageTitle, lines, colours );
|
||||
synchronized( m_inventory )
|
||||
{
|
||||
ItemStack remainder = InventoryUtil.storeItems( stack, m_itemHandlerAll, 7, 6, 7 );
|
||||
if( remainder.isEmpty() )
|
||||
for( int slot : bottomSlots )
|
||||
{
|
||||
m_printing = false;
|
||||
return true;
|
||||
if( m_inventory.get( slot ).isEmpty() )
|
||||
{
|
||||
m_inventory.set( slot, stack );
|
||||
m_printing = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.util;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ValidatingSlot extends Slot
|
||||
{
|
||||
public ValidatingSlot( IInventory inventoryIn, int index, int xPosition, int yPosition )
|
||||
{
|
||||
super( inventoryIn, index, xPosition, yPosition );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid( ItemStack stack )
|
||||
{
|
||||
return true; // inventory.isItemValidForSlot( slotNumber, stack );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user