Skip to content

Commit

Permalink
Energy and TOP
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryLoenwind committed Dec 3, 2016
1 parent 319e455 commit ba53356
Show file tree
Hide file tree
Showing 13 changed files with 582 additions and 37 deletions.
7 changes: 4 additions & 3 deletions resources/assets/enderio/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -1346,8 +1346,10 @@ enderio.top.action.none=nothing
enderio.top.machine.active=active
enderio.top.machine.idle=idle
enderio.top.progress.idle=idle
enderio.top.suffix.percent=%
enderio.top.suffix.rf=RF
enderio.top.suffix.percent= %
enderio.top.suffix.rf= RF
enderio.top.suffix.levels= Levels
enderio.top.suffix.items= Items
enderio.top.range.header=Range: %s
enderio.top.range=%sx%sx%s
enderio.top.machine.outofpower=No Power
Expand All @@ -1360,7 +1362,6 @@ enderio.top.tank.content.empty=Empty
enderio.top.tank.header.input=Input Tank: %s
enderio.top.tank.header.output=Output Tank: %s
enderio.top.tank.header.storage=%s
enderio.top.xp.levels= Levels
enderio.top.rf.header.maxin=Max Input:
enderio.top.rf.header.maxout=Max Output:
enderio.top.rf.header.avg=I/O:
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/crazypants/enderio/capability/EnderInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;
import java.util.Map.Entry;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import crazypants.util.Prep;
Expand All @@ -31,6 +32,29 @@ public static enum Type {
private final EnumMap<EnderInventory.Type, List<InventorySlot>> slots = new EnumMap<EnderInventory.Type, List<InventorySlot>>(EnderInventory.Type.class);
private final View allSlots = new View(EnderInventory.Type.ALL);
private @Nullable TileEntity owner = null;
public static final @Nonnull IItemHandler OFF = new IItemHandler() {

@Override
public int getSlots() {
return 0;
}

@Override
public ItemStack getStackInSlot(int slot) {
return Prep.getEmpty();
}

@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
return stack;
}

@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
return Prep.getEmpty();
}

};

