Skip to content

Commit

Permalink
fix(compat): add IGasHandler to Electrolyzer
Browse files Browse the repository at this point in the history
Reference: #123
  • Loading branch information
ROMVoid95 committed Feb 20, 2023
1 parent 5c07be2 commit f00896e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 50 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ forge_version=14.23.5.2860
mapping_channel=stable
mapping_version=39-1.12

mod_version=4.0.5
mod_version=4.0.6
version_suffix=

##Allows using your skin while testing, This can be with or without hyphens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,29 @@

package micdoodle8.mods.galacticraft.planets.mars.tile;

import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;

import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.common.Optional.Interface;
import net.minecraftforge.fml.relauncher.Side;

import micdoodle8.mods.miccore.Annotations.NetworkedField;

import micdoodle8.mods.galacticraft.annotations.ForRemoval;
import micdoodle8.mods.galacticraft.annotations.ReplaceWith;
import micdoodle8.mods.galacticraft.api.tile.IDisableableMachine;
Expand All @@ -31,37 +52,28 @@
import micdoodle8.mods.galacticraft.planets.asteroids.AsteroidsModule;
import micdoodle8.mods.galacticraft.planets.asteroids.items.ItemAtmosphericValve;
import micdoodle8.mods.galacticraft.planets.mars.blocks.BlockMachineMarsT2;
import micdoodle8.mods.miccore.Annotations.NetworkedField;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.relauncher.Side;

public class TileEntityElectrolyzer extends TileBaseElectricBlockWithInventory implements ISidedInventory, IDisableableMachine, IFluidHandlerWrapper, IOxygenStorage, IOxygenReceiver
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.IGasHandler;
import mekanism.common.capabilities.Capabilities;

@Interface(iface = "mekanism.api.gas.IGasHandler", modid = "mekanism")
public class TileEntityElectrolyzer extends TileBaseElectricBlockWithInventory implements ISidedInventory, IDisableableMachine, IFluidHandlerWrapper, IOxygenStorage, IOxygenReceiver, IGasHandler
{

private final int tankCapacity = 4000;
private final int tankCapacity = 4000;

@NetworkedField(targetSide = Side.CLIENT) public FluidTank waterTank = new FluidTank(this.tankCapacity);
@NetworkedField(targetSide = Side.CLIENT) public FluidTank liquidTank = new FluidTank(this.tankCapacity);
@NetworkedField(targetSide = Side.CLIENT) public FluidTank liquidTank2 = new FluidTank(this.tankCapacity);
@NetworkedField(targetSide = Side.CLIENT)
public FluidTank waterTank = new FluidTank(this.tankCapacity);
@NetworkedField(targetSide = Side.CLIENT)
public FluidTank liquidTank = new FluidTank(this.tankCapacity);
@NetworkedField(targetSide = Side.CLIENT)
public FluidTank liquidTank2 = new FluidTank(this.tankCapacity);

public int processTimeRequired = 3;
@NetworkedField(targetSide = Side.CLIENT) public int processTicks = 0;
public int processTimeRequired = 3;
@NetworkedField(targetSide = Side.CLIENT)
public int processTicks = 0;

public TileEntityElectrolyzer()
{
Expand Down Expand Up @@ -93,7 +105,7 @@ public <T> T getCapability(Capability<T> capability, EnumFacing facing)

if (EnergyUtil.checkMekGasHandler(capability))
{
return (T) this;
return Capabilities.GAS_HANDLER_CAPABILITY.cast(this);
}

return super.getCapability(capability, facing);
Expand Down Expand Up @@ -128,15 +140,17 @@ public void update()
if (this.processTicks == 0)
{
this.processTicks = this.processTimeRequired;
} else
}
else
{
if (--this.processTicks <= 0)
{
this.doElectrolysis();
this.processTicks = this.canProcess() ? this.processTimeRequired : 0;
}
}
} else
}
else
{
this.processTicks = 0;
}
Expand Down Expand Up @@ -271,8 +285,7 @@ public boolean hasCustomName()
@Override
public int[] getSlotsForFace(EnumFacing side)
{
return new int[]
{0, 1};
return new int[] {0, 1};
}

