mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-02-04 05:09:12 +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 {
|
processResources {
|
||||||
inputs.property "version", project.version
|
inputs.property "version", project.version
|
||||||
inputs.property "mcversion", project.version
|
inputs.property "mcversion", mc_version
|
||||||
|
|
||||||
def hash = 'none'
|
def hash = 'none'
|
||||||
Set<String> contributors = []
|
Set<String> contributors = []
|
||||||
@ -170,9 +170,9 @@ processResources {
|
|||||||
include 'mcmod.info'
|
include 'mcmod.info'
|
||||||
include 'assets/computercraft/lua/rom/help/credits.txt'
|
include 'assets/computercraft/lua/rom/help/credits.txt'
|
||||||
|
|
||||||
expand 'version':project.version,
|
expand 'version': project.version,
|
||||||
'mcversion':project.version,
|
'mcversion': mc_version,
|
||||||
'gitcontributors':contributors.sort(false, String.CASE_INSENSITIVE_ORDER).join('\n')
|
'gitcontributors': contributors.sort(false, String.CASE_INSENSITIVE_ORDER).join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
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.Minecraft;
|
||||||
import net.minecraft.client.gui.FontRenderer;
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
import net.minecraft.client.gui.GuiNewChat;
|
import net.minecraft.client.gui.GuiNewChat;
|
||||||
|
import net.minecraft.client.gui.GuiUtilRenderComponents;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TextFormatting;
|
import net.minecraft.util.text.TextFormatting;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ClientTableFormatter implements TableFormatter
|
public class ClientTableFormatter implements TableFormatter
|
||||||
{
|
{
|
||||||
@ -62,7 +64,13 @@ public class ClientTableFormatter implements TableFormatter
|
|||||||
@Override
|
@Override
|
||||||
public void writeLine( int id, ITextComponent component )
|
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
|
@Override
|
||||||
|
@ -101,6 +101,11 @@ public class TableBuilder
|
|||||||
return additional;
|
return additional;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAdditional( int additional )
|
||||||
|
{
|
||||||
|
this.additional = additional;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trim this table to a given height
|
* Trim this table to a given height
|
||||||
*
|
*
|
||||||
@ -110,8 +115,8 @@ public class TableBuilder
|
|||||||
{
|
{
|
||||||
if( rows.size() > height )
|
if( rows.size() > height )
|
||||||
{
|
{
|
||||||
additional += rows.size() - height;
|
additional += rows.size() - height - 1;
|
||||||
rows.subList( height, rows.size() ).clear();
|
rows.subList( height - 1, rows.size() ).clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,8 +74,6 @@ public interface TableFormatter
|
|||||||
int totalWidth = (columns - 1) * getWidth( SEPARATOR );
|
int totalWidth = (columns - 1) * getWidth( SEPARATOR );
|
||||||
for( int x : maxWidths ) totalWidth += x;
|
for( int x : maxWidths ) totalWidth += x;
|
||||||
|
|
||||||
// TODO: Limit the widths of some entries if totalWidth > maxWidth
|
|
||||||
|
|
||||||
if( headers != null )
|
if( headers != null )
|
||||||
{
|
{
|
||||||
TextComponentString line = new TextComponentString( "" );
|
TextComponentString line = new TextComponentString( "" );
|
||||||
|
@ -48,6 +48,8 @@ public class ChatTableClientMessage implements NetworkMessage
|
|||||||
{
|
{
|
||||||
for( ITextComponent column : row ) buf.writeTextComponent( column );
|
for( ITextComponent column : row ) buf.writeTextComponent( column );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf.writeVarInt( table.getAdditional() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -74,6 +76,8 @@ public class ChatTableClientMessage implements NetworkMessage
|
|||||||
for( int j = 0; j < columns; j++ ) row[j] = NBTUtil.readTextComponent( buf );
|
for( int j = 0; j < columns; j++ ) row[j] = NBTUtil.readTextComponent( buf );
|
||||||
table.row( row );
|
table.row( row );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table.setAdditional( buf.readVarInt() );
|
||||||
this.table = table;
|
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.PeripheralType;
|
||||||
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
|
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
|
||||||
import dan200.computercraft.shared.util.DefaultSidedInventory;
|
import dan200.computercraft.shared.util.DefaultSidedInventory;
|
||||||
import dan200.computercraft.shared.util.InventoryUtil;
|
|
||||||
import dan200.computercraft.shared.util.WorldUtil;
|
import dan200.computercraft.shared.util.WorldUtil;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
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
|
@Override
|
||||||
public boolean hasCustomName()
|
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();
|
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()
|
private boolean canInputPage()
|
||||||
@ -493,11 +509,14 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven
|
|||||||
ItemStack stack = ItemPrintout.createSingleFromTitleAndText( m_pageTitle, lines, colours );
|
ItemStack stack = ItemPrintout.createSingleFromTitleAndText( m_pageTitle, lines, colours );
|
||||||
synchronized( m_inventory )
|
synchronized( m_inventory )
|
||||||
{
|
{
|
||||||
ItemStack remainder = InventoryUtil.storeItems( stack, m_itemHandlerAll, 7, 6, 7 );
|
for( int slot : bottomSlots )
|
||||||
if( remainder.isEmpty() )
|
|
||||||
{
|
{
|
||||||
m_printing = false;
|
if( m_inventory.get( slot ).isEmpty() )
|
||||||
return true;
|
{
|
||||||
|
m_inventory.set( slot, stack );
|
||||||
|
m_printing = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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