Jump to content

Recommended Posts

Posted

Hey all,

 

I'm having a rather serious problem with spawning my entity. I've gotten it to work perfectly in SP but in MP the thing simply will not spawn.

 

Here is the relevant code:

 

package mod_DefenseGunPack;

//Credits:
//big help from: Zorn_Taov
//
//
//
//
//
//

import mod_DefenseGunPack.handlers.CraftingHandler;
import mod_DefenseGunPack.handlers.DG3x3_SpawnPacketHandler;
import mod_DefenseGunPack.client.ClientProxy;
import mod_DefenseGunPack.handlers.DG3x3_PacketHandler;
import mod_DefenseGunPack.items.DG3x3_Item;
import mod_DefenseGunPack.turrets.DG3x3_EntityLiving;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.block.material.Material;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemReed;
import net.minecraft.item.ItemStack;
import net.minecraft.src.ModLoader;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.ICraftingHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.IConnectionHandler;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkMod.SidedPacketHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.common.registry.GameRegistry;

@Mod(modid = "mod_DefenseGunPack", name = "mod_DefenseGunPack", version = "0.0.1")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Mod_Turrets
{
//public static final Block test = (new BlockDefenseGun3x3v1(250, mod_DefenseGunPack.EntityDefenseGun3x3v1.class))
//	.setHardness(0.5F) .setResistance(1F) .setBlockName("DefenseTurret3x3v1");

//	public static IPacketHandler packetHandler;
//
//    public static IPacketHandler packetSpawnHandler;

    public static Item DG3x3_Item;

    public void craftingRecipes()
    {
        GameRegistry.addRecipe(new ItemStack(DG3x3_Item, 1, 0), new Object[] { "##", "##", '#', Block.dirt});
    }

    @Instance("Mod_Turrets")
    public static Mod_Turrets instance;

    @SidedProxy(clientSide = "mod_DefenseGunPack.client.ClientProxy", serverSide = "mod_DefenseGunPack.CommonProxy")
    public static CommonProxy proxy;

    @PreInit
    public void preInt(FMLPreInitializationEvent event)
    {
        // stub Method
    }

    @Init
    public void load(FMLInitializationEvent event)
    {
//        packetHandler = new DG3x3_PacketHandler();
//        packetSpawnHandler = new DG3x3_SpawnPacketHandler();
//        
//        NetworkRegistry.instance().registerPacketHandler();
        
        DG3x3_Item = (new DG3x3_Item(5000-256)).setItemName("DefenseGun3x3v1")
                .setCreativeTab(CreativeTabs.tabRedstone).setIconCoord(12, 10); 
        
        craftingRecipes();
        
//        NetworkRegistry.instance().registerChannel(packetHandler, "DG3x3");
//        NetworkRegistry.instance().registerChannel(packetSpawnHandler, "DG3x3Spawn");
        
        int DG3x3id = EntityRegistry.findGlobalUniqueEntityId();
        EntityRegistry.registerGlobalEntityID(DG3x3_EntityLiving.class, "DefenseGun3x3v1", DG3x3id);
        EntityRegistry.registerModEntity(DG3x3_EntityLiving.class, "DefenseGun3x3v1",DG3x3id, this, 250, 5, false);
        
        GameRegistry.registerItem(DG3x3_Item, "DefenseGun3x3v1");
        LanguageRegistry.addName(DG3x3_Item, "DefenseGun3x3v1");
        
        ClientProxy.registerRenderInformation();
    }

    @PostInit
    public void postInit(FMLPostInitializationEvent event)
    {
        // stub Method
    }
}

 

package mod_DefenseGunPack;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.world.World;
import cpw.mods.fml.common.INetworkHandler;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkMod.NULL;
import cpw.mods.fml.common.network.NetworkMod.SidedPacketHandler;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.common.registry.GameRegistry;
import mod_DefenseGunPack.handlers.DG3x3_PacketHandler;

public class CommonProxy 
{
    public static void registerRenderInformation()
    {
        //No rendering for servers
    }    
}

 

package mod_DefenseGunPack.client;

import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraft.client.model.ModelBase;
import net.minecraft.src.ModLoader;
import net.minecraftforge.client.MinecraftForgeClient;
import mod_DefenseGunPack.CommonProxy;
import mod_DefenseGunPack.turrets.DG3x3_EntityLiving;
import mod_DefenseGunPack.turrets.renderers.DG3x3_Renderer;
import mod_DefenseGunPack.turrets.models.DG3x3_Model;

