-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
162 additions
and
172 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
], | ||
"javaDirs":[ | ||
{ | ||
"path":"kotlin/" | ||
"path":"java/" | ||
} | ||
], | ||
"nativeDirs":[], | ||
|
Binary file not shown.
Binary file renamed
BIN
+58.7 KB
kotlin/classpath/kernelex-2.0.4.jar → java/classpath/kernelex-2.1.jar
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package io.nernar.innercore.signedit; | ||
|
||
import com.zhekasmirnov.innercore.api.NativeAPI; | ||
import com.zhekasmirnov.innercore.api.NativeTileEntity; | ||
import com.zhekasmirnov.innercore.api.commontypes.Coords; | ||
import com.zhekasmirnov.innercore.api.commontypes.ItemInstance; | ||
import com.zhekasmirnov.innercore.api.log.ICLog; | ||
import com.zhekasmirnov.innercore.api.mod.ScriptableObjectHelper; | ||
import com.zhekasmirnov.innercore.api.mod.util.ScriptableFunctionImpl; | ||
import com.zhekasmirnov.innercore.api.runtime.Callback; | ||
import com.zhekasmirnov.innercore.api.unlimited.IDRegistry; | ||
import com.zhekasmirnov.innercore.mod.build.Config; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.mozilla.javascript.Context; | ||
import org.mozilla.javascript.Scriptable; | ||
import org.mozilla.javascript.ScriptableObject; | ||
import vsdum.kex.util.AddonUtils; | ||
import vsdum.kex.natives.GlobalContext; | ||
import vsdum.kex.natives.LocalPlayer; | ||
|
||
public class SignEdit { | ||
public static final int SIGN_TILE_ENTITY_TYPE = 4; | ||
public static final String[] VANILLA_SIGN_IDS = new String[] { "oak_sign", "birch_sign", "spruce_sign", | ||
"dark_oak_sign", "acacia_sign", "jungle_sign", "warped_sign", "crimson_sign" }; | ||
|
||
private static final List<Integer> registeredIds = new ArrayList<>(); | ||
private static boolean signRequiredToEdit = true; | ||
|
||
public static boolean isSignRequiredToEdit() { | ||
return signRequiredToEdit; | ||
} | ||
|
||
public static void setIsSignRequiredToEdit(boolean required) { | ||
signRequiredToEdit = required; | ||
} | ||
|
||
private static final class ItemUseLocal extends ScriptableFunctionImpl { | ||
public Object call(Context context, Scriptable scriptable, Scriptable scope, Object[] objects) { | ||
long playerUid = ((Long) objects[3]).longValue(); | ||
if (NativeAPI.isSneaking(playerUid)) { | ||
return null; | ||
} | ||
|
||
if (signRequiredToEdit) { | ||
ItemInstance item = (ItemInstance) objects[1]; | ||
Integer id = Integer.valueOf(item.getId()); | ||
if (registeredIds.indexOf(id) == -1) { | ||
return null; | ||
} | ||
} | ||
|
||
Coords coords = (Coords) objects[0]; | ||
int x = ((Integer) coords.get("x")).intValue(); | ||
int y = ((Integer) coords.get("y")).intValue(); | ||
int z = ((Integer) coords.get("z")).intValue(); | ||
|
||
NativeTileEntity tile = NativeTileEntity.getTileEntity(x, y, z); | ||
if (tile != null && tile.getType() == SIGN_TILE_ENTITY_TYPE) { | ||
NativeAPI.preventDefault(); | ||
LocalPlayer player = GlobalContext.getLocalPlayer(); | ||
if (player.getPlayerPermissionLevel() > 0) { | ||
player.openSign(x, y, z); | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
private static final class BlocksDefined extends ScriptableFunctionImpl { | ||
public Object call(Context context, Scriptable scriptable, Scriptable scope, Object[] objects) { | ||
ScriptableObject object = ScriptableObjectHelper.createEmpty(); | ||
object.put("isSignRequiredToEdit", object, new ScriptableFunctionImpl() { | ||
public Object call(Context context, Scriptable scriptable, Scriptable scope, Object[] objects) { | ||
return Boolean.valueOf(isSignRequiredToEdit()); | ||
} | ||
}); | ||
object.put("setIsSignRequiredToEdit", object, new ScriptableFunctionImpl() { | ||
public Object call(Context context, Scriptable scriptable, Scriptable scope, Object[] objects) { | ||
setIsSignRequiredToEdit(((Boolean) objects[0]).booleanValue()); | ||
return null; | ||
} | ||
}); | ||
object.put("registerSign", object, new ScriptableFunctionImpl() { | ||
public Object call(Context context, Scriptable scriptable, Scriptable scope, Object[] objects) { | ||
if (objects[0] instanceof Number) { | ||
registerSign(((Integer) objects[0]).intValue()); | ||
return null; | ||
} | ||
registerSign((String) objects[0]); | ||
return null; | ||
} | ||
}); | ||
object.put("isRegisteredSign", object, new ScriptableFunctionImpl() { | ||
public Object call(Context context, Scriptable scriptable, Scriptable scope, Object[] objects) { | ||
if (objects[0] instanceof Number) { | ||
return Boolean.valueOf(isRegisteredSign(((Integer) objects[0]).intValue())); | ||
} | ||
return Boolean.valueOf(isRegisteredSign((String) objects[0])); | ||
} | ||
}); | ||
Callback.invokeAPICallback("API:SignEdit", new Object[] { object }); | ||
return null; | ||
} | ||
} | ||
|
||
static { | ||
for (String vanillaId : VANILLA_SIGN_IDS) { | ||
registeredIds.add(AddonUtils.getNumericIdFromIdentifier(vanillaId)); | ||
} | ||
Callback.addCallback("ItemUseLocal", new ItemUseLocal(), 0); | ||
Callback.addCallback("BlocksDefined", new BlocksDefined(), 0); | ||
} | ||
|
||
public static boolean isRegisteredSign(String namedId) { | ||
return isRegisteredSign(IDRegistry.getIDByName(namedId)); | ||
} | ||
|
||
public static boolean isRegisteredSign(int id) { | ||
Integer indexId = Integer.valueOf(id); | ||
return registeredIds.indexOf(indexId) != -1; | ||
} | ||
|
||
public static void registerSign(int id) { | ||
Integer indexId = Integer.valueOf(id); | ||
synchronized (registeredIds) { | ||
if (registeredIds.indexOf(indexId) == -1) { | ||
registeredIds.add(indexId); | ||
return; | ||
} | ||
} | ||
ICLog.d(SignEdit.class.getSimpleName(), "Sign id " + id + " already registered"); | ||
} | ||
|
||
public static void registerSign(String namedId) { | ||
int uid = IDRegistry.getIDByName(namedId); | ||
if (uid == 0) { | ||
ICLog.e(SignEdit.class.getSimpleName(), "Sign id " + namedId + " not even registered!", | ||
new NullPointerException(namedId + " == 0")); | ||
return; | ||
} | ||
for (String id : VANILLA_SIGN_IDS) { | ||
if (id.equals(namedId)) { | ||
ICLog.i(SignEdit.class.getSimpleName(), "Sign id " + namedId + " consist with vanilla"); | ||
return; | ||
} | ||
} | ||
registerSign(uid); | ||
} | ||
|
||
public static void setConfig(Config config) { | ||
signRequiredToEdit = config.getBool("sign_required_to_edit"); | ||
} | ||
} |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
ConfigureMultiplayer({ | ||
isClientOnly: false | ||
isClientOnly: true | ||
}); | ||
|
||
Packages.io.nernar.innercore.signedit.SignEdit.setConfig(__config__); | ||
Callback.addCallback("API:KernelExtension", function() { | ||
Packages.io.nernar.innercore.signedit.SignEdit.setConfig(__config__); | ||
}, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "SignEdit", | ||
"author": "Nernar", | ||
"version": "1.0", | ||
"version": "1.1", | ||
"description": "Click on sign to edit." | ||
} |