Bits of work on transporter logic
This commit is contained in:
parent
15aa17e441
commit
516dfb9ffb
10 changed files with 112 additions and 25 deletions
|
@ -1,11 +1,12 @@
|
|||
package mekanism.common;
|
||||
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.common.tileentity.TileEntityLogisticalSorter;
|
||||
import mekanism.common.transporter.TransporterStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public interface ILogisticalTransporter
|
||||
{
|
||||
|
@ -20,4 +21,8 @@ public interface ILogisticalTransporter
|
|||
public void setColor(EnumColor c);
|
||||
|
||||
public TileEntity getTile();
|
||||
|
||||
public boolean canInsert(ForgeDirection side);
|
||||
|
||||
public boolean canOutput(ForgeDirection side);
|
||||
}
|
||||
|
|
|
@ -494,7 +494,7 @@ public class Mekanism
|
|||
CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(new ItemStack(GasMask), new Object[] {
|
||||
" S ", "GCG", "S S", Character.valueOf('S'), "ingotSteel", Character.valueOf('G'), Block.glass, Character.valueOf('C'), "circuitBasic"
|
||||
}));
|
||||
CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(new ItemStack(ScubaTank), new Object[] {
|
||||
CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(ScubaTank.getEmptyItem(), new Object[] {
|
||||
" C ", "ATA", "SSS", Character.valueOf('C'), "circuitBasic", Character.valueOf('A'), EnrichedAlloy, Character.valueOf('S'), "ingotSteel"
|
||||
}));
|
||||
|
||||
|
|
|
@ -42,9 +42,9 @@ public class ItemPartTransmitter extends JItemMultiPart
|
|||
@Override
|
||||
public TMultiPart newPart(ItemStack stack, EntityPlayer player, World world, BlockCoord coord, int face, Vector3 vecHit)
|
||||
{
|
||||
TransmissionType type = TransmissionType.values()[stack.getItemDamage()];
|
||||
TransmitterType type = TransmitterType.values()[stack.getItemDamage()];
|
||||
|
||||
if(TransmissionType.values()[stack.getItemDamage()] != TransmissionType.ITEM)
|
||||
if(type.getTransmission() != TransmissionType.ITEM)
|
||||
{
|
||||
Coord4D obj = new Coord4D(coord.x, coord.y, coord.z);
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class ItemPartTransmitter extends JItemMultiPart
|
|||
{
|
||||
TileEntity tile = obj.getFromSide(side).getTileEntity(world);
|
||||
|
||||
if(tile instanceof IGridTransmitter && TransmissionType.checkTransmissionType(tile, type))
|
||||
if(tile instanceof IGridTransmitter && TransmissionType.checkTransmissionType(tile, type.getTransmission()))
|
||||
{
|
||||
networks.add(((IGridTransmitter)tile).getTransmitterNetwork());
|
||||
}
|
||||
|
|
|
@ -2,21 +2,23 @@ package mekanism.common.multipart;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.network.PacketTileEntity;
|
||||
import mekanism.common.tileentity.TileEntityDiversionTransporter;
|
||||
import mekanism.common.transporter.TransporterStack;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
public class PartDiversionTransporter extends PartLogisticalTransporter
|
||||
{
|
||||
public int[] modes = {0, 0, 0, 0, 0, 0};
|
||||
|
@ -119,9 +121,49 @@ public class PartDiversionTransporter extends PartLogisticalTransporter
|
|||
break;
|
||||
}
|
||||
|
||||
refreshConnections();
|
||||
tile().notifyPartChange(this);
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " " + MekanismUtils.localize("tooltip.configurator.toggleDiverter") + ": " + EnumColor.RED + description));
|
||||
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Coord4D.get(tile()), getNetworkedData(new ArrayList())), Coord4D.get(tile()), 50D);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ForgeDirection side)
|
||||
{
|
||||
if(!super.canInsert(side))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int mode = modes[side.ordinal()];
|
||||
boolean redstone = world().isBlockIndirectlyGettingPowered(x(), y(), z());
|
||||
|
||||
if((mode == 2 && redstone == true) || (mode == 1 && redstone == false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOutput(ForgeDirection side)
|
||||
{
|
||||
if(!super.canOutput(side))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int mode = modes[side.ordinal()];
|
||||
boolean redstone = world().isBlockIndirectlyGettingPowered(x(), y(), z());
|
||||
|
||||
if((mode == 2 && redstone == true) || (mode == 1 && redstone == false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ public class PartLogisticalTransporter extends PartSidedPipe implements ILogisti
|
|||
{
|
||||
TileEntity tileEntity = Coord4D.get(tile()).getFromSide(side).getTileEntity(world());
|
||||
|
||||
if(TransmissionType.checkTransmissionType(tileEntity, getTransmitter().getType()))
|
||||
if(TransmissionType.checkTransmissionType(tileEntity, getTransmitter().getTransmission()))
|
||||
{
|
||||
ILogisticalTransporter transporter = (ILogisticalTransporter)tileEntity;
|
||||
|
||||
|
@ -208,7 +208,7 @@ public class PartLogisticalTransporter extends PartSidedPipe implements ILogisti
|
|||
|
||||
if(!stack.isFinal(this))
|
||||
{
|
||||
if(next != null && stack.canInsertToTransporter(stack.getNext(this).getTileEntity(world())))
|
||||
if(next != null && stack.canInsertToTransporter(stack.getNext(this).getTileEntity(world()), ForgeDirection.getOrientation(stack.getSide(this))))
|
||||
{
|
||||
ILogisticalTransporter nextTile = (ILogisticalTransporter)next.getTileEntity(world());
|
||||
nextTile.entityEntering(stack);
|
||||
|
@ -299,7 +299,7 @@ public class PartLogisticalTransporter extends PartSidedPipe implements ILogisti
|
|||
TileEntity next = stack.getNext(this).getTileEntity(world());
|
||||
boolean recalculate = false;
|
||||
|
||||
if(!stack.canInsertToTransporter(next))
|
||||
if(!stack.canInsertToTransporter(next, ForgeDirection.getOrientation(stack.getSide(this))))
|
||||
{
|
||||
recalculate = true;
|
||||
}
|
||||
|
@ -370,7 +370,7 @@ public class PartLogisticalTransporter extends PartSidedPipe implements ILogisti
|
|||
stack.homeLocation = original;
|
||||
stack.color = color;
|
||||
|
||||
if(!stack.canInsertToTransporter(tile()))
|
||||
if(!stack.canInsertToTransporter(tile(), ForgeDirection.getOrientation(stack.getSide(this))))
|
||||
{
|
||||
return itemStack;
|
||||
}
|
||||
|
@ -400,7 +400,7 @@ public class PartLogisticalTransporter extends PartSidedPipe implements ILogisti
|
|||
stack.homeLocation = Coord4D.get(outputter);
|
||||
stack.color = color;
|
||||
|
||||
if(!stack.canInsertToTransporter(tile()))
|
||||
if(!stack.canInsertToTransporter(tile(), ForgeDirection.getOrientation(stack.getSide(this))))
|
||||
{
|
||||
return itemStack;
|
||||
}
|
||||
|
@ -693,4 +693,16 @@ public class PartLogisticalTransporter extends PartSidedPipe implements ILogisti
|
|||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ForgeDirection side)
|
||||
{
|
||||
return getConnectionType(side) == ConnectionType.PUSH || getConnectionType(side) == ConnectionType.NORMAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOutput(ForgeDirection side)
|
||||
{
|
||||
return getConnectionType(side) == ConnectionType.PUSH || getConnectionType(side) == ConnectionType.NORMAL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
|
|||
{
|
||||
TileEntity tileEntity = Coord4D.get(tile()).getFromSide(side).getTileEntity(world());
|
||||
|
||||
if(TransmissionType.checkTransmissionType(tileEntity, getTransmitter().getType()))
|
||||
if(TransmissionType.checkTransmissionType(tileEntity, getTransmitter().getTransmission()))
|
||||
{
|
||||
connections |= 1 << side.ordinal();
|
||||
}
|
||||
|
@ -565,7 +565,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
|
|||
return true;
|
||||
}
|
||||
else {
|
||||
return onConfigure(player, side, hit.subHit);
|
||||
return onConfigure(player, hit.subHit, side);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public enum TransmitterType
|
|||
return size;
|
||||
}
|
||||
|
||||
public TransmissionType getType()
|
||||
public TransmissionType getTransmission()
|
||||
{
|
||||
return transmissionType;
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile
|
|||
|
||||
if(!stack.isFinal(this))
|
||||
{
|
||||
if(next != null && stack.canInsertToTransporter(stack.getNext(this).getTileEntity(worldObj)))
|
||||
if(next != null && stack.canInsertToTransporter(stack.getNext(this).getTileEntity(worldObj), ForgeDirection.getOrientation(stack.getSide(this))))
|
||||
{
|
||||
ILogisticalTransporter nextTile = (ILogisticalTransporter)next.getTileEntity(worldObj);
|
||||
nextTile.entityEntering(stack);
|
||||
|
@ -181,7 +181,7 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile
|
|||
TileEntity next = stack.getNext(this).getTileEntity(worldObj);
|
||||
boolean recalculate = false;
|
||||
|
||||
if(!stack.canInsertToTransporter(next))
|
||||
if(!stack.canInsertToTransporter(next, ForgeDirection.getOrientation(stack.getSide(this))))
|
||||
{
|
||||
recalculate = true;
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile
|
|||
stack.homeLocation = original;
|
||||
stack.color = color;
|
||||
|
||||
if(!stack.canInsertToTransporter(this))
|
||||
if(!stack.canInsertToTransporter(this, ForgeDirection.getOrientation(stack.getSide(this))))
|
||||
{
|
||||
return itemStack;
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile
|
|||
stack.homeLocation = Coord4D.get(outputter);
|
||||
stack.color = color;
|
||||
|
||||
if(!stack.canInsertToTransporter(this))
|
||||
if(!stack.canInsertToTransporter(this, ForgeDirection.getOrientation(stack.getSide(this))))
|
||||
{
|
||||
return itemStack;
|
||||
}
|
||||
|
@ -573,4 +573,16 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile
|
|||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ForgeDirection side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOutput(ForgeDirection side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public final class TransporterPathfinder
|
|||
{
|
||||
TileEntity tile = pointer.getFromSide(side).getTileEntity(worldObj);
|
||||
|
||||
if(transportStack.canInsertToTransporter(tile) && !currentPath.contains(Coord4D.get(tile)))
|
||||
if(transportStack.canInsertToTransporter(tile, side) && !currentPath.contains(Coord4D.get(tile)))
|
||||
{
|
||||
if(TransporterUtils.checkDiversionLogic(pointer.getTileEntity(worldObj), tile, side.ordinal()))
|
||||
{
|
||||
|
@ -207,7 +207,7 @@ public final class TransporterPathfinder
|
|||
rejects.put(Coord4D.get(tile), stack);
|
||||
}
|
||||
}
|
||||
else if(transportStack.canInsertToTransporter(tile) && !iterated.contains(Coord4D.get(tile)))
|
||||
else if(transportStack.canInsertToTransporter(tile, side) && !iterated.contains(Coord4D.get(tile)))
|
||||
{
|
||||
loop(Coord4D.get(tile));
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ public final class TransporterPathfinder
|
|||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
||||
Coord4D neighbor = start.translate(direction.offsetX, direction.offsetY, direction.offsetZ);
|
||||
|
||||
if(!transportStack.canInsertToTransporter(neighbor.getTileEntity(worldObj)) && (!neighbor.equals(finalNode) || !destChecker.isValid(transportStack, i, neighbor.getTileEntity(worldObj))))
|
||||
if(!transportStack.canInsertToTransporter(neighbor.getTileEntity(worldObj), direction) && (!neighbor.equals(finalNode) || !destChecker.isValid(transportStack, i, neighbor.getTileEntity(worldObj))))
|
||||
{
|
||||
blockCount++;
|
||||
}
|
||||
|
@ -416,7 +416,7 @@ public final class TransporterPathfinder
|
|||
ForgeDirection direction = ForgeDirection.getOrientation(i);
|
||||
Coord4D neighbor = currentNode.getFromSide(direction);
|
||||
|
||||
if(transportStack.canInsertToTransporter(neighbor.getTileEntity(worldObj)))
|
||||
if(transportStack.canInsertToTransporter(neighbor.getTileEntity(worldObj), direction))
|
||||
{
|
||||
TileEntity tile = neighbor.getTileEntity(worldObj);
|
||||
double tentativeG = gScore.get(currentNode) + currentNode.distanceTo(neighbor);
|
||||
|
|
|
@ -3,8 +3,8 @@ package mekanism.common.transporter;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.common.ILogisticalTransporter;
|
||||
import mekanism.common.tileentity.TileEntityLogisticalSorter;
|
||||
import mekanism.common.transporter.TransporterPathfinder.Destination;
|
||||
|
@ -12,6 +12,7 @@ import mekanism.common.util.TransporterUtils;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
|
@ -268,14 +269,29 @@ public class TransporterStack
|
|||
return 0;
|
||||
}
|
||||
|
||||
public boolean canInsertToTransporter(TileEntity tileEntity)
|
||||
public boolean canInsertToTransporter(TileEntity tileEntity, ForgeDirection side)
|
||||
{
|
||||
if(!(tileEntity instanceof ILogisticalTransporter))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity from = Coord4D.get(tileEntity).getFromSide(side.getOpposite()).getTileEntity(tileEntity.worldObj);
|
||||
ILogisticalTransporter transporter = (ILogisticalTransporter)tileEntity;
|
||||
|
||||
if(!transporter.canInsert(side.getOpposite()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(from instanceof ILogisticalTransporter)
|
||||
{
|
||||
if(!((ILogisticalTransporter)from).canOutput(side))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return transporter.getColor() == color || transporter.getColor() == null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue