use of am2.api.blocks.IKeystoneLockable in project ArsMagica2 by Mithion.
the class BlocksCommonProxy method getNextKeystoneLocationInWorld.
public AMVector3 getNextKeystoneLocationInWorld(World world, int x, int y, int z, long key) {
AMVector3 location = new AMVector3(x, y, z);
ArrayList<AMVector3> dimensionList = KeystonePortalLocations.get(world.provider.dimensionId);
if (dimensionList == null || dimensionList.size() < 1) {
return null;
}
int index = dimensionList.indexOf(location);
index++;
if (index >= dimensionList.size())
index = 0;
AMVector3 newLocation = dimensionList.get(index);
while (!newLocation.equals(location)) {
TileEntity te = world.getTileEntity((int) newLocation.x, (int) newLocation.y, (int) newLocation.z);
if (te != null && te instanceof TileEntityKeystoneRecepticle) {
if (KeystoneUtilities.instance.getKeyFromRunes(((IKeystoneLockable) te).getRunesInKey()) == key) {
return newLocation;
}
}
index++;
if (index >= dimensionList.size())
index = 0;
newLocation = dimensionList.get(index);
}
return location;
}
use of am2.api.blocks.IKeystoneLockable in project ArsMagica2 by Mithion.
the class BlockMagiciansWorkbench method onBlockActivated.
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntityMagiciansWorkbench) {
if (KeystoneUtilities.HandleKeystoneRecovery(player, (IKeystoneLockable) te))
return true;
if (KeystoneUtilities.instance.canPlayerAccess((IKeystoneLockable) te, player, KeystoneAccessType.USE)) {
super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9);
if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == ItemsCommonProxy.workbenchUpgrade) {
((TileEntityMagiciansWorkbench) te).setUpgradeStatus(TileEntityMagiciansWorkbench.UPG_CRAFT, true);
if (!world.isRemote) {
ItemStack stack = player.getCurrentEquippedItem();
stack.stackSize--;
if (stack.stackSize <= 0)
stack = null;
player.inventory.setInventorySlotContents(player.inventory.currentItem, stack);
}
return true;
} else {
if (!world.isRemote) {
super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9);
FMLNetworkHandler.openGui(player, AMCore.instance, ArsMagicaGuiIdList.GUI_MAGICIANS_WORKBENCH, world, x, y, z);
}
}
}
}
return true;
}
use of am2.api.blocks.IKeystoneLockable in project ArsMagica2 by Mithion.
the class BlockKeystoneDoor method onBlockHarvested.
@Override
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer player) {
if (world.isRemote)
return;
if (world.getBlock(x, y - 1, z) == BlocksCommonProxy.keystoneDoor)
y--;
IKeystoneLockable lockable = (IKeystoneLockable) world.getTileEntity(x, y, z);
if (lockable == null)
return;
if (!KeystoneUtilities.instance.canPlayerAccess(lockable, player, KeystoneAccessType.BREAK))
return;
super.onBlockHarvested(world, x, y, z, meta, player);
}
use of am2.api.blocks.IKeystoneLockable in project ArsMagica2 by Mithion.
the class Dig method applyEffectBlock.
@Override
public boolean applyEffectBlock(ItemStack stack, World world, int blockx, int blocky, int blockz, int blockFace, double impactX, double impactY, double impactZ, EntityLivingBase caster) {
Block block = world.getBlock(blockx, blocky, blockz);
if (block == Blocks.air) {
return false;
}
TileEntity te = world.getTileEntity(blockx, blocky, blockz);
if (te != null) {
if (!AMCore.config.getDigBreaksTileEntities())
return false;
if (te instanceof IKeystoneLockable && !KeystoneUtilities.instance.canPlayerAccess((IKeystoneLockable) te, DummyEntityPlayer.fromEntityLiving(caster), KeystoneAccessType.BREAK))
return false;
}
if (disallowedBlocks.contains(block))
return false;
if (block.getBlockHardness(world, blockx, blocky, blockz) == -1)
return false;
int meta = world.getBlockMetadata(blockx, blocky, blockz);
int harvestLevel = block.getHarvestLevel(meta);
int miningLevel = 2 + SpellUtils.instance.countModifiers(SpellModifiers.MINING_POWER, stack, 0);
if (harvestLevel > miningLevel)
return false;
EntityPlayer casterPlayer = DummyEntityPlayer.fromEntityLiving(caster);
if (ForgeEventFactory.doPlayerHarvestCheck(casterPlayer, block, true)) {
float xMana = block.getBlockHardness(world, blockx, blocky, blockz) * hardnessManaFactor;
float xBurnout = ArsMagicaApi.instance.getBurnoutFromMana(xMana);
if (!world.isRemote) {
BreakEvent event = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) casterPlayer).theItemInWorldManager.getGameType(), (EntityPlayerMP) casterPlayer, blockx, blocky, blockz);
if (event.isCanceled()) {
return false;
}
block.onBlockHarvested(world, blockx, blocky, blockz, meta, casterPlayer);
boolean flag = block.removedByPlayer(world, casterPlayer, blockx, blocky, blockz, true);
if (flag) {
block.onBlockDestroyedByPlayer(world, blockx, blocky, blockz, meta);
block.harvestBlock(world, casterPlayer, blockx, blocky, blockz, meta);
}
}
ExtendedProperties.For(caster).deductMana(xMana);
ExtendedProperties.For(caster).addBurnout(xBurnout);
return true;
}
return false;
}
Aggregations