1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-12-01 20:08:05 +00:00

gradle=7.1.1, gradle migrateMappings

This commit is contained in:
Merith
2021-07-11 01:33:21 +00:00
parent cbff505297
commit 9bc4e9530c
435 changed files with 54771 additions and 91 deletions

View File

@@ -0,0 +1,101 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
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 BlockWithEntity
{
private final BlockEntityType<? extends TileGeneric> type;
public BlockGeneric( Settings settings, BlockEntityType<? extends TileGeneric> type )
{
super( settings );
this.type = type;
}
@Override
public BlockRenderType getRenderType( BlockState state )
{
return BlockRenderType.MODEL;
}
@Override
@Deprecated
public final void neighborUpdate( @Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull Block neighbourBlock,
@Nonnull BlockPos neighbourPos, boolean isMoving )
{
BlockEntity tile = world.getBlockEntity( pos );
if( tile instanceof TileGeneric )
{
((TileGeneric) tile).onNeighbourChange( neighbourPos );
}
}
@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();
}
}
@Nonnull
@Override
@Deprecated
public final ActionResult onUse( @Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull PlayerEntity player, @Nonnull Hand hand,
@Nonnull BlockHitResult hit )
{
BlockEntity tile = world.getBlockEntity( pos );
return tile instanceof TileGeneric ? ((TileGeneric) tile).onActivate( player, hand, hit ) : ActionResult.PASS;
}
@Override
@Deprecated
public void scheduledTick( @Nonnull BlockState state, ServerWorld world, @Nonnull BlockPos pos, @Nonnull Random rand )
{
BlockEntity te = world.getBlockEntity( pos );
if( te instanceof TileGeneric )
{
((TileGeneric) te).blockTick();
}
}
@Nullable
@Override
public BlockEntity createBlockEntity( @Nonnull BlockView world )
{
return type.instantiate();
}
}

View File

@@ -0,0 +1,97 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.network.client.TerminalState;
import net.minecraft.nbt.NbtCompound;
public class ClientTerminal implements ITerminal
{
private boolean colour;
private Terminal terminal;
private boolean terminalChanged;
public ClientTerminal( boolean colour )
{
this.colour = colour;
terminal = null;
terminalChanged = false;
}
public boolean pollTerminalChanged()
{
boolean changed = terminalChanged;
terminalChanged = false;
return changed;
}
// ITerminal implementation
@Override
public Terminal getTerminal()
{
return terminal;
}
@Override
public boolean isColour()
{
return colour;
}
public void read( TerminalState state )
{
colour = state.colour;
if( state.hasTerminal() )
{
resizeTerminal( state.width, state.height );
state.apply( terminal );
}
else
{
deleteTerminal();
}
}
private void resizeTerminal( int width, int height )
{
if( terminal == null )
{
terminal = new Terminal( width, height, () -> terminalChanged = true );
terminalChanged = true;
}
else
{
terminal.resize( width, height );
}
}
private void deleteTerminal()
{
if( terminal != null )
{
terminal = null;
terminalChanged = true;
}
}
public void readDescription( NbtCompound nbt )
{
colour = nbt.getBoolean( "colour" );
if( nbt.contains( "terminal" ) )
{
NbtCompound terminal = nbt.getCompound( "terminal" );
resizeTerminal( terminal.getInt( "term_width" ), terminal.getInt( "term_height" ) );
this.terminal.readFromNBT( terminal );
}
else
{
deleteTerminal();
}
}
}

View File

@@ -0,0 +1,107 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
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 final class ColourableRecipe extends SpecialCraftingRecipe
{
public static final RecipeSerializer<?> SERIALIZER = new SpecialRecipeSerializer<>( ColourableRecipe::new );
private 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;
}
else
{
DyeColor dye = ColourUtils.getStackColour( stack );
if( dye != null ) tracker.addColour( dye );
}
}
if( colourable.isEmpty() ) return ItemStack.EMPTY;
ItemStack stack = ((IColouredItem) colourable.getItem()).withColour( colourable, tracker.getColour() );
stack.setCount( 1 );
return stack;
}
@Override
public boolean fits( int x, int y )
{
return x >= 2 && y >= 2;
}
@Override
@Nonnull
public RecipeSerializer<?> getSerializer()
{
return SERIALIZER;
}
}

View File

