Search in sources :

Example 16 with NonNullList

use of net.minecraft.util.NonNullList in project ImmersiveEngineering by BluSunrize.

the class TileEntityAssembler method update.

@Override
public void update() {
    super.update();
    if (isDummy() || isRSDisabled() || world.isRemote || world.getTotalWorldTime() % 16 != ((getPos().getX() ^ getPos().getZ()) & 15))
        return;
    boolean update = false;
    NonNullList<ItemStack>[] outputBuffer = new NonNullList[patterns.length];
    for (int p = 0; p < patterns.length; p++) {
        CrafterPatternInventory pattern = patterns[p];
        if (isComputerControlled && !computerOn[p])
            continue;
        if (!pattern.inv.get(9).isEmpty() && canOutput(pattern.inv.get(9), p)) {
            ItemStack output = pattern.inv.get(9).copy();
            // List of all available inputs in the inventory
            ArrayList<ItemStack> availableStacks = new ArrayList<>();
            for (NonNullList<ItemStack> bufferedStacks : outputBuffer) if (bufferedStacks != null)
                for (ItemStack stack : bufferedStacks) if (!stack.isEmpty())
                    availableStacks.add(stack);
            for (ItemStack stack : this.inventory) if (!stack.isEmpty())
                availableStacks.add(stack);
            int consumed = IEConfig.Machines.assembler_consumption;
            AssemblerHandler.IRecipeAdapter adapter = AssemblerHandler.findAdapter(pattern.recipe);
            AssemblerHandler.RecipeQuery[] queries = adapter.getQueriedInputs(pattern.recipe, pattern.inv);
            if (queries == null)
                continue;
            if (this.energyStorage.extractEnergy(consumed, true) == consumed && this.consumeIngredients(queries, availableStacks, false, null)) {
                this.energyStorage.extractEnergy(consumed, false);
                // List of all outputs for the current recipe. This includes discarded containers
                NonNullList<ItemStack> outputList = NonNullList.create();
                outputList.add(output);
                NonNullList<ItemStack> gridItems = NonNullList.withSize(9, ItemStack.EMPTY);
                this.consumeIngredients(queries, availableStacks, true, gridItems);
                NonNullList<ItemStack> remainingItems = pattern.recipe.getRemainingItems(Utils.InventoryCraftingFalse.createFilledCraftingInventory(3, 3, gridItems));
                for (ItemStack rem : remainingItems) if (!rem.isEmpty())
                    outputList.add(rem);
                outputBuffer[p] = outputList;
                update = true;
            }
        }
    }
    BlockPos outputPos = getPos().offset(facing, 2);
    TileEntity inventoryTile = Utils.getExistingTileEntity(world, outputPos);
    for (int buffer = 0; buffer < outputBuffer.length; buffer++) if (outputBuffer[buffer] != null && outputBuffer[buffer].size() > 0)
        for (int iOutput = 0; iOutput < outputBuffer[buffer].size(); iOutput++) {
            ItemStack output = outputBuffer[buffer].get(iOutput);
            if (!output.isEmpty() && output.getCount() > 0) {
                if (!isRecipeIngredient(output, buffer) && inventoryTile != null) {
                    output = Utils.insertStackIntoInventory(inventoryTile, output, facing.getOpposite());
                    if (output.isEmpty() || output.getCount() <= 0)
                        continue;
                }
                int free = -1;
                if (// Main recipe output
                iOutput == 0) {
                    if (this.inventory.get(18 + buffer).isEmpty() && free < 0)
                        free = 18 + buffer;
                    else if (!this.inventory.get(18 + buffer).isEmpty() && OreDictionary.itemMatches(output, this.inventory.get(18 + buffer), true) && this.inventory.get(18 + buffer).getCount() + output.getCount() <= this.inventory.get(18 + buffer).getMaxStackSize()) {
                        this.inventory.get(18 + buffer).grow(output.getCount());
                        free = -1;
                        continue;
                    }
                } else
                    for (int i = 0; i < this.inventory.size(); i++) {
                        if (this.inventory.get(i).isEmpty() && free < 0)
                            free = i;
                        else if (!this.inventory.get(i).isEmpty() && OreDictionary.itemMatches(output, this.inventory.get(i), true) && this.inventory.get(i).getCount() + output.getCount() <= this.inventory.get(i).getMaxStackSize()) {
                            this.inventory.get(i).grow(output.getCount());
                            free = -1;
                            break;
                        }
                    }
                if (free >= 0)
                    this.inventory.set(free, output.copy());
            }
        }
    for (int i = 0; i < 3; i++) if (!isRecipeIngredient(this.inventory.get(18 + i), i) && inventoryTile != null)
        this.inventory.set(18 + i, Utils.insertStackIntoInventory(inventoryTile, this.inventory.get(18 + i), facing.getOpposite()));
    if (update) {
        this.markDirty();
        this.markContainingBlockForUpdate(null);
    }
}
Also used : ArrayList(java.util.ArrayList) AssemblerHandler(blusunrize.immersiveengineering.api.tool.AssemblerHandler) TileEntity(net.minecraft.tileentity.TileEntity) NonNullList(net.minecraft.util.NonNullList) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 17 with NonNullList

