net.minecraftforge.common.ForgeHooks Java Examples

The following examples show how to use net.minecraftforge.common.ForgeHooks. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GTUtility.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static List<Tuple<ItemStack, Integer>> getGrassSeedEntries() {
    ArrayList<Tuple<ItemStack, Integer>> result = new ArrayList<>();
    try {
        Field seedListField = ForgeHooks.class.getDeclaredField("seedList");
        seedListField.setAccessible(true);
        Class<?> seedEntryClass = Class.forName("net.minecraftforge.common.ForgeHooks$SeedEntry");
        Field seedField = seedEntryClass.getDeclaredField("seed");
        seedField.setAccessible(true);
        List<WeightedRandom.Item> seedList = (List<WeightedRandom.Item>) seedListField.get(null);
        for (WeightedRandom.Item seedEntryObject : seedList) {
            ItemStack seedStack = (ItemStack) seedField.get(seedEntryObject);
            int chanceValue = seedEntryObject.itemWeight;
            if (!seedStack.isEmpty())
                result.add(new Tuple<>(seedStack, chanceValue));
        }
    } catch (ReflectiveOperationException exception) {
        GTLog.logger.error("Failed to get forge grass seed list", exception);
    }
    return result;
}
 
Example #2
Source File: BlockPedestal.java    From Artifacts with MIT License 6 votes vote down vote up
@Override
public float getPlayerRelativeBlockHardness(EntityPlayer player, World world, int x, int y, int z)
   {
	TileEntity te = world.getTileEntity(x, y, z);
	TileEntityDisplayPedestal ted = (TileEntityDisplayPedestal)te;

	if((ted.ownerUUID.getLeastSignificantBits() == player.getUniqueID().getLeastSignificantBits() &&
			ted.ownerUUID.getMostSignificantBits() == player.getUniqueID().getMostSignificantBits()) ||
			ted.ownerName.equals(player.getCommandSenderName()) ||
			ted.ownerName == null || ted.ownerName.equals("") ||
			ted.ownerUUID == null || ted.ownerUUID.equals(new UUID(0,0))) {

		float f = this.getBlockHardness(world, x, y, z);
		return ForgeHooks.blockStrength(this, player, world, x, y, z);
	}
	else {
		return 0;
	}
   }
 
Example #3
Source File: EnchantmentUtils.java    From OpenModsLib with MIT License 6 votes vote down vote up
public static float getPower(World world, BlockPos position) {
	float power = 0;

	for (int deltaZ = -1; deltaZ <= 1; ++deltaZ) {
		for (int deltaX = -1; deltaX <= 1; ++deltaX) {
			if ((deltaZ != 0 || deltaX != 0)
					&& world.isAirBlock(position.add(deltaX, 0, deltaZ))
					&& world.isAirBlock(position.add(deltaX, 1, deltaZ))) {
				power += ForgeHooks.getEnchantPower(world, position.add(deltaX * 2, 0, deltaZ * 2));
				power += ForgeHooks.getEnchantPower(world, position.add(deltaX * 2, 1, deltaZ * 2));
				if (deltaX != 0 && deltaZ != 0) {
					power += ForgeHooks.getEnchantPower(world, position.add(deltaX * 2, 0, deltaZ));
					power += ForgeHooks.getEnchantPower(world, position.add(deltaX * 2, 1, deltaZ));
					power += ForgeHooks.getEnchantPower(world, position.add(deltaX, 0, deltaZ * 2));
					power += ForgeHooks.getEnchantPower(world, position.add(deltaX, 1, deltaZ * 2));
				}
			}
		}
	}
	return power;
}
 
