спавн моба

29
6
Всем привет, как правильно заспавнить моба (существующего)?
 
709
9
106
world.spawnEntity(entityIn)
 
709
9
106
Скинь CrashLog
Java:
EntityZombie zombie = new EntityZombie(world);
zombie.setPositionAndUpdate(x, y, z);
world.spawnEntityInWorld(zombie);
 
Последнее редактирование:
29
6
java.lang.NullPointerException: Exception ticking world
at com.xmafee.aide.EventHandler.onSpawnEntity(EventHandler.java:84)
at cpw.mods.fml.common.eventhandler.ASMEventHandler_9_EventHandler_onSpawnEntity_LivingSpawnEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140)
at net.minecraftforge.event.ForgeEventFactory.canEntitySpawn(ForgeEventFactory.java:112)
at net.minecraft.world.SpawnerAnimals.findChunksForSpawning(SpawnerAnimals.java:174)
at net.minecraft.world.WorldServer.tick(WorldServer.java:169)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:692)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)
 
29
6
Попрошу весь класс
Java:
public class EventHandler {       
    
    Minecraft mc;
    EntityPlayer player;
    World world;
    
    @SubscribeEvent
    public void onSpawnEntity(LivingSpawnEvent e) {
        if(Keyboard.isKeyDown(Keyboard.KEY_H)) {
            EntityZombie zombie = new EntityZombie(world);
            int pX = player.serverPosX, pY = player.serverPosY, pZ = player.serverPosZ;
            zombie.setPosition(pX + 1, pY, pZ);
            world.spawnEntityInWorld(zombie);
        }
    }
}
 
160
2
48
У тебя ошибка на строке #84 ты мне отправляешь 16 строк :) Куда остальные потерял? Конечно у тебя по такой логике null будет.
Ты не указываешь какой игрок, ты не указываешь какой мир, а minecraft - вообще переменная для клиента.
 
709
9
106
@xMafee скинь весь файл, от начала "package ..." до последнего "}".
 
29
6
Java:
package com.xmafee.aide;

import java.awt.Color;
import java.util.ArrayList;

import org.lwjgl.input.Keyboard;

import com.xmafee.entities.EntityLayout;
import com.xmafee.gui.CustomGuiChest;
import com.xmafee.gui.CustomGuiMainMenu;
import com.xmafee.network.NetworkHandler;
import com.xmafee.packets.client.CPacketParticles;
import com.xmafee.packets.server.SPacketParticles;
import com.xmafee.storages.StorageKeys;

import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemPickupEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StatCollector;
import net.minecraft.util.Vec3;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.world.World;
import net.minecraftforge.client.GuiIngameForge;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.client.event.RenderItemInFrameEvent;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.event.world.WorldEvent;

public class EventHandler {       
    
    Minecraft mc;
    EntityPlayer player;
    World world;
    
    private boolean survivalMode() {
        return Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode == false;
    }
    
    @SubscribeEvent
    public void onSpawnEntity(LivingSpawnEvent e) {
        if(Keyboard.isKeyDown(Keyboard.KEY_H)) {
            EntityZombie zombie = new EntityZombie(world);
            int pX = player.serverPosX, pY = player.serverPosY, pZ = player.serverPosZ;
            zombie.setPosition(pX + 1, pY, pZ);
            world.spawnEntityInWorld(zombie);
        }
    }

    @SubscribeEvent
    public void onPlaceBlock(BlockEvent.PlaceEvent e) {
        if(world.isRemote == false)
            if (survivalMode())
                e.setCanceled(true);
    }
    
    @SubscribeEvent
    public void onBreakBlock(BlockEvent.BreakEvent e) {
        if(world.isRemote == false)
            if (survivalMode())
                e.setCanceled(true);
    }
    
    @SideOnly(Side.CLIENT)
    @SubscribeEvent
    public void onOpenMainMenuGui(GuiOpenEvent e) {
        if (e.gui instanceof GuiMainMenu)
            e.gui = (GuiScreen)new CustomGuiMainMenu();
    }
    
    @SideOnly(Side.CLIENT)
    @SubscribeEvent
    public void onRenderDebug(RenderGameOverlayEvent e) {
        if (e.type == ElementType.DEBUG)
            e.setCanceled(true);
    }
    
    @SideOnly(Side.CLIENT)
    @SubscribeEvent
    public void onDrawBlockHighlight(DrawBlockHighlightEvent e) {
        if (survivalMode())
            e.setCanceled(true);
    }
}
 
1,153
48
126
Мир равен null. Возьми его с ивента.
Сразу говорю, это работать корректно не будет, так как спавнить сущности можно на стороне сервера, а на сервере клавиатуры клиента нету.
 
29
6
Java:
    @SubscribeEvent
    public void onBreakBlock(BlockEvent.BreakEvent e) {
        if(e.world.isRemote == false) {
            EntityZombie zombie = new EntityZombie(e.world);
            int pX = player.serverPosX, pY = player.serverPosY, pZ = player.serverPosZ;
            zombie.setPosition(pX + 1, pY, pZ);
            e.world.spawnEntityInWorld(zombie);     
        }
    }
вообщем в итоге решил сделать так, краш:

java.lang.NullPointerException: Ticking memory connection
at com.xmafee.aide.EventHandler.onBreakBlock(EventHandler.java:106) (int pX = player.serverPosX, pY = player.serverPosY, pZ = player.serverPosZ)

at cpw.mods.fml.common.eventhandler.ASMEventHandler_12_EventHandler_onBreakBlock_BreakEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140)
at net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(ForgeHooks.java:469)
at net.minecraft.server.management.ItemInWorldManager.tryHarvestBlock(ItemInWorldManager.java:285)
at net.minecraft.server.management.ItemInWorldManager.uncheckedTryHarvestBlock(ItemInWorldManager.java:234)
at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:532)
at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:61)
at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:94)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)
 
160
2
48
Добавь после
if(e.world.isRemote == false) {
Код похожий на этот
EntityPlayer player = Minecraft.getInstance().player
Не уверен, что в 1.7.10 именно так, но сходство должно быть.
 
709
9
106
29
6
Всё, всем спасибо, разобрался.

Честно, ребят, без понятия кому поставить лучший ответ, все помогли хорошо)
 
Сверху