use of net.minecraft.util.EnumHand in project QuarryPlus by Kotori316.
the class BlockRefinery method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(hand);
if (InvUtils.isDebugItem(playerIn, hand))
return true;
if (BuildcraftHelper.isWrench(playerIn, hand, stack, new RayTraceResult(new Vec3d(hitX, hitY, hitZ), facing, pos))) {
worldIn.setBlockState(pos, state.withProperty(FACING, state.getValue(FACING).rotateYCCW()));
return true;
}
Optional<TileRefinery> tileEntity = Optional.ofNullable((TileRefinery) worldIn.getTileEntity(pos));
Consumer<TileRefinery> sendPacket = t -> PacketHandler.sendToAround(TileMessage.create(t), worldIn, pos);
if (stack.getItem() == QuarryPlusI.itemTool() && stack.getItemDamage() == 0) {
if (!worldIn.isRemote) {
Consumer<TileRefinery> consumer1 = t -> t.sendEnchantMassage(playerIn);
tileEntity.ifPresent(consumer1.andThen(sendPacket));
}
return true;
} else if (FluidUtil.getFluidHandler(stack) != null) {
if (!worldIn.isRemote) {
Consumer<TileRefinery> consumer1 = refinery -> fill(refinery, playerIn, hand, facing);
tileEntity.ifPresent(consumer1.andThen(sendPacket));
}
return true;
} else if (!worldIn.isRemote) {
tileEntity.ifPresent(sendPacket);
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
use of net.minecraft.util.EnumHand in project pyrotech-1.12 by codetaylor.
the class CampfireComfortEffectEventHandler method on.
@SubscribeEvent
public void on(PlayerInteractEvent.RightClickItem event) {
ItemStack itemStack = event.getItemStack();
Item item = itemStack.getItem();
if (!(item instanceof ItemFood)) {
// We're only interested if the item is food.
return;
}
ItemFood itemFood = (ItemFood) item;
if (this.isAlwaysEdible(itemFood)) {
// We're only interested in food that isn't already always edible.
return;
}
EntityLivingBase entityLiving = event.getEntityLiving();
if (!(entityLiving instanceof EntityPlayer)) {
// If the entity isn't a player, we're not interested.
return;
}
EntityPlayer player = (EntityPlayer) entityLiving;
if (player.canEat(false)) {
// We're only interested in players that can't eat.
return;
}
PotionEffect effect = player.getActivePotionEffect(ModuleTechBasic.Potions.COMFORT);
if (effect == null) {
// If the player doesn't have the appropriate effect, we're not interested.
return;
}
World world = player.getEntityWorld();
EnumHand hand = event.getHand();
if (world.isRemote) {
int itemStackCount = itemStack.getCount();
ActionResult<ItemStack> actionResult = this.useFood(itemStack, world, player, hand);
ItemStack resultItemStack = actionResult.getResult();
if (resultItemStack != itemStack || resultItemStack.getCount() != itemStackCount) {
player.setHeldItem(hand, resultItemStack);
if (resultItemStack.isEmpty()) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, itemStack, hand);
}
}
} else {
int i = itemStack.getCount();
int j = itemStack.getMetadata();
ItemStack copyBeforeUse = itemStack.copy();
ActionResult<ItemStack> actionResult = this.useFood(itemStack, world, player, hand);
ItemStack resultItemStack = actionResult.getResult();
player.setHeldItem(hand, resultItemStack);
if (player.isCreative()) {
resultItemStack.setCount(i);
if (resultItemStack.isItemStackDamageable()) {
resultItemStack.setItemDamage(j);
}
}
if (resultItemStack.isEmpty()) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyBeforeUse, hand);
player.setHeldItem(hand, ItemStack.EMPTY);
}
if (!player.isHandActive()) {
((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer);
}
}
event.setCanceled(true);
}
use of net.minecraft.util.EnumHand in project UniqueEnchantments by TinyModularThings.
the class UtilsHandler method damageShield.
public static void damageShield(float damage, EntityPlayer player) {
if (damage >= 3.0F && player.getActiveItemStack().getItem().isShield(player.getActiveItemStack(), player)) {
ItemStack copyBeforeUse = player.getActiveItemStack().copy();
int i = 1 + MathHelper.floor(damage);
player.getActiveItemStack().damageItem(i, player);
if (player.getActiveItemStack().isEmpty()) {
EnumHand enumhand = player.getActiveHand();
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyBeforeUse, enumhand);
if (enumhand == EnumHand.MAIN_HAND) {
player.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
} else {
player.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, ItemStack.EMPTY);
}
player.resetActiveHand();
player.playSound(SoundEvents.ITEM_SHIELD_BREAK, 0.8F, 0.8F + player.world.rand.nextFloat() * 0.4F);
}
}
}
use of net.minecraft.util.EnumHand in project tweakeroo by maruohon.
the class PlacementTweaks method onAttackTick.
private static void onAttackTick(Minecraft mc) {
if (FeatureToggle.TWEAK_FAST_LEFT_CLICK.getBooleanValue()) {
final int count = Configs.Generic.FAST_LEFT_CLICK_COUNT.getIntegerValue();
for (int i = 0; i < count; ++i) {
InventoryUtils.trySwapCurrentToolIfNearlyBroken(EnumHand.MAIN_HAND);
isEmulatedClick = true;
((IMinecraftAccessor) mc).leftClickMouseAccessor();
isEmulatedClick = false;
}
} else {
EnumHand hand = EnumHand.MAIN_HAND;
InventoryUtils.trySwapCurrentToolIfNearlyBroken(hand);
tryRestockHand(mc.player, hand, stackBeforeUse[hand.ordinal()]);
}
}
use of net.minecraft.util.EnumHand in project tweakeroo by maruohon.
the class PlacementTweaks method onUsingTick.
private static void onUsingTick() {
EntityPlayerSP player = GameUtils.getClientPlayer();
if (player == null) {
return;
}
Minecraft mc = GameUtils.getClient();
if (posFirst != null && FeatureToggle.TWEAK_FAST_BLOCK_PLACEMENT.getBooleanValue() && canUseItemWithRestriction(FAST_PLACEMENT_ITEM_RESTRICTION, player)) {
World world = player.getEntityWorld();
final double reach = mc.playerController.getBlockReachDistance();
final int maxCount = Configs.Generic.FAST_BLOCK_PLACEMENT_COUNT.getIntegerValue();
mc.objectMouseOver = player.rayTrace(reach, mc.getRenderPartialTicks());
for (int i = 0; i < maxCount; ++i) {
RayTraceResult trace = mc.objectMouseOver;
if (trace == null || trace.typeOfHit != RayTraceResult.Type.BLOCK) {
break;
}
EnumHand hand = handFirst;
EnumFacing side = trace.sideHit;
BlockPos pos = trace.getBlockPos();
BlockPos posNew = getPlacementPositionForTargetedPosition(pos, side, world);
if (hand != null && posNew.equals(posLast) == false && canPlaceBlockIntoPosition(posNew, world) && isPositionAllowedByPlacementRestriction(posNew, side) && canPlaceBlockAgainst(world, pos, player, hand)) {
/*
IBlockState state = world.getBlockState(pos);
float x = (float) (trace.hitVec.x - pos.getX());
float y = (float) (trace.hitVec.y - pos.getY());
float z = (float) (trace.hitVec.z - pos.getZ());
if (state.getBlock().onBlockActivated(world, posNew, state, player, hand, side, x, y, z))
{
return;
}
*/
Vec3d hitVec = hitVecFirst.add(posNew.getX(), posNew.getY(), posNew.getZ());
EnumActionResult result = tryPlaceBlock(mc.playerController, player, mc.world, posNew, sideFirst, sideRotatedFirst, playerYawFirst, hitVec, hand, hitPartFirst, false);
if (result == EnumActionResult.SUCCESS) {
posLast = posNew;
mc.objectMouseOver = player.rayTrace(reach, mc.getRenderPartialTicks());
} else {
break;
}
} else {
break;
}
}
// Reset the timer to prevent the regular process method from re-firing
((IMinecraftAccessor) mc).setRightClickDelayTimer(4);
} else if (FeatureToggle.TWEAK_FAST_RIGHT_CLICK.getBooleanValue() && isVanillaKeybindHeld(mc.gameSettings.keyBindUseItem) && canUseFastRightClick(mc.player)) {
final int count = Configs.Generic.FAST_RIGHT_CLICK_COUNT.getIntegerValue();
for (int i = 0; i < count; ++i) {
isEmulatedClick = true;
((IMinecraftAccessor) mc).rightClickMouseAccessor();
isEmulatedClick = false;
}
}
}
Aggregations