use of net.minecraft.util.EnumHand in project Tropicraft by Tropicraft.
the class TropicraftGuiHandler method getServerGuiElement.
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
if (id == 0) {
EnumHand hand = EnumHand.values()[x];
ItemStack held = player.getHeldItem(hand);
if (held != null && held.getItem() instanceof ItemScubaChestplateGear) {
return new ContainerScubaHarness(player.inventory, held.getCapability(ScubaCapabilities.getGearCapability(), null), hand);
}
}
return null;
}
use of net.minecraft.util.EnumHand in project SpongeForge by SpongePowered.
the class SpongeForgeEventFactory method createPlayerInteractEvent.
// Bulk Event Handling
private static InteractBlockEvent createPlayerInteractEvent(Event event) {
InteractBlockEvent spongeEvent = (InteractBlockEvent) event;
Player player = spongeEvent.getCause().first(Player.class).orElse(null);
// Forge doesn't support left-click AIR
if (player == null || (spongeEvent instanceof InteractBlockEvent.Primary && spongeEvent.getTargetBlock() == BlockSnapshot.NONE)) {
return spongeEvent;
}
BlockPos pos = VecHelper.toBlockPos(spongeEvent.getTargetBlock().getPosition());
EnumFacing face = DirectionFacingProvider.getInstance().get(spongeEvent.getTargetSide()).orElse(null);
Vec3d hitVec = null;
final EntityPlayerMP entityPlayerMP = EntityUtil.toNative(player);
if (spongeEvent.getInteractionPoint().isPresent()) {
hitVec = VecHelper.toVec3d(spongeEvent.getInteractionPoint().get());
}
if (spongeEvent instanceof InteractBlockEvent.Primary) {
PlayerInteractEvent.LeftClickBlock forgeEvent = new PlayerInteractEvent.LeftClickBlock(entityPlayerMP, pos, face, hitVec);
((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
if (forgeEvent.isCanceled()) {
spongeEvent.setCancelled(true);
}
} else if (face != null && spongeEvent instanceof InteractBlockEvent.Secondary) {
EnumHand hand = spongeEvent instanceof InteractBlockEvent.Secondary.MainHand ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
PlayerInteractEvent.RightClickBlock forgeEvent = new PlayerInteractEvent.RightClickBlock(entityPlayerMP, hand, pos, face, hitVec);
((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
if (forgeEvent.isCanceled()) {
spongeEvent.setCancelled(true);
}
// Mods have higher priority
if (forgeEvent.getUseItem() != Result.DEFAULT) {
((InteractBlockEvent.Secondary) spongeEvent).setUseItemResult(getTristateFromResult(forgeEvent.getUseItem()));
}
if (forgeEvent.getUseBlock() != Result.DEFAULT) {
((InteractBlockEvent.Secondary) spongeEvent).setUseBlockResult(getTristateFromResult(forgeEvent.getUseBlock()));
}
}
return spongeEvent;
}
use of net.minecraft.util.EnumHand in project ClaySoldiersMod by SanAndreasP.
the class ItemDisruptor method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
ItemStack itemStackIn = playerIn.getHeldItem(hand);
NBTTagCompound nbt = itemStackIn.getOrCreateSubCompound("disruptor");
long lastTimeMillis = nbt.getLong("lastActivated");
long currTimeMillis = System.currentTimeMillis();
if (lastTimeMillis + 2_000 < currTimeMillis) {
if (!worldIn.isRemote) {
AxisAlignedBB aabb = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 64.0D, 64.0D, 64.0D).offset(playerIn.posX, playerIn.posY, playerIn.posZ).offset(-32.0D, -32.0D, -32.0D);
worldIn.getEntitiesWithinAABB(EntityCreature.class, aabb).stream().filter(entity -> entity instanceof IDisruptable).map(entity -> (IDisruptable) entity).collect(Collectors.toList()).forEach(IDisruptable::disrupt);
nbt.setLong("lastActivated", currTimeMillis);
if (itemStackIn.isItemStackDamageable()) {
itemStackIn.damageItem(1, playerIn);
}
}
return ActionResult.newResult(EnumActionResult.SUCCESS, itemStackIn);
} else {
return super.onItemRightClick(worldIn, playerIn, hand);
}
}
use of net.minecraft.util.EnumHand in project Solar by ArekkuusuJerii.
the class BlockQelaion method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (world.isRemote)
return true;
ItemStack stack = player.getHeldItem(hand);
if (stack.getItem() == ModItems.QELAION) {
Optional<TileQelaion> optional = getTile(TileQelaion.class, world, pos);
if (optional.isPresent()) {
TileQelaion qelaion = optional.get();
Optional<UUID> nodes = ((IEntangledStack) stack.getItem()).getKey(stack);
Optional<UUID> parent = qelaion.getKey();
if (nodes.isPresent() && parent.isPresent()) {
qelaion.setNodes(nodes.get());
return true;
}
return false;
}
} else if (stack.isEmpty()) {
getTile(TileQelaion.class, world, pos).ifPresent(qelaion -> {
if (!player.isSneaking()) {
qelaion.put(facing);
} else
qelaion.setNodes(null);
});
}
return false;
}
use of net.minecraft.util.EnumHand in project ForestryMC by ForestryMC.
the class GuiHandler method getServerGuiElement.
@Override
@Nullable
public Object getServerGuiElement(int guiData, EntityPlayer player, World world, int x, int y, int z) {
GuiId guiId = decodeGuiID(guiData);
if (guiId == null) {
return null;
}
short data = decodeGuiData(guiData);
BlockPos pos = new BlockPos(x, y, z);
switch(guiId.getGuiType()) {
case Item:
{
for (EnumHand hand : EnumHand.values()) {
ItemStack heldItem = player.getHeldItem(hand);
if (!heldItem.isEmpty()) {
Item item = heldItem.getItem();
if (guiId.getGuiHandlerClass().isInstance(item)) {
return ((IGuiHandlerItem) item).getContainer(player, heldItem, data);
}
}
}
break;
}
case Tile:
{
TileEntity tileEntity = TileUtil.getTile(world, pos);
if (guiId.getGuiHandlerClass().isInstance(tileEntity)) {
return ((IGuiHandlerTile) tileEntity).getContainer(player, data);
}
break;
}
case Entity:
{
Entity entity = world.getEntityByID(x);
if (guiId.getGuiHandlerClass().isInstance(entity)) {
return ((IGuiHandlerEntity) entity).getContainer(player, data);
}
break;
}
}
return null;
}
Aggregations