use of am2.blocks.tileentities.TileEntityKeystoneRecepticle in project ArsMagica2 by Mithion.
the class BlockKeystoneReceptacle method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLiving, ItemStack stack) {
int p = MathHelper.floor_double((par5EntityLiving.rotationYaw * 4F) / 360F + 0.5D) & 3;
byte byte0 = 3;
if (p == 0) {
byte0 = 1;
}
if (p == 1) {
byte0 = 0;
}
if (p == 2) {
byte0 = 3;
}
if (p == 3) {
byte0 = 2;
}
AMCore.instance.proxy.blocks.registerKeystonePortal(par2, par3, par4, par1World.provider.dimensionId);
par1World.setBlockMetadataWithNotify(par2, par3, par4, byte0, 2);
TileEntityKeystoneRecepticle receptacle = (TileEntityKeystoneRecepticle) par1World.getTileEntity(par2, par3, par4);
receptacle.onPlaced();
super.onBlockPlacedBy(par1World, par2, par3, par4, par5EntityLiving, stack);
}
use of am2.blocks.tileentities.TileEntityKeystoneRecepticle in project ArsMagica2 by Mithion.
the class BlockKeystoneReceptacle method onBlockActivated.
@Override
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) {
super.onBlockActivated(par1World, x, y, z, par5EntityPlayer, par6, par7, par8, par9);
if (HandleSpecialItems(par1World, par5EntityPlayer, x, y, z)) {
return true;
}
TileEntity myTE = par1World.getTileEntity(x, y, z);
if (myTE == null || !(myTE instanceof TileEntityKeystoneRecepticle)) {
return true;
}
TileEntityKeystoneRecepticle receptacle = (TileEntityKeystoneRecepticle) myTE;
if (KeystoneUtilities.HandleKeystoneRecovery(par5EntityPlayer, receptacle)) {
return true;
}
if (par5EntityPlayer.isSneaking()) {
if (!par1World.isRemote && KeystoneUtilities.instance.canPlayerAccess(receptacle, par5EntityPlayer, KeystoneAccessType.USE)) {
FMLNetworkHandler.openGui(par5EntityPlayer, AMCore.instance, ArsMagicaGuiIdList.GUI_KEYSTONE_LOCKABLE, par1World, x, y, z);
}
} else {
if (receptacle.canActivate()) {
long key = 0;
ItemStack rightClickItem = par5EntityPlayer.getCurrentEquippedItem();
if (rightClickItem != null && rightClickItem.getItem() instanceof ItemKeystone) {
key = ((ItemKeystone) rightClickItem.getItem()).getKey(rightClickItem);
}
receptacle.setActive(key);
} else if (receptacle.isActive()) {
receptacle.deactivate();
}
}
return true;
}
use of am2.blocks.tileentities.TileEntityKeystoneRecepticle 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;
}
Aggregations