Example #4
Source File: BreakBlockAction.java    From OpenModsLib with MIT License 6 votes vote down vote up
private void selectTool(IBlockState state, OpenModsFakePlayer fakePlayer) {
	if (findEffectiveTool) {
		final ItemStack optimalTool = effectiveToolCache.getIfPresent(state);

		if (optimalTool != null) {
			setPlayerTool(fakePlayer, optimalTool);
		} else {
			for (ItemStack tool : ConfigAccess.probeTools()) {
				setPlayerTool(fakePlayer, tool);

				if (ForgeHooks.canHarvestBlock(state.getBlock(), fakePlayer, worldObj, blockPos)) {
					effectiveToolCache.put(state, tool);
					return;
				}
			}

			// default clause - use most universal one
			final ItemStack fallbackTool = createToolStack(Items.DIAMOND_PICKAXE);
			effectiveToolCache.put(state, fallbackTool);
			setPlayerTool(fakePlayer, fallbackTool);
		}
	} else {
		setPlayerTool(fakePlayer, stackToUse);
	}
}
 
Example #5
Source File: GuiCustomizeWorld.java    From YUNoMakeGoodMap with Apache License 2.0 6 votes vote down vote up
private List<ITextComponent> resizeContent(List<String> lines)
{
    List<ITextComponent> ret = new ArrayList<ITextComponent>();
    for (String line : lines)
    {
        if (line == null)
        {
            ret.add(null);
            continue;
        }

        ITextComponent chat = ForgeHooks.newChatWithLinks(line, false);
        ret.addAll(GuiUtilRenderComponents.splitText(chat, this.listWidth-8, GuiCustomizeWorld.this.fontRenderer, false, true));
    }
    return ret;
}
 
Example #6
Source File: BlockUtils.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Breaks the block as a player, and thus drops the item(s) from it
 */
public static void breakBlockAsPlayer(World world, BlockPos pos, EntityPlayerMP playerMP, ItemStack toolStack)
{
    PlayerInteractionManager manager = playerMP.interactionManager;
    int exp = ForgeHooks.onBlockBreakEvent(world, manager.getGameType(), playerMP, pos);

    if (exp != -1)
    {
        IBlockState stateExisting = world.getBlockState(pos);
        Block blockExisting = stateExisting.getBlock();

        blockExisting.onBlockHarvested(world, pos, stateExisting, playerMP);
        boolean harvest = blockExisting.removedByPlayer(stateExisting, world, pos, playerMP, true);

        if (harvest)
        {
            blockExisting.onPlayerDestroy(world, pos, stateExisting);
            blockExisting.harvestBlock(world, playerMP, pos, stateExisting, world.getTileEntity(pos), toolStack);
        }
    }
}
 
Example #7
Source File: RecipeCrudeHaloInfusion.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(@Nonnull InventoryCrafting inv) {
	NonNullList<ItemStack> remainingItems = ForgeHooks.defaultRecipeGetRemainingItems(inv);

	ItemStack gluestick;
	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() == Items.SLIME_BALL) {
			gluestick = stack.copy();
			remainingItems.set(i, gluestick);
			break;
		}
	}

	return remainingItems;
}
 
Example #8
Source File: RecipeJam.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(@Nonnull InventoryCrafting inv) {
	NonNullList<ItemStack> remainingItems = ForgeHooks.defaultRecipeGetRemainingItems(inv);

	ItemStack sword;
	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() == Items.GOLDEN_SWORD) {
			sword = stack.copy();
			sword.setItemDamage(sword.getItemDamage() + 1);
			if (sword.getItemDamage() > sword.getMaxDamage()) sword = null;
			if (sword != null) {
				remainingItems.set(i, sword);
			}
			break;
		}
	}

	return remainingItems;
}
 
