mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-15 12:37:13 +00:00
Started work on upgrading to 1.16.1. Not in a compilable state yet
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.computer.items;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class ComputerItemFactory
|
||||
{
|
||||
private ComputerItemFactory() {}
|
||||
|
||||
@Nonnull
|
||||
public static ItemStack create( TileComputer tile )
|
||||
{
|
||||
String label = tile.getLabel();
|
||||
int id = label != null ? tile.getComputerID() : -1;
|
||||
return create( id, label, tile.getFamily() );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static ItemStack create( int id, String label, ComputerFamily family )
|
||||
{
|
||||
switch( family )
|
||||
{
|
||||
case Normal:
|
||||
return ComputerCraft.Items.computerNormal.create( id, label );
|
||||
case Advanced:
|
||||
return ComputerCraft.Items.computerAdvanced.create( id, label );
|
||||
case Command:
|
||||
return ComputerCraft.Items.computerCommand.create( id, label );
|
||||
default:
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.computer.items;
|
||||
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public interface IComputerItem
|
||||
{
|
||||
String NBT_ID = "ComputerId";
|
||||
|
||||
default int getComputerID( @Nonnull ItemStack stack )
|
||||
{
|
||||
CompoundTag nbt = stack.getTag();
|
||||
return nbt != null && nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
|
||||
}
|
||||
|
||||
default String getLabel( @Nonnull ItemStack stack )
|
||||
{
|
||||
return stack.hasCustomName() ? stack.getName().getString() : null;
|
||||
}
|
||||
|
||||
ComputerFamily getFamily();
|
||||
|
||||
ItemStack withFamily( @Nonnull ItemStack stack, @Nonnull ComputerFamily family );
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.computer.items;
|
||||
|
||||
import dan200.computercraft.shared.computer.blocks.BlockComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ItemComputer extends ItemComputerBase
|
||||
{
|
||||
public ItemComputer( BlockComputer block, Settings settings )
|
||||
{
|
||||
super( block, settings );
|
||||
}
|
||||
|
||||
public ItemStack create( int id, String label )
|
||||
{
|
||||
ItemStack result = new ItemStack( this );
|
||||
if( id >= 0 ) result.getOrCreateTag().putInt( NBT_ID, id );
|
||||
if( label != null ) result.setCustomName( new LiteralText( label ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack withFamily( @Nonnull ItemStack stack, @Nonnull ComputerFamily family )
|
||||
{
|
||||
ItemStack result = ComputerItemFactory.create( getComputerID( stack ), null, family );
|
||||
if( stack.hasCustomName() ) result.setCustomName( stack.getName() );
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.computer.items;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
import dan200.computercraft.api.media.IMedia;
|
||||
import dan200.computercraft.shared.computer.blocks.BlockComputerBase;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ItemComputerBase extends BlockItem implements IComputerItem, IMedia
|
||||
{
|
||||
private final ComputerFamily family;
|
||||
|
||||
public ItemComputerBase( BlockComputerBase<?> block, Settings settings )
|
||||
{
|
||||
super( block, settings );
|
||||
family = block.getFamily();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendTooltip( @Nonnull ItemStack stack, @Nullable World world, @Nonnull List<Text> list, @Nonnull TooltipContext options )
|
||||
{
|
||||
if( options.isAdvanced() )
|
||||
{
|
||||
int id = getComputerID( stack );
|
||||
if( id >= 0 )
|
||||
{
|
||||
list.add( new TranslatableText( "gui.computercraft.tooltip.computer_id", id )
|
||||
.formatted( Formatting.GRAY ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel( @Nonnull ItemStack stack )
|
||||
{
|
||||
return stack.hasCustomName() ? stack.getName().getString() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ComputerFamily getFamily()
|
||||
{
|
||||
return family;
|
||||
}
|
||||
|
||||
// IMedia implementation
|
||||
|
||||
@Override
|
||||
public boolean setLabel( @Nonnull ItemStack stack, String label )
|
||||
{
|
||||
if( label != null )
|
||||
{
|
||||
stack.setCustomName( new LiteralText( label ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.removeCustomName();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world )
|
||||
{
|
||||
ComputerFamily family = getFamily();
|
||||
if( family != ComputerFamily.Command )
|
||||
{
|
||||
int id = getComputerID( stack );
|
||||
if( id >= 0 )
|
||||
{
|
||||
return ComputerCraftAPI.createSaveDirMount( world, "computer/" + id, ComputerCraft.computerSpaceLimit );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user