ZotCore
- добавлена возможность вешать onRandomTick на кастум блоки - добавлена возможность создавать рецепты(надеюсь работатет) - на NativeBlock.setShape,NativeItem.addToCreativeGroup, NativeItem.setGlint поставлена заглушка
This commit is contained in:
@@ -6,9 +6,12 @@ import cn.nukkit.api.BlockStorage;
|
||||
import cn.nukkit.block.*;
|
||||
import cn.nukkit.item.Item;
|
||||
import cn.nukkit.item.ItemTool;
|
||||
import cn.nukkit.level.Level;
|
||||
import cn.nukkit.math.BlockFace;
|
||||
import com.reider745.api.CustomManager;
|
||||
import com.zhekasmirnov.horizon.runtime.logger.Logger;
|
||||
import com.zhekasmirnov.innercore.api.NativeBlock;
|
||||
import com.zhekasmirnov.innercore.api.mod.adaptedscript.AdaptedScriptAPI;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -69,14 +72,22 @@ public class CustomBlock extends BlockSolidMeta {
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
private boolean TickingTile;
|
||||
|
||||
protected CustomBlock(int id, int meta, CustomManager manager, String name) {
|
||||
super(meta);
|
||||
|
||||
this.manager = manager;
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
|
||||
TickingTile = manager.get("TickingTile:"+meta, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRandomTickBlocks() {
|
||||
return TickingTile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
@@ -98,6 +109,14 @@ public class CustomBlock extends BlockSolidMeta {
|
||||
return new Item[]{Item.get(id, this.getDamage(), 1)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onUpdate(int type) {
|
||||
if (type == Level.BLOCK_UPDATE_RANDOM) {
|
||||
NativeBlock.onRandomTickCallback((int) this.x, (int) this.y, (int) this.z, id, this.getDamage(), AdaptedScriptAPI.BlockSource.getFromCallbackPointer(this.level));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block clone() {
|
||||
CustomBlock customBlock = (CustomBlock) super.clone();
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.reider745.InnerCoreServer;
|
||||
import com.reider745.block.CustomBlock;
|
||||
import com.reider745.item.CustomItem;
|
||||
import com.zhekasmirnov.apparatus.api.player.NetworkPlayerRegistry;
|
||||
import com.zhekasmirnov.apparatus.mcpe.NativeWorkbench;
|
||||
import com.zhekasmirnov.apparatus.multiplayer.Network;
|
||||
import com.zhekasmirnov.apparatus.multiplayer.NetworkJsAdapter;
|
||||
import com.zhekasmirnov.apparatus.multiplayer.mod.IdConversionMap;
|
||||
@@ -97,6 +98,8 @@ public class Apparatus {
|
||||
CustomItem.init();
|
||||
|
||||
CustomItem.creative.forEach(item -> Item.addCreativeItem(Item.get(item[0], item[2], item[1])));
|
||||
|
||||
NativeWorkbench.init();
|
||||
}
|
||||
|
||||
public static int getVersionCode() {
|
||||
|
||||
@@ -1,19 +1,67 @@
|
||||
package com.zhekasmirnov.apparatus.mcpe;
|
||||
|
||||
import cn.nukkit.Server;
|
||||
import cn.nukkit.inventory.CraftingManager;
|
||||
import cn.nukkit.inventory.Recipe;
|
||||
import cn.nukkit.inventory.ShapedRecipe;
|
||||
import cn.nukkit.inventory.ShapelessRecipe;
|
||||
import cn.nukkit.item.Item;
|
||||
import com.zhekasmirnov.apparatus.adapter.innercore.game.item.ItemStack;
|
||||
import com.zhekasmirnov.horizon.runtime.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class NativeWorkbench {
|
||||
private static native void addShapedRecipe(int resultId, int resultCount, int resultData, long resultExtraPtr, String[] pattern, int[] ingredients);
|
||||
private static ArrayList<Recipe> recipes = new ArrayList<>();
|
||||
private static void addShapedRecipe(int resultId, int resultCount, int resultData, long resultExtraPtr, String[] pattern, int[] ingredients){
|
||||
if(resultId == 0){
|
||||
Logger.error("Recipe result id 0");
|
||||
return;
|
||||
}
|
||||
if(ingredients.length % 3 != 0){
|
||||
Logger.error("error ingredients");
|
||||
return;
|
||||
}
|
||||
|
||||
final HashMap<Character, Item> ingredients_ = new HashMap<>();
|
||||
for(int i = 0;i < ingredients.length;i+=3)
|
||||
ingredients_.put((char) ingredients[i], Item.get(ingredients[i+1], ingredients[i+2]));
|
||||
|
||||
recipes.add(new ShapedRecipe(Item.get(resultId, resultData, resultCount), pattern, ingredients_, new ArrayList<>()));
|
||||
}
|
||||
|
||||
public static void addShapedRecipe(ItemStack result, String[] pattern, int[] ingredients) {
|
||||
addShapedRecipe(result.id, result.count, result.data, result.getExtraPtr(), pattern, ingredients);
|
||||
}
|
||||
|
||||
private static native void addShapelessRecipe(int resultId, int resultCount, int resultData, long resultExtraPtr, int[] ingredients);
|
||||
private static void addShapelessRecipe(int resultId, int resultCount, int resultData, long resultExtraPtr, int[] ingredients){
|
||||
if(resultId == 0){
|
||||
Logger.error("Recipe result id 0");
|
||||
return;
|
||||
}
|
||||
if(ingredients.length % 3 != 0){
|
||||
Logger.error("error ingredients");
|
||||
return;
|
||||
}
|
||||
|
||||
final Collection<Item> ingredients_ = new ArrayList<>();
|
||||
for(int i = 0;i < ingredients.length;i+=3)
|
||||
ingredients_.add(Item.get(ingredients[i+1], ingredients[i+2]));
|
||||
recipes.add(new ShapelessRecipe(Item.get(resultId, resultData, resultCount), ingredients_));
|
||||
}
|
||||
|
||||
public static void addShapelessRecipe(ItemStack result, int[] ingredients) {
|
||||
addShapelessRecipe(result.id, result.count, result.data, result.getExtraPtr(), ingredients);
|
||||
}
|
||||
|
||||
public static native void removeRecipeByResult(int resultId, int resultCount, int resultData);
|
||||
|
||||
public static void init(){
|
||||
CraftingManager craftingManager = Server.getInstance().getCraftingManager();
|
||||
for(Recipe recipe : recipes)
|
||||
craftingManager.registerRecipe(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,9 @@ public class NativeBlock {
|
||||
public static native void setRedstoneTileNative(int id, int data, boolean redstone);
|
||||
public static native void setRedstoneConnectorNative(int id, int data, boolean redstone);
|
||||
public static native void setRedstoneEmitterNative(int id, int data, boolean redstone);
|
||||
public static native void setTickingTile(int id, int data, boolean ticking);
|
||||
public static void setTickingTile(int id, int data, boolean ticking){
|
||||
CustomBlock.getBlockManager(id).put("TickingTile:"+data, ticking);
|
||||
}
|
||||
public static native void setAnimatedTile(int id, int data, boolean ticking);
|
||||
public static native void setReceivingEntityInsideEvent(int id, boolean value);
|
||||
public static native void setReceivingEntityStepOnEvent(int id, boolean value);
|
||||
@@ -120,7 +122,9 @@ public class NativeBlock {
|
||||
public static native void setMapColor(int id, int mapColor);
|
||||
public static native void setCanContainLiquid(int id, boolean canContainLiquid);
|
||||
public static native void setCanBeExtraBlock(int id, boolean canBeExtraBlock);
|
||||
public static native void setShape(int id, int data, float x1, float y1, float z1, float x2, float y2, float z2);
|
||||
public static void setShape(int id, int data, float x1, float y1, float z1, float x2, float y2, float z2){
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static HashMap<Integer, Float> blockDestroyTimes = new HashMap<>();
|
||||
|
||||
@@ -217,7 +217,9 @@ public class NativeItem {
|
||||
|
||||
|
||||
|
||||
public static native void setGlint(CustomManager ptr, boolean val);
|
||||
public static void setGlint(CustomManager ptr, boolean val){
|
||||
|
||||
}
|
||||
|
||||
public static native void setHandEquipped(CustomManager ptr, boolean val);
|
||||
|
||||
@@ -275,7 +277,7 @@ public class NativeItem {
|
||||
}
|
||||
|
||||
@JSStaticFunction
|
||||
public static native void addToCreativeGroup(String groupName, String displayName, int id);
|
||||
public static void addToCreativeGroup(String groupName, String displayName, int id){}
|
||||
|
||||
@JSStaticFunction
|
||||
public static void addToCreative(int id, int count, int data, Object extra) {
|
||||
|
||||
Reference in New Issue
Block a user