mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-15 11:45:42 +00:00
Merge branch 'mc-1.17.x' into mc-1.18.x
This commit is contained in:
commit
632db1cfa5
@ -50,7 +50,6 @@ tasks.withType(JavaExec).configureEach {
|
|||||||
sourceSets {
|
sourceSets {
|
||||||
main.java {
|
main.java {
|
||||||
exclude 'dan200/computercraft/shared/integration/jei/**'
|
exclude 'dan200/computercraft/shared/integration/jei/**'
|
||||||
exclude 'dan200/computercraft/shared/integration/morered/**'
|
|
||||||
}
|
}
|
||||||
main.resources {
|
main.resources {
|
||||||
srcDir 'src/generated/resources'
|
srcDir 'src/generated/resources'
|
||||||
@ -491,7 +490,7 @@ task checkRelease {
|
|||||||
}
|
}
|
||||||
check.dependsOn checkRelease
|
check.dependsOn checkRelease
|
||||||
|
|
||||||
def isStable = false
|
def isStable = true
|
||||||
|
|
||||||
curseforge {
|
curseforge {
|
||||||
apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ''
|
apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ''
|
||||||
|
@ -173,7 +173,6 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.rewind();
|
|
||||||
toUpload.add( new FileUpload( name, buffer, digest ) );
|
toUpload.add( new FileUpload( name, buffer, digest ) );
|
||||||
}
|
}
|
||||||
catch( IOException e )
|
catch( IOException e )
|
||||||
|
@ -106,7 +106,8 @@ class DfpwmStream implements AudioStream
|
|||||||
if( head == null ) break;
|
if( head == null ) break;
|
||||||
|
|
||||||
int toRead = Math.min( head.remaining(), result.remaining() );
|
int toRead = Math.min( head.remaining(), result.remaining() );
|
||||||
result.put( head.array(), head.position(), toRead ); // TODO: In 1.17 convert this to a ByteBuffer override
|
result.put( result.position(), head, head.position(), toRead );
|
||||||
|
result.position( result.position() + toRead );
|
||||||
head.position( head.position() + toRead );
|
head.position( head.position() + toRead );
|
||||||
|
|
||||||
if( head.hasRemaining() ) break;
|
if( head.hasRemaining() ) break;
|
||||||
|
@ -400,9 +400,6 @@ public final class Registry
|
|||||||
|
|
||||||
CauldronInteraction.WATER.put( ModItems.TURTLE_NORMAL.get(), ItemTurtle.CAULDRON_INTERACTION );
|
CauldronInteraction.WATER.put( ModItems.TURTLE_NORMAL.get(), ItemTurtle.CAULDRON_INTERACTION );
|
||||||
CauldronInteraction.WATER.put( ModItems.TURTLE_ADVANCED.get(), ItemTurtle.CAULDRON_INTERACTION );
|
CauldronInteraction.WATER.put( ModItems.TURTLE_ADVANCED.get(), ItemTurtle.CAULDRON_INTERACTION );
|
||||||
|
|
||||||
// Mod integration code.
|
|
||||||
// TODO: if( ModList.get().isLoaded( MoreRedIntegration.MOD_ID ) ) MoreRedIntegration.initialise();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerLoot()
|
public static void registerLoot()
|
||||||
|
@ -56,7 +56,7 @@ public interface IContainerComputer
|
|||||||
void continueUpload( @Nonnull UUID uploadId, @Nonnull List<FileSlice> slices );
|
void continueUpload( @Nonnull UUID uploadId, @Nonnull List<FileSlice> slices );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finish off an upload. This either writes the uploaded files or
|
* Finish off an upload. This either writes the uploaded files or informs the user that files will be overwritten.
|
||||||
*
|
*
|
||||||
* @param uploader The player uploading files.
|
* @param uploader The player uploading files.
|
||||||
* @param uploadId The unique ID of this upload.
|
* @param uploadId The unique ID of this upload.
|
||||||
|
@ -53,11 +53,6 @@ public class FileSlice
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes.rewind();
|
file.put( offset, bytes, bytes.position(), bytes.remaining() );
|
||||||
file.position( offset );
|
|
||||||
file.put( bytes );
|
|
||||||
file.rewind();
|
|
||||||
|
|
||||||
if( bytes.remaining() != 0 ) throw new IllegalStateException( "Should have read the whole buffer" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class FileUpload
|
|||||||
|
|
||||||
public boolean checksumMatches()
|
public boolean checksumMatches()
|
||||||
{
|
{
|
||||||
// This is meant to be a checksum. Doesn't need to be cryptographically secure, hence non constant time.
|
// This is meant to be a checksum. Doesn't need to be cryptographically secure, hence non-constant time.
|
||||||
byte[] digest = getDigest( bytes );
|
byte[] digest = getDigest( bytes );
|
||||||
return digest != null && Arrays.equals( checksum, digest );
|
return digest != null && Arrays.equals( checksum, digest );
|
||||||
}
|
}
|
||||||
@ -66,9 +66,8 @@ public class FileUpload
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bytes.rewind();
|
|
||||||
MessageDigest digest = MessageDigest.getInstance( "SHA-256" );
|
MessageDigest digest = MessageDigest.getInstance( "SHA-256" );
|
||||||
digest.update( bytes );
|
digest.update( bytes.duplicate() );
|
||||||
return digest.digest();
|
return digest.digest();
|
||||||
}
|
}
|
||||||
catch( NoSuchAlgorithmException e )
|
catch( NoSuchAlgorithmException e )
|
||||||
|
@ -1,123 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.integration.morered;
|
|
||||||
|
|
||||||
import commoble.morered.api.ChanneledPowerSupplier;
|
|
||||||
import commoble.morered.api.MoreRedAPI;
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
|
||||||
import dan200.computercraft.shared.common.IBundledRedstoneBlock;
|
|
||||||
import dan200.computercraft.shared.util.CapabilityUtil;
|
|
||||||
import dan200.computercraft.shared.util.FixedPointTileEntityType;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
|
||||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
|
||||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
public class MoreRedIntegration
|
|
||||||
{
|
|
||||||
public static final String MOD_ID = "morered";
|
|
||||||
|
|
||||||
private static final ResourceLocation ID = new ResourceLocation( ComputerCraft.MOD_ID, "morered" );
|
|
||||||
|
|
||||||
private static final class BundledPowerSupplier implements ICapabilityProvider, ChanneledPowerSupplier
|
|
||||||
{
|
|
||||||
private final IBundledRedstoneBlock block;
|
|
||||||
private final BlockEntity tile;
|
|
||||||
private LazyOptional<ChanneledPowerSupplier> instance;
|
|
||||||
|
|
||||||
private BundledPowerSupplier( IBundledRedstoneBlock block, BlockEntity tile )
|
|
||||||
{
|
|
||||||
this.block = block;
|
|
||||||
this.tile = tile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public <T> LazyOptional<T> getCapability( @Nonnull Capability<T> cap, @Nullable Direction side )
|
|
||||||
{
|
|
||||||
if( cap != MoreRedAPI.CHANNELED_POWER_CAPABILITY ) return LazyOptional.empty();
|
|
||||||
|
|
||||||
if( tile.isRemoved() || !block.getBundledRedstoneConnectivity( tile.getLevel(), tile.getBlockPos(), side ) )
|
|
||||||
{
|
|
||||||
return LazyOptional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (instance == null ? (instance = LazyOptional.of( () -> this )) : instance).cast();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPowerOnChannel( @Nonnull Level world, @Nonnull BlockPos wirePos, @Nonnull BlockState wireState, @Nullable Direction wireFace, int channel )
|
|
||||||
{
|
|
||||||
if( wireFace == null ) return 0;
|
|
||||||
|
|
||||||
BlockPos pos = wirePos.relative( wireFace );
|
|
||||||
BlockState state = world.getBlockState( pos );
|
|
||||||
if( !(state.getBlock() instanceof IBundledRedstoneBlock block) ) return 0;
|
|
||||||
|
|
||||||
return (block.getBundledRedstoneOutput( world, pos, wireFace.getOpposite() ) & (1 << channel)) != 0 ? 31 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void invalidate()
|
|
||||||
{
|
|
||||||
instance = CapabilityUtil.invalidate( instance );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void attachBlockCapabilities( AttachCapabilitiesEvent<BlockEntity> event )
|
|
||||||
{
|
|
||||||
BlockEntity tile = event.getObject();
|
|
||||||
if( !(tile.getType() instanceof FixedPointTileEntityType) ) return;
|
|
||||||
|
|
||||||
Block block = ((FixedPointTileEntityType<?>) tile.getType()).getBlock();
|
|
||||||
if( !(block instanceof IBundledRedstoneBlock) ) return;
|
|
||||||
|
|
||||||
BundledPowerSupplier provider = new BundledPowerSupplier( (IBundledRedstoneBlock) block, tile );
|
|
||||||
event.addCapability( ID, provider );
|
|
||||||
event.addListener( provider::invalidate );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void initialise()
|
|
||||||
{
|
|
||||||
MinecraftForge.EVENT_BUS.register( MoreRedIntegration.class );
|
|
||||||
ComputerCraftAPI.registerBundledRedstoneProvider( MoreRedIntegration::getBundledPower );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getBundledPower( Level world, BlockPos pos, Direction side )
|
|
||||||
{
|
|
||||||
BlockEntity tile = world.getBlockEntity( pos );
|
|
||||||
if( tile == null ) return -1;
|
|
||||||
|
|
||||||
ChanneledPowerSupplier power = CapabilityUtil.unwrapUnsafe( tile.getCapability( MoreRedAPI.CHANNELED_POWER_CAPABILITY, side ) );
|
|
||||||
if( power == null ) return -1;
|
|
||||||
|
|
||||||
BlockState state = tile.getBlockState();
|
|
||||||
|
|
||||||
// Skip ones already handled by CC. We can do this more efficiently.
|
|
||||||
if( state.getBlock() instanceof IBundledRedstoneBlock ) return -1;
|
|
||||||
|
|
||||||
int mask = 0;
|
|
||||||
for( int i = 0; i < 16; i++ )
|
|
||||||
{
|
|
||||||
mask |= power.getPowerOnChannel( world, pos, state, side, i ) > 0 ? (1 << i) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mask;
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared.network.server;
|
package dan200.computercraft.shared.network.server;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
|
||||||
import dan200.computercraft.shared.computer.core.IContainerComputer;
|
import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||||
import dan200.computercraft.shared.computer.upload.FileSlice;
|
import dan200.computercraft.shared.computer.upload.FileSlice;
|
||||||
@ -122,9 +121,9 @@ public class UploadFileMessage extends ComputerServerMessage
|
|||||||
buf.writeByte( slice.getFileId() );
|
buf.writeByte( slice.getFileId() );
|
||||||
buf.writeVarInt( slice.getOffset() );
|
buf.writeVarInt( slice.getOffset() );
|
||||||
|
|
||||||
slice.getBytes().rewind();
|
ByteBuffer bytes = slice.getBytes().duplicate();
|
||||||
buf.writeShort( slice.getBytes().remaining() );
|
buf.writeShort( bytes.remaining() );
|
||||||
buf.writeBytes( slice.getBytes() );
|
buf.writeBytes( bytes );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +157,6 @@ public class UploadFileMessage extends ComputerServerMessage
|
|||||||
|
|
||||||
int canWrite = Math.min( remaining, capacity - currentOffset );
|
int canWrite = Math.min( remaining, capacity - currentOffset );
|
||||||
|
|
||||||
ComputerCraft.log.info( "Adding slice from {} to {}", currentOffset, currentOffset + canWrite - 1 );
|
|
||||||
contents.position( currentOffset ).limit( currentOffset + canWrite );
|
contents.position( currentOffset ).limit( currentOffset + canWrite );
|
||||||
slices.add( new FileSlice( fileId, currentOffset, contents.slice() ) );
|
slices.add( new FileSlice( fileId, currentOffset, contents.slice() ) );
|
||||||
currentOffset += canWrite;
|
currentOffset += canWrite;
|
||||||
|
Loading…
Reference in New Issue
Block a user