Example #9
Source File: RecipeShapedFluid.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
	NonNullList<ItemStack> remains = ForgeHooks.defaultRecipeGetRemainingItems(inv);
	for (int i = 0; i < height * width; i++) {
		ItemStack stack = inv.getStackInSlot(i);
		NonNullList<Ingredient> matchedIngredients = this.input;
		if (matchedIngredients.get(i) instanceof IngredientFluidStack) {
			if (!stack.isEmpty()) {
				ItemStack copy = stack.copy();
				copy.setCount(1);
				remains.set(i, copy);
			}
			IFluidHandlerItem handler = FluidUtil.getFluidHandler(remains.get(i));
			if (handler != null) {
				FluidStack fluid = ((IngredientFluidStack) matchedIngredients.get(i)).getFluid();
				handler.drain(fluid.amount, true);
				remains.set(i, handler.getContainer());
			}
		}
	}
	return remains;
}
 
Example #10
Source File: BlockPitKiln.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
	if(state.getValue(FILL) > 0 && state.getValue(FILLTYPE) == FillType.Charcoal && 
			ForgeHooks.isToolEffective(worldIn, pos, player.getHeldItemMainhand()))
	{
		Core.giveItem(worldIn, player, pos, new ItemStack(Items.COAL, 1, 1));
		worldIn.setBlockState(pos, state.withProperty(FILL, state.getValue(FILL)-1));
	}
}
 
Example #11
Source File: DiamondTofuToolHandler.java    From TofuCraftReload with MIT License 5 votes vote down vote up
private boolean canBreakExtraBlock(ItemStack stack, World world, EntityPlayer player, BlockPos pos, BlockPos refPos) {
    if (world.isAirBlock(pos)) {
        return false;
    }
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (tool.getDestroySpeed(stack, state) <= 1.0F)
        return false;

    IBlockState refState = world.getBlockState(refPos);
    float refStrength = ForgeHooks.blockStrength(refState, player, world, refPos);
    float strength = ForgeHooks.blockStrength(state, player, world, pos);

    if (!ForgeHooks.canHarvestBlock(block, player, world, pos) || refStrength / strength > 10f) {
        return false;
    }

    if (player.capabilities.isCreativeMode) {
        block.onBlockHarvested(world, pos, state, player);
        if (block.removedByPlayer(state, world, pos, player, false)) {
            block.onBlockDestroyedByPlayer(world, pos, state);
        }
        // send update to client
        if (!world.isRemote) {
            if (player instanceof EntityPlayerMP && ((EntityPlayerMP) player).connection != null) {
                ((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos));
            }
        }
        return false;
    }
    return true;
}
 
Example #12
Source File: CustomRecipeBase.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
	NonNullList<ItemStack> result = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);

	for (int i = 0; i < result.size(); ++i) {
		ItemStack itemstack = inv.getStackInSlot(i);
		result.set(i, ForgeHooks.getContainerItem(itemstack));
	}

	return result;
}
 
Example #13
Source File: CachedRecipeData.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean performRecipe(EntityPlayer player) {
    this.lastTickChecked = -1L;
    if (!checkRecipeValid()) {
        return false;
    }
    if (!consumeRecipeItems(false)) {
        this.lastTickChecked = -1L;
        return false;
    }
    ForgeHooks.setCraftingPlayer(player);
    NonNullList<ItemStack> remainingItems = recipe.getRemainingItems(inventory);
    ForgeHooks.setCraftingPlayer(null);
    for (ItemStack itemStack : remainingItems) {
        itemStack = itemStack.copy();
        ItemStackKey stackKey = new ItemStackKey(itemStack);
        int remainingAmount = itemStack.getCount() - itemSourceList.insertItem(stackKey, itemStack.getCount(), false, InsertMode.HIGHEST_PRIORITY);
        if (remainingAmount > 0) {
            itemStack.setCount(remainingAmount);
            player.addItemStackToInventory(itemStack);
            if (itemStack.getCount() > 0) {
                player.dropItem(itemStack, false, false);
            }
        }
    }
    this.lastTickChecked = -1L;
    return true;
}
 
