use of net.minecraftforge.fluids.FluidTank in project LogisticsPipes by RS485.
the class PipeFluidBasic method sinkAmount.
@Override
public int sinkAmount(FluidStack stack) {
if (!guiOpenedBy.isEmpty()) {
//Don't sink when the gui is open
return 0;
}
FluidIdentifier ident = FluidIdentifier.get(stack);
if (filterInv.getStackInSlot(0) == null) {
return 0;
}
if (!ident.equals(FluidIdentifier.get(filterInv.getIDStackInSlot(0).getItem()))) {
return 0;
}
int onTheWay = this.countOnRoute(ident);
int freeSpace = -onTheWay;
for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(true)) {
FluidTank tank = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue2().ordinal()];
freeSpace += ident.getFreeSpaceInsideTank((IFluidHandler) pair.getValue1(), pair.getValue2().getOpposite());
freeSpace += ident.getFreeSpaceInsideTank(tank);
if (freeSpace >= stack.amount) {
return stack.amount;
}
}
return freeSpace;
}
use of net.minecraftforge.fluids.FluidTank in project PneumaticCraft by MineMaarten.
the class NetworkUtils method getSyncedFieldsForField.
private static List<SyncedField> getSyncedFieldsForField(Field field, Object te, Class searchedAnnotation) {
boolean isLazy = field.getAnnotation(LazySynced.class) != null;
List<SyncedField> syncedFields = new ArrayList<SyncedField>();
SyncedField syncedField = getSyncedFieldForField(field, te);
if (syncedField != null) {
syncedFields.add(syncedField.setLazy(isLazy));
return syncedFields;
} else {
Object o;
try {
int filteredIndex = field.getAnnotation(FilteredSynced.class) != null ? field.getAnnotation(FilteredSynced.class).index() : -1;
field.setAccessible(true);
o = field.get(te);
if (o instanceof int[]) {
int[] array = (int[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedInt(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedInt(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o instanceof float[]) {
float[] array = (float[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedFloat(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedFloat(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o instanceof double[]) {
double[] array = (double[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedDouble(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedDouble(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o instanceof boolean[]) {
boolean[] array = (boolean[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedBoolean(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedBoolean(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o instanceof String[]) {
String[] array = (String[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedString(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedString(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o.getClass().isArray() && o.getClass().getComponentType().isEnum()) {
Object[] enumArray = (Object[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedEnum(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < enumArray.length; i++) {
syncedFields.add(new SyncedEnum(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o instanceof ItemStack[]) {
ItemStack[] array = (ItemStack[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedItemStack(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedItemStack(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (o instanceof FluidTank[]) {
FluidTank[] array = (FluidTank[]) o;
if (filteredIndex >= 0) {
syncedFields.add(new SyncedFluidTank(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
} else {
for (int i = 0; i < array.length; i++) {
syncedFields.add(new SyncedFluidTank(te, field).setArrayIndex(i).setLazy(isLazy));
}
}
return syncedFields;
}
if (field.getType().isArray()) {
Object[] array = (Object[]) o;
for (Object obj : array) {
syncedFields.addAll(getSyncedFields(obj, searchedAnnotation));
}
} else {
syncedFields.addAll(getSyncedFields(o, searchedAnnotation));
}
if (syncedFields.size() > 0)
return syncedFields;
} catch (Exception e) {
e.printStackTrace();
}
Log.warning("Field " + field + " didn't produce any syncable fields!");
return syncedFields;
}
}
use of net.minecraftforge.fluids.FluidTank in project PneumaticCraft by MineMaarten.
the class SemiBlockLogistics method addDrops.
@Override
public void addDrops(List<ItemStack> drops) {
super.addDrops(drops);
boolean shouldAddTag = false;
for (int i = 0; i < filters.getSizeInventory(); i++) {
if (filters.getStackInSlot(i) != null) {
//Only set a tag when there are requests.
shouldAddTag = true;
break;
}
}
for (FluidTank fluidFilter : fluidFilters) {
if (fluidFilter.getFluidAmount() > 0) {
shouldAddTag = true;
break;
}
}
if (invisible)
shouldAddTag = true;
if (shouldAddTag) {
ItemStack drop = drops.get(0);
NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
drop.setTagCompound(tag);
}
}
use of net.minecraftforge.fluids.FluidTank in project ImmersiveEngineering by BluSunrize.
the class TileEntitySheetmetalTank method getComparatorInputOverride.
@Override
public int getComparatorInputOverride() {
if (pos == 4)
return (15 * tank.getFluidAmount()) / tank.getCapacity();
TileEntitySheetmetalTank master = master();
if (//4 layers of storage
offset[1] >= 1 && offset[1] <= 4 && master != null) {
FluidTank t = master.tank;
int layer = offset[1] - 1;
int vol = t.getCapacity() / 4;
int filled = t.getFluidAmount() - layer * vol;
int ret = Math.min(15, Math.max(0, (15 * filled) / vol));
return ret;
}
return 0;
}
use of net.minecraftforge.fluids.FluidTank in project PneumaticCraft by MineMaarten.
the class SemiBlockLogistics method writeToNBT.
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
TileEntityBase.writeInventoryToNBT(tag, filters, "filters");
NBTTagList tagList = new NBTTagList();
for (int i = 0; i < fluidFilters.length; i++) {
FluidTank filter = fluidFilters[i];
if (filter.getFluid() != null) {
NBTTagCompound t = new NBTTagCompound();
t.setInteger("index", i);
filter.writeToNBT(t);
tagList.appendTag(t);
}
}
tag.setTag("fluidFilters", tagList);
tag.setBoolean("invisible", invisible);
}
Aggregations