Skip to content

Commit

Permalink
fix: name block, UI.UIWindowStandard, feat: added new commands
Browse files Browse the repository at this point in the history
- Исправлено создание блока без имени
- Добавлены команды которые отображают список кастумных блоков\предметов
- Улучшена заглушка на интерфейсы
- Удалены не которых debug, warning сообщения
  • Loading branch information
Reider745 committed Dec 1, 2023
1 parent def0c53 commit 6d13eb7
Show file tree
Hide file tree
Showing 12 changed files with 723 additions and 16 deletions.
10 changes: 7 additions & 3 deletions src/main/java/com/reider745/block/CustomBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void init(){
CustomManager manager = getBlockManager(id);
ArrayList<String> variants = getVariants(manager);
for(int data = 0;data < variants.size();data++)
registerBlock(id, data, new CustomBlock(id, data, manager));
registerBlock(id, data, new CustomBlock(id, data, manager, variants.get(data)));
});
}

Expand All @@ -85,7 +85,7 @@ public static ArrayList<String> getVariants(CustomManager manager){

public static HashMap<String, Integer> customBlocks = new HashMap<>();

public static CustomManager registerBlock(String textId, int id, String name, Class item){
public static CustomManager registerBlock(String textId, int id, String name, Class<?> item){
CustomManager manager = new CustomManager(id, item, "block");
manager.put("name", name);

Expand All @@ -111,11 +111,15 @@ protected CustomBlock(int id, int meta){
}

protected CustomBlock(int id, int meta, CustomManager manager) {
this(id, meta, manager, "blank");
}

protected CustomBlock(int id, int meta, CustomManager manager, String name) {
super(meta);

this.manager = manager;
this.id = id;
this.name = manager.get("name");
this.name = name;

TickingTile = manager.get("TickingTile:"+meta, false);
}
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/reider745/commands/CustomBlocksCommands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.reider745.commands;

import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import com.reider745.api.CustomManager;
import com.reider745.block.CustomBlock;
import com.reider745.item.CustomItem;
import com.reider745.item.ItemMethod;

public class CustomBlocksCommands extends Command {
public CustomBlocksCommands() {
super("mods", "get list custom blocks");
}

@Override
public boolean execute(CommandSender commandSender, String s, String[] strings) {
if(!commandSender.isOp()) return false;

String message = "===CustomBlocks===";
for(Integer id : CustomBlock.blocks.keySet()) {
CustomManager manager = CustomItem.getItemManager(id);
message += "\n"+manager.get(ItemMethod.PropertiesNames.NAME)+", id: "+id;
}
commandSender.sendMessage(message);
return true;
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/reider745/commands/CustomItemsCommands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.reider745.commands;

import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import com.reider745.api.CustomManager;
import com.reider745.item.CustomItem;
import com.reider745.item.ItemMethod;


public class CustomItemsCommands extends Command {
public CustomItemsCommands() {
super("mods", "get list custom items");
}

@Override
public boolean execute(CommandSender commandSender, String s, String[] strings) {
if(!commandSender.isOp()) return false;

String message = "===CustomItems===";
for(Integer id : CustomItem.items.keySet()) {
CustomManager manager = CustomItem.getItemManager(id);
message += "\n"+manager.get(ItemMethod.PropertiesNames.NAME)+", id: "+id;
}
commandSender.sendMessage(message);
return true;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/reider745/hooks/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@Hooks(class_name = "cn.nukkit.item.Item")
public class ItemUtils implements HookClass {
public static PointersStorage<Item> items_pointers = new PointersStorage<>("items", ItemExtraDataProvider::new);
public static final PointersStorage<Item> items_pointers = new PointersStorage<>("items", ItemExtraDataProvider::new);

@Inject(signature = "(ILjava/lang/Integer;I[B)Lcn/nukkit/item/Item;")
public static Item get(int id, Integer meta, int count, byte[] tags){
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/reider745/item/CustomItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ private static <T>void addFirst(ArrayList<T> list, T value){
public static void checkAddedItem(int id, int damage){

if(!CustomItem.isCreativeItem(id, damage) && id > 2000) {
System.out.println(creative);
Server.getInstance().getLogger().info("clone item "+id+":"+damage);
//System.out.println(creative);
// Server.getInstance().getLogger().info("clone item "+id+":"+damage);

CustomItem.addToCreativeGroup(CustomItem.TECHNICAL_GROUP, id);
addFirst(CustomItem.creative, new int[] {id, 1, damage});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void addBox(float x1, float y1, float z1, float x2, float y2, float z2, S

for (int i = 0; i < 6; i++) {
if (!ResourcePackManager.isValidBlockTexture(names[i], ids[i])) {
Logger.debug(BlockRegistry.LOGGER_TAG, "invalid block texture will be replaced with default: " + names[i] + " " + ids[i]);
//Logger.debug(BlockRegistry.LOGGER_TAG, "invalid block texture will be replaced with default: " + names[i] + " " + ids[i]);
names[i] = "missing_block";
ids[i] = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/zhekasmirnov/innercore/api/NativeItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static NativeItem createArmorItem(int id, String nameId, String name, Str
nameId = NativeAPI.convertNameId(nameId); // any name id must be lowercase

if (!ResourcePackManager.isValidItemTexture(iconName, iconIndex)) {
Logger.debug("WARNING", "invalid item icon: " + iconName + " " + iconIndex);
//Logger.debug("WARNING", "invalid item icon: " + iconName + " " + iconIndex);
iconName = "missing_icon";
iconIndex = 0;
}
Expand All @@ -187,7 +187,7 @@ public static NativeItem createThrowableItem(int id, String nameId, String name,
nameId = NativeAPI.convertNameId(nameId); // any name id must be lowercase

if (!ResourcePackManager.isValidItemTexture(iconName, iconIndex)) {
Logger.debug("WARNING", "invalid item icon: " + iconName + " " + iconIndex);
// Logger.debug("WARNING", "invalid item icon: " + iconName + " " + iconIndex);
iconName = "missing_icon";
iconIndex = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2049,11 +2049,11 @@ public WindowGroup() {
// legacy
public static class StandartWindow extends UIWindowStandard {
public StandartWindow(ScriptableObject content) {

super(content);
}

public StandartWindow() {

super(ScriptableObjectHelper.createEmpty());
}

protected boolean isLegacyFormat() {
Expand All @@ -2064,11 +2064,14 @@ protected boolean isLegacyFormat() {
// new one
public static class StandardWindow extends UIWindowStandard {
public StandardWindow(ScriptableObject content) {
super(content);
}

public StandardWindow() {
super(ScriptableObjectHelper.createEmpty());
}

@Override
protected boolean isLegacyFormat() {
return false;
}
Expand Down
Loading

0 comments on commit 6d13eb7

Please sign in to comment.