feat: Экслюзивный метод Item.setFireResistant
This commit is contained in:
@@ -32,6 +32,14 @@ public class CustomManager {
|
||||
parameters.put(key, value);
|
||||
}
|
||||
|
||||
public boolean containsKey(String key) {
|
||||
return parameters.containsKey(key);
|
||||
}
|
||||
|
||||
public void remove(String key) {
|
||||
parameters.remove(key);
|
||||
}
|
||||
|
||||
private static HashMap<Integer, CustomManager> storage = new HashMap<>();
|
||||
|
||||
public static CustomManager getFor(int id){
|
||||
|
||||
@@ -401,6 +401,22 @@ public class EventListener implements Listener {
|
||||
}));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onItemSpawn(ItemSpawnEvent event) {
|
||||
EntityItem itemEntity = event.getEntity();
|
||||
Item nukkitItem = itemEntity.getItem();
|
||||
|
||||
if (nukkitItem != null) {
|
||||
EntryItem item = NukkitIdConvertor.getInnerCoreForNukkit(nukkitItem.getId(), nukkitItem.getDamage());
|
||||
CustomManager manager = CustomManager.getFor(item.id);
|
||||
if (manager != null && manager.containsKey("fire_resistant")) {
|
||||
boolean fireproof = manager.get("fire_resistant", false);
|
||||
itemEntity.fireProof = fireproof;
|
||||
ReflectHelper.setField(itemEntity, "floatsInLava", fireproof);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: onPathNavigationDone
|
||||
|
||||
// TODO: onBlockSpawnResources
|
||||
|
||||
@@ -29,6 +29,7 @@ public class ItemMethod {
|
||||
public static final String ARMOR_DAMAGEABLE = "armor_damageable";
|
||||
public static final String REPAIRS = "repairs";
|
||||
public static final String CREATIVE_CATEGORY = "creative_category";
|
||||
public static final String FIRE_RESISTANT = "fire_resistant";
|
||||
|
||||
public static class Armors {
|
||||
public static final String SLOT = "slot";
|
||||
|
||||
@@ -128,6 +128,14 @@ public class NativeItem {
|
||||
ItemMethod.setArmorDamageable(itemManager, value);
|
||||
}
|
||||
|
||||
public void setFireResistant(boolean resist) {
|
||||
if (resist || (id >= Item.NETHERITE_INGOT && id <= Item.NETHERITE_SCRAP)) {
|
||||
itemManager.put(PropertiesNames.FIRE_RESISTANT, resist);
|
||||
} else {
|
||||
itemManager.remove(PropertiesNames.FIRE_RESISTANT);
|
||||
}
|
||||
}
|
||||
|
||||
@JSStaticFunction
|
||||
public static NativeItem getItemById(int id) {
|
||||
if (id < 0 || id >= MAX_ITEM_ID) {
|
||||
@@ -287,8 +295,6 @@ public class NativeItem {
|
||||
|
||||
public static void addToCreativeInternal(int id, int count, int data, long extra) {
|
||||
CustomItem.addCreative(id, count, data, extra);
|
||||
|
||||
// TODO: Item.addCreativeItem(Item.get(id, data, count));
|
||||
}
|
||||
|
||||
@JSStaticFunction
|
||||
|
||||
@@ -2399,6 +2399,9 @@ var ItemRegistry = {
|
||||
setMaxUseDuration: function(id, duration) {
|
||||
this.getItemById(id).setMaxUseDuration(duration);
|
||||
},
|
||||
setFireResistant: function(id, resist) {
|
||||
this.getItemById(id).setFireResistant(resist);
|
||||
},
|
||||
registerUseFunctionForID: function(numericID, useFunc) {
|
||||
this.useFunctions[numericID] = useFunc;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user