Skip to content

Commit

Permalink
Fixed Lightningrod not playing nice with other mods' energy transport
Browse files Browse the repository at this point in the history
  • Loading branch information
BluSunrize committed Aug 27, 2018
1 parent 51cc12f commit 33c29f2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 23 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Fixed an edgecase crash with Cartographer Maps (BluSunrize)
- Fixed ArcFurnace requiring additional inputs to start a recipe (BluSunrize)
- Fixed upgrades vanishing in the Workbench (Malte)
- Fixed Lightningrod not playing nice with other mods' energy transport (BluSunrize)

#####Version 0.12-84 - BUILT
- Changed handling of Potions in the mixer: (BluSunrize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
package blusunrize.immersiveengineering.common.blocks.metal;

import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.IEEnums.SideConfig;
import blusunrize.immersiveengineering.api.energy.immersiveflux.FluxStorage;
import blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxProvider;
import blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver;
import blusunrize.immersiveengineering.common.Config.IEConfig;
import blusunrize.immersiveengineering.common.IEContent;
import blusunrize.immersiveengineering.common.blocks.TileEntityMultiblockPart;
import blusunrize.immersiveengineering.common.blocks.multiblocks.MultiblockLightningrod;
import blusunrize.immersiveengineering.common.util.EnergyHelper;
import blusunrize.immersiveengineering.common.util.EnergyHelper.IEForgeEnergyWrapper;
import blusunrize.immersiveengineering.common.util.EnergyHelper.IIEInternalFluxHandler;
import blusunrize.immersiveengineering.common.util.Utils;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.item.ItemStack;
Expand All @@ -30,10 +32,11 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;

public class TileEntityLightningrod extends TileEntityMultiblockPart<TileEntityLightningrod> implements IFluxProvider
public class TileEntityLightningrod extends TileEntityMultiblockPart<TileEntityLightningrod> implements IIEInternalFluxHandler
{
FluxStorage energyStorage = new FluxStorage(IEConfig.Machines.lightning_output);

Expand All @@ -58,13 +61,9 @@ public void update()
for(EnumFacing f : EnumFacing.HORIZONTALS)
{
tileEntity = Utils.getExistingTileEntity(world, getPos().offset(f, 2));
if(tileEntity instanceof IFluxReceiver)
{
IFluxReceiver ifr = (IFluxReceiver)tileEntity;
int accepted = ifr.receiveEnergy(f.getOpposite(), energyStorage.getEnergyStored(), true);
int extracted = energyStorage.extractEnergy(accepted, false);
ifr.receiveEnergy(f.getOpposite(), extracted, false);
}
int output = EnergyHelper.insertFlux(tileEntity, f.getOpposite(), energyStorage.getLimitExtract(), true);
output = energyStorage.extractEnergy(output, false);
EnergyHelper.insertFlux(tileEntity, f.getOpposite(), output, false);
}
}

Expand Down Expand Up @@ -241,32 +240,64 @@ public AxisAlignedBB getRenderBoundingBox()
return renderAABB;
}

@Nonnull
@Override
public int extractEnergy(@Nullable EnumFacing from, int energy, boolean simulate)
public FluxStorage getFluxStorage()
{
if(pos!=10&&pos!=12&&pos!=14&pos!=16)
return 0;
TileEntityLightningrod master = master();
return master==null?0: master.energyStorage.extractEnergy(energy, simulate);
TileEntityLightningrod master = this.master();
if(master!=null)
return master.energyStorage;
return energyStorage;
}

@Nonnull
@Override
public int getEnergyStored(@Nullable EnumFacing from)
public SideConfig getEnergySideConfig(@Nullable EnumFacing facing)
{
TileEntityLightningrod master = master();
return master==null?0: master.energyStorage.getEnergyStored();
return this.formed&&this.isEnergyPos()?SideConfig.OUTPUT: SideConfig.NONE;
}

IEForgeEnergyWrapper wrapper = new IEForgeEnergyWrapper(this, null);

@Override
public int getMaxEnergyStored(@Nullable EnumFacing from)
public IEForgeEnergyWrapper getCapabilityWrapper(EnumFacing facing)
{
TileEntityLightningrod master = master();
return master==null?0: master.energyStorage.getMaxEnergyStored();
if(this.formed&&this.isEnergyPos())
return wrapper;
return null;
}

@Override
public boolean canConnectEnergy(@Nullable EnumFacing from)
private boolean isEnergyPos()
{
return pos==10||pos==12||pos==14||pos==16;
}

// @Override
// public int extractEnergy(@Nullable EnumFacing from, int energy, boolean simulate)
// {
// if(pos!=10&&pos!=12&&pos!=14&pos!=16)
// return 0;
// TileEntityLightningrod master = master();
// return master==null?0: master.energyStorage.extractEnergy(energy, simulate);
// }
//
// @Override
// public int getEnergyStored(@Nullable EnumFacing from)
// {
// TileEntityLightningrod master = master();
// return master==null?0: master.energyStorage.getEnergyStored();
// }
//
// @Override
// public int getMaxEnergyStored(@Nullable EnumFacing from)
// {
// TileEntityLightningrod master = master();
// return master==null?0: master.energyStorage.getMaxEnergyStored();
// }
//
// @Override
// public boolean canConnectEnergy(@Nullable EnumFacing from)
// {
// return ;
// }
}

0 comments on commit 33c29f2

Please sign in to comment.