mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-26 14:53:03 +00:00
- Updated to new Forge version
- Added script locking
This commit is contained in:
1 parent
ea47aec970
commit
00bcf843e5
9 files changed
+93
-7
No files matched your search
@@ -586,6 +586,29 @@ public class MineTweakerImplementationAPI {
|
||||
events.onPlayerLoggedOut(LISTEN_LOGOUT);
|
||||
}
|
||||
|
||||
|
||||
byte[] currentScript = MineTweakerAPI.tweaker.getScriptData();
|
||||
if (currentScript != null) {
|
||||
System.out.println("Already loaded a script before");
|
||||
|
||||
// alread loaded a script
|
||||
byte[] stagedScript = MineTweakerAPI.tweaker.getStagedScriptData();
|
||||
|
||||
if (Arrays.equals(currentScript, stagedScript)) {
|
||||
System.out.println("No reload needed");
|
||||
return; // no reload necessary
|
||||
}
|
||||
|
||||
if (MineTweakerAPI.game.isLocked()) {
|
||||
System.out.println("Reload blocked");
|
||||
MineTweakerAPI.game.signalLockError();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
System.out.println("First time loading a script, go ahead");
|
||||
}
|
||||
|
||||
|
||||
MineTweakerAPI.tweaker.rollback();
|
||||
|
||||
if (MineTweakerAPI.server != null) {
|
||||
|
||||
@@ -94,4 +94,26 @@ public interface IGame {
|
||||
*/
|
||||
@ZenMethod
|
||||
public String localize(String key, String lang);
|
||||
|
||||
/**
|
||||
* Lock the game and disable reload. Recommended for distributed versions.
|
||||
*
|
||||
* Once locked, reload cannot be unlocked - a game restart is required to
|
||||
* alter the scripts.
|
||||
*/
|
||||
@ZenMethod
|
||||
public void lock();
|
||||
|
||||
/**
|
||||
* Returns the lock state. True if locked.
|
||||
*
|
||||
* @return lock state
|
||||
*/
|
||||
@ZenGetter("locked")
|
||||
public boolean isLocked();
|
||||
|
||||
/**
|
||||
* Signals a modified script while in locked mode.
|
||||
*/
|
||||
public void signalLockError();
|
||||
}
|
||||
@@ -18,6 +18,13 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
*/
|
||||
@ZenClass("minetweaker.IMineTweaker")
|
||||
public interface ITweaker {
|
||||
/**
|
||||
* Retrieves the script data to be loaded.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public byte[] getStagedScriptData();
|
||||
|
||||
/**
|
||||
* Executes a specified MineTweaker action. Will print a log message and
|
||||
* adds the action to the undo list.
|
||||
|
||||
@@ -45,6 +45,11 @@ public class MTTweaker implements ITweaker {
|
||||
private IScriptProvider scriptProvider;
|
||||
private byte[] scriptData;
|
||||
|
||||
@Override
|
||||
public byte[] getStagedScriptData() {
|
||||
return ScriptProviderMemory.collect(scriptProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(IUndoableAction action) {
|
||||
MineTweakerAPI.logInfo(action.describe());
|
||||
|
||||
@@ -21,12 +21,14 @@ import minetweaker.api.item.IItemDefinition;
|
||||
import minetweaker.api.liquid.ILiquidDefinition;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import minetweaker.api.world.IBiome;
|
||||
import minetweaker.mc1710.GuiCannotRemodify;
|
||||
import minetweaker.mc1710.entity.MCEntityDefinition;
|
||||
import minetweaker.mc1710.item.MCItemDefinition;
|
||||
import minetweaker.mc1710.liquid.MCLiquidDefinition;
|
||||
import minetweaker.mc1710.util.MineTweakerHacks;
|
||||
import minetweaker.mc1710.util.MineTweakerPlatformUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
@@ -40,6 +42,8 @@ public class MCGame implements IGame {
|
||||
|
||||
public static final MCGame INSTANCE = new MCGame();
|
||||
|
||||
private boolean locked = false;
|
||||
|
||||
private MCGame() {}
|
||||
|
||||
@Override
|
||||
@@ -111,6 +115,32 @@ public class MCGame implements IGame {
|
||||
public String localize(String key, String lang) {
|
||||
return LanguageRegistry.instance().getStringLocalization(key, lang);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lock()
|
||||
{
|
||||
locked = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocked()
|
||||
{
|
||||
return locked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void signalLockError()
|
||||
{
|
||||
MineTweakerAPI.getLogger().logError("Reload of scripts blocked (script lock)");
|
||||
|
||||
if (Minecraft.isGuiEnabled()) {
|
||||
Minecraft.getMinecraft().displayGuiScreen(
|
||||
new GuiCannotRemodify(
|
||||
"Minecraft has been tweaked for another server",
|
||||
"with modifications that cannot be rolled back.",
|
||||
"Please restart your game."));
|
||||
}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
|
||||
@@ -73,14 +73,14 @@ public class MCLiquidStack implements ILiquidStack {
|
||||
|
||||
@Override
|
||||
public ILiquidStack withTag(IData data) {
|
||||
FluidStack result = new FluidStack(stack.fluidID, stack.amount);
|
||||
FluidStack result = new FluidStack(stack.getFluid(), stack.amount);
|
||||
result.tag = (NBTTagCompound) NBTConverter.from(data);
|
||||
return new MCLiquidStack(result, data.immutable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidStack withAmount(int amount) {
|
||||
FluidStack result = new FluidStack(stack.fluidID, amount);
|
||||
FluidStack result = new FluidStack(stack.getFluid(), amount);
|
||||
result.tag = stack.tag;
|
||||
return new MCLiquidStack(result, tag);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@ sourceCompatibility = '1.6'
|
||||
targetCompatibility = '1.6'
|
||||
|
||||
dependencies {
|
||||
compile group: 'org.ow2.asm', name: 'asm', version:'4.2'
|
||||
compile group: 'org.ow2.asm', name: 'asm-commons', version:'4.2'
|
||||
compile 'org.ow2.asm:asm-debug-all:5.0.3'
|
||||
//compile files("${System.properties['java.home']}/../lib/tools.jar")
|
||||
//compile files("libs/tools.jar")
|
||||
}
|
||||
@@ -9,6 +9,6 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compile gradleApi()
|
||||
compile 'org.ow2.asm:asm-debug-all:4.1'
|
||||
compile 'org.ow2.asm:asm-debug-all:5.0.3'
|
||||
compile files(javaToolsJar)
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// ### Global settings ###
|
||||
// #######################
|
||||
|
||||
ext.mineTweakerVersion = "3.0.9C"
|
||||
ext.mineTweakerVersion = "3.0.9D_alpha"
|
||||
ext.mineTweakerDebug = "false"
|
||||
ext.javaToolsJar = new File("C:/Program Files/Java/jdk1.8.0_05/lib/tools.jar")
|
||||
|
||||
@@ -37,7 +37,7 @@ ext.projects172 = [
|
||||
// ### 1.7.10 settings ###
|
||||
// #######################
|
||||
|
||||
ext.forgeVersion1710 = "1.7.10-10.13.0.1180"
|
||||
ext.forgeVersion1710 = "1.7.10-10.13.2.1291"
|
||||
ext.projects1710 = [
|
||||
'MineTweaker3-MC1710-Main',
|
||||
'MineTweaker3-MC1710-Mod-IC2',
|
||||
|
||||
Reference in new issue
Block a user