@@ -0,0 +1,100 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.network.container.HeldItemContainerData;
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ContainerHeldItem extends ScreenHandler
{
private final ItemStack stack;
private final Hand hand;
public ContainerHeldItem( ScreenHandlerType<? extends ContainerHeldItem> type, int id, PlayerEntity player, Hand hand )
{
super( type, id );
this.hand = hand;
stack = player.getStackInHand( hand )
.copy();
}
public static ContainerHeldItem createPrintout( int id, PlayerInventory inventory, PacketByteBuf data )
{
return createPrintout( id, inventory, new HeldItemContainerData( data ) );
}
public static ContainerHeldItem createPrintout( int id, PlayerInventory inventory, HeldItemContainerData data )
{
return new ContainerHeldItem( ComputerCraftRegistry.ModContainers.PRINTOUT, id, inventory.player, data.getHand() );
}
@Nonnull
public ItemStack getStack()
{
return stack;
}
@Override
public boolean canUse( @Nonnull PlayerEntity player )
{
if( !player.isAlive() )
{
return false;
}
ItemStack stack = player.getStackInHand( hand );
return stack == this.stack || !stack.isEmpty() && !this.stack.isEmpty() && stack.getItem() == this.stack.getItem();
}
public static class Factory implements ExtendedScreenHandlerFactory
{
private final ScreenHandlerType<ContainerHeldItem> type;
private final Text name;
private final Hand hand;
public Factory( ScreenHandlerType<ContainerHeldItem> type, ItemStack stack, Hand hand )
{
this.type = type;
name = stack.getName();
this.hand = hand;
}
@Nonnull
@Override
public Text getDisplayName()
{
return name;
}
@Nullable
@Override
public ScreenHandler createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player )
{
return new ContainerHeldItem( type, id, player, hand );
}
@Override
public void writeScreenOpeningData( ServerPlayerEntity serverPlayerEntity, PacketByteBuf packetByteBuf )
{
packetByteBuf.writeEnumConstant( hand );
}
}
}

View File

@@ -0,0 +1,39 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. 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;
}
}

View File

@@ -0,0 +1,18 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. 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 );
}

View File

@@ -0,0 +1,50 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. 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.NbtCompound;
public interface IColouredItem
{
String NBT_COLOUR = "Color";
default int getColour( ItemStack stack )
{
return getColourBasic( stack );
}
static int getColourBasic( ItemStack stack )
{
NbtCompound tag = stack.getNbt();
return tag != null && tag.contains( NBT_COLOUR ) ? tag.getInt( NBT_COLOUR ) : -1;
}
default ItemStack withColour( ItemStack stack, int colour )
{
ItemStack copy = stack.copy();
setColourBasic( copy, colour );
return copy;
}
static void setColourBasic( ItemStack stack, int colour )
{
if( colour == -1 )
{
NbtCompound tag = stack.getNbt();
if( tag != null )
{
tag.remove( NBT_COLOUR );
}
}
else
{
stack.getOrCreateNbt()
.putInt( NBT_COLOUR, colour );
}
}
}

View File

@@ -0,0 +1,16 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. 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();
}

View File

@@ -0,0 +1,99 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.network.client.TerminalState;
import java.util.concurrent.atomic.AtomicBoolean;
import net.minecraft.nbt.NbtCompound;
public class ServerTerminal implements ITerminal
{
private final boolean colour;
private final AtomicBoolean terminalChanged = new AtomicBoolean( false );
private Terminal terminal;
private boolean terminalChangedLastFrame = false;
public ServerTerminal( boolean colour )
{
this.colour = colour;
terminal = null;
}
public ServerTerminal( boolean colour, int terminalWidth, int terminalHeight )
{
this.colour = colour;
terminal = new Terminal( terminalWidth, terminalHeight, this::markTerminalChanged );
}
protected void markTerminalChanged()
{
terminalChanged.set( true );
}
protected void resize( int width, int height )
{
if( terminal == null )
{
terminal = new Terminal( width, height, this::markTerminalChanged );
markTerminalChanged();
}
else
{
terminal.resize( width, height );
}
}
public void delete()
{
if( terminal != null )
{
terminal = null;
markTerminalChanged();
}
}
public void update()
{
terminalChangedLastFrame = terminalChanged.getAndSet( false );
}
public boolean hasTerminalChanged()
{
return terminalChangedLastFrame;
}
@Override
public Terminal getTerminal()
{
return terminal;
}
@Override
public boolean isColour()
{
return colour;
}
public TerminalState write()
{
return new TerminalState( colour, terminal );
}
public void writeDescription( NbtCompound nbt )
{
nbt.putBoolean( "colour", colour );
if( terminal != null )
{
NbtCompound terminal = new NbtCompound();
terminal.putInt( "term_width", this.terminal.getWidth() );
terminal.putInt( "term_height", this.terminal.getHeight() );
this.terminal.writeToNBT( terminal );
nbt.put( "terminal", terminal );
}
}
}

View File

@@ -0,0 +1,104 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. 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.NbtCompound;
import net.minecraft.util.ActionResult;
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 void onChunkUnloaded()
{
}
public final void updateBlock()
{
markDirty();
BlockPos pos = getPos();
BlockState state = getCachedState();
getWorld().updateListeners( pos, state, state, 3 );
}
@Nonnull
public ActionResult onActivate( PlayerEntity player, Hand hand, BlockHitResult hit )
{
return ActionResult.PASS;
}
public void onNeighbourChange( @Nonnull BlockPos neighbour )
{
}
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
{
}
protected void blockTick()
{
}
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 double getInteractRange( PlayerEntity player )
{
return 8.0;
}
@Override
public void fromClientTag( NbtCompound compoundTag )
{
readDescription( compoundTag );
}
protected void readDescription( @Nonnull NbtCompound nbt )
{
}
@Override
public NbtCompound toClientTag( NbtCompound compoundTag )
{
writeDescription( compoundTag );
return compoundTag;
}
protected void writeDescription( @Nonnull NbtCompound nbt )
{
}
}