use of net.minecraft.util.ActionResult in project Railcraft by Railcraft.
the class ItemFluidContainer method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
RayTraceResult trace = rayTrace(world, player, false);
if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK) {
BlockPos pos = trace.getBlockPos();
if (!world.isBlockModifiable(player, pos))
return new ActionResult<>(EnumActionResult.FAIL, stack);
pos = pos.offset(trace.sideHit);
if (!player.canPlayerEdit(pos, trace.sideHit, stack))
return new ActionResult<>(EnumActionResult.FAIL, stack);
if (tryPlaceContainedLiquid(world, pos) && !player.capabilities.isCreativeMode) {
if (stack.getCount() == 1) {
ItemStack emptied = getContainerItem(stack);
if (InvTools.isEmpty(emptied)) {
emptied = stack.copy();
setSize(emptied, 0);
}
return new ActionResult<>(EnumActionResult.SUCCESS, emptied);
} else {
ItemStack emptied = getContainerItem(stack);
if (!InvTools.isEmpty(emptied)) {
if (!player.addItemStackToInventory(emptied)) {
player.dropItem(emptied, true);
}
}
InvTools.dec(stack);
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
}
}
return new ActionResult<>(EnumActionResult.PASS, stack);
}
use of net.minecraft.util.ActionResult in project Railcraft by Railcraft.
the class ItemFilterBeeGenome method onItemRightClick.
@Optional.Method(modid = ForestryPlugin.FORESTRY_ID)
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
NBTTagCompound nbt = InvToolsAPI.getRailcraftDataSubtag(stack, "filter").orElse(null);
if (nbt != null) {
try {
EnumBeeChromosome chromosome = EnumBeeChromosome.SPECIES;
try {
chromosome = EnumBeeChromosome.valueOf(nbt.getString("chromosome"));
} catch (IllegalArgumentException ignored) {
}
chromosome = EnumTools.next(chromosome, EnumBeeChromosome.values());
nbt.setString("chromosome", chromosome.name());
} catch (Throwable throwable) {
Game.log().api(Mod.FORESTRY.modId, throwable, EnumBeeChromosome.class);
}
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack.copy());
}
use of net.minecraft.util.ActionResult in project BiomesOPlenty by Glitchfiend.
the class ItemBOPBoat method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
ItemStack itemstack = playerIn.getHeldItem(handIn);
float f = 1.0F;
float f1 = playerIn.prevRotationPitch + (playerIn.rotationPitch - playerIn.prevRotationPitch) * 1.0F;
float f2 = playerIn.prevRotationYaw + (playerIn.rotationYaw - playerIn.prevRotationYaw) * 1.0F;
double d0 = playerIn.prevPosX + (playerIn.posX - playerIn.prevPosX) * 1.0D;
double d1 = playerIn.prevPosY + (playerIn.posY - playerIn.prevPosY) * 1.0D + (double) playerIn.getEyeHeight();
double d2 = playerIn.prevPosZ + (playerIn.posZ - playerIn.prevPosZ) * 1.0D;
Vec3d vec3d = new Vec3d(d0, d1, d2);
float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI);
float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI);
float f5 = -MathHelper.cos(-f1 * 0.017453292F);
float f6 = MathHelper.sin(-f1 * 0.017453292F);
float f7 = f4 * f5;
float f8 = f3 * f5;
double d3 = 5.0D;
Vec3d vec3d1 = vec3d.addVector((double) f7 * 5.0D, (double) f6 * 5.0D, (double) f8 * 5.0D);
RayTraceResult raytraceresult = worldIn.rayTraceBlocks(vec3d, vec3d1, true);
if (raytraceresult == null) {
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
} else {
Vec3d vec3d2 = playerIn.getLook(1.0F);
boolean flag = false;
List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity(playerIn, playerIn.getEntityBoundingBox().expand(vec3d2.x * 5.0D, vec3d2.y * 5.0D, vec3d2.z * 5.0D).grow(1.0D));
for (int i = 0; i < list.size(); ++i) {
Entity entity = list.get(i);
if (entity.canBeCollidedWith()) {
AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().grow((double) entity.getCollisionBorderSize());
if (axisalignedbb.contains(vec3d)) {
flag = true;
}
}
}
if (flag) {
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
} else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK) {
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
} else {
Block block = worldIn.getBlockState(raytraceresult.getBlockPos()).getBlock();
boolean flag1 = block == Blocks.WATER || block == Blocks.FLOWING_WATER;
EntityBOPBoat entitybopboat = new EntityBOPBoat(worldIn, raytraceresult.hitVec.x, flag1 ? raytraceresult.hitVec.y - 0.12D : raytraceresult.hitVec.y, raytraceresult.hitVec.z);
entitybopboat.setBoatType(this.type);
entitybopboat.rotationYaw = playerIn.rotationYaw;
if (!worldIn.getCollisionBoxes(entitybopboat, entitybopboat.getEntityBoundingBox().grow(-0.1D)).isEmpty()) {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
} else {
if (!worldIn.isRemote) {
worldIn.spawnEntity(entitybopboat);
}
if (!playerIn.capabilities.isCreativeMode) {
itemstack.shrink(1);
}
playerIn.addStat(StatList.getObjectUseStats(this));
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
}
}
}
use of net.minecraft.util.ActionResult in project BiomesOPlenty by Glitchfiend.
the class ItemFlowerBasket method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!world.isRemote) {
NBTTagCompound compound = NBTUtil.getOrCreateStackNBT(stack);
// Ensure there are no other open baskets in the player's inventory
// This oculd potentially happen if the inventory is never properly closed
clearOpenBaskets(player);
// Tag this basket as open
compound.setBoolean("BasketOpen", true);
// Set the stack's data in case it didn't previously have any
player.openGui(BiomesOPlenty.instance, GuiHandler.FLOWER_BASKET_ID, world, 0, 0, 0);
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
use of net.minecraft.util.ActionResult in project BiomesOPlenty by Glitchfiend.
the class ItemJarEmpty method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
RayTraceResult hit = this.rayTrace(world, player, true);
if (hit == null) {
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
} else {
if (hit.typeOfHit == RayTraceResult.Type.BLOCK) {
BlockPos pos = hit.getBlockPos();
if (!world.isBlockModifiable(player, pos) || !player.canPlayerEdit(pos.offset(hit.sideHit), hit.sideHit, stack)) {
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
// determine if the block is one of our BOP fluids
// note - no need to check level - you don't get a hit unless it's full
IBlockState state = world.getBlockState(pos);
ItemJarFilled.JarContents jarContents = null;
if (state.getBlock() == BOPBlocks.honey) {
jarContents = ItemJarFilled.JarContents.HONEY;
}
// if it was honey, return the corresponding filled jar
if (jarContents != null) {
world.setBlockToAir(pos);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, this.fillJar(stack, player, new ItemStack(BOPItems.jar_filled, 1, jarContents.ordinal())));
}
}
}
player.setActiveHand(hand);
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
Aggregations