Search in sources :

Example 1 with EntityWaterMob

use of net.minecraft.entity.passive.EntityWaterMob in project MineFactoryReloaded by powercrystals.

the class TileEntityAutoSpawner method activateMachine.

@Override
protected boolean activateMachine() {
    ItemStack item = getStackInSlot(0);
    if (!isStackValidForSlot(0, item)) {
        setWorkDone(0);
        return false;
    }
    NBTTagCompound itemTag = item.getTagCompound();
    String entityID = itemTag.getString("id");
    boolean isBlackListed = MFRRegistry.getAutoSpawnerBlacklist().contains(entityID);
    blackList: if (!isBlackListed) {
        Class<?> e = (Class<?>) EntityList.stringToClassMapping.get(entityID);
        if (e == null) {
            isBlackListed = true;
            break blackList;
        }
        for (Class<?> t : MFRRegistry.getAutoSpawnerClassBlacklist()) {
            if (t.isAssignableFrom(e)) {
                isBlackListed = true;
                break blackList;
            }
        }
    }
    if (isBlackListed) {
        setWorkDone(0);
        return false;
    }
    if (getWorkDone() < getWorkMax()) {
        if (_tank.getLiquid() != null && _tank.getLiquid().amount >= 10) {
            _tank.getLiquid().amount -= 10;
            setWorkDone(getWorkDone() + 1);
            return true;
        } else {
            return false;
        }
    } else {
        Entity spawnedEntity = EntityList.createEntityByName(entityID, worldObj);
        if (!(spawnedEntity instanceof EntityLiving)) {
            return false;
        }
        EntityLiving spawnedLiving = (EntityLiving) spawnedEntity;
        if (_spawnExact) {
            NBTTagCompound tag = (NBTTagCompound) itemTag.copy();
            spawnedLiving.readEntityFromNBT(tag);
            for (int i = 0; i < 5; ++i) {
                spawnedLiving.func_96120_a(i, 0);
            }
        }
        double x = xCoord + (worldObj.rand.nextDouble() - worldObj.rand.nextDouble()) * _spawnRange;
        double y = yCoord + worldObj.rand.nextInt(3) - 1;
        double z = zCoord + (worldObj.rand.nextDouble() - worldObj.rand.nextDouble()) * _spawnRange;
        spawnedLiving.setLocationAndAngles(x, y, z, worldObj.rand.nextFloat() * 360.0F, 0.0F);
        if (!worldObj.checkNoEntityCollision(spawnedLiving.boundingBox) || !worldObj.getCollidingBoundingBoxes(spawnedLiving, spawnedLiving.boundingBox).isEmpty() || (worldObj.isAnyLiquid(spawnedLiving.boundingBox) != (spawnedLiving instanceof EntityWaterMob))) {
            return false;
        }
        if (!_spawnExact) {
            spawnedLiving.initCreature();
        }
        worldObj.spawnEntityInWorld(spawnedLiving);
        worldObj.playAuxSFX(2004, this.xCoord, this.yCoord, this.zCoord, 0);
        spawnedLiving.spawnExplosionParticle();
        setWorkDone(0);
        return true;
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityLiving(net.minecraft.entity.EntityLiving) EntityWaterMob(net.minecraft.entity.passive.EntityWaterMob) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 2 with EntityWaterMob

use of net.minecraft.entity.passive.EntityWaterMob in project NetherEx by LogicTechCorp.

the class EntityObsidianBoat method onUpdate.

@Override
public void onUpdate() {
    previousStatus = status;
    status = getBoatStatus();
    if (status != Status.UNDER_LAVA && status != Status.UNDER_FLOWING_LAVA) {
        outOfControlTicks = 0.0F;
    } else {
        ++outOfControlTicks;
    }
    if (!world.isRemote && outOfControlTicks >= 60.0F) {
        removePassengers();
    }
    if (getTimeSinceHit() > 0) {
        setTimeSinceHit(getTimeSinceHit() - 1);
    }
    if (getDamageTaken() > 0.0F) {
        setDamageTaken(getDamageTaken() - 1.0F);
    }
    prevPosX = posX;
    prevPosY = posY;
    prevPosZ = posZ;
    if (!world.isRemote) {
        setFlag(6, isGlowing());
    }
    onEntityUpdate();
    tickLerp();
    if (canPassengerSteer()) {
        if (getPassengers().size() == 0 || !(getPassengers().get(0) instanceof EntityPlayer)) {
            setPaddleState(false, false);
        }
        updateMotion();
        if (world.isRemote) {
            controlBoat();
            world.sendPacketToServer(new CPacketSteerBoat(getPaddleState(0), getPaddleState(1)));
        }
        move(MoverType.SELF, motionX, motionY, motionZ);
    } else {
        motionX = 0.0D;
        motionY = 0.0D;
        motionZ = 0.0D;
    }
    for (int i = 0; i <= 1; ++i) {
        if (getPaddleState(i)) {
            paddlePositions[i] = (float) ((double) paddlePositions[i] + 0.01D);
        } else {
            paddlePositions[i] = 0.0F;
        }
    }
    doBlockCollisions();
    List<Entity> list = world.getEntitiesInAABBexcluding(this, getEntityBoundingBox().expand(0.20000000298023224D, -0.009999999776482582D, 0.20000000298023224D), EntitySelectors.getTeamCollisionPredicate(this));
    if (!list.isEmpty()) {
        boolean flag = !world.isRemote && !(getControllingPassenger() instanceof EntityPlayer);
        for (Entity entity : list) {
            if (!entity.isPassenger(this)) {
                if (flag && getPassengers().size() < 2 && !entity.isRiding() && entity.width < width && entity instanceof EntityLivingBase && !(entity instanceof EntityWaterMob) && !(entity instanceof EntityPlayer)) {
                    entity.startRiding(this);
                } else {
                    applyEntityCollision(entity);
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) CPacketSteerBoat(net.minecraft.network.play.client.CPacketSteerBoat) EntityWaterMob(net.minecraft.entity.passive.EntityWaterMob) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

Entity (net.minecraft.entity.Entity)2 EntityWaterMob (net.minecraft.entity.passive.EntityWaterMob)2 EntityLiving (net.minecraft.entity.EntityLiving)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 CPacketSteerBoat (net.minecraft.network.play.client.CPacketSteerBoat)1