Example #14
Source File: HoeBehaviour.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, BlockPos blockPos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (player.canPlayerEdit(blockPos, facing, stack) && !world.isAirBlock(blockPos)) {
        IBlockState blockState = world.getBlockState(blockPos);
        if (blockState.getBlock() == Blocks.GRASS || blockState.getBlock() == Blocks.DIRT) {
            if (blockState.getBlock() == Blocks.GRASS && player.isSneaking()) {
                if (GTUtility.doDamageItem(stack, this.cost, false)) {
                    if (world.rand.nextInt(3) == 0) {
                        ItemStack grassSeed = ForgeHooks.getGrassSeed(world.rand, 0);
                        Block.spawnAsEntity(world, blockPos.up(), grassSeed);
                    }
                    world.playSound(null, blockPos, SoundEvents.ITEM_HOE_TILL, SoundCategory.PLAYERS, 1.0F, 1.0F);
                    world.setBlockState(blockPos, Blocks.DIRT.getDefaultState()
                        .withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT));
                    return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
                }
            } else if (blockState.getBlock() == Blocks.GRASS
                || blockState.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT
                || blockState.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.COARSE_DIRT) {
                if (GTUtility.doDamageItem(stack, this.cost, false)) {
                    world.playSound(null, blockPos, SoundEvents.ITEM_HOE_TILL, SoundCategory.PLAYERS, 1.0F, 1.0F);
                    world.setBlockState(blockPos, Blocks.FARMLAND.getDefaultState());
                    return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
                }
            }
        }
    }
    return ActionResult.newResult(EnumActionResult.FAIL, stack);
}
 
Example #15
Source File: FakePlayerItemInWorldManager.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Attempts to harvest a block at the given coordinate
 */
@Override
public boolean tryHarvestBlock(int x, int y, int z){
    BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(theWorld, getGameType(), thisPlayerMP, x, y, z);
    if(event.isCanceled()) {
        return false;
    } else {
        ItemStack stack = thisPlayerMP.getCurrentEquippedItem();
        if(stack != null && stack.getItem().onBlockStartBreak(stack, x, y, z, thisPlayerMP)) {
            return false;
        }
        Block block = theWorld.getBlock(x, y, z);
        int l = theWorld.getBlockMetadata(x, y, z);
        theWorld.playAuxSFXAtEntity(thisPlayerMP, 2001, x, y, z, Block.getIdFromBlock(block) + (theWorld.getBlockMetadata(x, y, z) << 12));
        boolean flag = false;

        ItemStack itemstack = thisPlayerMP.getCurrentEquippedItem();

        if(itemstack != null) {
            itemstack.func_150999_a(theWorld, block, x, y, z, thisPlayerMP);

            if(itemstack.stackSize == 0) {
                thisPlayerMP.destroyCurrentEquippedItem();
            }
        }

        if(removeBlock(x, y, z)) {
            block.harvestBlock(theWorld, thisPlayerMP, x, y, z, l);
            flag = true;
        }

        // Drop experience
        if(!isCreative() && flag && event != null) {
            block.dropXpOnBlockBreak(theWorld, x, y, z, event.getExpToDrop());
        }
        drone.addAir(null, -PneumaticValues.DRONE_USAGE_DIG);
        return true;
    }
}
 
Example #16
Source File: ItemTaintShovel.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
@Override
public float getDigSpeed(ItemStack stack, Block block, int meta)
{
    if (ForgeHooks.isToolEffective(stack, block, meta) ||
            (block.getMaterial() == Config.taintMaterial && block != ForbiddenBlocks.taintLog && block != ForbiddenBlocks.taintPlanks
            && block != ForbiddenBlocks.taintStone))
    {
        return efficiencyOnProperMaterial;
    }

    return func_150893_a(stack, block);
}
 
