use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class ItemCrystalWrench method storePairLocation.
private void storePairLocation(World world, TileEntity te, ItemStack stack, EntityPlayer player, double hitX, double hitY, double hitZ) {
AMVector3 destination = new AMVector3(te);
if (!world.isRemote) {
if (te instanceof TileEntityFlickerHabitat) {
NBTTagCompound habLoc = new NBTTagCompound();
destination.writeToNBT(habLoc);
stack.stackTagCompound.setTag(HAB_PAIRLOC, habLoc);
} else {
NBTTagCompound pairLoc = new NBTTagCompound();
destination.writeToNBT(pairLoc);
stack.stackTagCompound.setTag(KEY_PAIRLOC, pairLoc);
}
if (player.isSneaking()) {
stack.stackTagCompound.setBoolean(KEEP_BINDING, true);
}
} else {
spawnLinkParticles(world, hitX, hitY, hitZ);
}
}
use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class FlickerOperatorFelledOak method getPlantLocation.
private AMVector3 getPlantLocation(World worldObj, IFlickerController habitat, ItemStack sapling) {
if (sapling.getItem() instanceof ItemBlock == false)
return null;
TileEntity te = (TileEntity) habitat;
byte[] data = habitat.getMetadata(this);
AMVector3 offset = null;
if (data == null || data.length == 0) {
offset = new AMVector3(te.xCoord - radius_horiz, te.yCoord - radius_vert, te.zCoord - radius_horiz);
} else {
AMDataReader reader = new AMDataReader(data, false);
offset = new AMVector3(reader.getInt(), te.yCoord - radius_vert, reader.getInt());
}
Block treeBlock = ((ItemBlock) sapling.getItem()).field_150939_a;
for (int i = (int) offset.x; i <= te.xCoord + radius_horiz; i += 2) {
for (int k = (int) offset.z; k <= te.zCoord + radius_horiz; k += 2) {
for (int j = (int) offset.y; j <= te.yCoord + radius_vert; ++j) {
Block block = worldObj.getBlock(i, j, k);
if (block.isReplaceable(worldObj, i, j, k) && treeBlock.canPlaceBlockAt(worldObj, i, j, k)) {
AMDataWriter writer = new AMDataWriter();
writer.add(i).add(k);
habitat.setMetadata(this, writer.generate());
return new AMVector3(i, j, k);
}
}
}
}
AMDataWriter writer = new AMDataWriter();
writer.add(te.xCoord - radius_horiz).add(te.zCoord - radius_horiz);
habitat.setMetadata(this, writer.generate());
return null;
}
use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class FlickerOperatorFelledOak method plantTree.
private void plantTree(World worldObj, IFlickerController habitat, boolean powered) {
if (!powered || worldObj.isRemote)
return;
ItemStack sapling = getSaplingFromNearbyChest(worldObj, habitat);
if (sapling == null)
return;
AMVector3 plantLoc = getPlantLocation(worldObj, habitat, sapling);
if (plantLoc == null)
return;
deductSaplingFromNearbyChest(worldObj, habitat);
ItemBlock block = (ItemBlock) sapling.getItem();
worldObj.setBlock((int) plantLoc.x, (int) plantLoc.y, (int) plantLoc.z, block.field_150939_a, block.getMetadata(sapling.getItemDamage()), 3);
}
use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class FlickerOperatorItemTransport method DoOperation.
@Override
public boolean DoOperation(World worldObj, IFlickerController controller, boolean powered, Affinity[] flickers) {
if (worldObj.isRemote) {
return false;
}
// Gets the habitat running this operation
TileEntityFlickerHabitat habitat = null;
if (controller instanceof TileEntityFlickerHabitat) {
habitat = (TileEntityFlickerHabitat) controller;
} else {
// if the habitat couldn't be found, bail
return false;
}
int toMove = 0;
// if(powered){
for (int i = 0; i < 6; i++) {
if (flickers[i] == Affinity.ARCANE) {
toMove += 32;
}
}
// }
// ensure toMove is at least 1
toMove = Math.max(toMove, 1);
// initiate the arrays for any input crystals
ArrayList<ItemStack> itemsToTransfer = new ArrayList<ItemStack>();
ArrayList<AMVector3> removeFromInList = new ArrayList<AMVector3>();
boolean itemFound = false;
// if the in list position has exceeded the size of the list reset it
if (habitat.getInListPosition() >= habitat.getInListSize()) {
habitat.setInListPosition(0);
}
for (int inIterator = habitat.getInListPosition(); inIterator < habitat.getInListSize(); ++inIterator) {
// Gets the tile entity for the attached crystal marker at the specified location
AMVector3 vector = habitat.getInListAt(inIterator);
TileEntity te = null;
TileEntityCrystalMarker crystalMarkerTE = GetCrystalMarkerTileEntity(worldObj, (int) vector.x, (int) vector.y, (int) vector.z);
if (crystalMarkerTE == null) {
// crystal marker no longer exists, remove it from the list
removeFromInList.add(vector);
break;
}
te = GetAttachedCrystalMarkerTileEntity(worldObj, crystalMarkerTE, vector);
if (te != null && te instanceof IInventory) {
// if the crystal is attached to an inventory
itemFound = moveItem(worldObj, (IInventory) te, crystalMarkerTE, habitat, toMove);
if (itemFound) {
// if an item was found the break out of the current loop
habitat.setInListPosition(inIterator + 1);
break;
} else if (te instanceof TileEntityChest) {
// This is to handle the special case of double chests
TileEntityChest adjacent = InventoryUtilities.getAdjacentChest((TileEntityChest) te);
if (adjacent != null) {
itemFound = moveItem(worldObj, adjacent, crystalMarkerTE, habitat, toMove);
if (itemFound) {
habitat.setInListPosition(inIterator + 1);
}
}
}
}
}
if (itemFound == false) {
// if no items were found to move then reset the input list position
habitat.setInListPosition(0);
}
for (AMVector3 vector : removeFromInList) {
// remove the invalid in list positions from the maintained in list
habitat.removeInListAt(vector);
}
return itemFound;
}
use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class FlickerOperatorMoonstoneAttractor method RemoveOperator.
@Override
public void RemoveOperator(World worldObj, IFlickerController habitat, boolean powered) {
AMVector3 vec = new AMVector3((TileEntity) habitat);
attractors.remove(vec);
}
Aggregations