Хостинг серверов Minecraft playvds.com
  1. Вы находитесь в русском сообществе Bukkit. Мы - администраторы серверов Minecraft, разрабатываем собственные плагины и переводим на русский язык плагины наших собратьев из других стран.
    Скрыть объявление

[1.5.2]Проблема с добавление эффектов

Тема в разделе "Модификации клиента", создана пользователем RedEnergy, 17 июн 2014.

  1. Автор темы
    RedEnergy

    RedEnergy Старожил Пользователь

    Баллы:
    103
    День добрый, пытался добавить эффект, дабы в последствие использовать как зелье
    В файле мода добавил:
    Код:
    public static Potion fly = new fly(50, true, 1).setPotionName("fly");// fly - название эффекта
    
    В файле эффекта
    Код:
    package mods.utc.cruel;
    import net.minecraft.potion.Potion;
    public class fly extends Potion{
    public fly(int par1, boolean par2, int par3) {
    super(par1, par2, par3);
    
    }
    public Potion setIconIndex(int par1, int par2) {
    super.setIconIndex(par1, par2);
    return this;
    }
    }
    
    В файле функционала эффекта
    Код:
    package mods.utc.cruel;
    import cpw.mods.fml.common.network.Player;
    import mods.utc.xmod.xModCore;
    import net.minecraft.entity.EntityLiving;
    import net.minecraft.entity.boss.EntityDragon;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraftforge.event.ForgeSubscribe;
    import net.minecraftforge.event.entity.EntityJoinWorldEvent;
    import net.minecraftforge.event.entity.living.LivingDeathEvent;
    import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
    public class flyFunc {
    @ForgeSubscribe
    public void onEntityUpdate(LivingUpdateEvent event) {
    if (event.entityLiving.isPotionActive(CruelCore.fly)) {
    event.entityLiving.setInWeb();
    }
    }
    }
    
    В результате получил ошибку:
    Код:
    2014-06-16 22:56:44 [SEVERE] [ForgeModLoader] Fatal errors were detected during the transition from INITIALIZATION to POSTINITIALIZATION. Loading cannot continue
    2014-06-16 22:56:44 [SEVERE] [ForgeModLoader]
    mcp{7.51} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized
    FML{5.2.23.738} [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized
    Forge{7.8.1.738} [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized
    cruel{0.1} [UTC's Cruel by RedEnergy] (bin) Unloaded->Constructed->Pre-initialized->Errored
    xmod{1.1} [UTC's xMod by RedEnergy] (bin) Unloaded->Constructed->Pre-initialized->Initialized
    2014-06-16 22:56:44 [SEVERE] [ForgeModLoader] The following problems were captured during this phase
    2014-06-16 22:56:44 [SEVERE] [ForgeModLoader] Caught exception from cruel
    java.lang.ArrayIndexOutOfBoundsException: 50
    at net.minecraft.potion.Potion.<init>(Potion.java:89)
    at mods.utc.cruel.fly.<init>(fly.java:8)
    at mods.utc.cruel.CruelCore.load(CruelCore.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:494)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
    at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)
    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
    at com.google.common.eventbus.EventBus.post(EventBus.java:267)
    at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:192)
    at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:172)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
    at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)
    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
    at com.google.common.eventbus.EventBus.post(EventBus.java:267)
    at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:103)
    at cpw.mods.fml.common.Loader.initializeMods(Loader.java:691)
    at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:213)
    at net.minecraft.client.Minecraft.startGame(Minecraft.java:448)
    at net.minecraft.client.MinecraftAppletImpl.startGame(MinecraftAppletImpl.java:44)
    at net.minecraft.client.Minecraft.run(Minecraft.java:733)
    at java.lang.Thread.run(Unknown Source)
    2014-06-16 22:56:44 [INFO] [STDERR] java.lang.ArrayIndexOutOfBoundsException: 50
    2014-06-16 22:56:44 [INFO] [STDERR] at net.minecraft.potion.Potion.<init>(Potion.java:89)
    2014-06-16 22:56:44 [INFO] [STDERR] at mods.utc.cruel.fly.<init>(fly.java:8)
    2014-06-16 22:56:44 [INFO] [STDERR] at mods.utc.cruel.CruelCore.load(CruelCore.java:34)
    2014-06-16 22:56:44 [INFO] [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2014-06-16 22:56:44 [INFO] [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    2014-06-16 22:56:44 [INFO] [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    2014-06-16 22:56:44 [INFO] [STDERR] at java.lang.reflect.Method.invoke(Unknown Source)
    2014-06-16 22:56:44 [INFO] [STDERR] at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:494)
    2014-06-16 22:56:44 [INFO] [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2014-06-16 22:56:44 [INFO] [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    2014-06-16 22:56:44 [INFO] [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    2014-06-16 22:56:44 [INFO] [STDERR] at java.lang.reflect.Method.invoke(Unknown Source)
    2014-06-16 22:56:44 [INFO] [STDERR] at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
    2014-06-16 22:56:44 [INFO] [STDERR] at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
    2014-06-16 22:56:44 [INFO] [STDERR] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)
    2014-06-16 22:56:44 [INFO] [STDERR] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
    2014-06-16 22:56:44 [INFO] [STDERR] at com.google.common.eventbus.EventBus.post(EventBus.java:267)
    2014-06-16 22:56:44 [INFO] [STDERR] at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:192)
    2014-06-16 22:56:44 [INFO] [STDERR] at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:172)
    2014-06-16 22:56:44 [INFO] [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2014-06-16 22:56:44 [INFO] [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    2014-06-16 22:56:44 [INFO] [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    2014-06-16 22:56:44 [INFO] [STDERR] at java.lang.reflect.Method.invoke(Unknown Source)
    2014-06-16 22:56:44 [INFO] [STDERR] at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
    2014-06-16 22:56:44 [INFO] [STDERR] at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
    2014-06-16 22:56:44 [INFO] [STDERR] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)
    2014-06-16 22:56:44 [INFO] [STDERR] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
    2014-06-16 22:56:44 [INFO] [STDERR] at com.google.common.eventbus.EventBus.post(EventBus.java:267)
    2014-06-16 22:56:44 [INFO] [STDERR] at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:103)
    2014-06-16 22:56:44 [INFO] [STDERR] at cpw.mods.fml.common.Loader.initializeMods(Loader.java:691)
    2014-06-16 22:56:44 [INFO] [STDERR] at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:213)
    2014-06-16 22:56:44 [INFO] [STDERR] at net.minecraft.client.Minecraft.startGame(Minecraft.java:448)
    2014-06-16 22:56:44 [INFO] [STDERR] at net.minecraft.client.MinecraftAppletImpl.startGame(MinecraftAppletImpl.java:44)
    2014-06-16 22:56:44 [INFO] [STDERR] at net.minecraft.client.Minecraft.run(Minecraft.java:733)
    2014-06-16 22:56:44 [INFO] [STDERR] at java.lang.Thread.run(Unknown Source)
    
    Срочно нужна помощь, версия 152
     
  2. Хостинг MineCraft
    <
  3. Agravaine

    Agravaine Активный участник Пользователь

    Баллы:
    88
    Имя в Minecraft:
    Agravaine25
    Еще раз будешь называть так классы - помогать не буду, ну реально, блин.
    Код:
    java.lang.ArrayIndexOutOfBoundsException: 50
    Массив поушенов расчитан на 32 элемента и они все заняты.
    Ты же ставишь 50, вот и кидаешь эксепшен.
    Чтобы сделать новый эффект, нужно с помощью рефлексии увеличить массив.
    Я делаю это так:
    Код:
    public static void increaseArray(Class<?> clazz, int length, String... args){
            Object[] oldArray = null;
            for(Field field : clazz.getDeclaredFields()){
                try{
                    for(String s : args){
                        if(field.getName().equals(s)){
                            field.setAccessible(true);
                            if(Modifier.isFinal(field.getModifiers())){
                                Field modfield = Field.class.getDeclaredField("modifiers");
                                modfield.setAccessible(true);
                                modfield.setInt(field, field.getModifiers() & ~Modifier.FINAL);
                            }
                            oldArray = (Object[])field.get(null);
                            Object newArray = Array.newInstance(field.get(null).getClass().getComponentType(), length);
                            System.arraycopy(oldArray, 0, newArray, 0, oldArray.length);
                            field.set(null, newArray);
                        }
                    }
                }catch(ReflectiveOperationException e){
                    e.printStackTrace();
                }
            }
        }
    Напиши это себе куда-то и в главной классе мода вызывай, но перед тем, как добавляешь свой эффект:
    increaseArray(Potion.class, 256, "potionTypes", "field_76425_a");
    То есть мы увеличили массив до 256 элементов.
    Можно и большо, но я не вижу смысла, ибо 256 и так много, даже 128 хватит.
    Как хочешь, это на твое усмотрение.
     
    Последнее редактирование: 17 июн 2014
  4. Автор темы
    RedEnergy

    RedEnergy Старожил Пользователь

    Баллы:
    103
    По поводу массива я уже понял, расширил его, но немного другим способом.
    Код:
               Potion[] potionTypes = null;
    
               for (Field f : Potion.class.getDeclaredFields()) {
               f.setAccessible(true);
               try {
               if (f.getName().equals("potionTypes") || f.getName().equals("field_76425_a")) {
               Field modfield = Field.class.getDeclaredField("modifiers");
               modfield.setAccessible(true);
               modfield.setInt(f, f.getModifiers() & ~Modifier.FINAL);
    
               potionTypes = (Potion[])f.get(null);
               final Potion[] newPotionTypes = new Potion[256];
               System.arraycopy(potionTypes, 0, newPotionTypes, 0, potionTypes.length);
               f.set(null, newPotionTypes);
                              }
               }
               catch (Exception e) {
                        System.err.println("Ошибка, сообщите автору мода:");
               System.err.println(e);
                              }
                  }
    
               }
    А что не так с названиями классов?
     
  5. Agravaine

    Agravaine Активный участник Пользователь

    Баллы:
    88
    Имя в Minecraft:
    Agravaine25
    С маленькой буквы.
    Аж глаза режет.
    P.S Как расширил?
     

Поделиться этой страницей