use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.
the class DetectorLocomotive method testCarts.
@Override
public int testCarts(List<EntityMinecart> carts) {
for (EntityMinecart cart : carts) {
if (cart instanceof EntityLocomotive) {
EntityLocomotive loco = (EntityLocomotive) cart;
ItemStack primary = getFilters().getStackInSlot(0);
if (primary != null && EnumColor.fromItemStack(primary) != EnumColor.fromDye(loco.getPrimaryColor())) {
continue;
}
ItemStack secondary = getFilters().getStackInSlot(1);
if (secondary != null && EnumColor.fromItemStack(secondary) != EnumColor.fromDye(loco.getSecondaryColor())) {
continue;
}
return FULL_POWER;
}
}
return NO_POWER;
}
use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.
the class DetectorTank method testCarts.
@Override
public int testCarts(List<EntityMinecart> carts) {
for (EntityMinecart cart : carts) {
IFluidHandler fluidHandler = FluidTools.getFluidHandler(null, cart);
if (fluidHandler != null) {
AdvancedFluidHandler tank = new AdvancedFluidHandler(fluidHandler);
boolean liquidMatches = false;
Fluid filterFluid = getFilterFluid();
FluidStack tankLiquid = tank.drain(1, false);
if (filterFluid == null)
liquidMatches = true;
else if (Fluids.areEqual(filterFluid, tankLiquid))
liquidMatches = true;
else if (tank.canPutFluid(new FluidStack(filterFluid, 1)))
liquidMatches = true;
boolean quantityMatches = false;
ButtonState state = buttonController.getButtonState();
switch(state) {
case VOID:
quantityMatches = true;
break;
case EMPTY:
if (filterFluid != null && tank.isTankEmpty(filterFluid))
quantityMatches = true;
else if (filterFluid == null && tank.areTanksEmpty())
quantityMatches = true;
break;
case NOT_EMPTY:
if (filterFluid != null && tank.getFluidQty(filterFluid) > 0)
quantityMatches = true;
else if (filterFluid == null && tank.isFluidInTank())
quantityMatches = true;
break;
case FULL:
if (filterFluid != null && tank.isTankFull(filterFluid))
quantityMatches = true;
else if (filterFluid == null && tank.areTanksFull())
quantityMatches = true;
break;
default:
float level = filterFluid != null ? tank.getFluidLevel(filterFluid) : tank.getFluidLevel();
switch(state) {
case ANALOG:
return (int) (FULL_POWER * level);
case QUARTER:
quantityMatches = level >= 0.25f;
break;
case HALF:
quantityMatches = level >= 0.5f;
break;
case MOST:
quantityMatches = level >= 0.75f;
break;
case LESS_THAN_QUARTER:
quantityMatches = level < 0.25f;
break;
case LESS_THAN_HALF:
quantityMatches = level < 0.5f;
break;
case LESS_THAN_MOST:
quantityMatches = level < 0.75f;
break;
case LESS_THAN_FULL:
quantityMatches = level < 1f;
break;
}
}
return liquidMatches && quantityMatches ? FULL_POWER : NO_POWER;
}
}
return NO_POWER;
}
use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.
the class CommandDebug method executeSubCommand.
@Override
public void executeSubCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length != 0)
CommandHelpers.throwWrongUsage(sender, this);
RayTraceResult rayTraceResult = MiscTools.rayTracePlayerLook((EntityPlayer) sender);
List<String> debug = Collections.emptyList();
switch(rayTraceResult.typeOfHit) {
case ENTITY:
Entity entity = rayTraceResult.entityHit;
if (entity instanceof EntityMinecart) {
debug = CartTools.getDebugOutput((EntityMinecart) entity);
} else {
CommandHelpers.throwWrongUsage(sender, this);
}
break;
case BLOCK:
World world = CommandHelpers.getWorld(sender);
TileEntity tile = WorldPlugin.getBlockTile(world, rayTraceResult.getBlockPos());
if (tile instanceof RailcraftTileEntity) {
debug = ((RailcraftTileEntity) tile).getDebugOutput();
} else {
CommandHelpers.throwWrongUsage(sender, this);
}
break;
}
for (String s : debug) {
printLine(sender, s);
}
}
use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.
the class LinkageManager method linkIterator.
public Iterable<EntityMinecart> linkIterator(final EntityMinecart start, final LinkType type) {
return () -> new Iterator<EntityMinecart>() {
private final LinkageManager lm = LinkageManager.instance();
private EntityMinecart last;
private EntityMinecart current = start;
@Override
public boolean hasNext() {
if (last == null) {
EntityMinecart next = lm.getLinkedCart(current, type);
return next != null;
}
EntityMinecart next = lm.getLinkedCartA(current);
if (next != null && next != last)
return true;
next = lm.getLinkedCartB(current);
return next != null && next != last;
}
@Override
public EntityMinecart next() {
if (last == null) {
EntityMinecart next = lm.getLinkedCart(current, type);
if (next == null)
throw new NoSuchElementException();
last = current;
current = next;
return current;
}
EntityMinecart next = lm.getLinkedCartA(current);
if (next != null && next != last) {
last = current;
current = next;
return current;
}
next = lm.getLinkedCartB(current);
if (next != null && next != last) {
last = current;
current = next;
return current;
}
throw new NoSuchElementException();
}
@Override
public void remove() {
throw new UnsupportedOperationException("Removal not supported.");
}
};
}
use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.
the class LinkageHandler method adjustLinkedCart.
private boolean adjustLinkedCart(EntityMinecart cart, LinkageManager.LinkType linkType) {
boolean linked = false;
LinkageManager lm = LinkageManager.instance();
EntityMinecart link = lm.getLinkedCart(cart, linkType);
if (link != null) {
// sanity check to ensure links are consistent
if (!lm.areLinked(cart, link)) {
lm.repairLink(cart, link);
}
if (!isLaunched(link) && !isOnElevator(link)) {
linked = true;
adjustVelocity(cart, link, linkType);
// adjustCartFromHistory(cart, link);
}
}
return linked;
}
Aggregations