Example #17
Source File: ItemMorphPickaxe.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase player) {
    if(EnchantmentHelper.getEnchantmentLevel(DarkEnchantments.impact.effectId, stack) <= 0)
        return super.onBlockDestroyed(stack, world, block, x, y, z, player);
    if(!player.worldObj.isRemote) {
        int meta = world.getBlockMetadata(x, y, z);
        if(ForgeHooks.isToolEffective(stack, block, meta)) {
            for(int aa = -1; aa <= 1; ++aa) {
                for(int bb = -1; bb <= 1; ++bb) {
                    int xx = 0;
                    int yy = 0;
                    int zz = 0;
                    if(this.side <= 1) {
                        xx = aa;
                        zz = bb;
                    } else if(this.side <= 3) {
                        xx = aa;
                        yy = bb;
                    } else {
                        zz = aa;
                        yy = bb;
                    }

                    if(!(player instanceof EntityPlayer) || world.canMineBlock((EntityPlayer)player, x + xx, y + yy, z + zz)) {
                        Block bl = world.getBlock(x + xx, y + yy, z + zz);
                        meta = world.getBlockMetadata(x + xx, y + yy, z + zz);
                        if(bl.getBlockHardness(world, x + xx, y + yy, z + zz) >= 0.0F && ForgeHooks.isToolEffective(stack, bl, meta)) {
                            stack.damageItem(1, player);
                            BlockUtils.harvestBlock(world, (EntityPlayer)player, x + xx, y + yy, z + zz, true, 2);
                        }
                    }
                }
            }
        }
        else
            return super.onBlockDestroyed(stack, world, block, x, y, z, player);
    }

    return super.onBlockDestroyed(stack, world, block, x, y, z, player);
}
 
Example #18
Source File: ItemMorphShovel.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase player) {
    if(EnchantmentHelper.getEnchantmentLevel(DarkEnchantments.impact.effectId, stack) <= 0)
        return super.onBlockDestroyed(stack, world, block, x, y, z, player);
    if(!player.worldObj.isRemote) {
        int meta = world.getBlockMetadata(x, y, z);
        if(ForgeHooks.isToolEffective(stack, block, meta)) {
            for(int aa = -1; aa <= 1; ++aa) {
                for(int bb = -1; bb <= 1; ++bb) {
                    int xx = 0;
                    int yy = 0;
                    int zz = 0;
                    if(this.side <= 1) {
                        xx = aa;
                        zz = bb;
                    } else if(this.side <= 3) {
                        xx = aa;
                        yy = bb;
                    } else {
                        zz = aa;
                        yy = bb;
                    }

                    if(!(player instanceof EntityPlayer) || world.canMineBlock((EntityPlayer)player, x + xx, y + yy, z + zz)) {
                        Block bl = world.getBlock(x + xx, y + yy, z + zz);
                        meta = world.getBlockMetadata(x + xx, y + yy, z + zz);
                        if(bl.getBlockHardness(world, x + xx, y + yy, z + zz) >= 0.0F && ForgeHooks.isToolEffective(stack, bl, meta)) {
                            stack.damageItem(1, player);
                            BlockUtils.harvestBlock(world, (EntityPlayer)player, x + xx, y + yy, z + zz, true, 2);
                        }
                    }
                }
            }
        }
        else
            return super.onBlockDestroyed(stack, world, block, x, y, z, player);
    }

    return super.onBlockDestroyed(stack, world, block, x, y, z, player);
}
 