use of net.minecraft.util.NonNullList in project ImmersiveEngineering by BluSunrize.

the class ClientEventHandler method onRenderTooltip.

@SubscribeEvent()
public void onRenderTooltip(RenderTooltipEvent.PostText event) {
    ItemStack stack = event.getStack();
    if (stack.getItem() instanceof IBulletContainer) {
        NonNullList<ItemStack> bullets = ((IBulletContainer) stack.getItem()).getBullets(stack, true);
        if (bullets != null) {
            int bulletAmount = ((IBulletContainer) stack.getItem()).getBulletCount(stack);
            int line = event.getLines().size() - Utils.findSequenceInList(event.getLines(), BULLET_TOOLTIP, (s, s2) -> s.equals(s2.substring(2)));
            int currentX = event.getX();
            int currentY = line > 0 ? event.getY() + (event.getHeight() + 1 - line * 10) : event.getY() - 42;
            GlStateManager.pushMatrix();
            GlStateManager.enableBlend();
            GlStateManager.enableRescaleNormal();
            GlStateManager.translate(currentX, currentY, 700);
            GlStateManager.scale(.5f, .5f, 1);
            GuiRevolver.drawExternalGUI(bullets, bulletAmount);
            GlStateManager.disableRescaleNormal();
            GlStateManager.popMatrix();
        }
    }
}
Also used : ShaderWrapper(blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper) EnumHand(net.minecraft.util.EnumHand) FMLCommonHandler(net.minecraftforge.fml.common.FMLCommonHandler) TileEntityTurntable(blusunrize.immersiveengineering.common.blocks.wooden.TileEntityTurntable) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) I18n(net.minecraft.client.resources.I18n) IFluxReceiver(blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) Pair(org.apache.commons.lang3.tuple.Pair) Side(net.minecraftforge.fml.relauncher.Side) NonNullList(net.minecraft.util.NonNullList) GL11(org.lwjgl.opengl.GL11) TileEntitySampleDrill(blusunrize.immersiveengineering.common.blocks.metal.TileEntitySampleDrill) IEPotions(blusunrize.immersiveengineering.common.util.IEPotions) IResourceManagerReloadListener(net.minecraft.client.resources.IResourceManagerReloadListener) Mouse(org.lwjgl.input.Mouse) Config(blusunrize.immersiveengineering.common.Config) BlastFurnaceRecipe(blusunrize.immersiveengineering.api.crafting.BlastFurnaceRecipe) EntityJoinWorldEvent(net.minecraftforge.event.entity.EntityJoinWorldEvent) MessageRequestBlockUpdate(blusunrize.immersiveengineering.common.util.network.MessageRequestBlockUpdate) BlueprintCraftingRecipe(blusunrize.immersiveengineering.api.crafting.BlueprintCraftingRecipe) ItemTooltipEvent(net.minecraftforge.event.entity.player.ItemTooltipEvent) IEMuffledSound(blusunrize.immersiveengineering.common.util.sound.IEMuffledSound) IAdvancedSelectionBounds(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IAdvancedSelectionBounds) FluidStack(net.minecraftforge.fluids.FluidStack) TickEvent(net.minecraftforge.fml.common.gameevent.TickEvent) java.util(java.util) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) PotionEffect(net.minecraft.potion.PotionEffect) TileRenderAutoWorkbench(blusunrize.immersiveengineering.client.render.TileRenderAutoWorkbench) ZoomHandler(blusunrize.immersiveengineering.api.tool.ZoomHandler) MessageMagnetEquip(blusunrize.immersiveengineering.common.util.network.MessageMagnetEquip) EnumHandSide(net.minecraft.util.EnumHandSide) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Utils(blusunrize.immersiveengineering.common.util.Utils) World(net.minecraft.world.World) TextFormatting(net.minecraft.util.text.TextFormatting) TextureMap(net.minecraft.client.renderer.texture.TextureMap) BlockPos(net.minecraft.util.math.BlockPos) TileEntityRendererDispatcher(net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher) ItemNBTHelper(blusunrize.immersiveengineering.common.util.ItemNBTHelper) LivingDeathEvent(net.minecraftforge.event.entity.living.LivingDeathEvent) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IZoomTool(blusunrize.immersiveengineering.api.tool.ZoomHandler.IZoomTool) MessageChemthrowerSwitch(blusunrize.immersiveengineering.common.util.network.MessageChemthrowerSwitch) Phase(net.minecraftforge.fml.common.gameevent.TickEvent.Phase) EnergyHelper(blusunrize.immersiveengineering.common.util.EnergyHelper) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) TileEntity(net.minecraft.tileentity.TileEntity) GuiToolbox(blusunrize.immersiveengineering.client.gui.GuiToolbox) GLContext(org.lwjgl.opengl.GLContext) Axis(net.minecraft.util.EnumFacing.Axis) net.minecraftforge.client.event(net.minecraftforge.client.event) IEContent(blusunrize.immersiveengineering.common.IEContent) ImmersiveEngineering(blusunrize.immersiveengineering.ImmersiveEngineering) MessageRevolverRotate(blusunrize.immersiveengineering.common.util.network.MessageRevolverRotate) CapabilityShader(blusunrize.immersiveengineering.api.shader.CapabilityShader) blusunrize.immersiveengineering.common.items(blusunrize.immersiveengineering.common.items) OreDictionary(net.minecraftforge.oredict.OreDictionary) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Lib(blusunrize.immersiveengineering.api.Lib) BlockTypes_MetalDevice1(blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDevice1) GuiRevolver(blusunrize.immersiveengineering.client.gui.GuiRevolver) BlueprintLines(blusunrize.immersiveengineering.client.render.TileRenderAutoWorkbench.BlueprintLines) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModelVillager(net.minecraft.client.model.ModelVillager) IWireCoil(blusunrize.immersiveengineering.api.energy.wires.IWireCoil) EventPriority(net.minecraftforge.fml.common.eventhandler.EventPriority) IBulletContainer(blusunrize.immersiveengineering.common.items.IEItemInterfaces.IBulletContainer) SourceFactor(net.minecraft.client.renderer.GlStateManager.SourceFactor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WireType(blusunrize.immersiveengineering.api.energy.wires.WireType) Entry(java.util.Map.Entry) ITickableSound(net.minecraft.client.audio.ITickableSound) ClientConnectedToServerEvent(net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent) IEMuffledTickableSound(blusunrize.immersiveengineering.common.util.sound.IEMuffledTickableSound) ModelBiped(net.minecraft.client.model.ModelBiped) net.minecraft.client.renderer(net.minecraft.client.renderer) GuiIngameForge(net.minecraftforge.client.GuiIngameForge) FluidUtil(net.minecraftforge.fluids.FluidUtil) IDrillHead(blusunrize.immersiveengineering.api.tool.IDrillHead) DestFactor(net.minecraft.client.renderer.GlStateManager.DestFactor) PositionedSoundRecord(net.minecraft.client.audio.PositionedSoundRecord) IBlockOverlayText(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IBlockOverlayText) PlaySoundEvent(net.minecraftforge.client.event.sound.PlaySoundEvent) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) RayTraceResult(net.minecraft.util.math.RayTraceResult) ImmutableList(com.google.common.collect.ImmutableList) Minecraft(net.minecraft.client.Minecraft) IResourceManager(net.minecraft.client.resources.IResourceManager) GuiBlastFurnace(blusunrize.immersiveengineering.client.gui.GuiBlastFurnace) Entity(net.minecraft.entity.Entity) PlayerControllerMP(net.minecraft.client.multiplayer.PlayerControllerMP) EnumFacing(net.minecraft.util.EnumFacing) Type(net.minecraft.util.math.RayTraceResult.Type) ModelBase(net.minecraft.client.model.ModelBase) IEConfig(blusunrize.immersiveengineering.common.Config.IEConfig) ParticleFractal(blusunrize.immersiveengineering.client.fx.ParticleFractal) FontRenderer(net.minecraft.client.gui.FontRenderer) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) IBulletContainer(blusunrize.immersiveengineering.common.items.IEItemInterfaces.IBulletContainer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 18 with NonNullList

use of net.minecraft.util.NonNullList in project BluePower by Qmunity.

the class BPRecyclingReloadListener method onResourceManagerReload.

public static void onResourceManagerReload(RecipeManager recipeManager) {
    AlloyFurnaceRegistry.getInstance().blacklist.clear();
    List<String> blacklistStr = Arrays.asList(BPConfig.CONFIG.alloyFurnaceBlacklist.get().split(","));
    for (String configString : blacklistStr) {
        Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(configString));
        if (item != null) {
            AlloyFurnaceRegistry.getInstance().blacklist.add(item);
        }
    }
    AlloyFurnaceRegistry.getInstance().recyclingRecipes.clear();
    for (ItemStack outputItem : AlloyFurnaceRegistry.getInstance().recyclingItems) {
        // Build the blacklist based on config
        Set<Item> blacklist = new HashSet<>(AlloyFurnaceRegistry.getInstance().blacklist);
        for (IRecipe<?> recipe : recipeManager.getAllRecipesFor(IRecipeType.CRAFTING)) {
            // Take into account other mods with Dynamic Recipes
            NonNullList<Ingredient> ingredients = null;
            try {
                ingredients = recipe.getIngredients();
            } catch (IllegalStateException ignored) {
            }
            // If Recipe Contains a Recyclable Item check the recipe
            if (ingredients != null && !recipe.isSpecial() && ingredients.stream().anyMatch(ingredient -> ingredient.test(outputItem))) {
                int recyclingAmount = 0;
                ItemStack currentlyRecycledInto = ItemStack.EMPTY;
                for (ItemStack recyclingItem : AlloyFurnaceRegistry.getInstance().recyclingItems) {
                    try {
                        if (recipe instanceof ICraftingRecipe) {
                            if (!recipe.getIngredients().isEmpty()) {
                                for (Ingredient input : recipe.getIngredients()) {
                                    if (!input.isEmpty()) {
                                        // Serialize and Deserialize the Object so the base tag isn't affected.
                                        Ingredient ingredient = Ingredient.fromJson(input.toJson());
                                        if (ingredient.test(recyclingItem)) {
                                            ItemStack moltenDownItem = AlloyFurnaceRegistry.getInstance().getRecyclingStack(recyclingItem);
                                            if (currentlyRecycledInto.isEmpty() || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
                                                currentlyRecycledInto = moltenDownItem;
                                                recyclingAmount += moltenDownItem.getCount();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } catch (Throwable e) {
                        BluePower.log.error("Error when generating an Alloy Furnace recipe for item " + recyclingItem.getDisplayName().getString() + ", recipe output: " + recipe.getResultItem().getDisplayName().getString());
                        e.printStackTrace();
                    }
                }
                if (recyclingAmount > 0 && recipe.getResultItem().getCount() > 0) {
                    // Try to avoid Duping
                    if (!blacklist.contains(recipe.getResultItem().getItem()) && recipe.getResultItem().getCount() > recyclingAmount) {
                        blacklist.add(recipe.getResultItem().getItem());
                    }
                    // Skip item if it is on the blacklist
                    if (blacklist.contains(recipe.getResultItem().getItem())) {
                        continue;
                    }
                    // Divide by the Recipe Output
                    ItemStack output = new ItemStack(currentlyRecycledInto.getItem(), Math.min(64, recyclingAmount / recipe.getResultItem().getCount()));
                    AlloyFurnaceRegistry.getInstance().recyclingRecipes.put(recipe.getResultItem().getItem(), output);
                }
            }
        }
    }
}
Also used : Arrays(java.util.Arrays) Item(net.minecraft.item.Item) ItemStackUtils(com.bluepowermod.util.ItemStackUtils) IResourceManager(net.minecraft.resources.IResourceManager) BPConfig(com.bluepowermod.init.BPConfig) Set(java.util.Set) AlloyFurnaceRegistry(com.bluepowermod.recipe.AlloyFurnaceRegistry) net.minecraft.item.crafting(net.minecraft.item.crafting) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) ResourceLocation(net.minecraft.util.ResourceLocation) DataPackRegistries(net.minecraft.resources.DataPackRegistries) NonNullList(net.minecraft.util.NonNullList) BluePower(com.bluepowermod.BluePower) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) IResourceManagerReloadListener(net.minecraft.resources.IResourceManagerReloadListener) Item(net.minecraft.item.Item) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) HashSet(java.util.HashSet)

Example 19 with NonNullList

use of net.minecraft.util.NonNullList in project malmo by Microsoft.

the class CraftingHelper method attemptCrafting.

/**
 * Attempt to craft the given recipe.<br>
 * This pays no attention to tedious things like using the right crafting table / brewing stand etc, or getting the right shape.<br>
 * It simply takes the raw ingredients out of the player's inventory, and inserts the output of the recipe, if possible.
 *
 * @param player the SERVER SIDE player that will do the crafting.
 * @param recipe the IRecipe we wish to craft.
 * @return true if the recipe had an output, and the player had the required ingredients to create it; false otherwise.
 */
public static boolean attemptCrafting(EntityPlayerMP player, IRecipe recipe) {
    if (player == null || recipe == null)
        return false;
    ItemStack is = recipe.getRecipeOutput();
    List<ItemStack> ingredients = getIngredients(recipe);
    if (playerHasIngredients(player, ingredients)) {
        // We have the ingredients we need, so directly manipulate the inventory.
        // First, remove the ingredients:
        removeIngredientsFromPlayer(player, ingredients);
        // Now add the output of the recipe:
        ItemStack resultForInventory = is.copy();
        ItemStack resultForReward = is.copy();
        player.inventory.addItemStackToInventory(resultForInventory);
        RewardForCollectingItemImplementation.GainItemEvent event = new RewardForCollectingItemImplementation.GainItemEvent(resultForReward);
        event.setCause(1);
        MinecraftForge.EVENT_BUS.post(event);
        // Now trigger a craft event
        List<IRecipe> recipes = getRecipesForRequestedOutput(resultForReward, true);
        for (IRecipe iRecipe : recipes) {
            if (iRecipe instanceof ShapedRecipes) {
                ShapedRecipes shapedRecipe = (ShapedRecipes) iRecipe;
                InventoryCrafting craftMatrix;
                if (shapedRecipe.recipeItems.length <= 4)
                    craftMatrix = new InventoryCrafting(player.inventoryContainer, 2, 2);
                else
                    craftMatrix = new InventoryCrafting(player.inventoryContainer, 3, 3);
                for (int i = 0; i < shapedRecipe.recipeItems.length; i++) craftMatrix.setInventorySlotContents(i, shapedRecipe.recipeItems[i]);
                MinecraftForge.EVENT_BUS.post(new PlayerEvent.ItemCraftedEvent(player, resultForReward, craftMatrix));
                break;
            } else if (iRecipe instanceof ShapelessRecipes) {
                ShapelessRecipes shapelessRecipe = (ShapelessRecipes) iRecipe;
                InventoryCrafting craftMatrix;
                if (shapelessRecipe.recipeItems.size() <= 4) {
                    craftMatrix = new InventoryCrafting(player.inventoryContainer, 2, 2);
                    for (int i = 0; i < shapelessRecipe.recipeItems.size(); i++) craftMatrix.setInventorySlotContents(i, shapelessRecipe.recipeItems.get(i));
                } else {
                    craftMatrix = new InventoryCrafting(player.inventoryContainer, 3, 3);
                    for (int i = 0; i < shapelessRecipe.recipeItems.size(); i++) craftMatrix.setInventorySlotContents(i, shapelessRecipe.recipeItems.get(i));
                }
                MinecraftForge.EVENT_BUS.post(new PlayerEvent.ItemCraftedEvent(player, resultForReward, craftMatrix));
                break;
            } else if (iRecipe instanceof ShapedOreRecipe) {
                ShapedOreRecipe oreRecipe = (ShapedOreRecipe) iRecipe;
                Object[] input = oreRecipe.getInput();
                InventoryCrafting craftMatrix = new InventoryCrafting(player.inventoryContainer, 3, 3);
                for (int i = 0; i < input.length; i++) {
                    if (input[i] instanceof ItemStack)
                        craftMatrix.setInventorySlotContents(i, (ItemStack) input[i]);
                    else if (input[i] instanceof NonNullList)
                        if (((NonNullList) input[i]).size() != 0)
                            craftMatrix.setInventorySlotContents(i, (ItemStack) ((NonNullList) input[i]).get(0));
                }
                MinecraftForge.EVENT_BUS.post(new PlayerEvent.ItemCraftedEvent(player, resultForReward, craftMatrix));
            }
        }
        return true;
    }
    return false;
}
Also used : ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) PlayerEvent(net.minecraftforge.fml.common.gameevent.PlayerEvent) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) NonNullList(net.minecraft.util.NonNullList) JsonObject(com.google.gson.JsonObject) ItemStack(net.minecraft.item.ItemStack) RewardForCollectingItemImplementation(com.microsoft.Malmo.MissionHandlers.RewardForCollectingItemImplementation)

Example 20 with NonNullList

use of net.minecraft.util.NonNullList in project Almura by AlmuraDev.

the class MixinBlockTallGrass method getDrops.

/**
 * @author Zidane - Chris Sanders
 * @reason Add in content seeds to drop list for Tall Grass
 */
@Overwrite(remap = false)
public void getDrops(final NonNullList<ItemStack> drops, final IBlockAccess access, final BlockPos pos, final IBlockState state, final int fortune) {
    World world;
    if (access instanceof ChunkCache) {
        world = ((ChunkCache) access).world;
    } else if (access instanceof World) {
        world = (World) access;
    } else {
        return;
    }
    final Random random = world.rand;
    // Roll 1 is Vanilla's 1/8 chance to drop a seed
    final int roll1 = random.nextInt(8);
    if (roll1 == 0) {
        // Forge Start - Lookup seed each time and then do random check. Almura handles its own chance code
        final ItemStack modSeed = net.minecraftforge.common.ForgeHooks.getGrassSeed(random, fortune);
        if (!modSeed.isEmpty()) {
            drops.add(modSeed);
            // Don't double up with Vanilla/mod drops
            return;
        }
        final Biome biome = world.getBiome(pos);
        // Roll 2 is shuffling Almura seeds and picking the first one after shuffling
        registry.getAllOf(ItemType.class).stream().filter(itemType -> itemType instanceof SeedItem && ((SeedItem) itemType).getGrass() != null).collect(Collectors.collectingAndThen(Collectors.toList(), collected -> {
            Collections.shuffle(collected);
            return collected.stream();
        })).findFirst().ifPresent((itemType) -> {
            final SeedItem seed = (SeedItem) itemType;
            final IntRange amountRange = seed.getGrass().getOrLoadAmountRequiredRangeForBiome(biome);
            if (amountRange != null) {
                final int stackSize = amountRange.random(random);
                final DoubleRange chanceRange = seed.getGrass().getOrLoadChanceRangeForBiome(biome);
                if (chanceRange != null) {
                    final double chance = chanceRange.random(random);
                    // Roll 3 is allowing the seed configuration to determine the chance for the drop
                    if (random.nextDouble() <= (chance / 100)) {
                        drops.add((ItemStack) (Object) org.spongepowered.api.item.inventory.ItemStack.of(itemType, stackSize));
                    }
                } else {
                    drops.add((ItemStack) (Object) org.spongepowered.api.item.inventory.ItemStack.of(itemType, stackSize));
                }
            }
        });
    }
// Almura End
}
Also used : ChunkCache(net.minecraft.world.ChunkCache) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) Random(java.util.Random) Overwrite(org.spongepowered.asm.mixin.Overwrite) SeedItem(com.almuradev.content.type.item.type.seed.SeedItem) BlockTallGrass(net.minecraft.block.BlockTallGrass) Collectors(java.util.stream.Collectors) GameRegistry(org.spongepowered.api.GameRegistry) Inject(javax.inject.Inject) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) Mixin(org.spongepowered.asm.mixin.Mixin) MixinBlock(com.almuradev.content.type.block.mixin.impl.MixinBlock) DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) NonNullList(net.minecraft.util.NonNullList) ItemType(org.spongepowered.api.item.ItemType) Collections(java.util.Collections) IntRange(com.almuradev.toolbox.util.math.IntRange) IBlockAccess(net.minecraft.world.IBlockAccess) Biome(net.minecraft.world.biome.Biome) ChunkCache(net.minecraft.world.ChunkCache) ItemType(org.spongepowered.api.item.ItemType) IntRange(com.almuradev.toolbox.util.math.IntRange) World(net.minecraft.world.World) SeedItem(com.almuradev.content.type.item.type.seed.SeedItem) DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) Biome(net.minecraft.world.biome.Biome) Random(java.util.Random) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

NonNullList (net.minecraft.util.NonNullList)42 ItemStack (net.minecraft.item.ItemStack)37 List (java.util.List)13 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 Item (net.minecraft.item.Item)8 TileEntity (net.minecraft.tileentity.TileEntity)8 BlockPos (net.minecraft.util.math.BlockPos)7 ArrayList (java.util.ArrayList)6 Collectors (java.util.stream.Collectors)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 Iterator (java.util.Iterator)5 Map (java.util.Map)5 Nonnull (javax.annotation.Nonnull)5 Nullable (javax.annotation.Nullable)5 CreativeTabs (net.minecraft.creativetab.CreativeTabs)5 World (net.minecraft.world.World)5 Block (net.minecraft.block.Block)4 IBlockState (net.minecraft.block.state.IBlockState)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 RayTraceResult (net.minecraft.util.math.RayTraceResult)4