Search in sources :

Example 1 with ParametersAreNonnullByDefault

use of javax.annotation.ParametersAreNonnullByDefault in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretBaseContainer method transferStackInSlot.

@SuppressWarnings("ConstantConditions")
@ParametersAreNonnullByDefault
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
    ItemStack stack = ItemStackTools.getEmptyStack();
    Slot slotObject = inventorySlots.get(slot);
    // null checks and checks if the item can be stacked (maxStackSize > 1)
    if (slotObject != null && slotObject.getHasStack()) {
        ItemStack stackInSlot = slotObject.getStack();
        stack = ItemStackTools.safeCopy(stackInSlot);
        // Actual slot start index of turret base
        int slotStart = 36;
        int ammoSlotStart = 100, ammoSlotEnd = 0, addonSlotStart = 100, addonSlotEnd = 0, upgSlotStart = 100, upgSlotEnd = 0;
        // Determine the slot range for each type( According to the class constructor )
        for (int i = slotStart; i < this.inventorySlots.size(); i++) {
            Class slotClass = this.getSlot(i).getClass();
            if (slotClass == Slot.class) {
                ammoSlotStart = Math.min(i, ammoSlotStart);
                ammoSlotEnd = Math.max(i + 1, ammoSlotEnd);
            } else if (slotClass == AddonSlot.class) {
                addonSlotStart = Math.min(i, addonSlotStart);
                addonSlotEnd = Math.max(i + 1, addonSlotEnd);
            } else if (slotClass == UpgradeSlot.class) {
                upgSlotStart = Math.min(i, upgSlotStart);
                upgSlotEnd = Math.max(i + 1, upgSlotEnd);
            }
        }
        // Transfer from player inventory
        if (slot < slotStart) {
            // Priority addon and upgrade slot first
            if (stackInSlot.getItem() instanceof AddonMetaItem) {
                if (!mergeItemStackWithStackLimit(stackInSlot, addonSlotStart, addonSlotEnd, false, this)) {
                    return ItemStackTools.getEmptyStack();
                }
            } else if (stackInSlot.getItem() instanceof UpgradeMetaItem) {
                if (!mergeItemStackWithStackLimit(stackInSlot, upgSlotStart, upgSlotEnd, false, this)) {
                    return ItemStackTools.getEmptyStack();
                }
            } else {
                if (!mergeItemStackWithStackLimit(stackInSlot, slotStart, slotStart + 9, false, this)) {
                    return ItemStackTools.getEmptyStack();
                }
            }
        } else // Transfer from turret base inventory
        {
            if (!mergeItemStackWithStackLimit(stackInSlot, 0, slotStart, false, this)) {
                return ItemStackTools.getEmptyStack();
            }
        }
        if (getStackSize(stackInSlot) == 0) {
            slotObject.putStack(ItemStackTools.getEmptyStack());
        } else {
            slotObject.onSlotChanged();
        }
        if (getStackSize(stackInSlot) == getStackSize(stack)) {
            return ItemStackTools.getEmptyStack();
        }
        slotObject.onSlotChanged();
    }
    return stack;
}
Also used : AddonMetaItem(omtteam.openmodularturrets.items.AddonMetaItem) UpgradeSlot(omtteam.openmodularturrets.client.gui.customSlot.UpgradeSlot) AddonSlot(omtteam.openmodularturrets.client.gui.customSlot.AddonSlot) Slot(net.minecraft.inventory.Slot) AddonSlot(omtteam.openmodularturrets.client.gui.customSlot.AddonSlot) ItemStack(net.minecraft.item.ItemStack) UpgradeMetaItem(omtteam.openmodularturrets.items.UpgradeMetaItem) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 2 with ParametersAreNonnullByDefault

use of javax.annotation.ParametersAreNonnullByDefault in project OpenModularTurrets by OpenModularTurretsTeam.

the class RocketProjectile method onHitBlock.

@Override
@ParametersAreNonnullByDefault
public void onHitBlock(IBlockState hitBlock, BlockPos pos) {
    if (hitBlock.getBlock() instanceof BlockAbstractTurretHead) {
        return;
    }
    if (!hitBlock.getMaterial().isSolid()) {
        // Go through non solid block
        return;
    }
    if (!getEntityWorld().isRemote) {
        float strength = ConfigHandler.canRocketsDestroyBlocks ? 2.3F : 0.1F;
        getEntityWorld().createExplosion(null, posX, posY, posZ, strength, true);
        AxisAlignedBB axis = new AxisAlignedBB(this.posX - 5, this.posY - 5, this.posZ - 5, this.posX + 5, this.posY + 5, this.posZ + 5);
        List<EntityLivingBase> targets = getEntityWorld().getEntitiesWithinAABB(EntityLivingBase.class, axis);
        for (Entity mob : targets) {
            int damage = ConfigHandler.getRocketTurretSettings().getDamage();
            if (isAmped) {
                if (mob instanceof EntityLivingBase) {
                    EntityLivingBase elb = (EntityLivingBase) mob;
                    damage += ((int) elb.getHealth() * (0.08F * amp_level));
                }
            }
            if (mob instanceof EntityPlayer) {
                if (canDamagePlayer((EntityPlayer) mob)) {
                    mob.attackEntityFrom(new NormalDamageSource("rocket"), damage);
                    mob.hurtResistantTime = 0;
                }
            }
            if (ConfigHandler.isCanRocketsHurtEnderDragon() && mob instanceof EntityDragon) {
                ((EntityDragon) mob).setHealth(((EntityDragon) mob).getHealth() - damage);
                mob.hurtResistantTime = 0;
            } else {
                mob.attackEntityFrom(new NormalDamageSource("rocket"), damage);
                mob.hurtResistantTime = 0;
            }
        }
    }
    this.setDead();
}
Also used : BlockAbstractTurretHead(omtteam.openmodularturrets.blocks.turretheads.BlockAbstractTurretHead) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityDragon(net.minecraft.entity.boss.EntityDragon) EntityLivingBase(net.minecraft.entity.EntityLivingBase) NormalDamageSource(omtteam.openmodularturrets.entity.projectiles.damagesources.NormalDamageSource) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 3 with ParametersAreNonnullByDefault

