mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
nodespace foundry channels! (also fix arc furnace only accepting one stack from IO port if it triggers it to close)
This commit is contained in:
parent
176a2e58ee
commit
09dd5e37b5
@ -4,11 +4,17 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.hbm.blocks.ModBlocks;
|
import com.hbm.blocks.ModBlocks;
|
||||||
|
import com.hbm.inventory.material.NTMMaterial;
|
||||||
import com.hbm.inventory.material.Mats.MaterialStack;
|
import com.hbm.inventory.material.Mats.MaterialStack;
|
||||||
import com.hbm.items.machine.ItemScraps;
|
import com.hbm.items.machine.ItemScraps;
|
||||||
import com.hbm.lib.Library;
|
import com.hbm.lib.Library;
|
||||||
import com.hbm.lib.RefStrings;
|
import com.hbm.lib.RefStrings;
|
||||||
import com.hbm.tileentity.machine.TileEntityFoundryChannel;
|
import com.hbm.tileentity.machine.TileEntityFoundryChannel;
|
||||||
|
import com.hbm.uninos.GenNode;
|
||||||
|
import com.hbm.uninos.INetworkProvider;
|
||||||
|
import com.hbm.uninos.networkproviders.FoundryNetwork;
|
||||||
|
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||||
|
import com.hbm.util.fauxpointtwelve.DirPos;
|
||||||
|
|
||||||
import api.hbm.block.ICrucibleAcceptor;
|
import api.hbm.block.ICrucibleAcceptor;
|
||||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||||
@ -41,7 +47,7 @@ public class FoundryChannel extends BlockContainer implements ICrucibleAcceptor
|
|||||||
public FoundryChannel() {
|
public FoundryChannel() {
|
||||||
super(Material.rock);
|
super(Material.rock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public void registerBlockIcons(IIconRegister iconRegister) {
|
public void registerBlockIcons(IIconRegister iconRegister) {
|
||||||
@ -65,16 +71,16 @@ public class FoundryChannel extends BlockContainer implements ICrucibleAcceptor
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB entityBounding, List list, Entity entity) {
|
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB entityBounding, List list, Entity entity) {
|
||||||
|
|
||||||
List<AxisAlignedBB> bbs = new ArrayList();
|
List<AxisAlignedBB> bbs = new ArrayList();
|
||||||
|
|
||||||
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y, z + 0.3125D, x + 0.6875D, y + 0.5D, z + 0.6875D));
|
bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y, z + 0.3125D, x + 0.6875D, y + 0.5D, z + 0.6875D));
|
||||||
|
|
||||||
if(canConnectTo(world, x, y, z, Library.POS_X)) bbs.add(AxisAlignedBB.getBoundingBox(x + 0.6875D, y, z + 0.3125D, x + 1D, y + 0.5D, z + 0.6875D));
|
if(canConnectTo(world, x, y, z, Library.POS_X)) bbs.add(AxisAlignedBB.getBoundingBox(x + 0.6875D, y, z + 0.3125D, x + 1D, y + 0.5D, z + 0.6875D));
|
||||||
if(canConnectTo(world, x, y, z, Library.NEG_X)) bbs.add(AxisAlignedBB.getBoundingBox(x, y, z + 0.3125D, x + 0.3125D, y + 0.5D, z + 0.6875D));
|
if(canConnectTo(world, x, y, z, Library.NEG_X)) bbs.add(AxisAlignedBB.getBoundingBox(x, y, z + 0.3125D, x + 0.3125D, y + 0.5D, z + 0.6875D));
|
||||||
if(canConnectTo(world, x, y, z, Library.POS_Z)) bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y, z + 0.6875D, x + 0.6875D, y + 0.5D, z + 1D));
|
if(canConnectTo(world, x, y, z, Library.POS_Z)) bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y, z + 0.6875D, x + 0.6875D, y + 0.5D, z + 1D));
|
||||||
if(canConnectTo(world, x, y, z, Library.NEG_Z)) bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y, z, x + 0.6875D, y + 0.5D, z + 0.3125D));
|
if(canConnectTo(world, x, y, z, Library.NEG_Z)) bbs.add(AxisAlignedBB.getBoundingBox(x + 0.3125D, y, z, x + 0.6875D, y + 0.5D, z + 0.3125D));
|
||||||
|
|
||||||
for(AxisAlignedBB bb : bbs) {
|
for(AxisAlignedBB bb : bbs) {
|
||||||
if(entityBounding.intersectsWith(bb)) {
|
if(entityBounding.intersectsWith(bb)) {
|
||||||
list.add(bb);
|
list.add(bb);
|
||||||
@ -120,23 +126,23 @@ public class FoundryChannel extends BlockContainer implements ICrucibleAcceptor
|
|||||||
public boolean canAcceptPartialFlow(World world, int x, int y, int z, ForgeDirection side, MaterialStack stack) {
|
public boolean canAcceptPartialFlow(World world, int x, int y, int z, ForgeDirection side, MaterialStack stack) {
|
||||||
return ((ICrucibleAcceptor) world.getTileEntity(x, y, z)).canAcceptPartialFlow(world, x, y, z, side, stack);
|
return ((ICrucibleAcceptor) world.getTileEntity(x, y, z)).canAcceptPartialFlow(world, x, y, z, side, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MaterialStack flow(World world, int x, int y, int z, ForgeDirection side, MaterialStack stack) {
|
public MaterialStack flow(World world, int x, int y, int z, ForgeDirection side, MaterialStack stack) {
|
||||||
return ((ICrucibleAcceptor) world.getTileEntity(x, y, z)).flow(world, x, y, z, side, stack);
|
return ((ICrucibleAcceptor) world.getTileEntity(x, y, z)).flow(world, x, y, z, side, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canConnectTo(IBlockAccess world, int x, int y, int z, ForgeDirection dir) {
|
public boolean canConnectTo(IBlockAccess world, int x, int y, int z, ForgeDirection dir) {
|
||||||
|
|
||||||
if(dir == ForgeDirection.UP || dir == ForgeDirection.DOWN || dir == ForgeDirection.UNKNOWN)
|
if(dir == ForgeDirection.UP || dir == ForgeDirection.DOWN || dir == ForgeDirection.UNKNOWN)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Block b = world.getBlock(x + dir.offsetX, y, z + dir.offsetZ);
|
Block b = world.getBlock(x + dir.offsetX, y, z + dir.offsetZ);
|
||||||
int meta = world.getBlockMetadata(x + dir.offsetX, y, z + dir.offsetZ);
|
int meta = world.getBlockMetadata(x + dir.offsetX, y, z + dir.offsetZ);
|
||||||
|
|
||||||
if((b == ModBlocks.foundry_outlet || b == ModBlocks.foundry_slagtap) && meta == dir.ordinal())
|
if((b == ModBlocks.foundry_outlet || b == ModBlocks.foundry_slagtap) && meta == dir.ordinal())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return b == ModBlocks.foundry_channel || b == ModBlocks.foundry_mold;
|
return b == ModBlocks.foundry_channel || b == ModBlocks.foundry_mold;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,25 +152,25 @@ public class FoundryChannel extends BlockContainer implements ICrucibleAcceptor
|
|||||||
public int getRenderType() {
|
public int getRenderType() {
|
||||||
return renderID;
|
return renderID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOpaqueCube() {
|
public boolean isOpaqueCube() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean renderAsNormalBlock() {
|
public boolean renderAsNormalBlock() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||||
if(world.isRemote) {
|
if(world.isRemote) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileEntityFoundryChannel cast = (TileEntityFoundryChannel) world.getTileEntity(x, y, z);
|
TileEntityFoundryChannel cast = (TileEntityFoundryChannel) world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
if(player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ItemTool && ((ItemTool) player.getHeldItem().getItem()).getToolClasses(player.getHeldItem()).contains("shovel")) {
|
if(player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ItemTool && ((ItemTool) player.getHeldItem().getItem()).getToolClasses(player.getHeldItem()).contains("shovel")) {
|
||||||
if(cast.amount > 0) {
|
if(cast.amount > 0) {
|
||||||
ItemStack scrap = ItemScraps.create(new MaterialStack(cast.type, cast.amount));
|
ItemStack scrap = ItemScraps.create(new MaterialStack(cast.type, cast.amount));
|
||||||
@ -176,19 +182,18 @@ public class FoundryChannel extends BlockContainer implements ICrucibleAcceptor
|
|||||||
}
|
}
|
||||||
cast.amount = 0;
|
cast.amount = 0;
|
||||||
cast.type = null;
|
cast.type = null;
|
||||||
cast.propagateMaterial(null);
|
|
||||||
cast.markDirty();
|
cast.markDirty();
|
||||||
world.markBlockForUpdate(x, y, z);
|
world.markBlockForUpdate(x, y, z);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void breakBlock(World world, int x, int y, int z, Block b, int i) {
|
public void breakBlock(World world, int x, int y, int z, Block b, int i) {
|
||||||
|
|
||||||
TileEntityFoundryChannel channel = (TileEntityFoundryChannel) world.getTileEntity(x, y, z);
|
TileEntityFoundryChannel channel = (TileEntityFoundryChannel) world.getTileEntity(x, y, z);
|
||||||
if(channel.amount > 0) {
|
if(channel.amount > 0) {
|
||||||
ItemStack scrap = ItemScraps.create(new MaterialStack(channel.type, channel.amount));
|
ItemStack scrap = ItemScraps.create(new MaterialStack(channel.type, channel.amount));
|
||||||
@ -196,7 +201,24 @@ public class FoundryChannel extends BlockContainer implements ICrucibleAcceptor
|
|||||||
world.spawnEntityInWorld(item);
|
world.spawnEntityInWorld(item);
|
||||||
channel.amount = 0;
|
channel.amount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
super.breakBlock(world, x, y, z, b, i);
|
super.breakBlock(world, x, y, z, b, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class FoundryNode extends GenNode<FoundryNetwork> {
|
||||||
|
|
||||||
|
public NTMMaterial type;
|
||||||
|
|
||||||
|
public FoundryNode(INetworkProvider<FoundryNetwork> provider, BlockPos... positions) {
|
||||||
|
super(provider, positions);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FoundryNode setConnections(DirPos... connections) {
|
||||||
|
super.setConnections(connections);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,10 +5,14 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.hbm.blocks.ModBlocks;
|
import com.hbm.blocks.ModBlocks;
|
||||||
|
import com.hbm.blocks.machine.FoundryChannel.FoundryNode;
|
||||||
import com.hbm.inventory.material.MaterialShapes;
|
import com.hbm.inventory.material.MaterialShapes;
|
||||||
import com.hbm.inventory.material.Mats;
|
|
||||||
import com.hbm.inventory.material.Mats.MaterialStack;
|
import com.hbm.inventory.material.Mats.MaterialStack;
|
||||||
import com.hbm.inventory.material.NTMMaterial;
|
import com.hbm.lib.Library;
|
||||||
|
import com.hbm.uninos.UniNodespace;
|
||||||
|
import com.hbm.uninos.networkproviders.FoundryNetworkProvider;
|
||||||
|
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||||
|
import com.hbm.util.fauxpointtwelve.DirPos;
|
||||||
|
|
||||||
import api.hbm.block.ICrucibleAcceptor;
|
import api.hbm.block.ICrucibleAcceptor;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
@ -18,60 +22,54 @@ import net.minecraft.world.World;
|
|||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
public class TileEntityFoundryChannel extends TileEntityFoundryBase {
|
public class TileEntityFoundryChannel extends TileEntityFoundryBase {
|
||||||
|
|
||||||
public int nextUpdate;
|
public int nextUpdate;
|
||||||
public int lastFlow = 0;
|
public int lastFlow = 0;
|
||||||
|
|
||||||
protected NTMMaterial neighborType;
|
protected FoundryNode node;
|
||||||
protected boolean hasCheckedNeighbors;
|
|
||||||
protected int unpropagateTime;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
|
|
||||||
if(!worldObj.isRemote) {
|
if(!worldObj.isRemote) {
|
||||||
|
initNode();
|
||||||
|
|
||||||
// Initialise before allowing pours, so newly added channels will avoid causing clog feeds
|
if(this.node.type != null && this.amount == 0) {
|
||||||
if(!hasCheckedNeighbors) {
|
this.node.type = null;
|
||||||
List<TileEntityFoundryChannel> visited = new ArrayList<TileEntityFoundryChannel>();
|
|
||||||
visited.add(this);
|
|
||||||
|
|
||||||
neighborType = checkNeighbors(visited);
|
|
||||||
hasCheckedNeighbors = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.type == null && this.amount != 0) {
|
if(this.type == null && this.amount != 0) {
|
||||||
this.amount = 0;
|
this.amount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nextUpdate--;
|
nextUpdate--;
|
||||||
|
|
||||||
if(nextUpdate <= 0 && this.amount > 0 && this.type != null) {
|
if(nextUpdate <= 0 && this.amount > 0 && this.type != null) {
|
||||||
|
|
||||||
boolean hasOp = false;
|
boolean hasOp = false;
|
||||||
nextUpdate = 5;
|
nextUpdate = 5;
|
||||||
|
|
||||||
List<Integer> ints = new ArrayList<Integer>() {{ add(2); add(3); add(4); add(5); }};
|
List<Integer> ints = new ArrayList<Integer>() {{ add(2); add(3); add(4); add(5); }};
|
||||||
Collections.shuffle(ints);
|
Collections.shuffle(ints);
|
||||||
if(lastFlow > 0) {
|
if(lastFlow > 0) {
|
||||||
ints.remove((Integer) this.lastFlow);
|
ints.remove((Integer) this.lastFlow);
|
||||||
ints.add(this.lastFlow);
|
ints.add(this.lastFlow);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Integer i : ints) {
|
for(Integer i : ints) {
|
||||||
ForgeDirection dir = ForgeDirection.getOrientation(i);
|
ForgeDirection dir = ForgeDirection.getOrientation(i);
|
||||||
Block b = worldObj.getBlock(xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ);
|
Block b = worldObj.getBlock(xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ);
|
||||||
|
|
||||||
if(b instanceof ICrucibleAcceptor && b != ModBlocks.foundry_channel) {
|
if(b instanceof ICrucibleAcceptor && b != ModBlocks.foundry_channel) {
|
||||||
ICrucibleAcceptor acc = (ICrucibleAcceptor) b;
|
ICrucibleAcceptor acc = (ICrucibleAcceptor) b;
|
||||||
|
|
||||||
if(acc.canAcceptPartialFlow(worldObj, xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ, dir.getOpposite(), new MaterialStack(this.type, this.amount))) {
|
if(acc.canAcceptPartialFlow(worldObj, xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ, dir.getOpposite(), new MaterialStack(this.type, this.amount))) {
|
||||||
MaterialStack left = acc.flow(worldObj, xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ, dir.getOpposite(), new MaterialStack(this.type, this.amount));
|
MaterialStack left = acc.flow(worldObj, xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ, dir.getOpposite(), new MaterialStack(this.type, this.amount));
|
||||||
if(left == null) {
|
if(left == null) {
|
||||||
this.type = null;
|
this.type = null;
|
||||||
this.amount = 0;
|
this.amount = 0;
|
||||||
|
|
||||||
propagateMaterial(null);
|
this.node.type = null;
|
||||||
} else {
|
} else {
|
||||||
this.amount = left.amount;
|
this.amount = left.amount;
|
||||||
}
|
}
|
||||||
@ -80,31 +78,33 @@ public class TileEntityFoundryChannel extends TileEntityFoundryBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!hasOp) {
|
if(!hasOp) {
|
||||||
for(Integer i : ints) {
|
for(Integer i : ints) {
|
||||||
ForgeDirection dir = ForgeDirection.getOrientation(i);
|
ForgeDirection dir = ForgeDirection.getOrientation(i);
|
||||||
TileEntity b = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ);
|
TileEntity b = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ);
|
||||||
|
|
||||||
if(b instanceof TileEntityFoundryChannel) {
|
if(b instanceof TileEntityFoundryChannel) {
|
||||||
TileEntityFoundryChannel acc = (TileEntityFoundryChannel) b;
|
TileEntityFoundryChannel acc = (TileEntityFoundryChannel) b;
|
||||||
|
|
||||||
if(acc.type == null || acc.type == this.type || acc.amount == 0) {
|
if(acc.type == null || acc.type == this.type || acc.amount == 0) {
|
||||||
acc.type = this.type;
|
acc.type = this.type;
|
||||||
|
acc.initNode();
|
||||||
|
acc.node.type = this.type;
|
||||||
|
|
||||||
acc.lastFlow = dir.getOpposite().ordinal();
|
acc.lastFlow = dir.getOpposite().ordinal();
|
||||||
|
|
||||||
if(worldObj.rand.nextInt(5) == 0 || this.amount == 1) { //force swap operations with single quanta to keep them moving
|
if(worldObj.rand.nextInt(5) == 0 || this.amount == 1) { //force swap operations with single quanta to keep them moving
|
||||||
//1:4 chance that the fill states are simply swapped
|
//1:4 chance that the fill states are simply swapped
|
||||||
//this promotes faster spreading and prevents spread limits
|
//this promotes faster spreading and prevents spread limits
|
||||||
int buf = this.amount;
|
int buf = this.amount;
|
||||||
this.amount = acc.amount;
|
this.amount = acc.amount;
|
||||||
acc.amount = buf;
|
acc.amount = buf;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//otherwise, equalize the neighbors
|
//otherwise, equalize the neighbors
|
||||||
int diff = this.amount - acc.amount;
|
int diff = this.amount - acc.amount;
|
||||||
|
|
||||||
if(diff > 0) {
|
if(diff > 0) {
|
||||||
diff /= 2;
|
diff /= 2;
|
||||||
this.amount -= diff;
|
this.amount -= diff;
|
||||||
@ -117,24 +117,28 @@ public class TileEntityFoundryChannel extends TileEntityFoundryBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(neighborType != null && amount == 0) unpropagateTime++;
|
|
||||||
|
|
||||||
// every 5 seconds do a unprop test, will only occur once per contiguous channel per 5 seconds due to the timer getting updated in all channels from the prop
|
|
||||||
if(unpropagateTime > 100) {
|
|
||||||
propagateMaterial(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.amount == 0) {
|
if(this.amount == 0) {
|
||||||
this.lastFlow = 0;
|
this.lastFlow = 0;
|
||||||
this.nextUpdate = 5;
|
this.nextUpdate = 5;
|
||||||
} else {
|
|
||||||
unpropagateTime = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void initNode() {
|
||||||
|
if(this.node == null || this.node.expired) {
|
||||||
|
|
||||||
|
this.node = (FoundryNode) UniNodespace.getNode(worldObj, xCoord, yCoord, zCoord, FoundryNetworkProvider.THE_PROVIDER);
|
||||||
|
|
||||||
|
if(this.node == null || this.node.expired) {
|
||||||
|
this.node = this.createNode();
|
||||||
|
this.node.type = this.type;
|
||||||
|
UniNodespace.createNode(worldObj, this.node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCapacity() {
|
public int getCapacity() {
|
||||||
return MaterialShapes.INGOT.q(2);
|
return MaterialShapes.INGOT.q(2);
|
||||||
@ -144,95 +148,58 @@ public class TileEntityFoundryChannel extends TileEntityFoundryBase {
|
|||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt) {
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
this.lastFlow = nbt.getByte("flow");
|
this.lastFlow = nbt.getByte("flow");
|
||||||
this.neighborType = Mats.matById.get(nbt.getInteger("nType"));
|
|
||||||
this.hasCheckedNeighbors = nbt.getBoolean("init");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
public void writeToNBT(NBTTagCompound nbt) {
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
nbt.setByte("flow", (byte) this.lastFlow);
|
nbt.setByte("flow", (byte) this.lastFlow);
|
||||||
nbt.setInteger("nType", this.neighborType != null ? this.neighborType.id : -1);
|
|
||||||
nbt.setBoolean("init", hasCheckedNeighbors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Channels accept pouring as normal, except when neighbor channels already have material.
|
public void invalidate() {
|
||||||
* This prevents a contiguous channel from having multiple different types of material in it, causing clogs.
|
super.invalidate();
|
||||||
* If you connect two channels that have different materials already in them, god help you (nah jokes it'll just be clogged until you fix manually)
|
|
||||||
*/
|
if(!worldObj.isRemote) {
|
||||||
|
if(this.node != null) {
|
||||||
|
UniNodespace.destroyNode(worldObj, xCoord, yCoord, zCoord, FoundryNetworkProvider.THE_PROVIDER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public FoundryNode createNode() {
|
||||||
|
TileEntity tile = (TileEntity) this;
|
||||||
|
return new FoundryNode(FoundryNetworkProvider.THE_PROVIDER, new BlockPos(tile.xCoord, tile.yCoord, tile.zCoord)).setConnections(
|
||||||
|
new DirPos(tile.xCoord + 1, tile.yCoord, tile.zCoord, Library.POS_X),
|
||||||
|
new DirPos(tile.xCoord - 1, tile.yCoord, tile.zCoord, Library.NEG_X),
|
||||||
|
new DirPos(tile.xCoord, tile.yCoord, tile.zCoord + 1, Library.POS_Z),
|
||||||
|
new DirPos(tile.xCoord, tile.yCoord, tile.zCoord - 1, Library.NEG_Z)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canAcceptPartialPour(World world, int x, int y, int z, double dX, double dY, double dZ, ForgeDirection side, MaterialStack stack) {
|
public boolean canAcceptPartialPour(World world, int x, int y, int z, double dX, double dY, double dZ, ForgeDirection side, MaterialStack stack) {
|
||||||
if(!hasCheckedNeighbors || (neighborType != null && neighborType != stack.material)) return false;
|
if(this.node == null) return false;
|
||||||
|
for(Object o : this.node.net.links) {
|
||||||
|
FoundryNode node = (FoundryNode) o;
|
||||||
|
if(node.type != null && node.type != stack.material) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return super.canAcceptPartialPour(world, x, y, z, dX, dY, dZ, side, stack);
|
return super.canAcceptPartialPour(world, x, y, z, dX, dY, dZ, side, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Upon pouring, propagate the current material type along contiguous channels */
|
@Override
|
||||||
|
public MaterialStack flow(World world, int x, int y, int z, ForgeDirection side, MaterialStack stack) {
|
||||||
|
if(this.node != null) this.node.type = stack.material;
|
||||||
|
return super.flow(world, x, y, z, side, stack);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MaterialStack pour(World world, int x, int y, int z, double dX, double dY, double dZ, ForgeDirection side, MaterialStack stack) {
|
public MaterialStack pour(World world, int x, int y, int z, double dX, double dY, double dZ, ForgeDirection side, MaterialStack stack) {
|
||||||
propagateMaterial(stack.material);
|
if(this.node != null) this.node.type = stack.material;
|
||||||
return super.pour(world, x, y, z, dX, dY, dZ, side, stack);
|
return super.pour(world, x, y, z, dX, dY, dZ, side, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void propagateMaterial(NTMMaterial propType) {
|
|
||||||
if(propType != null && neighborType != null) return; // optimise away any pours that change nothing
|
|
||||||
|
|
||||||
List<TileEntityFoundryChannel> visited = new ArrayList<TileEntityFoundryChannel>();
|
|
||||||
visited.add(this);
|
|
||||||
|
|
||||||
boolean hasMaterial = propagateMaterial(propType, visited, false);
|
|
||||||
|
|
||||||
// since we are now fully clear, it's safe to unassign the contiguous channel type
|
|
||||||
if(propType == null && !hasMaterial) {
|
|
||||||
for(TileEntityFoundryChannel acc : visited) {
|
|
||||||
acc.neighborType = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean propagateMaterial(NTMMaterial propType, List<TileEntityFoundryChannel> visited, boolean hasMaterial) {
|
|
||||||
// if emptying, don't mark the channel as ready for a new material until it is entirely clear
|
|
||||||
if(propType != null) {
|
|
||||||
neighborType = propType;
|
|
||||||
} else {
|
|
||||||
// and when empty testing, update the last unpropagate time
|
|
||||||
unpropagateTime = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(ForgeDirection dir : new ForgeDirection[] { ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.WEST, ForgeDirection.EAST }) {
|
|
||||||
TileEntity b = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ);
|
|
||||||
|
|
||||||
if(b instanceof TileEntityFoundryChannel && !visited.contains(b)) {
|
|
||||||
TileEntityFoundryChannel acc = (TileEntityFoundryChannel) b;
|
|
||||||
visited.add(acc);
|
|
||||||
|
|
||||||
if(acc.amount > 0) hasMaterial = true;
|
|
||||||
|
|
||||||
hasMaterial = acc.propagateMaterial(propType, visited, hasMaterial);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasMaterial;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected NTMMaterial checkNeighbors(List<TileEntityFoundryChannel> visited) {
|
|
||||||
if(neighborType != null) return neighborType;
|
|
||||||
|
|
||||||
for(ForgeDirection dir : new ForgeDirection[] { ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.WEST, ForgeDirection.EAST }) {
|
|
||||||
TileEntity b = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ);
|
|
||||||
|
|
||||||
if(b instanceof TileEntityFoundryChannel && !visited.contains(b)) {
|
|
||||||
TileEntityFoundryChannel acc = (TileEntityFoundryChannel) b;
|
|
||||||
visited.add(acc);
|
|
||||||
|
|
||||||
NTMMaterial neighborMaterial = acc.checkNeighbors(visited);
|
|
||||||
|
|
||||||
// immediately propagate backwards if a material is found
|
|
||||||
if(neighborMaterial != null) return neighborMaterial;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,8 +113,8 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
|||||||
this.isProgressing = false;
|
this.isProgressing = false;
|
||||||
|
|
||||||
for(DirPos pos : getConPos()) this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
for(DirPos pos : getConPos()) this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||||
|
|
||||||
if(lid == 1) loadIngredients();
|
if(lid > 0) loadIngredients();
|
||||||
|
|
||||||
if(power > 0) {
|
if(power > 0) {
|
||||||
|
|
||||||
@ -269,17 +269,17 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Moves items from the input queue to the main grid */
|
/** Moves items from the input queue to the main grid */
|
||||||
public void loadIngredients() {
|
public void loadIngredients() {
|
||||||
|
|
||||||
boolean markDirty = false;
|
boolean markDirty = false;
|
||||||
|
|
||||||
for(int q /* queue */ = 25; q < 30; q++) {
|
for(int q /* queue */ = 25; q < 30; q++) {
|
||||||
if(slots[q] == null) continue;
|
if(slots[q] == null) continue;
|
||||||
ArcFurnaceRecipe recipe = ArcFurnaceRecipes.getOutput(slots[q], this.liquidMode);
|
ArcFurnaceRecipe recipe = ArcFurnaceRecipes.getOutput(slots[q], this.liquidMode);
|
||||||
if(recipe == null) continue;
|
if(recipe == null) continue;
|
||||||
|
|
||||||
// add to existing stacks
|
// add to existing stacks
|
||||||
for(int i /* ingredient */ = 5; i < 25; i++) {
|
for(int i /* ingredient */ = 5; i < 25; i++) {
|
||||||
if(slots[i] == null) continue;
|
if(slots[i] == null) continue;
|
||||||
@ -293,7 +293,7 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
|||||||
}
|
}
|
||||||
if(slots[q] == null) break;
|
if(slots[q] == null) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to empty slot
|
// add to empty slot
|
||||||
if(slots[q] != null) for(int i /* ingredient */ = 5; i < 25; i++) {
|
if(slots[q] != null) for(int i /* ingredient */ = 5; i < 25; i++) {
|
||||||
if(slots[i] != null) continue;
|
if(slots[i] != null) continue;
|
||||||
@ -306,7 +306,7 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
|||||||
if(slots[q] == null) break;
|
if(slots[q] == null) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(markDirty) this.markDirty();
|
if(markDirty) this.markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,10 @@
|
|||||||
|
package com.hbm.uninos.networkproviders;
|
||||||
|
|
||||||
|
import com.hbm.uninos.NodeNet;
|
||||||
|
|
||||||
|
public class FoundryNetwork extends NodeNet {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() { }
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package com.hbm.uninos.networkproviders;
|
||||||
|
|
||||||
|
import com.hbm.uninos.INetworkProvider;
|
||||||
|
|
||||||
|
public class FoundryNetworkProvider implements INetworkProvider<FoundryNetwork> {
|
||||||
|
|
||||||
|
public static FoundryNetworkProvider THE_PROVIDER = new FoundryNetworkProvider();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FoundryNetwork provideNetwork() {
|
||||||
|
return new FoundryNetwork();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user