use of net.minecraft.item.ItemStack in project MineFactoryReloaded by powercrystals.
the class TileEntityItemRouter method weightedRouteItem.
private ItemStack weightedRouteItem(ItemStack stack, int[] routes) {
ItemStack remainingOverall = stack.copy();
if (stack.stackSize >= totalWeight(routes)) {
int startingAmount = stack.stackSize;
for (int i = 0; i < routes.length; i++) {
ItemStack stackForThisRoute = stack.copy();
stackForThisRoute.stackSize = startingAmount * routes[i] / totalWeight(routes);
if (stackForThisRoute.stackSize > 0) {
ItemStack remainingFromThisRoute = UtilInventory.dropStack(this, stackForThisRoute, _outputDirections[i], _outputDirections[i]);
if (remainingFromThisRoute == null) {
remainingOverall.stackSize -= stackForThisRoute.stackSize;
} else {
remainingOverall.stackSize -= (stackForThisRoute.stackSize - remainingFromThisRoute.stackSize);
}
if (remainingOverall.stackSize <= 0) {
break;
}
}
}
}
if (0 < remainingOverall.stackSize && remainingOverall.stackSize < totalWeight(routes)) {
int outdir = weightedRandomSide(routes);
remainingOverall = UtilInventory.dropStack(this, remainingOverall, _outputDirections[outdir], _outputDirections[outdir]);
}
return remainingOverall;
}
use of net.minecraft.item.ItemStack in project MineFactoryReloaded by powercrystals.
the class TileEntityLaserDrill method getRandomDrop.
private ItemStack getRandomDrop() {
List<WeightedRandomItemStack> drops = new LinkedList<WeightedRandomItemStack>();
int boost = WeightedRandom.getTotalWeight(MFRRegistry.getLaserOres()) / 30;
for (WeightedRandomItem i : MFRRegistry.getLaserOres()) {
WeightedRandomItemStack oldStack = (WeightedRandomItemStack) i;
WeightedRandomItemStack newStack = new WeightedRandomItemStack(oldStack.itemWeight, oldStack.getStack());
drops.add(newStack);
for (ItemStack s : _inventory) {
if (s == null || s.itemID != MineFactoryReloadedCore.laserFocusItem.itemID || MFRRegistry.getLaserPreferredOres(s.getItemDamage()) == null) {
continue;
}
List<ItemStack> preferredOres = MFRRegistry.getLaserPreferredOres(s.getItemDamage());
for (ItemStack preferredOre : preferredOres) {
if (UtilInventory.stacksEqual(newStack.getStack(), preferredOre)) {
newStack.itemWeight += boost;
}
}
}
}
return ((WeightedRandomItemStack) WeightedRandom.getRandomItem(_rand, drops)).getStack();
}
use of net.minecraft.item.ItemStack in project MineFactoryReloaded by powercrystals.
the class TileEntityLiquiCrafter method decrStackSize.
@Override
public ItemStack decrStackSize(int slot, int size) {
ItemStack result = super.decrStackSize(slot, size);
if (slot < 9)
calculateOutput();
onFactoryInventoryChanged();
return result;
}
use of net.minecraft.item.ItemStack in project MineFactoryReloaded by powercrystals.
the class TileEntityFertilizer method activateMachine.
@Override
public boolean activateMachine() {
BlockPosition bp = _areaManager.getNextBlock();
int targetId = worldObj.getBlockId(bp.x, bp.y, bp.z);
if (!MFRRegistry.getFertilizables().containsKey(new Integer(targetId))) {
setIdleTicks(getIdleTicksMax());
return false;
}
for (int stackIndex = 0; stackIndex < getSizeInventory(); stackIndex++) {
ItemStack fertStack = getStackInSlot(stackIndex);
if (fertStack == null || !MFRRegistry.getFertilizers().containsKey(new Integer(fertStack.itemID))) {
continue;
}
IFactoryFertilizer fertilizer = MFRRegistry.getFertilizers().get(new Integer(fertStack.itemID));
IFactoryFertilizable fertilizable = MFRRegistry.getFertilizables().get(new Integer(targetId));
if (fertilizer.getFertilizerMeta() != fertStack.getItemDamage()) {
continue;
}
if (!fertilizable.canFertilizeBlock(worldObj, bp.x, bp.y, bp.z, fertilizer.getFertilizerType())) {
continue;
}
if (fertilizable.fertilize(worldObj, _rand, bp.x, bp.y, bp.z, fertilizer.getFertilizerType())) {
fertilizer.consume(fertStack);
if (fertStack.stackSize <= 0) {
setInventorySlotContents(stackIndex, null);
}
return true;
}
}
setIdleTicks(getIdleTicksMax());
return false;
}
use of net.minecraft.item.ItemStack in project MineFactoryReloaded by powercrystals.
the class TileEntityFisher method activateMachine.
@Override
public boolean activateMachine() {
if (_isJammed || worldObj.getWorldTime() % 137 == 0) {
Area fishingHole = _ham.getHarvestArea();
for (BlockPosition bp : fishingHole.getPositionsBottomFirst()) {
if (worldObj.getBlockId(bp.x, bp.y, bp.z) != Block.waterStill.blockID) {
_isJammed = true;
setIdleTicks(getIdleTicksMax());
return false;
}
}
}
_isJammed = false;
setWorkDone(getWorkDone() + 1);
if (getWorkDone() > getWorkMax()) {
doDrop(new ItemStack(Item.fishRaw));
setWorkDone(0);
}
return true;
}
Aggregations