use of net.minecraft.util.ActionResult in project SilentGems by SilentChaos512.
the class ItemBlockPlacer method onItemLeftClickSL.
@Override
public ActionResult<ItemStack> onItemLeftClickSL(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!player.world.isRemote && player.isSneaking() && getRemainingBlocks(stack) > 0) {
// Get the block this placer stores.
IBlockState state = getBlockPlaced(stack);
int meta = getBlockMetaDropped(stack);
// Create block stack to drop.
ItemStack toDrop = new ItemStack(state.getBlock(), 1, meta);
StackHelper.setCount(toDrop, Math.min(getRemainingBlocks(stack), toDrop.getMaxStackSize()));
setRemainingBlocks(stack, getRemainingBlocks(stack) - StackHelper.getCount(toDrop));
// Make the EntityItem and spawn in world.
Vec3d vec = player.getLookVec().scale(2.0);
EntityItem entity = new EntityItem(world, player.posX + vec.x, player.posY + 1 + vec.y, player.posZ + vec.x, toDrop);
vec = vec.scale(-0.125);
entity.motionX = vec.x;
entity.motionY = vec.y;
entity.motionZ = vec.z;
EntityHelper.safeSpawn(entity);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
use of net.minecraft.util.ActionResult in project SilentGems by SilentChaos512.
the class ItemBlockPlacer method clOnItemRightClick.
@Override
protected ActionResult<ItemStack> clOnItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!player.world.isRemote && player.isSneaking()) {
// Toggle auto-fill mode.
boolean mode = !getAutoFillMode(stack);
setAutoFillMode(stack, mode);
LocalizationHelper loc = SilentGems.localizationHelper;
String onOrOff = loc.getMiscText("state." + (mode ? "on" : "off"));
onOrOff = (mode ? TextFormatting.GREEN : TextFormatting.RED) + onOrOff;
String line = loc.getItemSubText("BlockPlacer", "autoFill", onOrOff);
ChatHelper.sendStatusMessage(player, line, true);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
use of net.minecraft.util.ActionResult in project Almura by AlmuraDev.
the class MixinItemBucket method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
boolean flag = this.containedBlock == Blocks.AIR;
ItemStack itemstack = playerIn.getHeldItem(handIn);
RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, flag);
ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onBucketUse(playerIn, worldIn, itemstack, raytraceresult);
if (ret != null)
return ret;
if (raytraceresult == null) {
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
} else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK) {
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
} else {
BlockPos blockpos = raytraceresult.getBlockPos();
if (!worldIn.isBlockModifiable(playerIn, blockpos)) {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
} else if (flag) {
if (!playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemstack)) {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
} else {
IBlockState iblockstate = worldIn.getBlockState(blockpos);
Material material = iblockstate.getMaterial();
if (material == Material.WATER && ((Integer) iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0) {
worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
playerIn.addStat(StatList.getObjectUseStats(this));
playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, this.fillBucket(itemstack, playerIn, Items.WATER_BUCKET));
} else if (material == Material.LAVA && ((Integer) iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0) {
playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL_LAVA, 1.0F, 1.0F);
worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
playerIn.addStat(StatList.getObjectUseStats(this));
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, this.fillBucket(itemstack, playerIn, Items.LAVA_BUCKET));
} else {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
}
}
} else {
boolean flag1 = worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
BlockPos blockpos1 = flag1 && raytraceresult.sideHit == EnumFacing.UP ? blockpos : blockpos.offset(raytraceresult.sideHit);
if (!playerIn.canPlayerEdit(blockpos1, raytraceresult.sideHit, itemstack)) {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
} else if (this.tryPlaceContainedLiquid(playerIn, worldIn, blockpos1)) {
if (playerIn instanceof EntityPlayerMP) {
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) playerIn, blockpos1, itemstack);
}
playerIn.addStat(StatList.getObjectUseStats(this));
if (itemstack.getCount() > 1) {
itemstack.shrink(1);
// Almura Mod
// Purpose: check to see if the bucket they just used has multiple quantities, if it does, shrink the stack size and return an empty bucket via inventory search.
returnItem(playerIn, new ItemStack(Items.BUCKET));
return !playerIn.capabilities.isCreativeMode ? new ActionResult(EnumActionResult.SUCCESS, itemstack) : new ActionResult(EnumActionResult.SUCCESS, itemstack);
} else {
return !playerIn.capabilities.isCreativeMode ? new ActionResult(EnumActionResult.SUCCESS, new ItemStack(Items.BUCKET)) : new ActionResult(EnumActionResult.SUCCESS, itemstack);
// End
}
} else {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
}
}
}
}
use of net.minecraft.util.ActionResult in project MorePlanets by SteveKunG.
the class ItemInfectedEgg method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack itemStack = player.getHeldItem(hand);
if (!player.capabilities.isCreativeMode) {
itemStack.shrink(1);
}
world.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_EGG_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
player.swingArm(hand);
if (!world.isRemote) {
EntityInfectedEgg entityegg = new EntityInfectedEgg(world, player);
entityegg.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
world.spawnEntity(entityegg);
}
player.addStat(StatList.getObjectUseStats(this));
return new ActionResult<>(EnumActionResult.SUCCESS, itemStack);
}
use of net.minecraft.util.ActionResult in project MorePlanets by SteveKunG.
the class ItemAlienDefenderReinforcement method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack itemStack = player.getHeldItem(hand);
int range = 16;
Vec3d playerEye = player.getPositionEyes(1.0F);
Vec3d playerLook = player.getLook(1.0F);
Vec3d lookRange = playerEye.addVector(playerLook.x * range, playerLook.y * range, playerLook.z * range);
RayTraceResult moving = world.rayTraceBlocks(playerEye, lookRange);
boolean disable = false;
if (moving != null && disable) {
BlockPos pos = moving.getBlockPos();
if (world.isAirBlock(pos.up())) {
if (world.isRemote) {
FMLClientHandler.instance().getClient().ingameGUI.setOverlayMessage(new JsonUtil().text(I18n.format("gui.alien_defender_beacon.message")).setStyle(new JsonUtil().colorFromConfig("yellow")).getFormattedText(), false);
player.swingArm(hand);
} else {
world.setBlockState(pos.up(), MPBlocks.ALIEN_DEFENDER_BEACON.getDefaultState());
TileEntityAlienDefenderBeacon beacon = (TileEntityAlienDefenderBeacon) world.getTileEntity(pos.up());
beacon.bossCountdown = 200 + world.rand.nextInt(400);
if (!player.capabilities.isCreativeMode) {
itemStack.shrink(1);
}
}
} else {
if (world.isRemote) {
FMLClientHandler.instance().getClient().ingameGUI.setOverlayMessage(new JsonUtil().text(I18n.format("gui.not_air_block.message")).setStyle(new JsonUtil().red()).getFormattedText(), false);
player.swingArm(hand);
}
}
} else {
if (world.isRemote && disable) {
FMLClientHandler.instance().getClient().ingameGUI.setOverlayMessage(new JsonUtil().text(I18n.format("gui.target_too_far.message", range)).setStyle(new JsonUtil().red()).getFormattedText(), false);
player.swingArm(hand);
}
}
return new ActionResult<>(EnumActionResult.PASS, itemStack);
}
Aggregations