1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-29 21:02:59 +00:00

remap with yarrnforge

This commit is contained in:
Devan-Kerman
2020-08-29 19:38:26 -05:00
parent fbcf26bdc9
commit 324519575c
566 changed files with 57853 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2020. 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.BlockState;
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 net.minecraft.world.WorldView;
import net.minecraftforge.fml.RegistryObject;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Random;
public abstract class BlockGeneric extends Block
{
private final RegistryObject<? extends BlockEntityType<? extends TileGeneric>> type;
public BlockGeneric( Settings settings, RegistryObject<? extends BlockEntityType<? extends TileGeneric>> type )
{
super( settings );
this.type = type;
}
@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 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
public final void onNeighborChange( BlockState state, WorldView world, BlockPos pos, BlockPos neighbour )
{
BlockEntity tile = world.getBlockEntity( pos );
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourTileEntityChange( neighbour );
}
@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();
}
@Override
public boolean hasTileEntity( BlockState state )
{
return true;
}
@Nullable
@Override
public BlockEntity createTileEntity( @Nonnull BlockState state, @Nonnull BlockView world )
{
return type.get().instantiate();
}
@Override
public boolean canBeReplacedByLeaves( BlockState state, WorldView world, BlockPos pos )
{
return false;
}
}

View File

@@ -0,0 +1,80 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2020. 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;
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;
return changed;
}
// ITerminal implementation
@Override
public Terminal getTerminal()
{
return m_terminal;
}
@Override
public boolean isColour()
{
return m_colour;
}
public void read( TerminalState state )
{
m_colour = state.colour;
if( state.hasTerminal() )
{
resizeTerminal( state.width, state.height );
state.apply( m_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;
}
}
}

View File

@@ -0,0 +1,103 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2020. 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 final class ColourableRecipe extends SpecialCraftingRecipe
{
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 getCraftingResult( @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 );
}

View File

@@ -0,0 +1,81 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
import dan200.computercraft.shared.Registry;
import dan200.computercraft.shared.network.container.HeldItemContainerData;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
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, HeldItemContainerData data )
{
return new ContainerHeldItem( Registry.ModContainers.PRINTOUT.get(), 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 NamedScreenHandlerFactory
{
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;
this.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 );
}
}
}

View File

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

View File

@@ -0,0 +1,15 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2020. 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,85 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2020. 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;
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()
{
m_terminalChangedLastFrame = m_terminalChanged.getAndSet( false );
}
public boolean hasTerminalChanged()
{
return m_terminalChangedLastFrame;
}
@Override
public Terminal getTerminal()
{
return m_terminal;
}
@Override
public boolean isColour()
{
return m_colour;
}
public TerminalState write()
{
return new TerminalState( m_colour, m_terminal );
}
}

View File

@@ -0,0 +1,112 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
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.network.ClientConnection;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
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
{
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 );
}
@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()
{
}
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 )
{
}
@Nonnull
@Override
public final BlockEntityUpdateS2CPacket toUpdatePacket()
{
CompoundTag nbt = new CompoundTag();
writeDescription( nbt );
return new BlockEntityUpdateS2CPacket( pos, 0, nbt );
}
@Override
public final void onDataPacket( ClientConnection net, BlockEntityUpdateS2CPacket packet )
{
if( packet.getBlockEntityType() == 0 ) readDescription( packet.getCompoundTag() );
}
@Nonnull
@Override
public CompoundTag toInitialChunkDataTag()
{
CompoundTag tag = super.toInitialChunkDataTag();
writeDescription( tag );
return tag;
}
@Override
public void handleUpdateTag( @Nonnull BlockState state, @Nonnull CompoundTag tag )
{
super.handleUpdateTag( state, tag );
readDescription( tag );
}
}