package org.cyclops.integrateddynamics.network;

import lombok.Data;
import lombok.EqualsAndHashCode;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack;
import org.cyclops.cyclopscore.datastructure.DimPos;
import org.cyclops.cyclopscore.helper.TileHelpers;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.network.INetworkElement;
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetwork;
import org.cyclops.integrateddynamics.api.network.IPositionedNetworkElement;
import org.cyclops.integrateddynamics.core.network.NetworkElementBase;
import org.cyclops.integrateddynamics.tileentity.TileCoalGenerator;

import java.util.List;
import java.util.Optional;

/**
 * Network element for coal generators.
 * @author rubensworks
 */
@EqualsAndHashCode(callSuper = false)
@Data
public class CoalGeneratorNetworkElement extends NetworkElementBase implements IPositionedNetworkElement {

    private final DimPos pos;

    protected Optional<TileCoalGenerator> getTile() {
        return TileHelpers.getSafeTile(getPos(), TileCoalGenerator.class);
    }

    @Override
    public void addDrops(List<ItemStack> itemStacks, boolean dropMainElement, boolean saveState) {
        getTile().ifPresent(tile -> InventoryHelper.dropInventoryItems(getPos().getWorld(true), getPos().getBlockPos(), tile.getInventory()));
    }

    @Override
    public void setPriorityAndChannel(INetwork network, int priority, int channel) {

    }

    @Override
    public int getPriority() {
        return 0;
    }

    @Override
    public int getChannel() {
        return IPositionedAddonsNetwork.DEFAULT_CHANNEL;
    }

    @Override
    public boolean canRevalidate(INetwork network) {
        return canRevalidatePositioned(network, pos);
    }

    @Override
    public void revalidate(INetwork network) {
        super.revalidate(network);
        revalidatePositioned(network, pos);
    }

    @Override
    public int compareTo(INetworkElement o) {
        if(o instanceof CoalGeneratorNetworkElement) {
            return getPos().compareTo(((CoalGeneratorNetworkElement) o).getPos());
        }
        return this.getClass().getCanonicalName().compareTo(o.getClass().getCanonicalName());
    }

    @Override
    public DimPos getPosition() {
        return this.pos;
    }
}

@@ -106,187 +106,51 @@
 ort 
-net.minecraft.inventory.InventoryHelper;%0Aimport net.minecraft.item.ItemStack;%0Aimport org.cyclops.cyclopscore.datastructure.DimPos;%0Aimport org.cyclops.cyclopscore.helper.TileHelper
+org.cyclops.cyclopscore.datastructure.DimPo
 s;%0Ai
@@ -502,127 +502,8 @@
 ase;
-%0Aimport org.cyclops.integrateddynamics.tileentity.TileCoalGenerator;%0A%0Aimport java.util.List;%0Aimport java.util.Optional;
 %0A%0A/*
@@ -719,24 +719,24 @@
 kElement %7B%0A%0A
+
     private 
@@ -758,407 +758,8 @@
 s;%0A%0A
-    protected Optional%3CTileCoalGenerator%3E getTile() %7B%0A        return TileHelpers.getSafeTile(getPos(), TileCoalGenerator.class);%0A    %7D%0A%0A    @Override%0A    public void addDrops(List%3CItemStack%3E itemStacks, boolean dropMainElement, boolean saveState) %7B%0A        getTile().ifPresent(tile -%3E InventoryHelper.dropInventoryItems(getPos().getWorld(true), getPos().getBlockPos(), tile.getInventory()));%0A    %7D%0A%0A
     

Fix coal generator duplicating drops, Closes #924