use of javax.annotation.ParametersAreNonnullByDefault in project RecurrentComplex by Ivorforce.

the class GenericVillagePiece method addComponentParts.

@Override
@ParametersAreNonnullByDefault
public boolean addComponentParts(World world, Random random, StructureBoundingBox boundingBox) {
    Structure<?> structure = StructureRegistry.INSTANCE.get(structureID);
    if (structure == null)
        return false;
    GenerationType generationType = structure.generationType(generationID);
    if (!(generationType instanceof VanillaGeneration))
        return false;
    VanillaGeneration vanillaGenInfo = (VanillaGeneration) generationType;
    AxisAlignedTransform2D transform = getCoordBaseMode() != null ? getTransform(vanillaGenInfo.front, mirrorX, getCoordBaseMode().getOpposite()) : AxisAlignedTransform2D.ORIGINAL;
    BlockPos structureShift = transform.apply(vanillaGenInfo.spawnShift, new int[] { 1, 1, 1 });
    if (this.averageGroundLvl < 0) {
        this.averageGroundLvl = this.getAverageGroundLevel(world, boundingBox);
        if (this.averageGroundLvl < 0)
            return true;
        // Structure shift y was included in bounding box, but must be re-added because it is overwritten
        this.boundingBox.offset(0, this.averageGroundLvl - this.boundingBox.minY + structureShift.getY(), 0);
    }
    if (world instanceof WorldServer)
        generate((WorldServer) world, boundingBox, structure, generationType, transform);
    return true;
}
Also used : AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) VanillaGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.VanillaGeneration) GenerationType(ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 4 with ParametersAreNonnullByDefault

use of javax.annotation.ParametersAreNonnullByDefault in project Hystrix by Netflix.

the class TypeHelper method flattenTypeVariables.

/**
     * Unwinds parametrized type into plain list that contains all parameters for the given type including nested parameterized types,
     * for example calling the method for the following type
     * <code>
     * GType<GType<GDoubleType<GType<GDoubleType<Parent, Parent>>, Parent>>>
     * </code>
     * will return list of 8 elements:
     * <code>
     * [GType, GType, GDoubleType, GType, GDoubleType, Parent, Parent, Parent]
     * </code>
     * if the given type is not parametrized then returns list with one element which is given type passed into method.
     *
     * @param type the parameterized type
     * @return list of {@link Type}
     */
@ParametersAreNonnullByDefault
public static List<Type> flattenTypeVariables(Type type) {
    Validate.notNull(type, "type cannot be null");
    List<Type> types = new ArrayList<Type>();
    TreeTraverser<Type> typeTraverser = new TreeTraverser<Type>() {

        @Override
        public Iterable<Type> children(Type root) {
            if (root instanceof ParameterizedType) {
                ParameterizedType pType = (ParameterizedType) root;
                return Arrays.asList(pType.getActualTypeArguments());
            } else if (root instanceof TypeVariable) {
                TypeVariable pType = (TypeVariable) root;
                return Arrays.asList(pType.getBounds());
            }
            return Collections.emptyList();
        }
    };
    for (Type t : typeTraverser.breadthFirstTraversal(type)) {
        types.add(t);
    }
    return types;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WildcardType(java.lang.reflect.WildcardType) TypeVariable(java.lang.reflect.TypeVariable) TreeTraverser(com.google.common.collect.TreeTraverser) ArrayList(java.util.ArrayList) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 5 with ParametersAreNonnullByDefault

use of javax.annotation.ParametersAreNonnullByDefault in project OpenModularTurrets by OpenModularTurretsTeam.

the class BlockTurretBase method getDrops.

@Override
@Nonnull
@ParametersAreNonnullByDefault
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
    ArrayList<ItemStack> drops = new ArrayList<>();
    drops.add(0, new ItemStack(ModBlocks.turretBase, 1, this.getMetaFromState(state)));
    return drops;
}
Also used : ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Aggregations

ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)9 ItemStack (net.minecraft.item.ItemStack)4 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)2 GenerationType (ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType)2 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 Entity (net.minecraft.entity.Entity)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 BlockPos (net.minecraft.util.math.BlockPos)2 WorldServer (net.minecraft.world.WorldServer)2 BlockAbstractTurretHead (omtteam.openmodularturrets.blocks.turretheads.BlockAbstractTurretHead)2 NormalDamageSource (omtteam.openmodularturrets.entity.projectiles.damagesources.NormalDamageSource)2 TreeTraverser (com.google.common.collect.TreeTraverser)1 BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)1 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)1 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)1 PacketEditTileEntity (ivorius.reccomplex.network.PacketEditTileEntity)1 OperationGenerateStructure (ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure)1