mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-12 19:33:00 +00:00
Initial update to Fabric
This commit is contained in:
@@ -7,27 +7,26 @@
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
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.IBlockReader;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
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 ITileEntityProvider
|
||||
public abstract class BlockGeneric extends Block implements BlockEntityProvider
|
||||
{
|
||||
private final TileEntityType<? extends TileGeneric> type;
|
||||
private final BlockEntityType<? extends TileGeneric> type;
|
||||
|
||||
public BlockGeneric( Properties settings, TileEntityType<? extends TileGeneric> type )
|
||||
public BlockGeneric( Settings settings, BlockEntityType<? extends TileGeneric> type )
|
||||
{
|
||||
super( settings );
|
||||
this.type = type;
|
||||
@@ -35,52 +34,45 @@ public abstract class BlockGeneric extends Block implements ITileEntityProvider
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void onReplaced( @Nonnull IBlockState block, @Nonnull World world, @Nonnull BlockPos pos, IBlockState replace, boolean bool )
|
||||
public final void onBlockRemoved( @Nonnull BlockState block, @Nonnull World world, @Nonnull BlockPos pos, BlockState replace, boolean bool )
|
||||
{
|
||||
if( block.getBlock() == replace.getBlock() ) return;
|
||||
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
super.onReplaced( block, world, pos, replace, bool );
|
||||
world.removeTileEntity( pos );
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
super.onBlockRemoved( block, world, pos, replace, bool );
|
||||
world.removeBlockEntity( pos );
|
||||
if( tile instanceof TileGeneric ) ((TileGeneric) tile).destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean onBlockActivated( IBlockState state, World world, BlockPos pos, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
public final boolean activate( BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
return tile instanceof TileGeneric && ((TileGeneric) tile).onActivate( player, hand, side, hitX, hitY, hitZ );
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
return tile instanceof TileGeneric && ((TileGeneric) tile).onActivate( player, hand, hit );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
@SuppressWarnings( "deprecation" )
|
||||
public final void neighborChanged( IBlockState state, World world, BlockPos pos, Block neighbourBlock, BlockPos neighbourPos )
|
||||
public final void neighborUpdate( BlockState state, World world, BlockPos pos, Block neighbourBlock, BlockPos neighbourPos, boolean flag )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
super.neighborUpdate( state, world, pos, neighbourBlock, neighbourPos, flag );
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbourPos );
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onNeighborChange( IBlockState state, IWorldReader world, BlockPos pos, BlockPos neighbour )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourTileEntityChange( neighbour );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void tick( IBlockState state, World world, BlockPos pos, Random rand )
|
||||
public void onScheduledTick( BlockState state, World world, BlockPos pos, Random rand )
|
||||
{
|
||||
TileEntity te = world.getTileEntity( pos );
|
||||
BlockEntity te = world.getBlockEntity( pos );
|
||||
if( te instanceof TileGeneric ) ((TileGeneric) te).blockTick();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TileEntity createNewTileEntity( @Nonnull IBlockReader world )
|
||||
public BlockEntity createBlockEntity( BlockView blockView )
|
||||
{
|
||||
return type.create();
|
||||
return type.instantiate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class ClientTerminal implements ITerminal
|
||||
{
|
||||
@@ -47,12 +47,12 @@ public class ClientTerminal implements ITerminal
|
||||
return m_colour;
|
||||
}
|
||||
|
||||
public void readDescription( NBTTagCompound nbt )
|
||||
public void readDescription( CompoundTag nbt )
|
||||
{
|
||||
m_colour = nbt.getBoolean( "colour" );
|
||||
if( nbt.contains( "terminal" ) )
|
||||
if( nbt.containsKey( "terminal" ) )
|
||||
{
|
||||
NBTTagCompound terminal = nbt.getCompound( "terminal" );
|
||||
CompoundTag terminal = nbt.getCompound( "terminal" );
|
||||
resizeTerminal( terminal.getInt( "term_width" ), terminal.getInt( "term_height" ) );
|
||||
m_terminal.readFromNBT( terminal );
|
||||
}
|
||||
|
||||
@@ -6,36 +6,35 @@
|
||||
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.util.AbstractRecipe;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import dan200.computercraft.shared.util.ColourTracker;
|
||||
import dan200.computercraft.shared.util.ColourUtils;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.RecipeSerializers;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.recipe.RecipeSerializer;
|
||||
import net.minecraft.recipe.SpecialRecipeSerializer;
|
||||
import net.minecraft.recipe.crafting.SpecialCraftingRecipe;
|
||||
import net.minecraft.util.DyeColor;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ColourableRecipe extends AbstractRecipe
|
||||
public class ColourableRecipe extends SpecialCraftingRecipe
|
||||
{
|
||||
public ColourableRecipe( ResourceLocation id )
|
||||
public ColourableRecipe( Identifier id )
|
||||
{
|
||||
super( id );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches( @Nonnull IInventory inv, @Nonnull World world )
|
||||
public boolean matches( @Nonnull CraftingInventory inv, @Nonnull World world )
|
||||
{
|
||||
boolean hasColourable = false;
|
||||
boolean hasDye = false;
|
||||
for( int i = 0; i < inv.getSizeInventory(); i++ )
|
||||
for( int i = 0; i < inv.getInvSize(); i++ )
|
||||
{
|
||||
ItemStack stack = inv.getStackInSlot( i );
|
||||
ItemStack stack = inv.getInvStack( i );
|
||||
if( stack.isEmpty() ) continue;
|
||||
|
||||
if( stack.getItem() instanceof IColouredItem )
|
||||
@@ -58,15 +57,15 @@ public class ColourableRecipe extends AbstractRecipe
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getCraftingResult( @Nonnull IInventory inv )
|
||||
public ItemStack craft( @Nonnull CraftingInventory inv )
|
||||
{
|
||||
ItemStack colourable = ItemStack.EMPTY;
|
||||
|
||||
ColourTracker tracker = new ColourTracker();
|
||||
|
||||
for( int i = 0; i < inv.getSizeInventory(); i++ )
|
||||
for( int i = 0; i < inv.getInvSize(); i++ )
|
||||
{
|
||||
ItemStack stack = inv.getStackInSlot( i );
|
||||
ItemStack stack = inv.getInvStack( i );
|
||||
|
||||
if( stack.isEmpty() ) continue;
|
||||
|
||||
@@ -76,7 +75,7 @@ public class ColourableRecipe extends AbstractRecipe
|
||||
}
|
||||
else
|
||||
{
|
||||
EnumDyeColor dye = ColourUtils.getStackColour( stack );
|
||||
DyeColor dye = ColourUtils.getStackColour( stack );
|
||||
if( dye == null ) continue;
|
||||
|
||||
Colour colour = Colour.fromInt( 15 - dye.getId() );
|
||||
@@ -89,19 +88,17 @@ public class ColourableRecipe extends AbstractRecipe
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFit( int x, int y )
|
||||
public boolean fits( int x, int y )
|
||||
{
|
||||
return x >= 2 && y >= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public IRecipeSerializer<?> getSerializer()
|
||||
public RecipeSerializer<?> getSerializer()
|
||||
{
|
||||
return SERIALIZER;
|
||||
}
|
||||
|
||||
public static final IRecipeSerializer<?> SERIALIZER = new RecipeSerializers.SimpleSerializer<>(
|
||||
ComputerCraft.MOD_ID + ":colour", ColourableRecipe::new
|
||||
);
|
||||
public static final RecipeSerializer<?> SERIALIZER = new SpecialRecipeSerializer<>( ColourableRecipe::new );
|
||||
}
|
||||
|
||||
@@ -7,22 +7,23 @@
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.shared.util.InventoryUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.container.Container;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.Hand;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ContainerHeldItem extends Container
|
||||
{
|
||||
private final ItemStack m_stack;
|
||||
private final EnumHand m_hand;
|
||||
private final Hand m_hand;
|
||||
|
||||
public ContainerHeldItem( EntityPlayer player, EnumHand hand )
|
||||
public ContainerHeldItem( int id, PlayerEntity player, Hand hand )
|
||||
{
|
||||
super( null, id );
|
||||
m_hand = hand;
|
||||
m_stack = InventoryUtil.copyItem( player.getHeldItem( hand ) );
|
||||
m_stack = InventoryUtil.copyItem( player.getStackInHand( hand ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -32,11 +33,11 @@ public class ContainerHeldItem extends Container
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith( @Nonnull EntityPlayer player )
|
||||
public boolean canUse( @Nonnull PlayerEntity player )
|
||||
{
|
||||
if( !player.isAlive() ) return false;
|
||||
|
||||
ItemStack stack = player.getHeldItem( m_hand );
|
||||
ItemStack stack = player.getStackInHand( m_hand );
|
||||
return stack == m_stack || !stack.isEmpty() && !m_stack.isEmpty() && stack.getItem() == m_stack.getItem();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -17,12 +17,12 @@ import javax.annotation.Nonnull;
|
||||
public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider
|
||||
{
|
||||
@Override
|
||||
public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
|
||||
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, EnumFacing side )
|
||||
public static int getDefaultBundledRedstoneOutput( World world, BlockPos pos, Direction side )
|
||||
{
|
||||
Block block = world.getBlockState( pos ).getBlock();
|
||||
if( block instanceof IBundledRedstoneBlock )
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
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, EnumFacing side );
|
||||
boolean getBundledRedstoneConnectivity( World world, BlockPos pos, Direction side );
|
||||
|
||||
int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side );
|
||||
int getBundledRedstoneOutput( World world, BlockPos pos, Direction side );
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public interface IColouredItem
|
||||
{
|
||||
@@ -27,15 +27,15 @@ public interface IColouredItem
|
||||
|
||||
static int getColourBasic( ItemStack stack )
|
||||
{
|
||||
NBTTagCompound tag = stack.getTag();
|
||||
return tag != null && tag.contains( NBT_COLOUR ) ? tag.getInt( NBT_COLOUR ) : -1;
|
||||
CompoundTag tag = stack.getTag();
|
||||
return tag != null && tag.containsKey( NBT_COLOUR ) ? tag.getInt( NBT_COLOUR ) : -1;
|
||||
}
|
||||
|
||||
static void setColourBasic( ItemStack stack, int colour )
|
||||
{
|
||||
if( colour == -1 )
|
||||
{
|
||||
NBTTagCompound tag = stack.getTag();
|
||||
CompoundTag tag = stack.getTag();
|
||||
if( tag != null ) tag.remove( NBT_COLOUR );
|
||||
}
|
||||
else
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@@ -86,12 +86,12 @@ public class ServerTerminal implements ITerminal
|
||||
|
||||
// Networking stuff
|
||||
|
||||
public void writeDescription( NBTTagCompound nbt )
|
||||
public void writeDescription( CompoundTag nbt )
|
||||
{
|
||||
nbt.putBoolean( "colour", m_colour );
|
||||
if( m_terminal != null )
|
||||
{
|
||||
NBTTagCompound terminal = new NBTTagCompound();
|
||||
CompoundTag terminal = new CompoundTag();
|
||||
terminal.putInt( "term_width", m_terminal.getWidth() );
|
||||
terminal.putInt( "term_height", m_terminal.getHeight() );
|
||||
m_terminal.writeToNBT( terminal );
|
||||
|
||||
@@ -6,22 +6,21 @@
|
||||
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
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 TileEntity
|
||||
public abstract class TileGeneric extends BlockEntity implements BlockEntityClientSerializable
|
||||
{
|
||||
public TileGeneric( TileEntityType<? extends TileGeneric> type )
|
||||
public TileGeneric( BlockEntityType<? extends TileGeneric> type )
|
||||
{
|
||||
super( type );
|
||||
}
|
||||
@@ -34,12 +33,12 @@ public abstract class TileGeneric extends TileEntity
|
||||
{
|
||||
markDirty();
|
||||
BlockPos pos = getPos();
|
||||
IBlockState state = getBlockState();
|
||||
getWorld().markBlockRangeForRenderUpdate( pos, pos );
|
||||
getWorld().notifyBlockUpdate( pos, state, state, 3 );
|
||||
BlockState state = getCachedState();
|
||||
getWorld().scheduleBlockRender( pos );
|
||||
getWorld().updateListeners( pos, state, state, 3 );
|
||||
}
|
||||
|
||||
public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ )
|
||||
public boolean onActivate( PlayerEntity player, Hand hand, BlockHitResult hit )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -56,58 +55,40 @@ public abstract class TileGeneric extends TileEntity
|
||||
{
|
||||
}
|
||||
|
||||
protected double getInteractRange( EntityPlayer player )
|
||||
protected double getInteractRange( PlayerEntity player )
|
||||
{
|
||||
return 8.0;
|
||||
}
|
||||
|
||||
public boolean isUsable( EntityPlayer player, boolean ignoreRange )
|
||||
public boolean isUsable( PlayerEntity player, boolean ignoreRange )
|
||||
{
|
||||
if( player == null || !player.isAlive() || getWorld().getTileEntity( getPos() ) != this ) return false;
|
||||
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.getDistanceSq( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= range * range;
|
||||
player.squaredDistanceTo( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= range * range;
|
||||
}
|
||||
|
||||
protected void writeDescription( @Nonnull NBTTagCompound nbt )
|
||||
protected void writeDescription( @Nonnull CompoundTag nbt )
|
||||
{
|
||||
}
|
||||
|
||||
protected void readDescription( @Nonnull NBTTagCompound nbt )
|
||||
protected void readDescription( @Nonnull CompoundTag nbt )
|
||||
{
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final SPacketUpdateTileEntity getUpdatePacket()
|
||||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
writeDescription( nbt );
|
||||
return new SPacketUpdateTileEntity( pos, 0, nbt );
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onDataPacket( NetworkManager net, SPacketUpdateTileEntity packet )
|
||||
public final CompoundTag toClientTag( CompoundTag tag )
|
||||
{
|
||||
if( packet.getTileEntityType() == 0 ) readDescription( packet.getNbtCompound() );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public NBTTagCompound getUpdateTag()
|
||||
{
|
||||
NBTTagCompound tag = super.getUpdateTag();
|
||||
writeDescription( tag );
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdateTag( @Nonnull NBTTagCompound tag )
|
||||
public final void fromClientTag( CompoundTag tag )
|
||||
{
|
||||
super.handleUpdateTag( tag );
|
||||
readDescription( tag );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user