Skip to content

Commit

Permalink
Fixed various bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MaXFeeD committed Apr 20, 2022
1 parent c110c89 commit 024c5bd
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 172 deletions.
Binary file removed .preview/logo.png
Binary file not shown.
Binary file removed .preview/logo_round.png
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
This project maintained from [CurseForge](https://www.curseforge.com/minecraft/mc-mods/signedit). All rights belong to mod developers on Forge and are based solely on ideas presented in this mod.

## Introduction
This lightweight Inner Core mod allows players to edit placed signs simply by right clicking them while holding a sign in their hand.
This lightweight Inner Core mod allows players to edit placed signs simply by right clicking or tapping them while holding a sign in their hand.
2 changes: 1 addition & 1 deletion build.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"javaDirs":[
{
"path":"kotlin/"
"path":"java/"
}
],
"nativeDirs":[],
Expand Down
Binary file added java/classes.dex
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions java/manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
154 changes: 154 additions & 0 deletions java/src/io/nernar/innercore/signedit/SignEdit.java
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 removed kotlin/classes.dex
Binary file not shown.
5 changes: 0 additions & 5 deletions kotlin/manifest

This file was deleted.

162 changes: 0 additions & 162 deletions kotlin/src/io/nernar/innercore/signedit/SignEdit.kt

This file was deleted.

6 changes: 4 additions & 2 deletions launcher.js
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);
2 changes: 1 addition & 1 deletion mod.info
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."
}

0 comments on commit 024c5bd

Please sign in to comment.