Example #19
Source File: GT_Container_CircuitProgrammer.java    From bartworks with MIT License 5 votes vote down vote up
@Override
public void setInventorySlotContents(int slotNR, ItemStack itemStack) {
    if (itemStack != null && itemStack.getItem() != null && itemStack.getItem().equals(GT_Utility.getIntegratedCircuit(0).getItem())) {
        this.Slot = BW_Util.setStackSize(itemStack.copy(),1);
        itemStack.stackSize--;
        this.tag = this.toBind.getTagCompound();
        this.tag.setBoolean("HasChip", true);
        this.tag.setByte("ChipConfig", (byte) itemStack.getItemDamage());
        this.toBind.setTagCompound(this.tag);
        this.Player.inventory.setInventorySlotContents(this.Player.inventory.currentItem, this.toBind);
        if (!this.Player.isClientWorld())
            MainMod.BW_Network_instance.sendToServer(new CircuitProgrammerPacket(this.Player.worldObj.provider.dimensionId, this.Player.getEntityId(), true, (byte) itemStack.getItemDamage()));
    } else if (BW_Util.checkStackAndPrefix(itemStack) && GT_OreDictUnificator.getAssociation(itemStack).mPrefix.equals(OrePrefixes.circuit) && GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial.equals(Materials.Basic)) {
        this.Slot = GT_Utility.getIntegratedCircuit(0);
        this.Slot.stackSize = 1;
        itemStack.stackSize--;
        this.tag = this.toBind.getTagCompound();
        this.tag.setBoolean("HasChip", true);
        this.tag.setByte("ChipConfig", (byte) 0);
        this.toBind.setTagCompound(this.tag);
        this.Player.inventory.setInventorySlotContents(this.Player.inventory.currentItem, this.toBind);
        if (!this.Player.isClientWorld())
            MainMod.BW_Network_instance.sendToServer(new CircuitProgrammerPacket(this.Player.worldObj.provider.dimensionId, this.Player.getEntityId(), true, (byte) 0));
    }/* else if (GT_Utility.isStackValid(itemStack) && itemStack.getItem() instanceof Circuit_Programmer) {
        ForgeHooks.onPlayerTossEvent(Player, itemStack, false);
        this.closeInventory();
        Player.closeScreen();
    }*/ else {
        ForgeHooks.onPlayerTossEvent(this.Player, itemStack, false);
        this.tag = this.toBind.getTagCompound();
        this.tag.setBoolean("HasChip", false);
        this.toBind.setTagCompound(this.tag);
        this.Player.inventory.setInventorySlotContents(this.Player.inventory.currentItem, this.toBind);
        if (!this.Player.isClientWorld())
            MainMod.BW_Network_instance.sendToServer(new CircuitProgrammerPacket(this.Player.worldObj.provider.dimensionId, this.Player.getEntityId(), false, (byte) 0));
    }
}
 
Example #20
Source File: DamageableShapelessOreRecipe.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
    NonNullList<ItemStack> items = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);

    matches(inv, null);

    for (int i = 0; i < invSlots.length; i++)
    {
        int amount = damageAmounts[i];
        int invIndex = invSlots[i];
        if (amount > 0)
        {
            ItemStack stack = inv.getStackInSlot(invIndex).copy();
            stack.setItemDamage(stack.getItemDamage() + amount);
            if (stack.getItemDamage() > stack.getMaxDamage())
            {
                stack = ForgeHooks.getContainerItem(stack);
            }
            items.set(invIndex, stack);
        } else
        {
            items.set(invIndex, ForgeHooks.getContainerItem(inv.getStackInSlot(invIndex)));
        }
    }

    return items;
}
 
Example #21
Source File: DamageableShapedOreRecipe.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
    NonNullList<ItemStack> items = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);

    getMatch(inv);

    int[] amounts = getAmounts(wasMirrored);

    for (int col = 0; col < getWidth(); col++)
    {
        for (int row = 0; row < getHeight(); row++)
        {
            int amountIndex = col + row * getWidth();
            int invIndex = matchX + col + (row + matchY) * inv.getWidth();
            int amount = amounts[amountIndex];
            if (amount > 0)
            {
                ItemStack stack = inv.getStackInSlot(invIndex).copy();
                stack.setItemDamage(stack.getItemDamage() + amount);
                if (stack.getItemDamage() > stack.getMaxDamage())
                {
                    stack = ForgeHooks.getContainerItem(stack);
                }
                items.set(invIndex, stack);
            } else
            {
                items.set(invIndex, ForgeHooks.getContainerItem(inv.getStackInSlot(invIndex)));
            }
        }
    }

    return items;
}
 
