mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-06 22:04:39 +00:00
Update CT integration
Sadly we have to disable -Werror, as the annotation class files are not available on maven, so this produces a warning.
This commit is contained in:
parent
037cbabb32
commit
4320a4f851
@ -139,7 +139,7 @@ jar {
|
|||||||
|
|
||||||
[compileJava, compileTestJava].forEach {
|
[compileJava, compileTestJava].forEach {
|
||||||
it.configure {
|
it.configure {
|
||||||
options.compilerArgs << "-Xlint" << "-Xlint:-processing" << "-Werror"
|
options.compilerArgs << "-Xlint" << "-Xlint:-processing"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
|||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import dan200.computercraft.shared.util.InventoryUtil;
|
import dan200.computercraft.shared.util.InventoryUtil;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.fml.ModContainer;
|
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
import net.minecraftforge.fml.ModLoadingContext;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -21,21 +20,18 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public final class TurtleUpgrades
|
public final class TurtleUpgrades
|
||||||
{
|
{
|
||||||
public static class Wrapper
|
private static class Wrapper
|
||||||
{
|
{
|
||||||
final ITurtleUpgrade upgrade;
|
final ITurtleUpgrade upgrade;
|
||||||
final int legacyId;
|
|
||||||
final String id;
|
final String id;
|
||||||
final String modId;
|
final String modId;
|
||||||
boolean enabled;
|
boolean enabled;
|
||||||
|
|
||||||
public Wrapper( ITurtleUpgrade upgrade )
|
public Wrapper( ITurtleUpgrade upgrade )
|
||||||
{
|
{
|
||||||
ModContainer mc = ModLoadingContext.get().getActiveContainer();
|
|
||||||
|
|
||||||
this.upgrade = upgrade;
|
this.upgrade = upgrade;
|
||||||
this.id = upgrade.getUpgradeID().toString();
|
this.id = upgrade.getUpgradeID().toString();
|
||||||
this.modId = mc != null && mc.getModId() != null ? mc.getModId() : null;
|
this.modId = ModLoadingContext.get().getActiveNamespace();
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,19 +40,21 @@ public final class TurtleUpgrades
|
|||||||
|
|
||||||
private static final Map<String, ITurtleUpgrade> upgrades = new HashMap<>();
|
private static final Map<String, ITurtleUpgrade> upgrades = new HashMap<>();
|
||||||
private static final IdentityHashMap<ITurtleUpgrade, Wrapper> wrappers = new IdentityHashMap<>();
|
private static final IdentityHashMap<ITurtleUpgrade, Wrapper> wrappers = new IdentityHashMap<>();
|
||||||
|
private static boolean needsRebuild;
|
||||||
|
|
||||||
private TurtleUpgrades() {}
|
private TurtleUpgrades() {}
|
||||||
|
|
||||||
public static void register( @Nonnull ITurtleUpgrade upgrade )
|
public static void register( @Nonnull ITurtleUpgrade upgrade )
|
||||||
{
|
{
|
||||||
Objects.requireNonNull( upgrade, "upgrade cannot be null" );
|
Objects.requireNonNull( upgrade, "upgrade cannot be null" );
|
||||||
|
rebuild();
|
||||||
|
|
||||||
Wrapper wrapper = new Wrapper( upgrade );
|
Wrapper wrapper = new Wrapper( upgrade );
|
||||||
String id = wrapper.id;
|
String id = wrapper.id;
|
||||||
ITurtleUpgrade existing = upgrades.get( id );
|
ITurtleUpgrade existing = upgrades.get( id );
|
||||||
if( existing != null )
|
if( existing != null )
|
||||||
{
|
{
|
||||||
throw new IllegalStateException( "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turle'. UpgradeID '" + id + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'" );
|
throw new IllegalStateException( "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. Upgrade ID '" + id + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'" );
|
||||||
}
|
}
|
||||||
|
|
||||||
upgrades.put( id, upgrade );
|
upgrades.put( id, upgrade );
|
||||||
@ -66,15 +64,10 @@ public final class TurtleUpgrades
|
|||||||
@Nullable
|
@Nullable
|
||||||
public static ITurtleUpgrade get( String id )
|
public static ITurtleUpgrade get( String id )
|
||||||
{
|
{
|
||||||
|
rebuild();
|
||||||
return upgrades.get( id );
|
return upgrades.get( id );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static ITurtleUpgrade get( int id )
|
|
||||||
{
|
|
||||||
return legacyUpgrades.get( id );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static String getOwner( @Nonnull ITurtleUpgrade upgrade )
|
public static String getOwner( @Nonnull ITurtleUpgrade upgrade )
|
||||||
{
|
{
|
||||||
@ -86,12 +79,14 @@ public final class TurtleUpgrades
|
|||||||
{
|
{
|
||||||
if( stack.isEmpty() ) return null;
|
if( stack.isEmpty() ) return null;
|
||||||
|
|
||||||
for( ITurtleUpgrade upgrade : upgrades.values() )
|
for( Wrapper wrapper : wrappers.values() )
|
||||||
{
|
{
|
||||||
ItemStack craftingStack = upgrade.getCraftingItem();
|
if( !wrapper.enabled ) continue;
|
||||||
|
|
||||||
|
ItemStack craftingStack = wrapper.upgrade.getCraftingItem();
|
||||||
if( !craftingStack.isEmpty() && InventoryUtil.areItemsSimilar( stack, craftingStack ) )
|
if( !craftingStack.isEmpty() && InventoryUtil.areItemsSimilar( stack, craftingStack ) )
|
||||||
{
|
{
|
||||||
return upgrade;
|
return wrapper.upgrade;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,9 +116,9 @@ public final class TurtleUpgrades
|
|||||||
return Arrays.stream( vanilla ).filter( x -> x != null && wrappers.get( x ).enabled );
|
return Arrays.stream( vanilla ).filter( x -> x != null && wrappers.get( x ).enabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Iterable<ITurtleUpgrade> getUpgrades()
|
public static Stream<ITurtleUpgrade> getUpgrades()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableCollection( upgrades.values() );
|
return wrappers.values().stream().filter( x -> x.enabled ).map( x -> x.upgrade );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean suitableForFamily( ComputerFamily family, ITurtleUpgrade upgrade )
|
public static boolean suitableForFamily( ComputerFamily family, ITurtleUpgrade upgrade )
|
||||||
@ -131,6 +126,41 @@ public final class TurtleUpgrades
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rebuild the cache of turtle upgrades. This is done before querying the cache or registering new upgrades.
|
||||||
|
*/
|
||||||
|
private static void rebuild()
|
||||||
|
{
|
||||||
|
if( !needsRebuild ) return;
|
||||||
|
|
||||||
|
upgrades.clear();
|
||||||
|
for( Wrapper wrapper : wrappers.values() )
|
||||||
|
{
|
||||||
|
if( !wrapper.enabled ) continue;
|
||||||
|
|
||||||
|
ITurtleUpgrade existing = upgrades.get( wrapper.id );
|
||||||
|
if( existing != null )
|
||||||
|
{
|
||||||
|
ComputerCraft.log.error( "Error registering '" + wrapper.upgrade.getUnlocalisedAdjective() + " Turtle'." +
|
||||||
|
" Upgrade ID '" + wrapper.id + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'" );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
upgrades.put( wrapper.id, wrapper.upgrade );
|
||||||
|
}
|
||||||
|
|
||||||
|
needsRebuild = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void enable( ITurtleUpgrade upgrade )
|
||||||
|
{
|
||||||
|
Wrapper wrapper = wrappers.get( upgrade );
|
||||||
|
if( wrapper.enabled ) return;
|
||||||
|
|
||||||
|
wrapper.enabled = true;
|
||||||
|
needsRebuild = true;
|
||||||
|
}
|
||||||
|
|
||||||
public static void disable( ITurtleUpgrade upgrade )
|
public static void disable( ITurtleUpgrade upgrade )
|
||||||
{
|
{
|
||||||
Wrapper wrapper = wrappers.get( upgrade );
|
Wrapper wrapper = wrappers.get( upgrade );
|
||||||
@ -138,6 +168,11 @@ public final class TurtleUpgrades
|
|||||||
|
|
||||||
wrapper.enabled = false;
|
wrapper.enabled = false;
|
||||||
upgrades.remove( wrapper.id );
|
upgrades.remove( wrapper.id );
|
||||||
if( wrapper.legacyId >= 0 ) legacyUpgrades.remove( wrapper.legacyId );
|
}
|
||||||
|
|
||||||
|
public static void remove( ITurtleUpgrade upgrade )
|
||||||
|
{
|
||||||
|
wrappers.remove( upgrade );
|
||||||
|
needsRebuild = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.shared.integration.crafttweaker;
|
||||||
|
|
||||||
|
import com.blamejared.crafttweaker.api.logger.ILogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger which tracks if it has any messages.
|
||||||
|
*/
|
||||||
|
public final class TrackingLogger
|
||||||
|
{
|
||||||
|
private final ILogger logger;
|
||||||
|
private boolean ok = true;
|
||||||
|
|
||||||
|
public TrackingLogger( ILogger logger )
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOk()
|
||||||
|
{
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warning( String message )
|
||||||
|
{
|
||||||
|
ok = false;
|
||||||
|
logger.warning( message );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void error( String message )
|
||||||
|
{
|
||||||
|
ok = false;
|
||||||
|
logger.error( message );
|
||||||
|
}
|
||||||
|
}
|
@ -6,65 +6,67 @@
|
|||||||
|
|
||||||
package dan200.computercraft.shared.integration.crafttweaker;
|
package dan200.computercraft.shared.integration.crafttweaker;
|
||||||
|
|
||||||
import crafttweaker.CraftTweakerAPI;
|
import com.blamejared.crafttweaker.api.CraftTweakerAPI;
|
||||||
import crafttweaker.annotations.ModOnly;
|
import com.blamejared.crafttweaker.api.annotations.ZenRegister;
|
||||||
import crafttweaker.annotations.ZenDoc;
|
import com.blamejared.crafttweaker.api.item.IItemStack;
|
||||||
import crafttweaker.annotations.ZenRegister;
|
|
||||||
import crafttweaker.api.item.IItemStack;
|
|
||||||
import crafttweaker.api.minecraft.CraftTweakerMC;
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
|
||||||
import dan200.computercraft.shared.integration.crafttweaker.actions.AddTurtleTool;
|
import dan200.computercraft.shared.integration.crafttweaker.actions.AddTurtleTool;
|
||||||
import dan200.computercraft.shared.integration.crafttweaker.actions.RemoveTurtleUpgradeByItem;
|
import dan200.computercraft.shared.integration.crafttweaker.actions.RemoveTurtleUpgradeByItem;
|
||||||
import dan200.computercraft.shared.integration.crafttweaker.actions.RemoveTurtleUpgradeByName;
|
import dan200.computercraft.shared.integration.crafttweaker.actions.RemoveTurtleUpgradeByName;
|
||||||
import stanhebben.zenscript.annotations.ZenClass;
|
import org.openzen.zencode.java.ZenCodeType;
|
||||||
import stanhebben.zenscript.annotations.ZenMethod;
|
|
||||||
|
|
||||||
@ZenRegister
|
@ZenRegister
|
||||||
@ZenClass( "dan200.computercraft.turtle" )
|
@ZenCodeType.Name( "dan200.computercraft.turtle" )
|
||||||
@ModOnly( ComputerCraft.MOD_ID )
|
|
||||||
public class TurtleTweaker
|
public class TurtleTweaker
|
||||||
{
|
{
|
||||||
@ZenMethod
|
/**
|
||||||
@ZenDoc( "Remove a turtle upgrade with the given id" )
|
* Remove a turtle upgrade with the given id
|
||||||
|
*
|
||||||
|
* @param upgrade The ID of the to remove
|
||||||
|
*/
|
||||||
|
@ZenCodeType.Method
|
||||||
public static void removeUpgrade( String upgrade )
|
public static void removeUpgrade( String upgrade )
|
||||||
{
|
{
|
||||||
CraftTweakerAPI.apply( new RemoveTurtleUpgradeByName( upgrade ) );
|
CraftTweakerAPI.apply( new RemoveTurtleUpgradeByName( upgrade ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ZenMethod
|
/**
|
||||||
@ZenDoc( "Remove a turtle upgrade crafted with the given item stack" )
|
* Remove a turtle upgrade crafted with the given item stack"
|
||||||
|
*
|
||||||
|
* @param stack The stack with which the upgrade is crafted.
|
||||||
|
*/
|
||||||
|
@ZenCodeType.Method
|
||||||
public static void removeUpgrade( IItemStack stack )
|
public static void removeUpgrade( IItemStack stack )
|
||||||
{
|
{
|
||||||
CraftTweakerAPI.apply( new RemoveTurtleUpgradeByItem( CraftTweakerMC.getItemStack( stack ) ) );
|
CraftTweakerAPI.apply( new RemoveTurtleUpgradeByItem( stack.getInternal() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ZenMethod
|
/**
|
||||||
@ZenDoc( "Add a new turtle tool with the given id, which crafts and acts using the given stack." )
|
* Add a new turtle tool with the given id, which crafts and acts using the given stack.
|
||||||
|
*
|
||||||
|
* @param id The new upgrade's ID
|
||||||
|
* @param stack The stack used for crafting the upgrade and used by the turtle as a tool.
|
||||||
|
*/
|
||||||
|
@ZenCodeType.Method
|
||||||
public static void addTool( String id, IItemStack stack )
|
public static void addTool( String id, IItemStack stack )
|
||||||
{
|
{
|
||||||
addTool( id, stack, stack, "tool" );
|
addTool( id, stack, stack, "tool" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ZenMethod
|
@ZenCodeType.Method
|
||||||
@ZenDoc( "Add a new turtle tool with the given id, which is crafted with one item, and uses another." )
|
|
||||||
public static void addTool( String id, IItemStack craftingStack, IItemStack toolStack )
|
public static void addTool( String id, IItemStack craftingStack, IItemStack toolStack )
|
||||||
{
|
{
|
||||||
addTool( id, craftingStack, toolStack, "tool" );
|
addTool( id, craftingStack, toolStack, "tool" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ZenMethod
|
@ZenCodeType.Method
|
||||||
@ZenDoc( "Add a new turtle tool with the given id, which crafts and acts using the given stack. You may also" +
|
|
||||||
"specify a 'kind' of tool, which limits what blocks the turtle can break (for instance, an 'axe' may only break wood)." )
|
|
||||||
public static void addTool( String id, IItemStack stack, String kind )
|
public static void addTool( String id, IItemStack stack, String kind )
|
||||||
{
|
{
|
||||||
addTool( id, stack, stack, kind );
|
addTool( id, stack, stack, kind );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ZenMethod
|
@ZenCodeType.Method
|
||||||
@ZenDoc( "Add a new turtle tool with the given id, which is crafted with one item, and uses another. You may also" +
|
|
||||||
"specify a 'kind' of tool, which limits what blocks the turtle can break (for instance, an 'axe' may only break wood)." )
|
|
||||||
public static void addTool( String id, IItemStack craftingStack, IItemStack toolStack, String kind )
|
public static void addTool( String id, IItemStack craftingStack, IItemStack toolStack, String kind )
|
||||||
{
|
{
|
||||||
CraftTweakerAPI.apply( new AddTurtleTool( id, CraftTweakerMC.getItemStack( craftingStack ), CraftTweakerMC.getItemStack( toolStack ), kind ) );
|
CraftTweakerAPI.apply( new AddTurtleTool( id, craftingStack.getInternal(), toolStack.getInternal(), kind ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,20 +6,24 @@
|
|||||||
|
|
||||||
package dan200.computercraft.shared.integration.crafttweaker.actions;
|
package dan200.computercraft.shared.integration.crafttweaker.actions;
|
||||||
|
|
||||||
|
import com.blamejared.crafttweaker.api.actions.IUndoableAction;
|
||||||
|
import com.blamejared.crafttweaker.api.logger.ILogger;
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.shared.TurtleUpgrades;
|
import dan200.computercraft.shared.TurtleUpgrades;
|
||||||
|
import dan200.computercraft.shared.integration.crafttweaker.TrackingLogger;
|
||||||
import dan200.computercraft.shared.turtle.upgrades.*;
|
import dan200.computercraft.shared.turtle.upgrades.*;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.fml.LogicalSide;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new turtle tool.
|
* Register a new turtle tool.
|
||||||
*/
|
*/
|
||||||
public class AddTurtleTool implements IAction
|
public class AddTurtleTool implements IUndoableAction
|
||||||
{
|
{
|
||||||
private interface Factory
|
private interface Factory
|
||||||
{
|
{
|
||||||
@ -42,6 +46,8 @@ public class AddTurtleTool implements IAction
|
|||||||
private final ItemStack toolItem;
|
private final ItemStack toolItem;
|
||||||
private final String kind;
|
private final String kind;
|
||||||
|
|
||||||
|
private ITurtleUpgrade upgrade;
|
||||||
|
|
||||||
public AddTurtleTool( String id, ItemStack craftItem, ItemStack toolItem, String kind )
|
public AddTurtleTool( String id, ItemStack craftItem, ItemStack toolItem, String kind )
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@ -53,16 +59,22 @@ public class AddTurtleTool implements IAction
|
|||||||
@Override
|
@Override
|
||||||
public void apply()
|
public void apply()
|
||||||
{
|
{
|
||||||
Factory factory = kinds.get( kind );
|
ITurtleUpgrade upgrade = this.upgrade;
|
||||||
if( factory == null )
|
if( upgrade == null )
|
||||||
{
|
{
|
||||||
ComputerCraft.log.error( "Unknown turtle upgrade kind '{}' (this should have been rejected by verify!)", kind );
|
Factory factory = kinds.get( kind );
|
||||||
return;
|
if( factory == null )
|
||||||
|
{
|
||||||
|
ComputerCraft.log.error( "Unknown turtle upgrade kind '{}' (this should have been rejected by verify!)", kind );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
upgrade = this.upgrade = factory.create( new ResourceLocation( id ), craftItem, toolItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TurtleUpgrades.register( factory.create( new ResourceLocation( id ), craftItem, toolItem ) );
|
TurtleUpgrades.register( upgrade );
|
||||||
}
|
}
|
||||||
catch( RuntimeException e )
|
catch( RuntimeException e )
|
||||||
{
|
{
|
||||||
@ -76,21 +88,40 @@ public class AddTurtleTool implements IAction
|
|||||||
return String.format( "Add new turtle %s '%s' (crafted with '%s', uses a '%s')", kind, id, craftItem, toolItem );
|
return String.format( "Add new turtle %s '%s' (crafted with '%s', uses a '%s')", kind, id, craftItem, toolItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<String> getValidationProblem()
|
@Override
|
||||||
|
public void undo()
|
||||||
{
|
{
|
||||||
if( craftItem.isEmpty() ) return Optional.of( "Crafting item stack is empty." );
|
if( upgrade != null ) TurtleUpgrades.remove( upgrade );
|
||||||
if( craftItem.hasTagCompound() && !craftItem.getTagCompound().isEmpty() )
|
}
|
||||||
{
|
|
||||||
return Optional.of( "Crafting item has NBT." );
|
@Override
|
||||||
}
|
public String describeUndo()
|
||||||
if( toolItem.isEmpty() ) return Optional.of( "Tool item stack is empty." );
|
{
|
||||||
if( !kinds.containsKey( kind ) ) return Optional.of( String.format( "Unknown kind '%s'.", kind ) );
|
return String.format( "Removing turtle upgrade %s.", id );
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validate( ILogger logger )
|
||||||
|
{
|
||||||
|
TrackingLogger trackLog = new TrackingLogger( logger );
|
||||||
|
|
||||||
|
if( craftItem.isEmpty() ) trackLog.warning( "Crafting item stack is empty." );
|
||||||
|
|
||||||
|
if( craftItem.hasTag() && !craftItem.getTag().isEmpty() ) trackLog.warning( "Crafting item has NBT." );
|
||||||
|
if( toolItem.isEmpty() ) trackLog.error( "Tool item stack is empty." );
|
||||||
|
|
||||||
|
if( !kinds.containsKey( kind ) ) trackLog.error( String.format( "Unknown kind '%s'.", kind ) );
|
||||||
|
|
||||||
if( TurtleUpgrades.get( id ) != null )
|
if( TurtleUpgrades.get( id ) != null )
|
||||||
{
|
{
|
||||||
return Optional.of( String.format( "An upgrade with the same name ('%s') has already been registered.", id ) );
|
trackLog.error( String.format( "An upgrade with the same name ('%s') has already been registered.", id ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.empty();
|
return trackLog.isOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldApplyOn( LogicalSide side )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
package dan200.computercraft.shared.integration.crafttweaker.actions;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An extension of {@link IAction} with a single validation function, rather than two.
|
|
||||||
*/
|
|
||||||
public interface IAction extends crafttweaker.IAction
|
|
||||||
{
|
|
||||||
default Optional<String> getValidationProblem()
|
|
||||||
{
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default boolean validate()
|
|
||||||
{
|
|
||||||
return !getValidationProblem().isPresent();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default String describeInvalid()
|
|
||||||
{
|
|
||||||
return getValidationProblem().orElse( "No problems found." );
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,18 +6,20 @@
|
|||||||
|
|
||||||
package dan200.computercraft.shared.integration.crafttweaker.actions;
|
package dan200.computercraft.shared.integration.crafttweaker.actions;
|
||||||
|
|
||||||
|
import com.blamejared.crafttweaker.api.actions.IUndoableAction;
|
||||||
|
import com.blamejared.crafttweaker.api.logger.ILogger;
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.shared.TurtleUpgrades;
|
import dan200.computercraft.shared.TurtleUpgrades;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.fml.LogicalSide;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a turtle upgrade crafted with the given stack.
|
* Removes a turtle upgrade crafted with the given stack.
|
||||||
*/
|
*/
|
||||||
public class RemoveTurtleUpgradeByItem implements IAction
|
public class RemoveTurtleUpgradeByItem implements IUndoableAction
|
||||||
{
|
{
|
||||||
private final ItemStack stack;
|
private final ItemStack stack;
|
||||||
|
private ITurtleUpgrade upgrade;
|
||||||
|
|
||||||
public RemoveTurtleUpgradeByItem( ItemStack stack )
|
public RemoveTurtleUpgradeByItem( ItemStack stack )
|
||||||
{
|
{
|
||||||
@ -27,7 +29,7 @@ public class RemoveTurtleUpgradeByItem implements IAction
|
|||||||
@Override
|
@Override
|
||||||
public void apply()
|
public void apply()
|
||||||
{
|
{
|
||||||
ITurtleUpgrade upgrade = TurtleUpgrades.get( stack );
|
ITurtleUpgrade upgrade = this.upgrade = TurtleUpgrades.get( stack );
|
||||||
if( upgrade != null ) TurtleUpgrades.disable( upgrade );
|
if( upgrade != null ) TurtleUpgrades.disable( upgrade );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,13 +40,32 @@ public class RemoveTurtleUpgradeByItem implements IAction
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getValidationProblem()
|
public void undo()
|
||||||
|
{
|
||||||
|
if( this.upgrade != null ) TurtleUpgrades.enable( upgrade );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describeUndo()
|
||||||
|
{
|
||||||
|
return String.format( "Adding back turtle upgrades crafted with '%s'", stack );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validate( ILogger logger )
|
||||||
{
|
{
|
||||||
if( TurtleUpgrades.get( stack ) == null )
|
if( TurtleUpgrades.get( stack ) == null )
|
||||||
{
|
{
|
||||||
return Optional.of( String.format( "Unknown turtle upgrade crafted with '%s'.", stack ) );
|
logger.error( String.format( "Unknown turtle upgrade crafted with '%s'.", stack ) );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.empty();
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldApplyOn( LogicalSide side )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,19 @@
|
|||||||
|
|
||||||
package dan200.computercraft.shared.integration.crafttweaker.actions;
|
package dan200.computercraft.shared.integration.crafttweaker.actions;
|
||||||
|
|
||||||
|
import com.blamejared.crafttweaker.api.actions.IUndoableAction;
|
||||||
|
import com.blamejared.crafttweaker.api.logger.ILogger;
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.shared.TurtleUpgrades;
|
import dan200.computercraft.shared.TurtleUpgrades;
|
||||||
|
import net.minecraftforge.fml.LogicalSide;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a turtle upgrade with the given id.
|
* Removes a turtle upgrade with the given id.
|
||||||
*/
|
*/
|
||||||
public class RemoveTurtleUpgradeByName implements IAction
|
public class RemoveTurtleUpgradeByName implements IUndoableAction
|
||||||
{
|
{
|
||||||
private final String id;
|
private final String id;
|
||||||
|
private ITurtleUpgrade upgrade;
|
||||||
|
|
||||||
public RemoveTurtleUpgradeByName( String id )
|
public RemoveTurtleUpgradeByName( String id )
|
||||||
{
|
{
|
||||||
@ -26,7 +28,7 @@ public class RemoveTurtleUpgradeByName implements IAction
|
|||||||
@Override
|
@Override
|
||||||
public void apply()
|
public void apply()
|
||||||
{
|
{
|
||||||
ITurtleUpgrade upgrade = TurtleUpgrades.get( id );
|
ITurtleUpgrade upgrade = this.upgrade = TurtleUpgrades.get( id );
|
||||||
if( upgrade != null ) TurtleUpgrades.disable( upgrade );
|
if( upgrade != null ) TurtleUpgrades.disable( upgrade );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,13 +39,32 @@ public class RemoveTurtleUpgradeByName implements IAction
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getValidationProblem()
|
public void undo()
|
||||||
|
{
|
||||||
|
if( this.upgrade != null ) TurtleUpgrades.enable( upgrade );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describeUndo()
|
||||||
|
{
|
||||||
|
return String.format( "Adding back turtle upgrade '%s'", id );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validate( ILogger logger )
|
||||||
{
|
{
|
||||||
if( TurtleUpgrades.get( id ) == null )
|
if( TurtleUpgrades.get( id ) == null )
|
||||||
{
|
{
|
||||||
return Optional.of( String.format( "Unknown turtle upgrade '%s'.", id ) );
|
logger.error( String.format( "Unknown turtle upgrade '%s'.", id ) );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.empty();
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldApplyOn( LogicalSide side )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,12 +76,10 @@ public class JEIComputerCraft implements IModPlugin
|
|||||||
List<ItemStack> upgradeItems = new ArrayList<>();
|
List<ItemStack> upgradeItems = new ArrayList<>();
|
||||||
for( ComputerFamily family : MAIN_FAMILIES )
|
for( ComputerFamily family : MAIN_FAMILIES )
|
||||||
{
|
{
|
||||||
for( ITurtleUpgrade upgrade : TurtleUpgrades.getUpgrades() )
|
TurtleUpgrades.getUpgrades()
|
||||||
{
|
.filter( x -> TurtleUpgrades.suitableForFamily( family, x ) )
|
||||||
if( !TurtleUpgrades.suitableForFamily( family, upgrade ) ) continue;
|
.map( x -> TurtleItemFactory.create( -1, null, -1, family, null, x, 0, null ) )
|
||||||
|
.forEach( upgradeItems::add );
|
||||||
upgradeItems.add( TurtleItemFactory.create( -1, null, -1, family, null, upgrade, 0, null ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
for( IPocketUpgrade upgrade : PocketUpgrades.getUpgrades() )
|
for( IPocketUpgrade upgrade : PocketUpgrades.getUpgrades() )
|
||||||
{
|
{
|
||||||
|
@ -53,15 +53,14 @@ class RecipeResolver implements IRecipeManagerPlugin
|
|||||||
if( initialised ) return;
|
if( initialised ) return;
|
||||||
initialised = true;
|
initialised = true;
|
||||||
|
|
||||||
for( ITurtleUpgrade upgrade : TurtleUpgrades.getUpgrades() )
|
TurtleUpgrades.getUpgrades().forEach( upgrade -> {
|
||||||
{
|
|
||||||
ItemStack stack = upgrade.getCraftingItem();
|
ItemStack stack = upgrade.getCraftingItem();
|
||||||
if( stack.isEmpty() ) continue;
|
if( stack.isEmpty() ) return;
|
||||||
|
|
||||||
UpgradeInfo info = new UpgradeInfo( stack, upgrade );
|
UpgradeInfo info = new UpgradeInfo( stack, upgrade );
|
||||||
upgradeItemLookup.computeIfAbsent( stack.getItem(), k -> new ArrayList<>( 1 ) ).add( info );
|
upgradeItemLookup.computeIfAbsent( stack.getItem(), k -> new ArrayList<>( 1 ) ).add( info );
|
||||||
turtleUpgrades.add( info );
|
turtleUpgrades.add( info );
|
||||||
}
|
} );
|
||||||
|
|
||||||
for( IPocketUpgrade upgrade : PocketUpgrades.getUpgrades() )
|
for( IPocketUpgrade upgrade : PocketUpgrades.getUpgrades() )
|
||||||
{
|
{
|
||||||
|
@ -66,12 +66,10 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem
|
|||||||
ComputerFamily family = getFamily();
|
ComputerFamily family = getFamily();
|
||||||
|
|
||||||
list.add( create( -1, null, -1, null, null, 0, null ) );
|
list.add( create( -1, null, -1, null, null, 0, null ) );
|
||||||
for( ITurtleUpgrade upgrade : TurtleUpgrades.getVanillaUpgrades() )
|
TurtleUpgrades.getVanillaUpgrades()
|
||||||
{
|
.filter( x -> TurtleUpgrades.suitableForFamily( family, x ) )
|
||||||
if( !TurtleUpgrades.suitableForFamily( family, upgrade ) ) continue;
|
.map( x -> create( -1, null, -1, null, x, 0, null ) )
|
||||||
|
.forEach( list::add );
|
||||||
list.add( create( -1, null, -1, null, upgrade, 0, null ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -65,7 +65,7 @@ public class TurtleTool extends AbstractTurtleUpgrade
|
|||||||
|
|
||||||
public TurtleTool( ResourceLocation id, ItemStack craftItem, ItemStack toolItem )
|
public TurtleTool( ResourceLocation id, ItemStack craftItem, ItemStack toolItem )
|
||||||
{
|
{
|
||||||
super( id, -1, TurtleUpgradeType.Tool, craftItem );
|
super( id, TurtleUpgradeType.Tool, craftItem );
|
||||||
this.item = toolItem;
|
this.item = toolItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user