Generalized some of the multiblock code into a stricter format
This commit is contained in:
parent
8f6cf7e1c9
commit
c97f617692
4 changed files with 91 additions and 57 deletions
|
@ -0,0 +1,19 @@
|
||||||
|
package mekanism.common.multiblock;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import mekanism.api.Coord4D;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
public abstract class MultiblockCache<T>
|
||||||
|
{
|
||||||
|
public HashSet<Coord4D> locations = new HashSet<Coord4D>();
|
||||||
|
|
||||||
|
public abstract void apply(T data);
|
||||||
|
|
||||||
|
public abstract void sync(T data);
|
||||||
|
|
||||||
|
public abstract void load(NBTTagCompound nbtTags);
|
||||||
|
|
||||||
|
public abstract void save(NBTTagCompound nbtTags);
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package mekanism.common.multiblock;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import mekanism.api.Coord4D;
|
||||||
|
import mekanism.common.tank.SynchronizedTankData;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
public abstract class SynchronizedData<T>
|
||||||
|
{
|
||||||
|
public Set<Coord4D> locations = new HashSet<Coord4D>();
|
||||||
|
|
||||||
|
public int volLength;
|
||||||
|
|
||||||
|
public int volWidth;
|
||||||
|
|
||||||
|
public int volHeight;
|
||||||
|
|
||||||
|
public int volume;
|
||||||
|
|
||||||
|
public int inventoryID;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
int code = 1;
|
||||||
|
code = 31 * locations.hashCode();
|
||||||
|
code = 31 * volLength;
|
||||||
|
code = 31 * volWidth;
|
||||||
|
code = 31 * volHeight;
|
||||||
|
code = 31 * volume;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
|
if(obj == null || obj.getClass() != getClass())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SynchronizedData<T> data = (SynchronizedData<T>)obj;
|
||||||
|
|
||||||
|
if(!data.locations.equals(locations))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data.volLength != volLength || data.volWidth != volWidth || data.volHeight != volHeight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data.volume != volume)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package mekanism.common.tank;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import mekanism.api.Coord4D;
|
import mekanism.api.Coord4D;
|
||||||
|
import mekanism.common.multiblock.MultiblockCache;
|
||||||
import mekanism.common.util.FluidContainerUtils.ContainerEditMode;
|
import mekanism.common.util.FluidContainerUtils.ContainerEditMode;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
@ -10,14 +11,13 @@ import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraftforge.common.util.Constants.NBT;
|
import net.minecraftforge.common.util.Constants.NBT;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
public class DynamicTankCache
|
public class DynamicTankCache extends MultiblockCache<SynchronizedTankData>
|
||||||
{
|
{
|
||||||
public HashSet<Coord4D> locations = new HashSet<Coord4D>();
|
|
||||||
|
|
||||||
public ItemStack[] inventory = new ItemStack[2];
|
public ItemStack[] inventory = new ItemStack[2];
|
||||||
public FluidStack fluid;
|
public FluidStack fluid;
|
||||||
public ContainerEditMode editMode = ContainerEditMode.BOTH;
|
public ContainerEditMode editMode = ContainerEditMode.BOTH;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void apply(SynchronizedTankData data)
|
public void apply(SynchronizedTankData data)
|
||||||
{
|
{
|
||||||
data.inventory = inventory;
|
data.inventory = inventory;
|
||||||
|
@ -25,6 +25,7 @@ public class DynamicTankCache
|
||||||
data.editMode = editMode;
|
data.editMode = editMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void sync(SynchronizedTankData data)
|
public void sync(SynchronizedTankData data)
|
||||||
{
|
{
|
||||||
inventory = data.inventory;
|
inventory = data.inventory;
|
||||||
|
@ -32,6 +33,7 @@ public class DynamicTankCache
|
||||||
editMode = data.editMode;
|
editMode = data.editMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void load(NBTTagCompound nbtTags)
|
public void load(NBTTagCompound nbtTags)
|
||||||
{
|
{
|
||||||
editMode = ContainerEditMode.values()[nbtTags.getInteger("editMode")];
|
editMode = ContainerEditMode.values()[nbtTags.getInteger("editMode")];
|
||||||
|
@ -56,6 +58,7 @@ public class DynamicTankCache
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void save(NBTTagCompound nbtTags)
|
public void save(NBTTagCompound nbtTags)
|
||||||
{
|
{
|
||||||
nbtTags.setInteger("editMode", editMode.ordinal());
|
nbtTags.setInteger("editMode", editMode.ordinal());
|
||||||
|
|
|
@ -4,25 +4,14 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import mekanism.api.Coord4D;
|
import mekanism.api.Coord4D;
|
||||||
|
import mekanism.common.multiblock.SynchronizedData;
|
||||||
import mekanism.common.util.FluidContainerUtils.ContainerEditMode;
|
import mekanism.common.util.FluidContainerUtils.ContainerEditMode;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
public class SynchronizedTankData
|
public class SynchronizedTankData extends SynchronizedData<SynchronizedTankData>
|
||||||
{
|
{
|
||||||
public Set<Coord4D> locations = new HashSet<Coord4D>();
|
|
||||||
|
|
||||||
public int volLength;
|
|
||||||
|
|
||||||
public int volWidth;
|
|
||||||
|
|
||||||
public int volHeight;
|
|
||||||
|
|
||||||
public int volume;
|
|
||||||
|
|
||||||
public int inventoryID;
|
|
||||||
|
|
||||||
public FluidStack fluidStored;
|
public FluidStack fluidStored;
|
||||||
|
|
||||||
public ContainerEditMode editMode = ContainerEditMode.BOTH;
|
public ContainerEditMode editMode = ContainerEditMode.BOTH;
|
||||||
|
@ -37,46 +26,6 @@ public class SynchronizedTankData
|
||||||
|
|
||||||
public Set<ValveData> valves = new HashSet<ValveData>();
|
public Set<ValveData> valves = new HashSet<ValveData>();
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
int code = 1;
|
|
||||||
code = 31 * locations.hashCode();
|
|
||||||
code = 31 * volLength;
|
|
||||||
code = 31 * volWidth;
|
|
||||||
code = 31 * volHeight;
|
|
||||||
code = 31 * volume;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj)
|
|
||||||
{
|
|
||||||
if(!(obj instanceof SynchronizedTankData))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SynchronizedTankData data = (SynchronizedTankData)obj;
|
|
||||||
|
|
||||||
if(!data.locations.equals(locations))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(data.volLength != volLength || data.volWidth != volWidth || data.volHeight != volHeight)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(data.volume != volume)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ValveData
|
public static class ValveData
|
||||||
{
|
{
|
||||||
public ForgeDirection side;
|
public ForgeDirection side;
|
||||||
|
|
Loading…
Add table
Reference in a new issue