use of net.minecraft.util.ChatComponentText in project PneumaticCraft by MineMaarten.
the class EventHandlerPneumaticCraft method onPlayerClick.
@SubscribeEvent
public void onPlayerClick(PlayerInteractEvent event) {
Block interactedBlock = event.world.getBlock(event.x, event.y, event.z);
if (!event.entityPlayer.capabilities.isCreativeMode || !event.entityPlayer.canCommandSenderUseCommand(2, "securityStation")) {
if (event.action != PlayerInteractEvent.Action.RIGHT_CLICK_AIR && event.world != null && !event.world.isRemote) {
if (interactedBlock != Blockss.securityStation || event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
ItemStack heldItem = event.entityPlayer.getCurrentEquippedItem();
boolean tryingToPlaceSecurityStation = heldItem != null && heldItem.getItem() instanceof ItemBlock && ((ItemBlock) heldItem.getItem()).field_150939_a == Blockss.securityStation;
int blockingStations = PneumaticCraftUtils.getProtectingSecurityStations(event.entity.worldObj, event.x, event.y, event.z, event.entityPlayer, true, tryingToPlaceSecurityStation);
if (blockingStations > 0) {
event.setCanceled(true);
event.entityPlayer.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocalFormatted(tryingToPlaceSecurityStation ? "message.securityStation.stationPlacementPrevented" : "message.securityStation.accessPrevented", blockingStations)));
}
}
}
}
/**
* Due to some weird quirk that causes Block#onBlockActivated not getting called on the server when the player is sneaking, this is a workaround.
*/
if (!event.isCanceled() && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && !event.world.isRemote) {
if (event.entityPlayer.isSneaking() && (interactedBlock == Blockss.elevatorCaller || interactedBlock == Blockss.chargingStation)) {
event.setCanceled(interactedBlock.onBlockActivated(event.world, event.x, event.y, event.z, event.entityPlayer, event.face, 0, 0, 0));
} else if (event.entityPlayer.getCurrentEquippedItem() != null && ModInteractionUtilImplementation.getInstance().isModdedWrench(event.entityPlayer.getCurrentEquippedItem().getItem())) {
if (interactedBlock instanceof IPneumaticWrenchable) {
((IPneumaticWrenchable) interactedBlock).rotateBlock(event.world, event.entityPlayer, event.x, event.y, event.z, ForgeDirection.getOrientation(event.face));
}
}
}
if (!event.isCanceled() && interactedBlock == Blocks.cobblestone) {
AchievementHandler.checkFor9x9(event.entityPlayer, event.x, event.y, event.z);
}
}
use of net.minecraft.util.ChatComponentText in project ArsMagica2 by Mithion.
the class BlockSeerStone method onBlockActivated.
@Override
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) {
super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9);
TileEntity te = par1World.getTileEntity(par2, par3, par4);
TileEntitySeerStone sste = null;
if (te != null && te instanceof TileEntitySeerStone) {
sste = (TileEntitySeerStone) te;
} else {
return true;
}
if (KeystoneUtilities.HandleKeystoneRecovery(par5EntityPlayer, sste)) {
return true;
}
if (!KeystoneUtilities.instance.canPlayerAccess(sste, par5EntityPlayer, KeystoneAccessType.USE)) {
return true;
}
if (par5EntityPlayer.isSneaking()) {
sste.invertDetection();
if (par1World.isRemote) {
par5EntityPlayer.addChatMessage(new ChatComponentText("Inverting detection mode: " + ((TileEntitySeerStone) te).isInvertingDetection()));
}
return true;
}
if (HandleSpecialItems(par1World, par5EntityPlayer, par2, par3, par4)) {
return true;
}
if (!par1World.isRemote)
FMLNetworkHandler.openGui(par5EntityPlayer, AMCore.instance, ArsMagicaGuiIdList.GUI_SEER_STONE, par1World, par2, par3, par4);
return true;
}
use of net.minecraft.util.ChatComponentText in project ArsMagica2 by Mithion.
the class BlockInscriptionTable method onBlockActivated.
@Override
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) {
super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9);
if (par1World.isRemote) {
return true;
}
TileEntityInscriptionTable te = (TileEntityInscriptionTable) par1World.getTileEntity(par2, par3, par4);
TileEntityInscriptionTable tealt = te;
int meta = par1World.getBlockMetadata(par2, par3, par4);
boolean isLeft = (meta & 0x8) == 0x0;
if (te != null) {
int checkMeta = meta & ~0x8;
if (!isLeft) {
switch(checkMeta) {
case 1:
par4--;
break;
case 2:
par2--;
break;
case 3:
par4++;
break;
case 4:
par2++;
break;
}
te = (TileEntityInscriptionTable) par1World.getTileEntity(par2, par3, par4);
} else {
int tx = par2;
int ty = par3;
int tz = par4;
switch(checkMeta) {
case 1:
tz++;
break;
case 2:
tx++;
break;
case 3:
tz--;
break;
case 4:
tx--;
break;
}
tealt = (TileEntityInscriptionTable) par1World.getTileEntity(tx, ty, tz);
}
}
if (te == null)
return true;
if (te.isInUse(par5EntityPlayer)) {
par5EntityPlayer.addChatMessage(new ChatComponentText("Someone else is using this."));
return true;
}
ItemStack curItem = par5EntityPlayer.getCurrentEquippedItem();
if (curItem != null && curItem.getItem() == ItemsCommonProxy.inscriptionUpgrade) {
if (te.getUpgradeState() == curItem.getItemDamage()) {
par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, null);
te.incrementUpgradeState();
tealt.incrementUpgradeState();
return true;
}
}
FMLNetworkHandler.openGui(par5EntityPlayer, AMCore.instance, ArsMagicaGuiIdList.GUI_INSCRIPTION_TABLE, par1World, par2, par3, par4);
return true;
}
use of net.minecraft.util.ChatComponentText in project ArsMagica2 by Mithion.
the class EntityLightMage method interact.
@Override
protected boolean interact(EntityPlayer player) {
if (worldObj.isRemote)
return false;
if (player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ItemNameTag)
return false;
if (SkillData.For(player).isEntryKnown(SkillTreeManager.instance.getSkillTreeEntry(SkillManager.instance.getSkill("MageBandI")))) {
if (EntityUtilities.isSummon(this)) {
player.addChatMessage(new ChatComponentText(String.format("\247o%s", StatCollector.translateToLocal("am2.npc.partyleave"))));
EntityUtilities.revertAI(this);
} else {
if (ExtendedProperties.For(player).getCanHaveMoreSummons()) {
if (ExtendedProperties.For(player).getMagicLevel() - 5 >= ExtendedProperties.For(this).getMagicLevel()) {
player.addChatMessage(new ChatComponentText(String.format("\247o%s", StatCollector.translateToLocal("am2.npc.partyjoin"))));
EntityUtilities.setOwner(this, player);
EntityUtilities.makeSummon_PlayerFaction(this, player, true);
EntityUtilities.setSummonDuration(this, -1);
} else {
player.addChatMessage(new ChatComponentText(String.format("\247o%s", StatCollector.translateToLocal("am2.npc.partyrefuse"))));
}
} else {
player.addChatMessage(new ChatComponentText(String.format("\247o%s", StatCollector.translateToLocal("am2.npc.partyfull"))));
}
}
} else {
player.addChatMessage(new ChatComponentText(String.format("\247o%s", StatCollector.translateToLocal("am2.npc.nopartyskill"))));
}
return false;
}
use of net.minecraft.util.ChatComponentText in project ArsMagica2 by Mithion.
the class Blink method applyEffectEntity.
@Override
public boolean applyEffectEntity(ItemStack stack, World world, EntityLivingBase caster, Entity target) {
if (!(target instanceof EntityLivingBase))
return false;
if (world.isRemote) {
ExtendedProperties.For((EntityLivingBase) target).astralBarrierBlocked = false;
}
double distance = GetTeleportDistance(stack, caster, target);
double motionX = -MathHelper.sin((target.rotationYaw / 180F) * 3.141593F) * MathHelper.cos((target.rotationPitch / 180F) * 3.141593F) * distance;
double motionZ = MathHelper.cos((target.rotationYaw / 180F) * 3.141593F) * MathHelper.cos((target.rotationPitch / 180F) * 3.141593F) * distance;
double motionY = -MathHelper.sin((target.rotationPitch / 180F) * 3.141593F) * distance;
double d = motionX, d1 = motionY, d2 = motionZ;
float f2 = MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2);
d /= f2;
d1 /= f2;
d2 /= f2;
d *= distance;
d1 *= distance;
d2 *= distance;
motionX = d;
motionY = d1;
motionZ = d2;
float f3 = MathHelper.sqrt_double(d * d + d2 * d2);
ArrayList<Long> keystoneKeys = KeystoneUtilities.instance.GetKeysInInvenory((EntityLivingBase) target);
double newX = target.posX + motionX;
double newZ = target.posZ + motionZ;
double newY = target.posY + motionY;
boolean coordsValid = false;
boolean astralBarrierBlocked = false;
TileEntityAstralBarrier finalBlocker = null;
while (!coordsValid && distance > 0) {
if (caster.isPotionActive(BuffList.astralDistortion.id)) {
coordsValid = true;
newX = caster.posX;
newY = caster.posY;
newZ = caster.posZ;
}
TileEntityAstralBarrier blocker = DimensionUtilities.GetBlockingAstralBarrier(world, (int) newX, (int) newY, (int) newZ, keystoneKeys);
while (blocker != null) {
finalBlocker = blocker;
astralBarrierBlocked = true;
int dx = (int) newX - blocker.xCoord;
int dy = (int) newY - blocker.yCoord;
int dz = (int) newZ - blocker.zCoord;
int sqDist = (dx * dx + dy * dy + dz * dz);
int delta = blocker.getRadius() - (int) Math.floor(Math.sqrt(sqDist));
distance -= delta;
if (distance < 0)
break;
motionX = -MathHelper.sin((target.rotationYaw / 180F) * 3.141593F) * MathHelper.cos((target.rotationPitch / 180F) * 3.141593F) * distance;
motionZ = MathHelper.cos((target.rotationYaw / 180F) * 3.141593F) * MathHelper.cos((target.rotationPitch / 180F) * 3.141593F) * distance;
motionY = -MathHelper.sin((target.rotationPitch / 180F) * 3.141593F) * distance;
d = motionX;
d1 = motionY;
d2 = motionZ;
f2 = MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2);
d /= f2;
d1 /= f2;
d2 /= f2;
d *= distance;
d1 *= distance;
d2 *= distance;
motionX = d;
motionY = d1;
motionZ = d2;
f3 = MathHelper.sqrt_double(d * d + d2 * d2);
newX = target.posX + motionX;
newZ = target.posZ + motionZ;
newY = target.posY + motionY;
blocker = DimensionUtilities.GetBlockingAstralBarrier(world, (int) newX, (int) newY, (int) newZ, keystoneKeys);
}
if (distance < 0) {
coordsValid = false;
break;
}
// rounding combinations, normal y
if (CheckCoords(world, (int) Math.floor(newX), (int) newY, (int) Math.floor(newZ))) {
newX = Math.floor(newX) + 0.5;
newZ = Math.floor(newZ) + 0.5;
coordsValid = true;
break;
} else if (CheckCoords(world, (int) Math.floor(newX), (int) newY, (int) Math.ceil(newZ))) {
newX = Math.floor(newX) + 0.5;
newZ = Math.ceil(newZ) + 0.5;
coordsValid = true;
break;
} else if (CheckCoords(world, (int) Math.ceil(newX), (int) newY, (int) Math.floor(newZ))) {
newX = Math.ceil(newX) + 0.5;
newZ = Math.floor(newZ) + 0.5;
coordsValid = true;
break;
} else if (CheckCoords(world, (int) Math.ceil(newX), (int) newY, (int) Math.ceil(newZ))) {
newX = Math.ceil(newX) + 0.5;
newZ = Math.ceil(newZ) + 0.5;
coordsValid = true;
break;
}
// rounding combinations, y-1
if (CheckCoords(world, (int) Math.floor(newX), (int) newY - 1, (int) Math.floor(newZ))) {
newX = Math.floor(newX) + 0.5;
newZ = Math.floor(newZ) + 0.5;
newY--;
coordsValid = true;
break;
} else if (CheckCoords(world, (int) Math.floor(newX), (int) newY - 1, (int) Math.ceil(newZ))) {
newX = Math.floor(newX) + 0.5;
newZ = Math.ceil(newZ) + 0.5;
newY--;
coordsValid = true;
break;
} else if (CheckCoords(world, (int) Math.ceil(newX), (int) newY - 1, (int) Math.floor(newZ))) {
newX = Math.ceil(newX) + 0.5;
newZ = Math.floor(newZ) + 0.5;
newY--;
coordsValid = true;
break;
} else if (CheckCoords(world, (int) Math.ceil(newX), (int) newY - 1, (int) Math.ceil(newZ))) {
newX = Math.ceil(newX) + 0.5;
newZ = Math.ceil(newZ) + 0.5;
newY--;
coordsValid = true;
break;
}
// rounding combinations, y+1
if (CheckCoords(world, (int) Math.floor(newX), (int) newY + 1, (int) Math.floor(newZ))) {
newX = Math.floor(newX) + 0.5;
newZ = Math.floor(newZ) + 0.5;
newY++;
coordsValid = true;
break;
} else if (CheckCoords(world, (int) Math.floor(newX), (int) newY + 1, (int) Math.ceil(newZ))) {
newX = Math.floor(newX) + 0.5;
newZ = Math.ceil(newZ) + 0.5;
newY++;
coordsValid = true;
break;
} else if (CheckCoords(world, (int) Math.ceil(newX), (int) newY + 1, (int) Math.floor(newZ))) {
newX = Math.ceil(newX) + 0.5;
newZ = Math.floor(newZ) + 0.5;
newY++;
coordsValid = true;
break;
} else if (CheckCoords(world, (int) Math.ceil(newX), (int) newY + 1, (int) Math.ceil(newZ))) {
newX = Math.ceil(newX) + 0.5;
newZ = Math.ceil(newZ) + 0.5;
newY++;
coordsValid = true;
break;
}
distance--;
motionX = -MathHelper.sin((target.rotationYaw / 180F) * 3.141593F) * MathHelper.cos((target.rotationPitch / 180F) * 3.141593F) * distance;
motionZ = MathHelper.cos((target.rotationYaw / 180F) * 3.141593F) * MathHelper.cos((target.rotationPitch / 180F) * 3.141593F) * distance;
motionY = -MathHelper.sin((target.rotationPitch / 180F) * 3.141593F) * distance;
d = motionX;
d1 = motionY;
d2 = motionZ;
f2 = MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2);
d /= f2;
d1 /= f2;
d2 /= f2;
d *= distance;
d1 *= distance;
d2 *= distance;
motionX = d;
motionY = d1;
motionZ = d2;
f3 = MathHelper.sqrt_double(d * d + d2 * d2);
newX = target.posX + motionX;
newZ = target.posZ + motionZ;
newY = target.posY + motionY;
}
if (world.isRemote && astralBarrierBlocked && coordsValid) {
ExtendedProperties.For((EntityLivingBase) target).astralBarrierBlocked = true;
if (finalBlocker != null) {
finalBlocker.onEntityBlocked((EntityLivingBase) target);
}
}
if (!world.isRemote) {
if (!coordsValid && target instanceof EntityPlayer) {
((EntityPlayer) target).addChatMessage(new ChatComponentText("Can't find a place to blink forward to."));
return false;
}
}
if (!world.isRemote) {
((EntityLivingBase) target).setPositionAndUpdate(newX, newY, newZ);
}
return true;
}
Aggregations