use of net.minecraft.util.MovingObjectPosition in project SecurityCraft by Geforce132.
the class ItemModifiedBucket method onItemRightClick.
/**
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
*/
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
boolean flag = this.isFull == Blocks.air;
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, flag);
if (movingobjectposition == null) {
return par1ItemStack;
} else {
FillBucketEvent event = new FillBucketEvent(par3EntityPlayer, par1ItemStack, par2World, movingobjectposition);
if (MinecraftForge.EVENT_BUS.post(event)) {
return par1ItemStack;
}
if (event.getResult() == Event.Result.ALLOW) {
if (par3EntityPlayer.capabilities.isCreativeMode) {
return par1ItemStack;
}
if (--par1ItemStack.stackSize <= 0) {
return event.result;
}
if (!par3EntityPlayer.inventory.addItemStackToInventory(event.result)) {
par3EntityPlayer.dropPlayerItemWithRandomChoice(event.result, false);
}
return par1ItemStack;
}
if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
int i = movingobjectposition.blockX;
int j = movingobjectposition.blockY;
int k = movingobjectposition.blockZ;
if (!par2World.canMineBlock(par3EntityPlayer, i, j, k)) {
return par1ItemStack;
}
if (flag) {
if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack)) {
return par1ItemStack;
}
Material material = par2World.getBlock(i, j, k).getMaterial();
int l = par2World.getBlockMetadata(i, j, k);
//if (material == Material.water && l == 0)
if (material == Material.water && l == 0) {
par2World.setBlockToAir(i, j, k);
// return this.func_150910_a(par1ItemStack, par3EntityPlayer, mod_SecurityCraft.fWaterBucket);
return new ItemStack(mod_SecurityCraft.fWaterBucket, 1, 0);
}
if (material == Material.lava && l == 0) {
par2World.setBlockToAir(i, j, k);
//return this.func_150910_a(par1ItemStack, par3EntityPlayer, mod_SecurityCraft.fLavaBucket);
return new ItemStack(mod_SecurityCraft.fLavaBucket, 1, 0);
}
} else {
if (this.isFull == Blocks.air) {
return new ItemStack(Items.bucket);
}
if (movingobjectposition.sideHit == 0) {
--j;
}
if (movingobjectposition.sideHit == 1) {
++j;
}
if (movingobjectposition.sideHit == 2) {
--k;
}
if (movingobjectposition.sideHit == 3) {
++k;
}
if (movingobjectposition.sideHit == 4) {
--i;
}
if (movingobjectposition.sideHit == 5) {
++i;
}
if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack)) {
return par1ItemStack;
}
if (this.tryPlaceContainedLiquid(par2World, i, j, k) && !par3EntityPlayer.capabilities.isCreativeMode) {
return new ItemStack(Items.bucket);
}
}
}
return par1ItemStack;
}
}
use of net.minecraft.util.MovingObjectPosition in project SecurityCraft by Geforce132.
the class ForgeEventHandler method getBlockInFront.
private int[] getBlockInFront(World par1World, EntityPlayer par2EntityPlayer, double reach) {
int[] blockInfo = { 0, 0, 0, 0, -1, 0 };
MovingObjectPosition movingobjectposition = getMovingObjectPositionFromPlayer(par1World, par2EntityPlayer, true, reach);
if (movingobjectposition != null) {
if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
blockInfo[1] = movingobjectposition.blockX;
blockInfo[2] = movingobjectposition.blockY;
blockInfo[3] = movingobjectposition.blockZ;
blockInfo[4] = movingobjectposition.sideHit;
blockInfo[5] = par1World.getBlockMetadata(blockInfo[1], blockInfo[2], blockInfo[3]);
blockInfo[0] = Block.getIdFromBlock(par1World.getBlock(blockInfo[1], blockInfo[2], blockInfo[3]));
}
}
return blockInfo;
}
use of net.minecraft.util.MovingObjectPosition in project SecurityCraft by Geforce132.
the class ItemModifiedBucket method onItemRightClick.
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
boolean flag = this.containedBlock == Blocks.air;
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, flag);
if (movingobjectposition == null) {
return itemStackIn;
} else {
ItemStack ret = net.minecraftforge.event.ForgeEventFactory.onBucketUse(playerIn, worldIn, itemStackIn, movingobjectposition);
if (ret != null)
return ret;
if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
BlockPos blockpos = movingobjectposition.getBlockPos();
if (!worldIn.isBlockModifiable(playerIn, blockpos)) {
return itemStackIn;
}
if (flag) {
if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn)) {
return itemStackIn;
}
IBlockState iblockstate = worldIn.getBlockState(blockpos);
Material material = iblockstate.getBlock().getMaterial();
if (material == Material.water && ((Integer) iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0) {
worldIn.setBlockToAir(blockpos);
playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
return this.fillBucket(itemStackIn, playerIn, mod_SecurityCraft.fWaterBucket);
}
if (material == Material.lava && ((Integer) iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0) {
worldIn.setBlockToAir(blockpos);
playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
return this.fillBucket(itemStackIn, playerIn, mod_SecurityCraft.fLavaBucket);
}
} else {
if (this.containedBlock == Blocks.air) {
return new ItemStack(Items.bucket);
}
BlockPos blockpos1 = blockpos.offset(movingobjectposition.sideHit);
if (!playerIn.canPlayerEdit(blockpos1, movingobjectposition.sideHit, itemStackIn)) {
return itemStackIn;
}
if (this.tryPlaceContainedLiquid(worldIn, blockpos1) && !playerIn.capabilities.isCreativeMode) {
playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
return new ItemStack(Items.bucket);
}
}
}
return itemStackIn;
}
}
use of net.minecraft.util.MovingObjectPosition in project BetterStorage by copygirl.
the class CommonProxy method onPlayerInteract.
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
World world = event.entity.worldObj;
int x = event.x;
int y = event.y;
int z = event.z;
EntityPlayer player = event.entityPlayer;
ItemStack holding = player.getCurrentEquippedItem();
Block block = world.getBlock(x, y, z);
boolean leftClick = (event.action == Action.LEFT_CLICK_BLOCK);
boolean rightClick = (event.action == Action.RIGHT_CLICK_BLOCK);
// Interact with attachments.
if (leftClick || rightClick) {
IHasAttachments hasAttachments = WorldUtils.get(world, x, y, z, IHasAttachments.class);
if (hasAttachments != null) {
EnumAttachmentInteraction interactionType = ((event.action == Action.LEFT_CLICK_BLOCK) ? EnumAttachmentInteraction.attack : EnumAttachmentInteraction.use);
if (hasAttachments.getAttachments().interact(WorldUtils.rayTrace(player, 1.0F), player, interactionType)) {
event.useBlock = Result.DENY;
event.useItem = Result.DENY;
}
}
}
// Use cauldron to remove color from dyable items
if (rightClick && (block == Blocks.cauldron)) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata > 0) {
IDyeableItem dyeable = (((holding != null) && (holding.getItem() instanceof IDyeableItem)) ? (IDyeableItem) holding.getItem() : null);
if ((dyeable != null) && (dyeable.canDye(holding))) {
StackUtils.remove(holding, "display", "color");
world.setBlockMetadataWithNotify(x, y, z, metadata - 1, 2);
world.func_147453_f(x, y, z, block);
event.useBlock = Result.DENY;
event.useItem = Result.DENY;
}
}
}
// Prevent players from breaking blocks with broken cardboard items.
if (leftClick && (holding != null) && (holding.getItem() instanceof ICardboardItem) && !ItemCardboardSheet.isEffective(holding))
event.useItem = Result.DENY;
// Attach locks to iron doors.
if (!world.isRemote && BetterStorageTiles.lockableDoor != null && rightClick && block == Blocks.iron_door) {
MovingObjectPosition target = WorldUtils.rayTrace(player, 1F);
if (target != null && getIronDoorHightlightBox(player, world, x, y, z, target.hitVec, block) != null) {
int meta = world.getBlockMetadata(x, y, z);
boolean isMirrored;
if (meta >= 8) {
isMirrored = meta == 9;
y -= 1;
meta = world.getBlockMetadata(x, y, z);
} else
isMirrored = world.getBlockMetadata(x, y + 1, z) == 9;
int rotation = meta & 3;
ForgeDirection orientation = rotation == 0 ? ForgeDirection.WEST : rotation == 1 ? ForgeDirection.NORTH : rotation == 2 ? ForgeDirection.EAST : ForgeDirection.SOUTH;
orientation = isMirrored ? (orientation == ForgeDirection.WEST ? ForgeDirection.SOUTH : orientation == ForgeDirection.NORTH ? ForgeDirection.WEST : orientation == ForgeDirection.EAST ? ForgeDirection.NORTH : ForgeDirection.EAST) : orientation;
world.setBlock(x, y, z, BetterStorageTiles.lockableDoor, 0, SetBlockFlag.SEND_TO_CLIENT);
world.setBlock(x, y + 1, z, BetterStorageTiles.lockableDoor, 8, SetBlockFlag.SEND_TO_CLIENT);
TileEntityLockableDoor te = WorldUtils.get(world, x, y, z, TileEntityLockableDoor.class);
te.orientation = orientation;
te.isOpen = isMirrored;
te.isMirrored = isMirrored;
te.setLock(holding);
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
}
// Prevent eating of slime buckets after capturing them.
if (preventSlimeBucketUse) {
event.setCanceled(true);
preventSlimeBucketUse = false;
}
}
use of net.minecraft.util.MovingObjectPosition in project BetterStorage by copygirl.
the class TileLockableDoor method collisionRayTrace.
@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 start, Vec3 end) {
int metadata = world.getBlockMetadata(x, y, z);
IHasAttachments te = WorldUtils.get(world, x, y - (metadata > 0 ? 1 : 0), z, IHasAttachments.class);
if (te == null)
return super.collisionRayTrace(world, x, y, z, start, end);
MovingObjectPosition pos = te.getAttachments().rayTrace(world, x, y - (metadata > 0 ? 1 : 0), z, start, end);
return pos != null ? pos : super.collisionRayTrace(world, x, y, z, start, end);
}
Aggregations