Example #22
Source File: RecipeUnmountPearl.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(@Nonnull InventoryCrafting inv) {
	NonNullList<ItemStack> remainingItems = ForgeHooks.defaultRecipeGetRemainingItems(inv);

	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() instanceof IPearlSwappable) {
			remainingItems.set(i, new ItemStack(stack.getItem()));
		}
	}

	return remainingItems;
}
 
Example #23
Source File: StatBase.java    From GokiStats with MIT License 5 votes vote down vote up
@Override
public boolean isEffectiveOn(Object... obj) {
    if (((obj[1] instanceof ItemStack)) && ((obj[2] instanceof BlockPos)) && ((obj[3] instanceof World))) {
        ItemStack stack = (ItemStack) obj[1];
        BlockPos pos = (BlockPos) obj[2];
        World world = (World) obj[3];

        return ForgeHooks.isToolEffective(world, pos, stack);
    }
    return false;
}
 
Example #24
Source File: GTItemJackHammer.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean canMineBlock(ItemStack stack, IBlockState state, IBlockAccess access, BlockPos pos) {
	return ForgeHooks.canToolHarvestBlock(access, pos, stack);
}
 
Example #25
Source File: RecipeMountPearl.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(@Nonnull InventoryCrafting inv) {
	return ForgeHooks.defaultRecipeGetRemainingItems(inv);
}
 
Example #26
Source File: GTItemRockCutter.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean canMineBlock(ItemStack stack, IBlockState state, IBlockAccess access, BlockPos pos) {
	return ForgeHooks.canToolHarvestBlock(access, pos, stack);
}
 
Example #27
Source File: BlockTeleportRail.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
private void teleport(EntityMinecart cart, MCPos destination){
    if(cart instanceof EntityMinecartContainer) {
        ((EntityMinecartContainer)cart).dropContentsWhenDead = false;
    }

    int dimensionIn = destination.getDimID();
    BlockPos destPos = destination.getPos();
    if(!ForgeHooks.onTravelToDimension(cart, destination.getDimID())) return;

    MinecraftServer minecraftserver = cart.getServer();
    int i = cart.dimension;
    WorldServer worldserver = minecraftserver.getWorld(i);
    WorldServer worldserver1 = minecraftserver.getWorld(dimensionIn);
    cart.dimension = dimensionIn;

    /*if (i == 1 && dimensionIn == 1)
    {
        worldserver1 = minecraftserver.getWorld(0);
        this.dimension = 0;
    }*/

    cart.world.removeEntity(cart);
    cart.isDead = false;
    BlockPos blockpos = destination.getPos();

    /* double moveFactor = worldserver.provider.getMovementFactor() / worldserver1.provider.getMovementFactor();
    double d0 = MathHelper.clamp(this.posX * moveFactor, worldserver1.getWorldBorder().minX() + 16.0D, worldserver1.getWorldBorder().maxX() - 16.0D);
    double d1 = MathHelper.clamp(this.posZ * moveFactor, worldserver1.getWorldBorder().minZ() + 16.0D, worldserver1.getWorldBorder().maxZ() - 16.0D);
    double d2 = 8.0D;*/

    cart.moveToBlockPosAndAngles(destPos, 90.0F, 0.0F);
    /*Teleporter teleporter = worldserver1.getDefaultTeleporter();
    teleporter.placeInExistingPortal(this, f);
    blockpos = new BlockPos(this);*/

    worldserver.updateEntityWithOptionalForce(cart, false);
    Entity entity = EntityList.newEntity(cart.getClass(), worldserver1);

    if(entity != null) {
        copyDataFromOld(entity, cart);

        entity.moveToBlockPosAndAngles(blockpos, entity.rotationYaw, entity.rotationPitch);

        IBlockState state = destination.getLoadedBlockState();
        if(state.getBlock() == ModBlocks.TELEPORT_RAIL) { //If the destination is a teleport track, use its rail direction to push the cart the right direction
            EnumFacing teleportDir = getTeleportDirection(state);
            double speed = 0.2;
            entity.motionX = teleportDir.getFrontOffsetX() * speed;
            entity.motionY = teleportDir.getFrontOffsetY() * speed;
            entity.motionZ = teleportDir.getFrontOffsetZ() * speed;
        } else {
            entity.motionX = entity.motionY = entity.motionZ = 0;
        }

        boolean flag = entity.forceSpawn;
        entity.forceSpawn = true;
        worldserver1.spawnEntity(entity);
        entity.forceSpawn = flag;
        worldserver1.updateEntityWithOptionalForce(entity, false);
    }

    cart.isDead = true;
    worldserver.resetUpdateEntityTick();
    worldserver1.resetUpdateEntityTick();
}
 