public class ClientProxy extends CommonProxy
{
    public static void registerRenderInformation()
    {
        MinecraftForgeClient.preloadTexture("/mod_DefenseGunPack/DefenseGun3x3v1.png");
        RenderingRegistry.registerEntityRenderingHandler(mod_DefenseGunPack.turrets.DG3x3_EntityLiving.class, new mod_DefenseGunPack.turrets.renderers.DG3x3_Renderer());
    }
}

 

package mod_DefenseGunPack.items;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;

import mod_DefenseGunPack.turrets.DG3x3_EntityLiving;
import net.minecraft.block.Block;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.DataWatcher;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.src.ModLoader;
import net.minecraft.stats.StatList;
import net.minecraft.util.ReportedException;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.EntitySpawnPacket;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;



public class DG3x3_Item extends Item
{
    private int spawnID;

    public EntityPlayer PlacingPlayer;

    public DG3x3_Item(int par1)
    {
        super(par1);
    }
    
    public boolean FW_CheckPlacementLocation(World par3World, int par4, int par5, int par6, int par7)
    {
        if (!par3World.isAirBlock(par4, par5, par6))
        {
            int id = par3World.getBlockId(par4, par5, par6);

            if (id == 42 || id == 45 || id == 01 || id == 02 || id == 03)
            {
                return true;
            }
        }

        System.out.println("Placement False");
        return false;
    }

    /**
     * Callback for item usage. If the item does something special on right
     * clicking, he will have one of those. Return True if something happen and
     * false if it don't. This is for ITEMS, not BLOCKS
     */
    @Override
    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    {
        int var11 = par3World.getBlockId(par4, par5, par6);

        if (var11 == Block.snow.blockID)
        {
            par7 = 1;
        }
        else if (var11 != Block.vine.blockID && var11 != Block.tallGrass.blockID && var11 != Block.deadBush.blockID)
        {
            if (par7 == 0)
            {
                --par5;
            }

            if (par7 == 1)
            {
                ++par5;
            }

            if (par7 == 2)
            {
                --par6;
            }

            if (par7 == 3)
            {
                ++par6;
            }

            if (par7 == 4)
            {
                --par4;
            }

            if (par7 == 5)
            {
                ++par4;
            }
        }

        if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack))
        {
            return false;
        }
        else if (par1ItemStack.stackSize == 0)
        {
            return false;
        }
        else
        {
            if (
                    (FW_CheckPlacementLocation(par3World, par4 - 1, par5 - 1, par6 + 1, par7) == true)
                    && (FW_CheckPlacementLocation(par3World, par4, par5 - 1, par6 + 1, par7) == true)
                    && (FW_CheckPlacementLocation(par3World, par4 + 1, par5 - 1, par6 + 1, par7) == true)
                    && (FW_CheckPlacementLocation(par3World, par4 - 1, par5 - 1, par6, par7) == true)
                    && (FW_CheckPlacementLocation(par3World, par4, par5 - 1, par6, par7) == true)
                    && (FW_CheckPlacementLocation(par3World, par4 + 1, par5 - 1, par6, par7) == true)
                    && (FW_CheckPlacementLocation(par3World, par4 - 1, par5 - 1, par6 - 1, par7) == true)
                    && (FW_CheckPlacementLocation(par3World, par4, par5 - 1, par6 - 1, par7) == true)
                    && (FW_CheckPlacementLocation(par3World, par4 + 1, par5 - 1, par6 - 1, par7) == true))
            {
                for (int i = 0; i < 3; i = i + 1)
                {
                    if (
                            (par3World.isAirBlock(par4 - 1, par5 + i, par6 + 1))
                            && (par3World.isAirBlock(par4, par5 + 1, par6 + 1))
                            && (par3World.isAirBlock(par4 + 1, par5 + i, par6 + 1))
                            && (par3World.isAirBlock(par4 - 1, par5 + i, par6))
                            && (par3World.isAirBlock(par4, par5 + 1, par6))
                            && (par3World.isAirBlock(par4 + 1, par5 + i, par6))
                            && (par3World.isAirBlock(par4 - 1, par5 + i, par6 - 1))
                            && (par3World.isAirBlock(par4, par5 + 1, par6 - 1))
                            && (par3World.isAirBlock(par4 + 1, par5 + i, par6 - 1))
                    )
                    {
                    }
                }
            }
            else
            {
                return false;
            }
        
            if(spawnTurret(par4, par5, par6, new DG3x3_EntityLiving(par3World), par3World, par2EntityPlayer))
            {
            	par1ItemStack.stackSize--;
            	return true;
            }
            par2EntityPlayer.swingItem();
            return false;
            
        }
    }

