use of net.minecraft.entity.player.EntityPlayerMP in project Almura by AlmuraDev.
the class SlabItemImpl method placeBlockAt.
@Override
public boolean placeBlockAt(final ItemStack stack, final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final IBlockState newState) {
this.checkAndDelegate();
if (!world.setBlockState(pos, newState, 11)) {
return false;
}
IBlockState state = world.getBlockState(pos);
if (state.getBlock() == this.getBlock()) {
setTileEntityNBT(world, player, pos, stack);
this.getBlock().onBlockPlacedBy(world, pos, state, player, stack);
if (player instanceof EntityPlayerMP) {
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, pos, stack);
}
}
return true;
}
use of net.minecraft.entity.player.EntityPlayerMP in project Almura by AlmuraDev.
the class SlabItemImpl method tryPlaceSingle.
private EnumActionResult tryPlaceSingle(final World world, final EntityPlayer player, final EnumHand hand, final ItemStack itemStack, BlockPos pos, final EnumFacing facing, final float hitX, final float hitY, final float hitZ) {
IBlockState previousState = world.getBlockState(pos);
final Block previousBlock = previousState.getBlock();
if (!previousBlock.isReplaceable(world, pos)) {
pos = pos.offset(facing);
}
if (!itemStack.isEmpty() && player.canPlayerEdit(pos, facing, itemStack) && world.mayPlace(this.singleSlab, pos, false, facing, player)) {
final IBlockState singleState = this.singleSlab.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, 0, player, hand);
if (world.setBlockState(pos, singleState, 11)) {
previousState = world.getBlockState(pos);
if (singleState.equals(previousState)) {
this.getBlock().onBlockPlacedBy(world, pos, singleState, player, itemStack);
if (player instanceof EntityPlayerMP) {
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, pos, itemStack);
}
final SoundType sounds = singleState.getBlock().getSoundType(singleState, world, pos, player);
world.playSound(player, pos, sounds.getPlaceSound(), SoundCategory.BLOCKS, (sounds.getVolume() + 1.0F) / 2.0F, sounds.getPitch() * 0.8F);
itemStack.shrink(1);
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.FAIL;
}
use of net.minecraft.entity.player.EntityPlayerMP in project VoodooCraft by Mod-DevCafeTeam.
the class HexSuffocate method activeUse.
@Override
public ItemStack activeUse(ItemStack stackIn, World world, EntityPlayer player, EnumHand hand, int strength, @Nullable EntityLivingBase target) {
if (!world.isRemote) {
RayTraceResult result = Minecraft.getMinecraft().objectMouseOver;
Entity e = result.entityHit;
if (e instanceof EntityPlayerMP) {
EntityPlayerMP p = (EntityPlayerMP) e;
if (!p.capabilities.isCreativeMode) {
for (int i = 0; i < p.getMaxHealth(); i++) {
int dif = world.getDifficulty().getDifficultyId();
p.setHealth(p.getHealth() - dif);
p.performHurtAnimation();
}
}
}
}
return super.activeUse(stackIn, world, player, hand, strength, target);
}
use of net.minecraft.entity.player.EntityPlayerMP in project ArsMagica2 by Mithion.
the class Appropriation 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) {
if (!(caster instanceof EntityPlayer))
return false;
ItemStack originalSpellStack = getOriginalSpellStack((EntityPlayer) caster);
if (originalSpellStack == null) {
return false;
}
if (originalSpellStack.stackTagCompound == null) {
return false;
}
Block block = world.getBlock(blockx, blocky, blockz);
if (block == null) {
return false;
}
for (String s : AMCore.config.getAppropriationBlockBlacklist()) {
if (block.getUnlocalizedName() == s) {
return false;
}
}
if (!world.isRemote) {
if (originalSpellStack.stackTagCompound.hasKey(storageKey)) {
if (world.getBlock(blockx, blocky, blockz) == Blocks.air)
blockFace = -1;
if (blockFace != -1) {
switch(blockFace) {
case 0:
blocky--;
break;
case 1:
blocky++;
break;
case 2:
blockz--;
break;
case 3:
blockz++;
break;
case 4:
blockx--;
break;
case 5:
blockx++;
break;
}
}
if (world.isAirBlock(blockx, blocky, blockz) || !world.getBlock(blockx, blocky, blockz).getMaterial().isSolid()) {
// save current spell
NBTTagCompound nbt = null;
if (stack.getTagCompound() != null) {
nbt = (NBTTagCompound) stack.getTagCompound().copy();
}
EntityPlayerMP casterPlayer = (EntityPlayerMP) DummyEntityPlayer.fromEntityLiving(caster);
world.captureBlockSnapshots = true;
restore((EntityPlayer) caster, world, originalSpellStack, blockx, blocky, blockz, impactX, impactY, impactZ);
world.captureBlockSnapshots = false;
// save new spell data
NBTTagCompound newNBT = null;
if (stack.getTagCompound() != null) {
newNBT = (NBTTagCompound) stack.getTagCompound().copy();
}
net.minecraftforge.event.world.BlockEvent.PlaceEvent placeEvent = null;
List<net.minecraftforge.common.util.BlockSnapshot> blockSnapshots = (List<net.minecraftforge.common.util.BlockSnapshot>) world.capturedBlockSnapshots.clone();
world.capturedBlockSnapshots.clear();
// restore original item data for event
if (nbt != null) {
stack.setTagCompound(nbt);
}
if (blockSnapshots.size() > 1) {
placeEvent = ForgeEventFactory.onPlayerMultiBlockPlace(casterPlayer, blockSnapshots, ForgeDirection.UNKNOWN);
} else if (blockSnapshots.size() == 1) {
placeEvent = ForgeEventFactory.onPlayerBlockPlace(casterPlayer, blockSnapshots.get(0), ForgeDirection.UNKNOWN);
}
if (placeEvent != null && (placeEvent.isCanceled())) {
// revert back all captured blocks
for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots) {
world.restoringBlockSnapshots = true;
blocksnapshot.restore(true, false);
world.restoringBlockSnapshots = false;
}
return false;
} else {
// Change the stack to its new content
if (nbt != null) {
stack.setTagCompound(newNBT);
}
for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots) {
int blockX = blocksnapshot.x;
int blockY = blocksnapshot.y;
int blockZ = blocksnapshot.z;
int metadata = world.getBlockMetadata(blockX, blockY, blockZ);
int updateFlag = blocksnapshot.flag;
Block oldBlock = blocksnapshot.replacedBlock;
Block newBlock = world.getBlock(blockX, blockY, blockZ);
if (newBlock != null && !(newBlock.hasTileEntity(metadata))) {
// Containers get placed automatically
newBlock.onBlockAdded(world, blockX, blockY, blockZ);
}
world.markAndNotifyBlock(blockX, blockY, blockZ, null, oldBlock, newBlock, updateFlag);
}
}
world.capturedBlockSnapshots.clear();
// restore((EntityPlayer)caster, world, originalSpellStack, blockx, blocky, blockz, impactX, impactY, impactZ);
}
} else {
if (block == null || block.getBlockHardness(world, blockx, blocky, blockz) == -1.0f) {
return false;
}
NBTTagCompound data = new NBTTagCompound();
data.setString(storageType, "block");
//data.setString("blockName", block.getUnlocalizedName().replace("tile.", ""));
data.setInteger("blockID", Block.getIdFromBlock(block));
int meta = world.getBlockMetadata(blockx, blocky, blockz);
data.setInteger("meta", meta);
EntityPlayerMP casterPlayer = (EntityPlayerMP) DummyEntityPlayer.fromEntityLiving(caster);
if (!ForgeEventFactory.doPlayerHarvestCheck(casterPlayer, block, true)) {
return false;
}
BreakEvent event = ForgeHooks.onBlockBreakEvent(world, casterPlayer.theItemInWorldManager.getGameType(), casterPlayer, blockx, blocky, blockz);
if (event.isCanceled()) {
return false;
}
TileEntity te = world.getTileEntity(blockx, blocky, blockz);
if (te != null) {
NBTTagCompound teData = new NBTTagCompound();
te.writeToNBT(teData);
data.setTag("tileEntity", teData);
// remove tile entity first to prevent content dropping which is already saved in the NBT
try {
world.removeTileEntity(blockx, blocky, blockz);
} catch (Throwable exception) {
exception.printStackTrace();
}
}
originalSpellStack.stackTagCompound.setTag(storageKey, data);
setOriginalSpellStackData((EntityPlayer) caster, originalSpellStack);
world.setBlockToAir(blockx, blocky, blockz);
}
}
return true;
}
use of net.minecraft.entity.player.EntityPlayerMP in project NewHorizonsCoreMod by GTNewHorizons.
the class CustomFuelsCommand method canCommandSenderUseCommand.
@Override
public boolean canCommandSenderUseCommand(ICommandSender pCommandSender) {
if (pCommandSender instanceof EntityPlayerMP) {
EntityPlayerMP tEP = (EntityPlayerMP) pCommandSender;
boolean tPlayerOpped = MinecraftServer.getServer().getConfigurationManager().func_152596_g(tEP.getGameProfile());
// && tIncreative;
return tPlayerOpped;
} else if (pCommandSender instanceof MinecraftServer)
return true;
else
return false;
}
Aggregations