Skip to content

Commit

Permalink
Fixed: Исправлено добаление рецептов после запуска ядра & исправлена …
Browse files Browse the repository at this point in the history
…команда tps
  • Loading branch information
Reider745 committed Aug 6, 2024
1 parent a497d3f commit fb61568
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 29 deletions.
54 changes: 32 additions & 22 deletions src/main/java/com/reider745/commands/TpsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;

import java.util.Arrays;

public class TpsCommand extends Command {
public static long[] innerCoreTimes = new long[20];
public static long[] nukkitTimes = new long[20];

public TpsCommand() {
super("tps");
}
Expand All @@ -15,29 +18,36 @@ public boolean execute(CommandSender commandSender, String s, String[] strings)
if(!commandSender.isOp())
return false;

long innerCoreSum = 0;
for(long time : innerCoreTimes)
if(time != 0)
innerCoreSum += Math.min(20, 1000 / time);
else{
commandSender.sendMessage("Not enough information");
return true;
}

long nukkitSum = 0;
for(long time : nukkitTimes)
if(time != 0)
nukkitSum += Math.min(20, 1000 / time);
else{
commandSender.sendMessage("Not enough information");
return true;
}

if(innerCoreSum != 0 && nukkitSum != 0) {
commandSender.sendMessage("Inner core tps: " + (innerCoreSum / 20.0f));
commandSender.sendMessage("Nukkit tps: " + (nukkitSum / 20.0f));
}else
try{
float aboba1 = 0, aboba2 = 0;
long innerCoreSum = 0;
for(long time : innerCoreTimes)
if(time != 0) {
innerCoreSum += Math.min(20, 1000 / time);
aboba1++;
}

long nukkitSum = 0;
for(long time : nukkitTimes)
if(time != 0) {
nukkitSum += Math.min(20, 1000 / time);
aboba2++;
}

if(innerCoreSum != 0)
commandSender.sendMessage("Inner core tps: " + (innerCoreSum / aboba1));
else
commandSender.sendMessage("Inner core tps: 20.0");

if(nukkitSum != 0)
commandSender.sendMessage("Nukkit tps: " + (nukkitSum / aboba2));
else
commandSender.sendMessage("Nukkit tps: 20.0");
}catch (Exception e){
commandSender.sendMessage("Not enough information");
commandSender.sendMessage(Arrays.toString(innerCoreTimes));
commandSender.sendMessage(Arrays.toString(nukkitTimes));
}

return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/reider745/hooks/ServerHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ public static boolean getPropertyBoolean(Server server, String variable, Object
}

private static long start_pre = 0;
private static int indexTime = 0;

@Inject
public static void checkTickUpdates(Server server, int tick) {
int indexTime = server.getTick() % 20;
indexTime = (indexTime + 1) % 20;
TpsCommand.nukkitTimes[indexTime] = System.currentTimeMillis() - start_pre;

try {
Expand Down
29 changes: 24 additions & 5 deletions src/main/java/com/zhekasmirnov/apparatus/mcpe/NativeWorkbench.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,16 @@ public void apply(RuntimeItemMapping mapping, CraftingManager craftingManager) {
if (accepted) {
craftingManager.registerRecipe(InnerCoreServer.RECIPES_PROTOCOL, new ShapelessRecipe(result, ingredients));
}

if(NativeWorkbench.craftingManager != null)
craftingManager.rebuildPacket();
}
}
}

private static final ArrayList<IApply> recipes = new ArrayList<>();
private static RuntimeItemMapping runtimeItemMapping = null;
private static CraftingManager craftingManager = null;

private static void addShapedRecipe(int resultId, int resultCount, int resultData, NativeItemInstanceExtra resultExtra,
String[] pattern, int[] ingredients) {
Expand All @@ -174,7 +179,12 @@ private static void addShapedRecipe(int resultId, int resultCount, int resultDat
final HashMap<Character, ItemStack> ingredients_ = new HashMap<>();
for (int i = 0; i < ingredients.length; i += 3)
ingredients_.put((char) ingredients[i], new ItemStack(ingredients[i + 1], 1, ingredients[i + 2]));
recipes.add(new RecipeRegistry(resultId, resultCount, resultData, resultExtra, pattern, ingredients_));

final RecipeRegistry recipe = new RecipeRegistry(resultId, resultCount, resultData, resultExtra, pattern, ingredients_);
if(craftingManager != null)
recipe.apply(runtimeItemMapping, craftingManager);
else
recipes.add(recipe);
}

public static void addShapedRecipe(ItemStack result, String[] pattern, int[] ingredients) {
Expand All @@ -188,7 +198,11 @@ private static void addShapelessRecipe(int resultId, int resultCount, int result
return;
}

recipes.add(new RecipeRegistry(resultId, resultCount, resultData, resultExtra, ingredients));
final RecipeRegistry recipe = new RecipeRegistry(resultId, resultCount, resultData, resultExtra, ingredients);
if(craftingManager != null)
recipe.apply(runtimeItemMapping, craftingManager);
else
recipes.add(recipe);
}

public static void addShapelessRecipe(ItemStack result, int[] ingredients) {
Expand All @@ -197,16 +211,21 @@ public static void addShapelessRecipe(ItemStack result, int[] ingredients) {


public static void removeRecipeByResult(int resultId, int resultCount, int resultData) {
recipes.add(new RecipeRemove(resultId, resultCount, resultData));
final RecipeRemove recipe = new RecipeRemove(resultId, resultCount, resultData);
if(craftingManager != null)
recipe.apply(runtimeItemMapping, craftingManager);
else
recipes.add(recipe);
}
public static void init() {
final RuntimeItemMapping mapping = RuntimeItems.getMapping(InnerCoreServer.PROTOCOL);
runtimeItemMapping = RuntimeItems.getMapping(InnerCoreServer.PROTOCOL);
final CraftingManager craftingManager = Server.getInstance().getCraftingManager();

for (IApply recipe : recipes)
recipe.apply(mapping, craftingManager);
recipe.apply(runtimeItemMapping, craftingManager);

recipes.clear();
craftingManager.rebuildPacket();
NativeWorkbench.craftingManager = craftingManager;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/zotecore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pack-version-code: 160

# Sets the list of mods and configs to load, you can specify
# name, folder name of a modpack from /modpacks or a path.
# modpack: StoneBlock
# modpack: LoveZote

# Use vanilla crafting table interface, instead of custom one.
# Attention: currently not recommended and recipes dislayed with bugs.
Expand Down

0 comments on commit fb61568

Please sign in to comment.