public static boolean spawnTurret(double x, double y, double z, Entity entity, World world, EntityPlayer player)
{
if(!world.isRemote)
{
	entity.setPosition(x, y, z);
	world.spawnEntityInWorld(entity);
	world.playAuxSFX(2001, (int)x, (int)y, (int)z, Block.stone.blockID);
	return true;
}
return false;
}

}

 

package mod_DefenseGunPack.turrets;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import java.util.UUID;

import mod_DefenseGunPack.Mod_Turrets;
import mod_DefenseGunPack.packet.DG3x3_Packet;
import mod_DefenseGunPack.projectiles.EntityExplosiveArrow;
import mod_DefenseGunPack.targetfilters.FilterITurret;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.command.IEntitySelector;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.entity.DataWatcher;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.IRangedAttackMob;
import net.minecraft.entity.WatchableObject;
import net.minecraft.entity.ai.EntityAIArrowAttack;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntitySlime;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ReportedException;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.EntitySpawnPacket;
import cpw.mods.fml.common.network.FMLPacket;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class DG3x3_EntityLiving extends EntityLiving implements IInventory, IRangedAttackMob, IEntitySelector
{
    private float field_70926_e;
    private float field_70924_f;

    private EntityAIArrowAttack field_85037_d = new EntityAIArrowAttack(this, 0F, 1, 25F);
    private EntityAIAttackOnCollide field_85038_e = new EntityAIAttackOnCollide(this, EntityPlayer.class, 0.31F, false);

    private ItemStack[] DG3X3v1Contents = new ItemStack[64];
    private boolean field_70279_a;
    private double field_70276_b;
    @SideOnly(Side.CLIENT)
    private double velocityX;
    @SideOnly(Side.CLIENT)
    private double velocityY;
    @SideOnly(Side.CLIENT)
    private double velocityZ;
    private EntityPlayer entityplayer;

    private IEntitySelector ientityselector = new FilterITurret();

    public DG3x3_Packet DG3x3packet;
    public DataOutputStream outputStream;

    public DG3x3_EntityLiving(World par1World)
    {
        super(par1World);
        this.field_70279_a = true;
        this.field_70276_b = 0.07D;
        this.preventEntitySpawning = true;
        this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
        this.tasks.addTask(2, this.field_85037_d);
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityLiving.class, 25F, 0, true, true, ientityselector));
        this.func_82164_bB();
        this.func_82162_bC();
        System.out.println("EntitySpawn 1");
    }

    public DG3x3_EntityLiving(World par1World, double par2, double par4, double par6, EntityPlayer player)
    {
        super(par1World);
        double xpos2 = par2 + 0.5;
        double zpos2 = par6 + 0.5;
        this.setPosition(xpos2, par4, zpos2);
        this.motionX = 0.0D;
        this.motionY = 0.0D;
        this.motionZ = 0.0D;
        this.prevPosX = xpos2;
        this.prevPosY = par4;
        this.prevPosZ = par6;
        this.height = 1.5F;
        this.boundingBox.setBounds(xpos2 - 1.5, par4 - 0, zpos2 - 1.5, xpos2 + 1.5, par4 + 3, zpos2 + 1.5);
        this.entityplayer = player;
        this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
        this.tasks.addTask(2, this.field_85037_d);
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityLiving.class, 25F, 0, true, true, ientityselector));
        System.out.println("EntitySpawn 2");
    }

    @Override
    public void setAttackTarget(EntityLiving par1EntityLiving)
    {
        super.setAttackTarget(par1EntityLiving);
    }

    @SideOnly(Side.CLIENT)
    public float getInterestedAngle(float par1)
    {
        return (this.field_70924_f + (this.field_70926_e - this.field_70924_f) * par1) * 0.15F * (float)Math.PI;
    }

    /**
     * random number generator for instance. Used in random item stack selection.
     */
    private Random DG3X3v1Random = new Random();

    /**
     * the movespeed used for the new AI system
     */
    @Override
    public float getAIMoveSpeed()
    {
        return 0;
    }

    /**
     * Returns the number of slots in the inventory.
     */
    @Override
    public int getSizeInventory()
    {
        return 1;
    }

    public boolean isAIEnabled()
    {
        return true;
    }

    public boolean attackEntityAsMob(Entity par1Entity)
    {
        if (super.attackEntityAsMob(par1Entity))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    /**
     * Returns the amount of damage a mob should deal.
     */
    public int getAttackStrength(Entity par1Entity)
    {
        return 999;
    }

    protected boolean canTriggerWalking()
    {
        return false;
    }

    protected void entityInit()
    {
        super.entityInit();
        this.dataWatcher.addObject(13, new Byte((byte)0));
        this.dataWatcher.addObject(16, Byte.valueOf((byte)0));
        this.dataWatcher.addObject(17, Integer.valueOf(0));
        this.dataWatcher.addObject(18, Integer.valueOf(0));
        this.dataWatcher.addObject(19, Integer.valueOf(0));
        this.dataWatcher.addObject(20, Byte.valueOf((byte)0));
    }

    /**
     * Returns a boundingBox used to collide the entity with other entities and blocks. This enables the entity to be
     * pushable on contact, like boats or minecarts.
     */
    @Override
    public AxisAlignedBB getCollisionBox(Entity par1Entity)
    {
        return par1Entity.boundingBox;
    }

    /**
     * returns the bounding box for this entity
     */
    @Override
    public AxisAlignedBB getBoundingBox()
    {
        return this.boundingBox;
    }

    /**
     * Returns true if this entity should push and be pushed by other entities when colliding.
     */
    @Override
    public boolean canBePushed()
    {
        return false;
    }

    /**
     * Called when the entity is attacked.
     */
    public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
    {
        if (this.func_85032_ar())
        {
            return false;
        }
        else if (!this.worldObj.isRemote && !this.isDead)
        {
            this.setForwardDirection(-this.getForwardDirection());
            this.setTimeSinceHit(10);
            this.setDamageTaken(this.getDamageTaken() + par2 * 10);
            this.setBeenAttacked();

            if (par1DamageSource.getEntity() instanceof EntityPlayer && ((EntityPlayer)par1DamageSource.getEntity()).capabilities.isCreativeMode)
            {
                this.setDamageTaken(100);
            }

            if (this.getDamageTaken() > 40)
            {
                this.dropItemWithOffset(Mod_Turrets.DG3x3_Item.shiftedIndex, 1, 0.0F);
                this.setDead();
            }

            return true;
        }
        else
        {
            return true;
        }
    }

    @SideOnly(Side.CLIENT)

    /**
     * Setups the entity to do the hurt animation. Only used by packets in multiplayer.
     */
    public void performHurtAnimation()
    {
        this.setForwardDirection(-this.getForwardDirection());
        this.setTimeSinceHit(10);
        this.setDamageTaken(this.getDamageTaken() * 11);
    }

    /**
     * Returns true if other Entities should be prevented from moving through this Entity.
     */
    public boolean canBeCollidedWith()
    {
        return !this.isDead;
    }

    @SideOnly(Side.CLIENT)

    /**
     * Sets the velocity to the args. Args: x, y, z
     */
    public void setVelocity(double par1, double par3, double par5)
    {
        this.velocityX = this.motionX = par1;
        this.velocityY = this.motionY = par3;
        this.velocityZ = this.motionZ = par5;
    }

    protected void func_82164_bB()
    {
        super.func_82164_bB();
        this.setCurrentItemOrArmor(0, new ItemStack(Item.bow));
    }

    /**
     * (abstract) Protected helper method to write subclass entity data to NBT.
     */
    @Override
    public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeEntityToNBT(par1NBTTagCompound);

        if (getSizeInventory() > 0)
        {
            NBTTagList var2 = new NBTTagList();

            for (int var3 = 0; var3 < this.getSizeInventory(); ++var3)
            {
                if (this.DG3X3v1Contents[var3] != null)
                {
                    NBTTagCompound var4 = new NBTTagCompound();
                    var4.setByte("Slot", (byte)var3);
                    this.DG3X3v1Contents[var3].writeToNBT(var4);
                    var2.appendTag(var4);
                }
            }

            par1NBTTagCompound.setTag("Items", var2);
        }
    }

    @Override
    public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readEntityFromNBT(par1NBTTagCompound);

        if (getSizeInventory() > 0)
        {
            NBTTagList var2 = par1NBTTagCompound.getTagList("Items");
            this.DG3X3v1Contents = new ItemStack[this.getSizeInventory()];

            for (int var3 = 0; var3 < var2.tagCount(); ++var3)
            {
                NBTTagCompound var4 = (NBTTagCompound)var2.tagAt(var3);
                int var5 = var4.getByte("Slot") & 255;

                if (var5 >= 0 && var5 < this.DG3X3v1Contents.length)
                {
                    this.DG3X3v1Contents[var5] = ItemStack.loadItemStackFromNBT(var4);
                }
            }
        }
    }

    protected boolean canDespawn()
    {
        return false;
    }

    /**
     * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
     */
    public boolean interact(EntityPlayer par1EntityPlayer)
    {
        if (getSizeInventory() > 0)
        {
            if (!this.worldObj.isRemote)
            {
                par1EntityPlayer.displayGUIChest(this);
            }
        }

        return true;
    }

    /**
     * Sets the damage taken from the last hit.
     */
    public void setDamageTaken(int par1)
    {
        this.dataWatcher.updateObject(19, Integer.valueOf(par1));
    }

    @SideOnly(Side.CLIENT)
    public float getShadowSize()
    {
        return 0.0F;
    }

    /**
     * Gets the damage taken from the last hit.
     */
    public int getDamageTaken()
    {
        return this.dataWatcher.getWatchableObjectInt(19);
    }

    /**
     * Sets the time to count down from since the last time entity was hit.
     */
    public void setTimeSinceHit(int par1)
    {
        this.dataWatcher.updateObject(17, Integer.valueOf(par1));
    }

    /**
     * Gets the time since the last hit.
     */
    public int getTimeSinceHit()
    {
        return this.dataWatcher.getWatchableObjectInt(17);
    }

    /**
     * Sets the forward direction of the entity.
     */
    public void setForwardDirection(int par1)
    {
        this.dataWatcher.updateObject(18, Integer.valueOf(par1));
    }

    /**
     * Gets the forward direction of the entity.
     */
    public int getForwardDirection()
    {
        return this.dataWatcher.getWatchableObjectInt(18);
    }

    /**
     * Returns the stack in slot i
     */
    @Override
    public ItemStack getStackInSlot(int par1)
    {
        return this.DG3X3v1Contents[par1];
    }

    /**
     * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
     * new stack.
     */
    @Override
    public ItemStack decrStackSize(int par1, int par2)
    {
        if (this.DG3X3v1Contents[par1] != null)
        {
            ItemStack var3;

            if (this.DG3X3v1Contents[par1].stackSize <= par2)
            {
                var3 = this.DG3X3v1Contents[par1];
                this.DG3X3v1Contents[par1] = null;
                this.onInventoryChanged();
                return var3;
            }
            else
            {
                var3 = this.DG3X3v1Contents[par1].splitStack(par2);

                if (this.DG3X3v1Contents[par1].stackSize == 0)
                {
                    this.DG3X3v1Contents[par1] = null;
                }

                this.onInventoryChanged();
                return var3;
            }
        }
        else
        {
            return null;
        }
    }

    /**
     * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
     * like when you close a workbench GUI.
     */
    @Override
    public ItemStack getStackInSlotOnClosing(int par1)
    {
        if (this.DG3X3v1Contents[par1] != null)
        {
            ItemStack var2 = this.DG3X3v1Contents[par1];
            this.DG3X3v1Contents[par1] = null;
            return var2;
        }
        else
        {
            return null;
        }
    }

    /**
     * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
     */
    @Override
    public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
    {
        this.DG3X3v1Contents[par1] = par2ItemStack;

        if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
        {
            par2ItemStack.stackSize = this.getInventoryStackLimit();
        }

        this.onInventoryChanged();
    }

    public int getRandomStackFromInventory()
    {
        int var1 = -1;
        int var2 = 1;

        for (int var3 = 0; var3 < this.DG3X3v1Contents.length; ++var3)
        {
            if (this.DG3X3v1Contents[var3] != null && this.DG3X3v1Random.nextInt(var2++) == 0)
            {
                var1 = var3;
            }
        }

        return var1;
    }

    public int func_70360_a(ItemStack par1ItemStack)
    {
        for (int var2 = 0; var2 < this.DG3X3v1Contents.length; ++var2)
        {
            if (this.DG3X3v1Contents[var2] == null || this.DG3X3v1Contents[var2].itemID == 0)
            {
                this.DG3X3v1Contents[var2] = par1ItemStack;
                return var2;
            }
        }

        return -1;
    }

    /**
     * Returns the name of the inventory.
     */
    @Override
    public String getInvName()
    {
        return "container.DefenseGun3x3v1"; //$NON-NLS-1$
    }

    @Override
    public int getInventoryStackLimit()
    {
        // TODO Auto-generated method stub
        return 64;
    }

    @Override
    public void onInventoryChanged()
    {
        // TODO Auto-generated method stub
    }

    /**
     * Do not make give this method the name canInteractWith because it clashes with Container
     */
    @Override
    public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
    {
        return true;
    }

    @Override
    public void openChest()
    {
        // TODO Auto-generated method stub
    }

    @Override
    public void closeChest()
    {
        // TODO Auto-generated method stub
    }

    @Override
    public int getMaxHealth()
    {
        return 30;
    }

    @Override
    public void onLivingUpdate()
    {
        this.posX = this.prevPosX;
        this.posY = this.prevPosY;
        this.posZ = this.prevPosZ;
        super.onLivingUpdate();
    }

    public void attackEntityWithRangedAttack(EntityLiving par1EntityLiving)
    {
        EntityExplosiveArrow var2 = new EntityExplosiveArrow(this.worldObj, this, par1EntityLiving, 1.6F, 12.0F);
        var2.setDamage(5);
        var2.setKnockbackStrength(3);
        this.func_85030_a("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
        this.worldObj.spawnEntityInWorld(var2);
    }

    public boolean FW_CheckPlacementLocation(World par3World, int par4, int par5, int par6, int par7)
    {
        if (!par3World.isAirBlock(par4, par5, par6))
        {
            int id = par3World.getBlockId(par4, par5, par6);

            if (id == 42 || id == 45 || id == 01 || id == 02 || id == 03)
            {
                return true;
            }
        }

        return false;
    }

    public void onUpdate()
    {
        super.onUpdate();
        this.posX = this.prevPosX;
        this.posY = this.prevPosY;
        this.posZ = this.prevPosZ;
        this.field_70924_f = this.field_70926_e;

        if (this.func_70922_bv())
        {
            this.field_70926_e += (1.0F - this.field_70926_e) * 0.4F;
        }
        else
        {
            this.field_70926_e += (0.0F - this.field_70926_e) * 0.4F;
        }

        for (int i = -1; i < 2; i = i + 1)
        {
            for (int j = -1; j < 2; j = j + 1)
            {
                if (!(FW_CheckPlacementLocation(this.worldObj, (int)this.posX + i, (int)posY - 1, (int)this.posZ + j, 0)))
                {
                    this.kill();
                }
            }
        }
    }

    public boolean func_70922_bv()
    {
        return this.dataWatcher.getWatchableObjectByte(20) == 1;
    }

    public void func_70918_i(boolean par1)
    {
        byte var2 = this.dataWatcher.getWatchableObjectByte(20);

        if (par1)
        {
            this.dataWatcher.updateObject(20, Byte.valueOf((byte)1));
        }
        else
        {
            this.dataWatcher.updateObject(20, Byte.valueOf((byte)0));
        }
    }

    public void onKillEntity(EntityLiving par1EntityLiving)
    {
        super.onKillEntity(par1EntityLiving);

        if (this.worldObj.difficultySetting >= 2 && par1EntityLiving instanceof EntityVillager)
        {
            if (this.worldObj.difficultySetting == 2 && this.rand.nextBoolean())
            {
                return;
            }

            this.dataWatcher.updateObject(20, Byte.valueOf((byte)0));
            this.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1016, (int)this.posX, (int)this.posY, (int)this.posZ, 0);
        }
    }

    @Override
    public boolean isEntityApplicable(Entity par1Entity)
    {
        if (par1Entity instanceof IMob)
        {
            return par1Entity instanceof IMob;
        }
        else if (par1Entity instanceof EntityLiving && !(par1Entity instanceof EntityPlayer) && !(par1Entity instanceof EntityVillager) && !(par1Entity instanceof EntityAnimal))
        {
            return par1Entity instanceof EntityLiving;
        }
        else if (par1Entity instanceof EntitySlime)
        {
            return par1Entity instanceof EntitySlime;
        }
        else
        {
            return false;
        }
    }
}

 

Can anyone help me figure out why this is not working in MP?

 

Thanks!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.