mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-24 18:37:38 +00:00
Merge branch 'mc-1.15.x' into mc-1.16.x
This commit is contained in:
@@ -14,6 +14,7 @@ import dan200.computercraft.core.apis.http.*;
|
||||
import dan200.computercraft.core.apis.http.request.HttpRequest;
|
||||
import dan200.computercraft.core.apis.http.websocket.Websocket;
|
||||
import io.netty.handler.codec.http.DefaultHttpHeaders;
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import io.netty.handler.codec.http.HttpMethod;
|
||||
|
||||
@@ -179,7 +180,7 @@ public class HTTPAPI implements ILuaAPI
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static HttpHeaders getHeaders( @Nonnull Map<?, ?> headerTable ) throws LuaException
|
||||
private HttpHeaders getHeaders( @Nonnull Map<?, ?> headerTable ) throws LuaException
|
||||
{
|
||||
HttpHeaders headers = new DefaultHttpHeaders();
|
||||
for( Map.Entry<?, ?> entry : headerTable.entrySet() )
|
||||
@@ -197,6 +198,11 @@ public class HTTPAPI implements ILuaAPI
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !headers.contains( HttpHeaderNames.USER_AGENT ) )
|
||||
{
|
||||
headers.set( HttpHeaderNames.USER_AGENT, apiEnvironment.getComputerEnvironment().getUserAgent() );
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ public class RedstoneAPI implements ILuaAPI
|
||||
@LuaFunction
|
||||
public final int getBundledInput( ComputerSide side )
|
||||
{
|
||||
return environment.getBundledOutput( side );
|
||||
return environment.getBundledInput( side );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -80,10 +80,6 @@ public final class HttpRequestHandler extends SimpleChannelInboundHandler<HttpOb
|
||||
{
|
||||
request.headers().set( HttpHeaderNames.ACCEPT_CHARSET, "UTF-8" );
|
||||
}
|
||||
if( !request.headers().contains( HttpHeaderNames.USER_AGENT ) )
|
||||
{
|
||||
request.headers().set( HttpHeaderNames.USER_AGENT, this.request.environment().getComputerEnvironment().getUserAgent() );
|
||||
}
|
||||
request.headers().set( HttpHeaderNames.HOST, uri.getPort() < 0 ? uri.getHost() : uri.getHost() + ":" + uri.getPort() );
|
||||
request.headers().set( HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE );
|
||||
|
||||
|
||||
@@ -58,10 +58,10 @@ public class HttpResponseHandle implements ObjectSource
|
||||
* If multiple headers are sent with the same name, they will be combined with a comma.
|
||||
*
|
||||
* @return The response's headers.
|
||||
* @cc.usage Make a request to [example.computercraft.cc](https://example.computercraft.cc), and print the
|
||||
* @cc.usage Make a request to [example.tweaked.cc](https://example.tweaked.cc), and print the
|
||||
* returned headers.
|
||||
* <pre>{@code
|
||||
* local request = http.get("https://example.computercraft.cc")
|
||||
* local request = http.get("https://example.tweaked.cc")
|
||||
* print(textutils.serialize(request.getResponseHeaders()))
|
||||
* -- => {
|
||||
* -- [ "Content-Type" ] = "text/plain; charset=utf8",
|
||||
|
||||
@@ -22,14 +22,12 @@ import javax.annotation.Nonnull;
|
||||
|
||||
public class BlockModelProvider extends BlockStateProvider
|
||||
{
|
||||
private final ModelFile monitorBase;
|
||||
private final ModelFile orientable;
|
||||
private ModelFile monitorBase;
|
||||
private ModelFile orientable;
|
||||
|
||||
public BlockModelProvider( DataGenerator generator, ExistingFileHelper existingFileHelper )
|
||||
{
|
||||
super( generator, ComputerCraft.MOD_ID, existingFileHelper );
|
||||
monitorBase = models().getExistingFile( new ResourceLocation( ComputerCraft.MOD_ID, "block/monitor_base" ) );
|
||||
orientable = models().getExistingFile( new ResourceLocation( "block/orientable" ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -42,6 +40,9 @@ public class BlockModelProvider extends BlockStateProvider
|
||||
@Override
|
||||
protected void registerStatesAndModels()
|
||||
{
|
||||
monitorBase = models().getExistingFile( new ResourceLocation( ComputerCraft.MOD_ID, "block/monitor_base" ) );
|
||||
orientable = models().getExistingFile( new ResourceLocation( "block/orientable" ) );
|
||||
|
||||
registerMonitors( Registry.ModBlocks.MONITOR_NORMAL.get() );
|
||||
registerMonitors( Registry.ModBlocks.MONITOR_ADVANCED.get() );
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public final class RecordMedia implements IMedia
|
||||
|
||||
try
|
||||
{
|
||||
return ObfuscationReflectionHelper.getPrivateValue( MusicDiscItem.class, (MusicDiscItem) item, "sound" );
|
||||
return ObfuscationReflectionHelper.getPrivateValue( MusicDiscItem.class, (MusicDiscItem) item, "field_185076_b" );
|
||||
}
|
||||
catch( UnableToAccessFieldException | UnableToFindFieldException e )
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.network.NetworkHandler;
|
||||
import dan200.computercraft.shared.network.client.MonitorClientMessage;
|
||||
import dan200.computercraft.shared.network.client.TerminalState;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
@@ -28,6 +29,7 @@ import java.util.Queue;
|
||||
public final class MonitorWatcher
|
||||
{
|
||||
private static final Queue<TileMonitor> watching = new ArrayDeque<>();
|
||||
private static final Queue<PlayerUpdate> playerUpdates = new ArrayDeque<>();
|
||||
|
||||
private MonitorWatcher()
|
||||
{
|
||||
@@ -58,10 +60,8 @@ public final class MonitorWatcher
|
||||
ServerMonitor serverMonitor = getMonitor( monitor );
|
||||
if( serverMonitor == null || monitor.enqueued ) continue;
|
||||
|
||||
// We use the cached terminal state if available - this is guaranteed to
|
||||
TerminalState state = monitor.cached;
|
||||
if( state == null ) state = monitor.cached = serverMonitor.write();
|
||||
NetworkHandler.sendToPlayer( event.getPlayer(), new MonitorClientMessage( monitor.getBlockPos(), state ) );
|
||||
// The chunk hasn't been sent to the client yet, so we can't send an update. Do it on tick end.
|
||||
playerUpdates.add( new PlayerUpdate( event.getPlayer(), monitor ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,23 @@ public final class MonitorWatcher
|
||||
{
|
||||
if( event.phase != TickEvent.Phase.END ) return;
|
||||
|
||||
PlayerUpdate playerUpdate;
|
||||
while( (playerUpdate = playerUpdates.poll()) != null )
|
||||
{
|
||||
TileMonitor tile = playerUpdate.monitor;
|
||||
if( tile.enqueued || tile.isRemoved() ) continue;
|
||||
|
||||
ServerMonitor monitor = getMonitor( tile );
|
||||
if( monitor == null ) continue;
|
||||
|
||||
// Some basic sanity checks to the player. It's possible they're no longer within range, but that's harder
|
||||
// to track efficiently.
|
||||
ServerPlayerEntity player = playerUpdate.player;
|
||||
if( !player.isAlive() || player.getLevel() != tile.getLevel() ) continue;
|
||||
|
||||
NetworkHandler.sendToPlayer( playerUpdate.player, new MonitorClientMessage( tile.getBlockPos(), getState( tile, monitor ) ) );
|
||||
}
|
||||
|
||||
long limit = ComputerCraft.monitorBandwidth;
|
||||
boolean obeyLimit = limit > 0;
|
||||
|
||||
@@ -90,7 +107,7 @@ public final class MonitorWatcher
|
||||
continue;
|
||||
}
|
||||
|
||||
TerminalState state = tile.cached = monitor.write();
|
||||
TerminalState state = getState( tile, monitor );
|
||||
NetworkHandler.sendToAllTracking( new MonitorClientMessage( pos, state ), chunk );
|
||||
|
||||
limit -= state.size();
|
||||
@@ -101,4 +118,23 @@ public final class MonitorWatcher
|
||||
{
|
||||
return !monitor.isRemoved() && monitor.getXIndex() == 0 && monitor.getYIndex() == 0 ? monitor.getCachedServerMonitor() : null;
|
||||
}
|
||||
|
||||
private static TerminalState getState( TileMonitor tile, ServerMonitor monitor )
|
||||
{
|
||||
TerminalState state = tile.cached;
|
||||
if( state == null ) state = tile.cached = monitor.write();
|
||||
return state;
|
||||
}
|
||||
|
||||
private static final class PlayerUpdate
|
||||
{
|
||||
final ServerPlayerEntity player;
|
||||
final TileMonitor monitor;
|
||||
|
||||
private PlayerUpdate( ServerPlayerEntity player, TileMonitor monitor )
|
||||
{
|
||||
this.player = player;
|
||||
this.monitor = monitor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,6 +182,10 @@ public class TurtleAPI implements ILuaAPI
|
||||
/**
|
||||
* Place a block or item into the world in front of the turtle.
|
||||
*
|
||||
* "Placing" an item allows it to interact with blocks and entities in front of the turtle. For instance, buckets
|
||||
* can pick up and place down fluids, and wheat can be used to breed cows. However, you cannot use {@link #place} to
|
||||
* perform arbitrary block interactions, such as clicking buttons or flipping levers.
|
||||
*
|
||||
* @param args Arguments to place.
|
||||
* @return The turtle command result.
|
||||
* @cc.tparam [opt] string text When placing a sign, set its contents to this text.
|
||||
@@ -202,6 +206,7 @@ public class TurtleAPI implements ILuaAPI
|
||||
* @cc.tparam [opt] string text When placing a sign, set its contents to this text.
|
||||
* @cc.treturn boolean Whether the block could be placed.
|
||||
* @cc.treturn string|nil The reason the block was not placed.
|
||||
* @see #place For more information about placing items.
|
||||
*/
|
||||
@LuaFunction
|
||||
public final MethodResult placeUp( IArguments args )
|
||||
@@ -217,6 +222,7 @@ public class TurtleAPI implements ILuaAPI
|
||||
* @cc.tparam [opt] string text When placing a sign, set its contents to this text.
|
||||
* @cc.treturn boolean Whether the block could be placed.
|
||||
* @cc.treturn string|nil The reason the block was not placed.
|
||||
* @see #place For more information about placing items.
|
||||
*/
|
||||
@LuaFunction
|
||||
public final MethodResult placeDown( IArguments args )
|
||||
|
||||
@@ -15,10 +15,8 @@ import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
public class TurtleCompareCommand implements ITurtleCommand
|
||||
@@ -52,19 +50,6 @@ public class TurtleCompareCommand implements ITurtleCommand
|
||||
Block lookAtBlock = lookAtState.getBlock();
|
||||
if( !lookAtBlock.isAir( lookAtState, world, newPosition ) )
|
||||
{
|
||||
// Try getSilkTouchDrop first
|
||||
if( !lookAtBlock.hasTileEntity( lookAtState ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
Method method = ObfuscationReflectionHelper.findMethod( Block.class, "func_180643_i", BlockState.class );
|
||||
lookAtStack = (ItemStack) method.invoke( lookAtBlock, lookAtState );
|
||||
}
|
||||
catch( ReflectiveOperationException | RuntimeException ignored )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// See if the block drops anything with the same ID as itself
|
||||
// (try 5 times to try and beat random number generators)
|
||||
for( int i = 0; i < 5 && lookAtStack.isEmpty(); i++ )
|
||||
|
||||
Reference in New Issue
Block a user