mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-12-01 03:48:06 +00:00
remap
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import dan200.computercraft.shared.util.NamedBlockEntityType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockEntityProvider;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class BlockGeneric extends Block implements BlockEntityProvider
|
||||
{
|
||||
private final BlockEntityType<? extends TileGeneric> type;
|
||||
|
||||
public BlockGeneric( Settings settings, NamedBlockEntityType<? extends TileGeneric> type )
|
||||
{
|
||||
super( settings );
|
||||
this.type = type;
|
||||
type.setBlock( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void onStateReplaced( @Nonnull BlockState block, @Nonnull World world, @Nonnull BlockPos pos, BlockState replace, boolean bool )
|
||||
{
|
||||
if( block.getBlock() == replace.getBlock() ) return;
|
||||
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
super.onStateReplaced( block, world, pos, replace, bool );
|
||||
world.removeBlockEntity( pos );
|
||||
if( tile instanceof TileGeneric ) ((TileGeneric) tile).destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean onUse( BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit )
|
||||
{
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
return tile instanceof TileGeneric && ((TileGeneric) tile).onActivate( player, hand, hit );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void neighborUpdate( BlockState state, World world, BlockPos pos, Block neighbourBlock, BlockPos neighbourPos, boolean flag )
|
||||
{
|
||||
super.neighborUpdate( state, world, pos, neighbourBlock, neighbourPos, flag );
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbourPos );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void scheduledTick( BlockState state, World world, BlockPos pos, Random rand )
|
||||
{
|
||||
BlockEntity te = world.getBlockEntity( pos );
|
||||
if( te instanceof TileGeneric ) ((TileGeneric) te).blockTick();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity createBlockEntity( BlockView blockView )
|
||||
{
|
||||
return type.instantiate();
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class ClientTerminal implements ITerminal
|
||||
{
|
||||
private boolean m_colour;
|
||||
private Terminal m_terminal;
|
||||
private boolean m_terminalChanged;
|
||||
|
||||
public ClientTerminal( boolean colour )
|
||||
{
|
||||
m_colour = colour;
|
||||
m_terminal = null;
|
||||
m_terminalChanged = false;
|
||||
}
|
||||
|
||||
public boolean pollTerminalChanged()
|
||||
{
|
||||
boolean changed = m_terminalChanged;
|
||||
m_terminalChanged = false;
|
||||
|
||||
Terminal terminal = m_terminal;
|
||||
if( terminal != null ) terminal.clearChanged();
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
// ITerminal implementation
|
||||
|
||||
@Override
|
||||
public Terminal getTerminal()
|
||||
{
|
||||
return m_terminal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isColour()
|
||||
{
|
||||
return m_colour;
|
||||
}
|
||||
|
||||
public void readDescription( CompoundTag nbt )
|
||||
{
|
||||
m_colour = nbt.getBoolean( "colour" );
|
||||
if( nbt.contains( "terminal" ) )
|
||||
{
|
||||
CompoundTag terminal = nbt.getCompound( "terminal" );
|
||||
resizeTerminal( terminal.getInt( "term_width" ), terminal.getInt( "term_height" ) );
|
||||
m_terminal.readFromNBT( terminal );
|
||||
}
|
||||
else
|
||||
{
|
||||
deleteTerminal();
|
||||
}
|
||||
}
|
||||
|
||||
private void resizeTerminal( int width, int height )
|
||||
{
|
||||
if( m_terminal == null )
|
||||
{
|
||||
m_terminal = new Terminal( width, height, () -> m_terminalChanged = true );
|
||||
m_terminalChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_terminal.resize( width, height );
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteTerminal()
|
||||
{
|
||||
if( m_terminal != null )
|
||||
{
|
||||
m_terminal = null;
|
||||
m_terminalChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import dan200.computercraft.shared.util.ColourTracker;
|
||||
import dan200.computercraft.shared.util.ColourUtils;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.RecipeSerializer;
|
||||
import net.minecraft.recipe.SpecialCraftingRecipe;
|
||||
import net.minecraft.recipe.SpecialRecipeSerializer;
|
||||
import net.minecraft.util.DyeColor;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ColourableRecipe extends SpecialCraftingRecipe
|
||||
{
|
||||
public ColourableRecipe( Identifier id )
|
||||
{
|
||||
super( id );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches( @Nonnull CraftingInventory inv, @Nonnull World world )
|
||||
{
|
||||
boolean hasColourable = false;
|
||||
boolean hasDye = false;
|
||||
for( int i = 0; i < inv.size(); i++ )
|
||||
{
|
||||
ItemStack stack = inv.getStack( i );
|
||||
if( stack.isEmpty() ) continue;
|
||||
|
||||
if( stack.getItem() instanceof IColouredItem )
|
||||
{
|
||||
if( hasColourable ) return false;
|
||||
hasColourable = true;
|
||||
}
|
||||
else if( ColourUtils.getStackColour( stack ) != null )
|
||||
{
|
||||
hasDye = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return hasColourable && hasDye;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack craft( @Nonnull CraftingInventory inv )
|
||||
{
|
||||
ItemStack colourable = ItemStack.EMPTY;
|
||||
|
||||
ColourTracker tracker = new ColourTracker();
|
||||
|
||||
for( int i = 0; i < inv.size(); i++ )
|
||||
{
|
||||
ItemStack stack = inv.getStack( i );
|
||||
|
||||
if( stack.isEmpty() ) continue;
|
||||
|
||||
if( stack.getItem() instanceof IColouredItem )
|
||||
{
|
||||
colourable = stack;
|
||||
}
|
||||
else
|
||||
{
|
||||
DyeColor dye = ColourUtils.getStackColour( stack );
|
||||
if( dye == null ) continue;
|
||||
|
||||
Colour colour = Colour.fromInt( 15 - dye.getId() );
|
||||
tracker.addColour( colour.getR(), colour.getG(), colour.getB() );
|
||||
}
|
||||
}
|
||||
|
||||
if( colourable.isEmpty() ) return ItemStack.EMPTY;
|
||||
return ((IColouredItem) colourable.getItem()).withColour( colourable, tracker.getColour() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fits( int x, int y )
|
||||
{
|
||||
return x >= 2 && y >= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public RecipeSerializer<?> getSerializer()
|
||||
{
|
||||
return SERIALIZER;
|
||||
}
|
||||
|
||||
public static final RecipeSerializer<?> SERIALIZER = new SpecialRecipeSerializer<>( ColourableRecipe::new );
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import dan200.computercraft.shared.util.InventoryUtil;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.util.Hand;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ContainerHeldItem extends ScreenHandler
|
||||
{
|
||||
private final ItemStack m_stack;
|
||||
private final Hand m_hand;
|
||||
|
||||
public ContainerHeldItem( int id, PlayerEntity player, Hand hand )
|
||||
{
|
||||
super( null, id );
|
||||
m_hand = hand;
|
||||
m_stack = InventoryUtil.copyItem( player.getStackInHand( hand ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public ItemStack getStack()
|
||||
{
|
||||
return m_stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse( @Nonnull PlayerEntity player )
|
||||
{
|
||||
if( !player.isAlive() ) return false;
|
||||
|
||||
ItemStack stack = player.getStackInHand( m_hand );
|
||||
return stack == m_stack || !stack.isEmpty() && !m_stack.isEmpty() && stack.getItem() == m_stack.getItem();
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider
|
||||
{
|
||||
@Override
|
||||
public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
return getDefaultBundledRedstoneOutput( world, pos, side );
|
||||
}
|
||||
|
||||
public static int getDefaultBundledRedstoneOutput( World world, BlockPos pos, Direction side )
|
||||
{
|
||||
Block block = world.getBlockState( pos ).getBlock();
|
||||
if( block instanceof IBundledRedstoneBlock )
|
||||
{
|
||||
IBundledRedstoneBlock generic = (IBundledRedstoneBlock) block;
|
||||
if( generic.getBundledRedstoneConnectivity( world, pos, side ) )
|
||||
{
|
||||
return generic.getBundledRedstoneOutput( world, pos, side );
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IBundledRedstoneBlock
|
||||
{
|
||||
boolean getBundledRedstoneConnectivity( World world, BlockPos pos, Direction side );
|
||||
|
||||
int getBundledRedstoneOutput( World world, BlockPos pos, Direction side );
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public interface IColouredItem
|
||||
{
|
||||
String NBT_COLOUR = "Color";
|
||||
|
||||
default int getColour( ItemStack stack )
|
||||
{
|
||||
return getColourBasic( stack );
|
||||
}
|
||||
|
||||
default ItemStack withColour( ItemStack stack, int colour )
|
||||
{
|
||||
ItemStack copy = stack.copy();
|
||||
setColourBasic( copy, colour );
|
||||
return copy;
|
||||
}
|
||||
|
||||
static int getColourBasic( ItemStack stack )
|
||||
{
|
||||
CompoundTag tag = stack.getTag();
|
||||
return tag != null && tag.contains( NBT_COLOUR ) ? tag.getInt( NBT_COLOUR ) : -1;
|
||||
}
|
||||
|
||||
static void setColourBasic( ItemStack stack, int colour )
|
||||
{
|
||||
if( colour == -1 )
|
||||
{
|
||||
CompoundTag tag = stack.getTag();
|
||||
if( tag != null ) tag.remove( NBT_COLOUR );
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.getOrCreateTag().putInt( NBT_COLOUR, colour );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
|
||||
public interface ITerminal
|
||||
{
|
||||
Terminal getTerminal();
|
||||
|
||||
boolean isColour();
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class ServerTerminal implements ITerminal
|
||||
{
|
||||
private final boolean m_colour;
|
||||
private Terminal m_terminal;
|
||||
private final AtomicBoolean m_terminalChanged = new AtomicBoolean( false );
|
||||
private boolean m_terminalChangedLastFrame = false;
|
||||
|
||||
public ServerTerminal( boolean colour )
|
||||
{
|
||||
m_colour = colour;
|
||||
m_terminal = null;
|
||||
}
|
||||
|
||||
public ServerTerminal( boolean colour, int terminalWidth, int terminalHeight )
|
||||
{
|
||||
m_colour = colour;
|
||||
m_terminal = new Terminal( terminalWidth, terminalHeight, this::markTerminalChanged );
|
||||
}
|
||||
|
||||
protected void resize( int width, int height )
|
||||
{
|
||||
if( m_terminal == null )
|
||||
{
|
||||
m_terminal = new Terminal( width, height, this::markTerminalChanged );
|
||||
markTerminalChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_terminal.resize( width, height );
|
||||
}
|
||||
}
|
||||
|
||||
public void delete()
|
||||
{
|
||||
if( m_terminal != null )
|
||||
{
|
||||
m_terminal = null;
|
||||
markTerminalChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected void markTerminalChanged()
|
||||
{
|
||||
m_terminalChanged.set( true );
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
Terminal terminal = m_terminal;
|
||||
if( terminal != null ) terminal.clearChanged();
|
||||
|
||||
m_terminalChangedLastFrame = m_terminalChanged.getAndSet( false );
|
||||
}
|
||||
|
||||
public boolean hasTerminalChanged()
|
||||
{
|
||||
return m_terminalChangedLastFrame;
|
||||
}
|
||||
|
||||
// ITerminal implementation
|
||||
|
||||
@Override
|
||||
public Terminal getTerminal()
|
||||
{
|
||||
return m_terminal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isColour()
|
||||
{
|
||||
return m_colour;
|
||||
}
|
||||
|
||||
// Networking stuff
|
||||
|
||||
public void writeDescription( CompoundTag nbt )
|
||||
{
|
||||
nbt.putBoolean( "colour", m_colour );
|
||||
if( m_terminal != null )
|
||||
{
|
||||
CompoundTag terminal = new CompoundTag();
|
||||
terminal.putInt( "term_width", m_terminal.getWidth() );
|
||||
terminal.putInt( "term_height", m_terminal.getHeight() );
|
||||
m_terminal.writeToNBT( terminal );
|
||||
nbt.put( "terminal", terminal );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public abstract class TileGeneric extends BlockEntity implements BlockEntityClientSerializable
|
||||
{
|
||||
public TileGeneric( BlockEntityType<? extends TileGeneric> type )
|
||||
{
|
||||
super( type );
|
||||
}
|
||||
|
||||
public void destroy()
|
||||
{
|
||||
}
|
||||
|
||||
public final void updateBlock()
|
||||
{
|
||||
markDirty();
|
||||
BlockPos pos = getPos();
|
||||
BlockState state = getCachedState();
|
||||
getWorld().updateListeners( pos, state, state, 3 );
|
||||
}
|
||||
|
||||
public boolean onActivate( PlayerEntity player, Hand hand, BlockHitResult hit )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onNeighbourChange( @Nonnull BlockPos neighbour )
|
||||
{
|
||||
}
|
||||
|
||||
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
|
||||
{
|
||||
}
|
||||
|
||||
protected void blockTick()
|
||||
{
|
||||
}
|
||||
|
||||
protected double getInteractRange( PlayerEntity player )
|
||||
{
|
||||
return 8.0;
|
||||
}
|
||||
|
||||
public boolean isUsable( PlayerEntity player, boolean ignoreRange )
|
||||
{
|
||||
if( player == null || !player.isAlive() || getWorld().getBlockEntity( getPos() ) != this ) return false;
|
||||
if( ignoreRange ) return true;
|
||||
|
||||
double range = getInteractRange( player );
|
||||
BlockPos pos = getPos();
|
||||
return player.getEntityWorld() == getWorld() &&
|
||||
player.squaredDistanceTo( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= range * range;
|
||||
}
|
||||
|
||||
protected void writeDescription( @Nonnull CompoundTag nbt )
|
||||
{
|
||||
}
|
||||
|
||||
protected void readDescription( @Nonnull CompoundTag nbt )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CompoundTag toClientTag( CompoundTag tag )
|
||||
{
|
||||
writeDescription( tag );
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void fromClientTag( CompoundTag tag )
|
||||
{
|
||||
readDescription( tag );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user