public EnderInventory() {
for (EnderInventory.Type type : EnderInventory.Type.values()) {
Expand Down Expand Up @@ -73,6 +97,7 @@ public InventorySlot getSlot(String ident) {
return idents.get(ident);
}

@Nonnull
public View getView(EnderInventory.Type type) {
return new View(type);
}
Expand Down
63 changes: 53 additions & 10 deletions src/main/java/crazypants/enderio/capability/Filters.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,104 @@
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;

import crazypants.enderio.capacitor.CapacitorHelper;
import crazypants.enderio.machine.sagmill.SagMillRecipeManager;
import crazypants.enderio.paint.IPaintable;
import crazypants.util.CapturedMob;
import crazypants.util.Prep;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;

import static crazypants.enderio.ModObject.itemBasicCapacitor;
import static crazypants.enderio.ModObject.itemSoulVessel;

public class Filters {

public static final Callback<ItemStack> NO_CALLBACK = new Callback<ItemStack>() {
public static final @Nonnull Callback<ItemStack> NO_CALLBACK = new Callback<ItemStack>() {
@Override
public final void onChange(@Nullable ItemStack oldStack, @Nullable ItemStack newStack) {
}
};

public static final Predicate<ItemStack> ALWAYS_TRUE = Predicates.<ItemStack> alwaysTrue();
@SuppressWarnings("null")
public static final @Nonnull Predicate<ItemStack> ALWAYS_TRUE = Predicates.<ItemStack> alwaysTrue();

public static final Predicate<ItemStack> ALWAYS_FALSE = Predicates.<ItemStack> alwaysFalse();
@SuppressWarnings("null")
public static final @Nonnull Predicate<ItemStack> ALWAYS_FALSE = Predicates.<ItemStack> alwaysFalse();

public static final Predicate<ItemStack> ONLY_STACKABLE = new PredicateItemStack() {
public static final @Nonnull Predicate<ItemStack> ONLY_STACKABLE = new PredicateItemStack() {
@Override
public boolean doApply(@Nonnull ItemStack input) {
return input.isStackable();
}
};

public static final Predicate<ItemStack> ONLY_PAINTABLE = new PredicateItemStack() {
public static final @Nonnull Predicate<ItemStack> PAINTABLE = new PredicateItemStack() {
@Override
public boolean doApply(@Nonnull ItemStack input) {
return Block.getBlockFromItem(input.getItem()) instanceof IPaintable;
}
};

public static final Predicate<ItemStack> ONLY_SOUL_VIALS = new PredicateItemStack() {
public static final @Nonnull Predicate<ItemStack> SOUL_VIALS = new PredicateItemStack() {
@Override
public boolean doApply(@Nonnull ItemStack input) {
return input.getItem() == itemSoulVessel.getItem();
}
};

public static final Predicate<ItemStack> ONLY_FILLED_SOUL_VIALS = new PredicateItemStack() {
public static final @Nonnull Predicate<ItemStack> WITH_MOB_SOUL = new PredicateItemStack() {
@Override
public boolean doApply(@Nonnull ItemStack input) {
return input.getItem() == itemSoulVessel.getItem() && CapturedMob.containsSoul(input);
return CapturedMob.containsSoul(input);
}
};

public static final Predicate<ItemStack> ONLY_GRINDING_BALLS = new PredicateItemStack() {
public static final @Nonnull Predicate<ItemStack> FILLED_SOUL_VIALS = and(SOUL_VIALS, WITH_MOB_SOUL);

public static final @Nonnull Predicate<ItemStack> EMPTY_SOUL_VIALS = and(SOUL_VIALS, not(WITH_MOB_SOUL));

public static final @Nonnull Predicate<ItemStack> GRINDING_BALLS = new PredicateItemStack() {
@Override
public boolean doApply(@Nonnull ItemStack input) {
return SagMillRecipeManager.getInstance().isValidSagBall(input);
}
};

public static final @Nonnull Predicate<ItemStack> CAPACITORS = new PredicateItemStack() {
@Override
public boolean doApply(@Nonnull ItemStack input) {
return (input.getItem() == itemBasicCapacitor.getItem() && input.getItemDamage() > 0) || CapacitorHelper.getCapacitorDataFromItemStack(input) != null;
}
};

public static @Nonnull Predicate<ItemStack> and(final @Nonnull Predicate<ItemStack> a, final @Nonnull Predicate<ItemStack> b) {
return new PredicateItemStack() {
@Override
public boolean doApply(@Nonnull ItemStack input) {
return a.apply(input) && b.apply(input);
}
};
}

public static @Nonnull Predicate<ItemStack> or(final @Nonnull Predicate<ItemStack> a, final @Nonnull Predicate<ItemStack> b) {
return new PredicateItemStack() {
@Override
public boolean doApply(@Nonnull ItemStack input) {
return a.apply(input) || b.apply(input);
}
};
}

public static @Nonnull Predicate<ItemStack> not(final @Nonnull Predicate<ItemStack> a) {
return new PredicateItemStack() {
@Override
public boolean doApply(@Nonnull ItemStack input) {
return !a.apply(input);
}
};
}

// ///////////////////////////////////////////////////////////////////

private Filters() {
Expand All @@ -80,7 +123,7 @@ public boolean equals(@Nullable Object obj) {

@Override
public boolean apply(@Nullable ItemStack input) {
return input != null && doApply(input);
return Prep.isValid(input) && doApply(input);
}

public abstract boolean doApply(@Nonnull ItemStack input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public InventorySlot(ItemStack itemStack, Predicate<ItemStack> filterIn, Predica
this.filterIn = filterIn != null ? filterIn : Filters.ALWAYS_TRUE;
this.filterOut = filterOut != null ? filterOut : Filters.ALWAYS_TRUE;
this.callback = callback != null ? callback : Filters.NO_CALLBACK;
this.limit = limit > 0 ? limit : Integer.MAX_VALUE;
this.limit = limit > 0 ? limit : 64;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package crazypants.enderio.capacitor;

import crazypants.enderio.ModObject;
import crazypants.enderio.IModObject;

public class DefaultCapacitorKey implements ICapacitorKey {

private final ModObject owner;
private final IModObject owner;
private final CapacitorKeyType valueType;
private final Scaler scaler;
private final int baseValue;

public DefaultCapacitorKey(ModObject owner, CapacitorKeyType valueType, Scaler scaler, int baseValue) {
public DefaultCapacitorKey(IModObject owner, CapacitorKeyType valueType, Scaler scaler, int baseValue) {
this.owner = owner;
this.valueType = valueType;
this.scaler = scaler;
Expand All @@ -27,7 +27,7 @@ public float getFloat(ICapacitorData capacitor) {
}

@Override
public ModObject getOwner() {
public IModObject getOwner() {
return owner;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/crazypants/enderio/capacitor/ICapacitorKey.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package crazypants.enderio.capacitor;

import crazypants.enderio.ModObject;
import crazypants.enderio.IModObject;

public interface ICapacitorKey {

Expand All @@ -20,7 +20,7 @@ public interface ICapacitorKey {
*/
float getFloat(ICapacitorData capacitor);

ModObject getOwner();
IModObject getOwner();

CapacitorKeyType getValueType();

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/crazypants/enderio/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ public String lc() {
public static boolean topShowMobsByDefault = true;
public static boolean topShowTanksByDefault = true;
public static boolean topShowXPByDefault = true;
public static boolean topShowItemCountDefault = true;

public static boolean paintedGlowstoneRequireSilkTouch = false;

Expand Down Expand Up @@ -1540,6 +1541,8 @@ public static void processConfig(Configuration config) {
"If true, the tank content will be shown always, otherwise only it will only be shown on 'extended' mode (e.g. with shift pressed)");
topShowXPByDefault = config.getBoolean("topShowXPByDefault", sectionTOP.name, topShowXPByDefault,
"If true, the XP level will be shown always, otherwise only it will only be shown on 'extended' mode (e.g. with shift pressed)");
topShowItemCountDefault = config.getBoolean("topShowItemCountDefault", sectionTOP.name, topShowItemCountDefault,
"If true, the item count will be shown always, otherwise only it will only be shown on 'extended' mode (e.g. with shift pressed)");

allowFovControlsInSurvivalMode = config.getBoolean("allowFovControlsInSurvivalMode", sectionMisc.name, allowFovControlsInSurvivalMode,
"If true, the FOV keyboard controls can be used in survival and advanture mode. Otherwise they are limited to create and spectator modes.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
Expand All @@ -40,6 +41,7 @@

import static crazypants.enderio.ModObject.blockTank;
import static crazypants.enderio.config.Config.topEnabled;
import static crazypants.enderio.config.Config.topShowItemCountDefault;
import static crazypants.enderio.config.Config.topShowMobsByDefault;
import static crazypants.enderio.config.Config.topShowPowerByDefault;
import static crazypants.enderio.config.Config.topShowProgressByDefault;
Expand Down Expand Up @@ -97,6 +99,8 @@ public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer play

mkTankLines(mode, eiobox, data);

mkItemFillLevelLine(mode, eiobox, data);

eiobox.finish();

EioBox mobbox = new EioBox(probeInfo);
Expand Down Expand Up @@ -132,6 +136,7 @@ public ILayoutStyle center() {
return probeinfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER);
}

@SuppressWarnings("unused")
public ILayoutStyle right() {
return probeinfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_BOTTOMRIGHT);
}
Expand Down Expand Up @@ -275,8 +280,21 @@ private void mkXPLine(ProbeMode mode, EioBox eiobox, TOPData data) {
// should be empty but we do have at least one level in, there will be a small error, as (levels/Integer.MAX_VALUE) > 0.
int scalemax = data.xpBarScaled > 0 ? data.experienceLevel * 100 / data.xpBarScaled : Integer.MAX_VALUE;
eiobox.get().horizontal(eiobox.center()).item(new ItemStack(Items.EXPERIENCE_BOTTLE)).progress(data.experienceLevel, scalemax,
eiobox.getProbeinfo().defaultProgressStyle().suffix(EnderIO.lang.localize("top.xp.levels")).filledColor(0xff00FF0F).alternateFilledColor(0xff00AA0A)
.borderColor(0xff00AA0A));
eiobox.getProbeinfo().defaultProgressStyle().suffix(EnderIO.lang.localize("top.suffix.levels")).filledColor(0xff00FF0F)
.alternateFilledColor(0xff00AA0A).borderColor(0xff00AA0A));
} else {
eiobox.addMore();
}
}
}

private void mkItemFillLevelLine(ProbeMode mode, EioBox eiobox, TOPData data) {
if (data.hasItemFillLevel) {
if (mode != ProbeMode.NORMAL || topShowItemCountDefault) {
eiobox.get().horizontal(eiobox.center()).item(new ItemStack(Blocks.CHEST)).progress(data.fillCur, data.fillMax,
eiobox.getProbeinfo().defaultProgressStyle().suffix(EnderIO.lang.localize("top.suffix.items")).filledColor(0xfff8f83c)
.alternateFilledColor(0xffcfac0b)
.borderColor(0xffcfac0b));
} else {
eiobox.addMore();
}
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/crazypants/enderio/integration/top/TOPData.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import com.enderio.core.api.common.util.ITankAccess.ITankData;
import com.enderio.core.client.render.BoundingBox;

import crazypants.enderio.capability.EnderInventory;
import crazypants.enderio.capability.InventorySlot;
import crazypants.enderio.conduit.IConduitBundle;
import crazypants.enderio.machine.AbstractCapabilityMachineEntity;
import crazypants.enderio.machine.AbstractCapabilityPoweredMachineEntity;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.AbstractPoweredTaskEntity;
import crazypants.enderio.machine.ContinuousTask;
Expand All @@ -19,17 +23,20 @@
import crazypants.enderio.machine.IoMode;
import crazypants.enderio.machine.RedstoneControlMode;
import crazypants.enderio.machine.RedstoneControlMode.IconHolder;
import crazypants.enderio.machine.invpanel.chest.TileInventoryChest;
import crazypants.enderio.machine.obelisk.spawn.AbstractMobObelisk;
import crazypants.enderio.machine.painter.blocks.TileEntityPaintedBlock;
import crazypants.enderio.machine.ranged.IRanged;
import crazypants.enderio.machine.spawner.TilePoweredSpawner;
import crazypants.enderio.paint.IPaintable.IPaintableTileEntity;
import crazypants.enderio.paint.PainterUtil2;
import crazypants.enderio.power.EnergyTank;
import crazypants.enderio.power.IInternalPoweredTile;
import crazypants.enderio.power.IPowerStorage;
import crazypants.enderio.xp.ExperienceContainer;
import crazypants.enderio.xp.IHaveExperience;
import crazypants.util.CapturedMob;
import crazypants.util.Prep;
import mcjty.theoneprobe.api.IProbeHitData;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
Expand All @@ -45,10 +52,10 @@ static enum ProgressResult {
NO_PROGRESS_IDLE;
}

boolean hasStatus, hasProgress, hasRF, hasRedstone, hasIOMode, hasRange, hasMobs, hasXP, hasRFIO;
boolean hasStatus, hasProgress, hasRF, hasRedstone, hasIOMode, hasRange, hasMobs, hasXP, hasRFIO, hasItemFillLevel;
boolean isActive, isPowered, redstoneControlStatus, isPainted;
float progress;
long rf, maxrf;
long rf, maxrf, fillMax, fillCur;
int experienceLevel, xpBarScaled, maxRFIn, maxRFOut, avgRF;
String redstoneTooltip, sideName, mobAction;
IWidgetIcon redstoneIcon;
Expand Down Expand Up @@ -86,6 +93,12 @@ public TOPData(TileEntity tileEntity, IProbeHitData hitData) {
isPowered = rf > 0;
hasRF = maxrf > 0;
}
} else if (tileEntity instanceof AbstractCapabilityPoweredMachineEntity) {
EnergyTank energy = ((AbstractCapabilityPoweredMachineEntity) tileEntity).getEnergy();
maxrf = energy.getMaxEnergyStored();
rf = energy.getEnergyStored();
isPowered = rf > 0;
hasRF = maxrf > 0;
}

if (tileEntity instanceof IProgressTile) {
Expand Down Expand Up @@ -161,6 +174,19 @@ public TOPData(TileEntity tileEntity, IProbeHitData hitData) {
isPainted = paint1 != null || paint2 != null;
}

if (tileEntity instanceof TileInventoryChest) {
fillMax = fillCur = 0L;
for (InventorySlot slot : ((AbstractCapabilityMachineEntity) tileEntity).getInventory().getView(EnderInventory.Type.INOUT)) {
if (Prep.isValid(slot.getStackInSlot(0))) {
fillMax += Math.min(slot.getMaxStackSize(), slot.getStackInSlot(0).getMaxStackSize());
fillCur += slot.getStackInSlot(0).stackSize;
} else {
fillMax += slot.getMaxStackSize();
}
}
hasItemFillLevel = true;
}

calculateProgress();
}

Expand Down
Loading

0 comments on commit ba53356

Please sign in to comment.