Example #28
Source File: SawmillTileEntity.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void tick()
{
    if (world.isRemote)
        return;

    boolean changes = false;

    if (needRefreshRecipe)
    {
        totalBurnTime = ForgeHooks.getBurnTime(inventory.getStackInSlot(1));
        totalCookTime = getSawmillTime(world, inventory.getStackInSlot(0));
        needRefreshRecipe = false;
    }

    if (this.isBurning())
    {
        --this.remainingBurnTime;
    }

    if (!this.world.isRemote)
    {
        ItemStack fuel = this.inventory.getStackInSlot(1);

        if (this.isBurning() || !fuel.isEmpty())
        {
            ChoppingContext ctx = new ChoppingContext(inventory, null, 0, 0, RANDOM);
            changes |= ChoppingRecipe.getRecipe(world, ctx).map(choppingRecipe -> {
                boolean changes2 = false;
                if (!this.isBurning() && this.canWork(ctx, choppingRecipe))
                {
                    this.totalBurnTime = ForgeHooks.getBurnTime(fuel);
                    this.remainingBurnTime = this.totalBurnTime;

                    if (this.isBurning())
                    {
                        changes2 = true;

                        if (!fuel.isEmpty())
                        {
                            Item item = fuel.getItem();
                            fuel.shrink(1);

                            if (fuel.isEmpty())
                            {
                                ItemStack containerItem = item.getContainerItem(fuel);
                                this.inventory.setStackInSlot(1, containerItem);
                            }
                        }
                    }
                }

                if (this.isBurning() && this.canWork(ctx, choppingRecipe))
                {
                    ++this.cookTime;

                    if (this.totalCookTime == 0)
                    {
                        this.totalCookTime = choppingRecipe.getSawingTime();
                    }

                    if (this.cookTime >= this.totalCookTime)
                    {
                        this.cookTime = 0;
                        this.totalCookTime = choppingRecipe.getSawingTime();
                        this.processItem(ctx, choppingRecipe);
                        changes2 = true;
                    }
                }
                else
                {
                    this.cookTime = 0;
                }

                return changes2;
            }).orElse(false);
        }
        if (!this.isBurning() && this.cookTime > 0)
        {
            this.cookTime = MathHelper.clamp(this.cookTime - 2, 0, this.totalCookTime);
        }
    }

    BlockState state = getBlockState();
    if (state.get(SawmillBlock.POWERED) != this.isBurning())
    {
        state = state.with(SawmillBlock.POWERED, this.isBurning());
        world.setBlockState(pos, state);
    }

    if (changes)
    {
        this.markDirty();
    }
}
 
Example #29
Source File: StatBase.java    From GokiStats with MIT License 4 votes vote down vote up
public final boolean isEffectiveOn(ItemStack stack, BlockPos pos, World world) {
    if (ForgeHooks.isToolEffective(world, pos, stack))
        return true;
    else return isEffectiveOn(stack);
}
 
Example #30
Source File: ReflectionUtil.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public static List getSeeds() {
	return getPrivateStaticObject(ForgeHooks.class, "seedList");
}