mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-02 22:53:15 +00:00
Compare commits
6 Commits
v1.16.1-1.
...
v1.16.1-1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b102a8142 | ||
|
|
ac7979fb46 | ||
|
|
c8a6888a2f | ||
|
|
9ce33f8a3f | ||
|
|
d51851e763 | ||
|
|
fb70a1a998 |
@@ -10,7 +10,7 @@ do use the issue templates - they provide a useful hint on what information to p
|
||||
|
||||
## Developing
|
||||
In order to develop CC: Tweaked, you'll need to download the source code and then run it. This is a pretty simple
|
||||
process.
|
||||
process. When building on Windows, Use `gradlew.bat` instead of `./gradlew`.
|
||||
|
||||
- **Clone the repository:** `git clone https://github.com/SquidDev-CC/CC-Tweaked.git && cd CC-Tweaked`
|
||||
- **Setup Forge:** `./gradlew build`
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Mod properties
|
||||
mod_version=1.90.1
|
||||
mod_version=1.90.2
|
||||
|
||||
# Minecraft properties (update mods.toml when changing)
|
||||
mc_version=1.16.1
|
||||
forge_version=32.0.69
|
||||
forge_version=32.0.75
|
||||
mappings_version=20200707-1.16.1
|
||||
|
||||
@@ -8,6 +8,7 @@ package dan200.computercraft;
|
||||
import dan200.computercraft.api.turtle.event.TurtleAction;
|
||||
import dan200.computercraft.core.apis.http.options.Action;
|
||||
import dan200.computercraft.core.apis.http.options.AddressRule;
|
||||
import dan200.computercraft.core.asm.GenericSource;
|
||||
import dan200.computercraft.shared.Config;
|
||||
import dan200.computercraft.shared.Registry;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
|
||||
@@ -16,6 +17,7 @@ import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
||||
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
|
||||
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
|
||||
import dan200.computercraft.shared.turtle.upgrades.*;
|
||||
import dan200.computercraft.shared.util.ServiceUtil;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -133,5 +135,6 @@ public final class ComputerCraft
|
||||
{
|
||||
Config.setup();
|
||||
Registry.setup();
|
||||
GenericSource.setup( () -> ServiceUtil.loadServicesForge( GenericSource.class ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ package dan200.computercraft.core.asm;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.lua.LuaFunction;
|
||||
import dan200.computercraft.shared.peripheral.generic.GenericPeripheralProvider;
|
||||
import dan200.computercraft.shared.util.ServiceUtil;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -16,11 +17,12 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* A generic source of {@link LuaMethod} functions. This allows for injecting methods onto objects you do not own.
|
||||
@@ -42,6 +44,18 @@ public interface GenericSource
|
||||
@Nonnull
|
||||
ResourceLocation id();
|
||||
|
||||
/**
|
||||
* Register a stream of generic sources.
|
||||
*
|
||||
* @param sources The source of generic methods.
|
||||
* @see ServiceUtil For ways to load this. Sadly {@link java.util.ServiceLoader} is broken under Forge, but we don't
|
||||
* want to add a hard-dep on Forge within core either.
|
||||
*/
|
||||
static void setup( Supplier<Stream<GenericSource>> sources )
|
||||
{
|
||||
GenericMethod.sources = sources;
|
||||
}
|
||||
|
||||
/**
|
||||
* A generic method is a method belonging to a {@link GenericSource} with a known target.
|
||||
*/
|
||||
@@ -51,6 +65,7 @@ public interface GenericSource
|
||||
final LuaFunction annotation;
|
||||
final Class<?> target;
|
||||
|
||||
static Supplier<Stream<GenericSource>> sources;
|
||||
private static List<GenericMethod> cache;
|
||||
|
||||
GenericMethod( Method method, LuaFunction annotation, Class<?> target )
|
||||
@@ -68,10 +83,16 @@ public interface GenericSource
|
||||
static List<GenericMethod> all()
|
||||
{
|
||||
if( cache != null ) return cache;
|
||||
return cache = StreamSupport
|
||||
.stream( ServiceLoader.load( GenericSource.class, GenericSource.class.getClassLoader() ).spliterator(), false )
|
||||
if( sources == null )
|
||||
{
|
||||
ComputerCraft.log.warn( "Getting GenericMethods without a provider" );
|
||||
return cache = Collections.emptyList();
|
||||
}
|
||||
|
||||
return cache = sources.get()
|
||||
.flatMap( x -> Arrays.stream( x.getClass().getDeclaredMethods() ) )
|
||||
.map( method -> {
|
||||
.map( method ->
|
||||
{
|
||||
LuaFunction annotation = method.getAnnotation( LuaFunction.class );
|
||||
if( annotation == null ) return null;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.Style;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.util.text.event.ClickEvent;
|
||||
import net.minecraft.util.text.event.HoverEvent;
|
||||
@@ -57,10 +58,8 @@ public final class CommandCopy
|
||||
|
||||
public static ITextComponent createCopyText( String text )
|
||||
{
|
||||
StringTextComponent name = new StringTextComponent( text );
|
||||
name.getStyle()
|
||||
return new StringTextComponent( text ).func_230530_a_( Style.EMPTY
|
||||
.setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, PREFIX + text ) )
|
||||
.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent( "gui.computercraft.tooltip.copy" ) ) );
|
||||
return name;
|
||||
.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent( "gui.computercraft.tooltip.copy" ) ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,14 +21,12 @@ public final class ChatHelpers
|
||||
|
||||
public static IFormattableTextComponent coloured( String text, TextFormatting colour )
|
||||
{
|
||||
IFormattableTextComponent component = new StringTextComponent( text == null ? "" : text );
|
||||
component.getStyle().setFormatting( colour );
|
||||
return component;
|
||||
return new StringTextComponent( text == null ? "" : text ).func_240699_a_( colour );
|
||||
}
|
||||
|
||||
public static <T extends IFormattableTextComponent> T coloured( T component, TextFormatting colour )
|
||||
{
|
||||
component.getStyle().setFormatting( colour );
|
||||
component.func_240699_a_( colour );
|
||||
return component;
|
||||
}
|
||||
|
||||
@@ -74,11 +72,11 @@ public final class ChatHelpers
|
||||
{
|
||||
Style style = component.getStyle();
|
||||
|
||||
if( style.getColor() == null ) style.setFormatting( TextFormatting.YELLOW );
|
||||
style.setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, command ) );
|
||||
style.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, toolTip ) );
|
||||
if( style.getColor() == null ) style = style.setFormatting( TextFormatting.YELLOW );
|
||||
style = style.setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, command ) );
|
||||
style = style.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, toolTip ) );
|
||||
|
||||
return component;
|
||||
return component.func_230530_a_( style );
|
||||
}
|
||||
|
||||
public static IFormattableTextComponent header( String text )
|
||||
|
||||
@@ -25,6 +25,7 @@ import net.minecraft.tileentity.SignTileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
@@ -129,6 +130,12 @@ public final class TurtlePlayer extends FakePlayer
|
||||
return Registry.ModEntities.TURTLE_PLAYER.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3d getPositionVec()
|
||||
{
|
||||
return new Vector3d( getPosX(), getPosY(), getPosZ() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEyeHeight( @Nonnull Pose pose )
|
||||
{
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public final class ServiceUtil
|
||||
{
|
||||
private static final Type AUTO_SERVICE = Type.getType( "Lcom/google/auto/service/AutoService;" );
|
||||
|
||||
private ServiceUtil()
|
||||
{
|
||||
}
|
||||
|
||||
public static <T> Stream<T> loadServices( Class<T> target )
|
||||
{
|
||||
return StreamSupport.stream( ServiceLoader.load( target, ServiceUtil.class.getClassLoader() ).spliterator(), false );
|
||||
}
|
||||
|
||||
public static <T> Stream<T> loadServicesForge( Class<T> target )
|
||||
{
|
||||
Type type = Type.getType( target );
|
||||
ClassLoader loader = ComputerCraftAPI.class.getClassLoader();
|
||||
return ModList.get().getAllScanData().stream()
|
||||
.flatMap( x -> x.getAnnotations().stream() )
|
||||
.filter( x -> x.getAnnotationType().equals( AUTO_SERVICE ) )
|
||||
.filter( x -> {
|
||||
Object value = x.getAnnotationData().get( "value" );
|
||||
return value instanceof List<?> && ((List<?>) value).contains( type );
|
||||
} )
|
||||
.flatMap( x -> {
|
||||
try
|
||||
{
|
||||
Class<?> klass = loader.loadClass( x.getClassType().getClassName() );
|
||||
if( !target.isAssignableFrom( klass ) )
|
||||
{
|
||||
ComputerCraft.log.error( "{} is not a subtype of {}", x.getClassType().getClassName(), target.getName() );
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
Class<? extends T> casted = klass.asSubclass( target );
|
||||
return Stream.of( casted.newInstance() );
|
||||
}
|
||||
catch( ReflectiveOperationException e )
|
||||
{
|
||||
ComputerCraft.log.error( "Cannot load {}", x.getClassType(), e );
|
||||
return Stream.empty();
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,9 @@
|
||||
# New features in CC: Tweaked 1.90.2
|
||||
|
||||
* Fix generic peripherals not being registered outside a dev environment.
|
||||
* Fix `turtle.attack()` failing.
|
||||
* Correctly set styles for the output of `/computercraft` commands.
|
||||
|
||||
# New features in CC: Tweaked 1.90.1
|
||||
|
||||
* Update to Forge 32.0.69
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
New features in CC: Tweaked 1.90.1
|
||||
New features in CC: Tweaked 1.90.2
|
||||
|
||||
* Update to Forge 32.0.69
|
||||
* Fix generic peripherals not being registered outside a dev environment.
|
||||
* Fix `turtle.attack()` failing.
|
||||
* Correctly set styles for the output of `/computercraft` commands.
|
||||
|
||||
Type "help changelog" to see the full version history.
|
||||
|
||||
Reference in New Issue
Block a user