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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations