use of net.minecraft.util.EnumHand in project Guide-API by TeamAmeriFrance.
the class EventHandler method renderOverlay.
@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void renderOverlay(RenderGameOverlayEvent.Pre event) {
if (event.getType() != RenderGameOverlayEvent.ElementType.CROSSHAIRS)
return;
RayTraceResult rayTrace = Minecraft.getMinecraft().objectMouseOver;
if (rayTrace == null || rayTrace.typeOfHit != RayTraceResult.Type.BLOCK)
return;
EntityPlayer player = Minecraft.getMinecraft().player;
World world = Minecraft.getMinecraft().world;
ItemStack held = ItemStack.EMPTY;
Book book = null;
for (EnumHand hand : EnumHand.values()) {
ItemStack heldStack = player.getHeldItem(hand);
if (heldStack.getItem() instanceof IGuideItem) {
held = heldStack;
book = ((IGuideItem) heldStack.getItem()).getBook(heldStack);
break;
}
}
if (book == null)
return;
IBlockState state = world.getBlockState(rayTrace.getBlockPos());
String linkedEntry = null;
if (state.getBlock() instanceof IGuideLinked) {
IGuideLinked linked = (IGuideLinked) state.getBlock();
ResourceLocation entryKey = linked.getLinkedEntry(world, rayTrace.getBlockPos(), player, held);
if (entryKey != null) {
for (CategoryAbstract category : book.getCategoryList()) {
if (category.entries.containsKey(entryKey)) {
linkedEntry = category.getEntry(entryKey).getLocalizedName();
break;
}
}
}
}
if (!Strings.isNullOrEmpty(linkedEntry)) {
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
int drawX = scaledResolution.getScaledWidth() / 2 + 10;
int drawY = scaledResolution.getScaledHeight() / 2 - 8;
Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(held, drawX, drawY);
drawY -= 2;
drawX += 20;
fontRenderer.drawStringWithShadow(TextFormatting.WHITE + linkedEntry, drawX, drawY, 0);
fontRenderer.drawStringWithShadow(TextFormatting.WHITE.toString() + TextFormatting.ITALIC.toString() + TextHelper.localize("text.linked.open"), drawX, drawY + 12, 0);
}
if (state.getBlock() instanceof IInfoRenderer.Block) {
IInfoRenderer infoRenderer = ((IInfoRenderer.Block) state.getBlock()).getInfoRenderer(book, world, rayTrace.getBlockPos(), state, rayTrace, player);
if (book == ((IInfoRenderer.Block) state.getBlock()).getBook() && infoRenderer != null)
infoRenderer.drawInformation(book, world, rayTrace.getBlockPos(), state, rayTrace, player);
}
Multimap<Class<? extends Block>, IInfoRenderer> bookRenderers = GuideAPI.getInfoRenderers().get(book);
if (bookRenderers == null)
return;
Collection<IInfoRenderer> renderers = bookRenderers.get(state.getBlock().getClass());
for (IInfoRenderer renderer : renderers) renderer.drawInformation(book, world, rayTrace.getBlockPos(), state, rayTrace, player);
}
use of net.minecraft.util.EnumHand in project LogisticsPipes by RS485.
the class ItemLogisticsPipe method onItemUse.
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
Block block = LPBlocks.pipe;
IBlockState iblockstate = worldIn.getBlockState(pos);
Block worldBlock = iblockstate.getBlock();
if (!worldBlock.isReplaceable(worldIn, pos)) {
pos = pos.offset(facing);
}
ItemStack itemstack = player.getHeldItem(hand);
if (itemstack.isEmpty()) {
return EnumActionResult.FAIL;
}
if (!dummyPipe.isMultiBlock()) {
if (player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(block, pos, false, facing, null)) {
CoreUnroutedPipe pipe = LogisticsBlockGenericPipe.createPipe(this);
if (pipe == null) {
LogisticsPipes.log.log(Level.WARN, "Pipe failed to create during placement at {0},{1},{2}", new Object[] { pos.getX(), pos.getY(), pos.getZ() });
return EnumActionResult.PASS;
}
if (LogisticsBlockGenericPipe.placePipe(pipe, worldIn, pos, block, null)) {
IBlockState state = worldIn.getBlockState(pos);
if (state.getBlock() == block) {
// setTileEntityNBT(world, player, pos, stack);
block.onBlockPlacedBy(worldIn, pos, state, player, itemstack);
if (player instanceof EntityPlayerMP)
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, pos, itemstack);
IBlockState newBlockState = worldIn.getBlockState(pos);
SoundType soundtype = newBlockState.getBlock().getSoundType(newBlockState, worldIn, pos, player);
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
itemstack.shrink(1);
}
}
return EnumActionResult.SUCCESS;
} else {
return EnumActionResult.FAIL;
}
} else {
CoreMultiBlockPipe multiPipe = (CoreMultiBlockPipe) dummyPipe;
boolean isFreeSpace = true;
DoubleCoordinates placeAt = new DoubleCoordinates(pos);
LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> globalPos = new LPPositionSet<>(DoubleCoordinatesType.class);
globalPos.add(new DoubleCoordinatesType<>(placeAt, CoreMultiBlockPipe.SubBlockTypeForShare.NON_SHARE));
LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> positions = multiPipe.getSubBlocks();
ITubeOrientation orientation = multiPipe.getTubeOrientation(player, pos.getX(), pos.getZ());
if (orientation == null) {
return EnumActionResult.FAIL;
}
orientation.rotatePositions(positions);
positions.stream().map(iPos -> iPos.add(placeAt)).forEach(globalPos::add);
globalPos.addToAll(orientation.getOffset());
placeAt.add(orientation.getOffset());
for (DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare> iPos : globalPos) {
if (!player.canPlayerEdit(iPos.getBlockPos(), facing, itemstack) || !worldIn.mayPlace(block, iPos.getBlockPos(), false, facing, null)) {
TileEntity tile = worldIn.getTileEntity(iPos.getBlockPos());
boolean canPlace = false;
if (tile instanceof LogisticsTileGenericSubMultiBlock) {
if (CoreMultiBlockPipe.canShare(((LogisticsTileGenericSubMultiBlock) tile).getSubTypes(), iPos.getType())) {
canPlace = true;
}
}
if (!canPlace) {
isFreeSpace = false;
break;
}
}
}
if (isFreeSpace) {
CoreUnroutedPipe pipe = LogisticsBlockGenericPipe.createPipe(this);
if (pipe == null) {
LogisticsPipes.log.log(Level.WARN, "Pipe failed to create during placement at {0},{1},{2}", new Object[] { pos.getX(), pos.getY(), pos.getZ() });
return EnumActionResult.SUCCESS;
}
if (LogisticsBlockGenericPipe.placePipe(pipe, worldIn, placeAt.getBlockPos(), block, orientation)) {
IBlockState state = worldIn.getBlockState(placeAt.getBlockPos());
if (state.getBlock() == block) {
// setTileEntityNBT(world, player, pos, stack);
block.onBlockPlacedBy(worldIn, pos, state, player, itemstack);
if (player instanceof EntityPlayerMP)
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, placeAt.getBlockPos(), itemstack);
IBlockState newBlockState = worldIn.getBlockState(placeAt.getBlockPos());
SoundType soundtype = newBlockState.getBlock().getSoundType(newBlockState, worldIn, placeAt.getBlockPos(), player);
worldIn.playSound(player, placeAt.getBlockPos(), soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
itemstack.shrink(1);
}
}
return EnumActionResult.SUCCESS;
} else {
return EnumActionResult.FAIL;
}
}
}
use of net.minecraft.util.EnumHand in project BuildCraft by BuildCraft.
the class ItemSchematicSingle method onItemUseFirst.
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
if (world.isRemote) {
return EnumActionResult.PASS;
}
ItemStack stack = player.getHeldItem(hand);
if (player.isSneaking()) {
NBTTagCompound itemData = NBTUtilBC.getItemData(StackUtil.asNonNull(stack));
itemData.removeTag(NBT_KEY);
if (itemData.hasNoTags()) {
stack.setTagCompound(null);
}
stack.setItemDamage(DAMAGE_CLEAN);
return EnumActionResult.SUCCESS;
}
int damage = stack.getItemDamage();
if (damage != DAMAGE_USED) {
IBlockState state = world.getBlockState(pos);
ISchematicBlock schematicBlock = SchematicBlockManager.getSchematicBlock(new SchematicBlockContext(world, pos, pos, state, state.getBlock()));
if (schematicBlock.isAir()) {
return EnumActionResult.FAIL;
}
NBTUtilBC.getItemData(stack).setTag(NBT_KEY, SchematicBlockManager.writeToNBT(schematicBlock));
stack.setItemDamage(DAMAGE_USED);
return EnumActionResult.SUCCESS;
} else {
BlockPos placePos = pos;
boolean replaceable = world.getBlockState(pos).getBlock().isReplaceable(world, pos);
if (!replaceable) {
placePos = placePos.offset(side);
}
if (!world.mayPlace(world.getBlockState(pos).getBlock(), placePos, false, side, null)) {
return EnumActionResult.FAIL;
}
if (replaceable && !world.isAirBlock(placePos)) {
world.setBlockToAir(placePos);
}
try {
ISchematicBlock schematicBlock = getSchematic(stack);
if (schematicBlock != null) {
if (!schematicBlock.isBuilt(world, placePos) && schematicBlock.canBuild(world, placePos)) {
List<FluidStack> requiredFluids = schematicBlock.computeRequiredFluids();
List<ItemStack> requiredItems = schematicBlock.computeRequiredItems();
if (requiredFluids.isEmpty()) {
InventoryWrapper itemTransactor = new InventoryWrapper(player.inventory);
if (StackUtil.mergeSameItems(requiredItems).stream().noneMatch(s -> itemTransactor.extract(extracted -> StackUtil.canMerge(s, extracted), s.getCount(), s.getCount(), true).isEmpty())) {
if (schematicBlock.build(world, placePos)) {
StackUtil.mergeSameItems(requiredItems).forEach(s -> itemTransactor.extract(extracted -> StackUtil.canMerge(s, extracted), s.getCount(), s.getCount(), false));
SoundUtil.playBlockPlace(world, placePos);
player.swingArm(hand);
return EnumActionResult.SUCCESS;
}
} else {
player.sendStatusMessage(new TextComponentString("Not enough items. Total needed: " + StackUtil.mergeSameItems(requiredItems).stream().map(s -> s.getTextComponent().getFormattedText() + " x " + s.getCount()).collect(Collectors.joining(", "))), true);
}
} else {
player.sendStatusMessage(new TextComponentString("Schematic requires fluids"), true);
}
}
}
} catch (InvalidInputDataException e) {
player.sendStatusMessage(new TextComponentString("Invalid schematic: " + e.getMessage()), true);
e.printStackTrace();
}
return EnumActionResult.FAIL;
}
}
use of net.minecraft.util.EnumHand in project BaseMetals by MinecraftModDevelopmentMods.
the class ItemMMDCrackHammer method onItemUse.
@Override
public EnumActionResult onItemUse(final EntityPlayer player, final World w, final BlockPos coord, final EnumHand hand, final EnumFacing facing, final float partialX, final float partialY, final float partialZ) {
final ItemStack item = player.getHeldItemMainhand();
if (facing != EnumFacing.UP) {
return EnumActionResult.PASS;
}
/*List<EntityItem> entities = */
AxisAlignedBB boundingBox = new AxisAlignedBB(coord.getX(), coord.getY() + 1, coord.getZ(), coord.getX() + 1, coord.getY() + 2, coord.getZ() + 1);
List<EntityItem> entities = w.getEntitiesWithinAABB(EntityItem.class, boundingBox).stream().filter(elem -> (elem.getItem() != null)).filter(elem -> (CrusherRecipeRegistry.getRecipeForInputItem(elem.getItem()) != null)).collect(Collectors.toList());
if (!entities.isEmpty()) {
ItemStack targetItem = entities.get(0).getItem();
ICrusherRecipe recipe = CrusherRecipeRegistry.getRecipeForInputItem(targetItem);
if (hardnessCheck(targetItem)) {
return EnumActionResult.PASS;
}
maybeDoCrack(recipe, targetItem, item, entities.get(0), player, w);
w.playSound(player, coord, SoundEvents.BLOCK_GRAVEL_BREAK, SoundCategory.BLOCKS, 0.5F, 0.5F + (itemRand.nextFloat() * 0.3F));
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
use of net.minecraft.util.EnumHand in project Tropicraft by Tropicraft.
the class TropicraftGuiHandler method getClientGuiElement.
@Override
public Object getClientGuiElement(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 GuiScubaHarness(new ContainerScubaHarness(player.inventory, held.getCapability(ScubaCapabilities.getGearCapability(), null), hand));
}
}
return null;
}
Aggregations