@Override
Expand Down Expand Up @@ -425,21 +438,19 @@ public int fill(EnumFacing from, FluidStack resource, boolean doFill)
@Override
public FluidTankInfo[] getTankInfo(EnumFacing from)
{
FluidTankInfo[] tankInfo = new FluidTankInfo[]
{};
FluidTankInfo[] tankInfo = new FluidTankInfo[] {};

if (from == this.byIndex().rotateY())
{
tankInfo = new FluidTankInfo[]
{new FluidTankInfo(this.waterTank)};
} else if (from == this.getHydrogenOutputDirection())
tankInfo = new FluidTankInfo[] {new FluidTankInfo(this.waterTank)};
}
else if (from == this.getHydrogenOutputDirection())
{
tankInfo = new FluidTankInfo[]
{new FluidTankInfo(this.liquidTank2)};
} else if (from == this.getOxygenOutputDirection())
tankInfo = new FluidTankInfo[] {new FluidTankInfo(this.liquidTank2)};
}
else if (from == this.getOxygenOutputDirection())
{
tankInfo = new FluidTankInfo[]
{new FluidTankInfo(this.liquidTank)};
tankInfo = new FluidTankInfo[] {new FluidTankInfo(this.liquidTank)};
}

return tankInfo;
Expand All @@ -451,6 +462,7 @@ public int getBlockMetadata()
return getBlockType().getMetaFromState(this.world.getBlockState(getPos()));
}

@Override
@Optional.Method(modid = "mekanism")
public int receiveGas(EnumFacing side, GasStack stack, boolean doTransfer)
{
Expand All @@ -463,6 +475,7 @@ public int receiveGas(EnumFacing side, GasStack stack)
return 0;
}

@Override
@Optional.Method(modid = "mekanism")
public GasStack drawGas(EnumFacing from, int amount, boolean doTransfer)
{
Expand All @@ -471,7 +484,8 @@ public GasStack drawGas(EnumFacing from, int amount, boolean doTransfer)
int amountH = Math.min(8, this.liquidTank2.getFluidAmount());
amountH = this.liquidTank2.drain(amountH, doTransfer).amount;
return new GasStack((Gas) EnergyConfigHandler.gasHydrogen, amountH);
} else if (from == this.getOxygenOutputDirection() && this.liquidTank.getFluid() != null)
}
else if (from == this.getOxygenOutputDirection() && this.liquidTank.getFluid() != null)
{
int amountO = Math.min(8, this.liquidTank.getFluidAmount());
amountO = this.liquidTank.drain(amountO, doTransfer).amount;
Expand All @@ -486,19 +500,22 @@ public GasStack drawGas(EnumFacing from, int amount)
return this.drawGas(from, amount, true);
}

@Override
@Optional.Method(modid = "mekanism")
public boolean canReceiveGas(EnumFacing side, Gas type)
{
return false;
}

@Override
@Optional.Method(modid = "mekanism")
public boolean canDrawGas(EnumFacing from, Gas type)
{
if (from == this.getHydrogenOutputDirection())
{
return type.getName().equals("hydrogen");
} else if (from == this.getOxygenOutputDirection())
}
else if (from == this.getOxygenOutputDirection())
{
return type.getName().equals("oxygen");
}
Expand All @@ -511,7 +528,8 @@ public boolean canTubeConnect(EnumFacing from)
if (from == this.getHydrogenOutputDirection())
{
return true;
} else if (from == this.getOxygenOutputDirection())
}
else if (from == this.getOxygenOutputDirection())
{
return true;
}
Expand Down Expand Up @@ -571,7 +589,8 @@ private boolean produceOxygen(EnumFacing outputDirection)
this.drawOxygen(usedGas, true);
return true;
}
} else if (outputTile instanceof IOxygenReceiver)
}
else if (outputTile instanceof IOxygenReceiver)
{
float requestedOxygen = ((IOxygenReceiver) outputTile).getOxygenRequest(outputDirection.getOpposite());

Expand Down Expand Up @@ -608,7 +627,8 @@ private boolean produceHydrogen(EnumFacing outputDirection)
this.drawHydrogen(usedGas, true);
return true;
}
} else if (outputTile instanceof TileEntityMethaneSynthesizer)
}
else if (outputTile instanceof TileEntityMethaneSynthesizer)
{
float requestedHydrogen = ((TileEntityMethaneSynthesizer) outputTile).getHydrogenRequest(outputDirection.getOpposite());

Expand Down Expand Up @@ -731,7 +751,7 @@ public EnumFacing byIndex()
}
return EnumFacing.NORTH;
}

@Override
@Deprecated
@ForRemoval(deadline = "4.1.0")
Expand Down

0 comments on commit f00896e

Please sign in to comment.