use of mods.railcraft.common.util.inventory.wrappers.InventoryCopy in project Railcraft by Railcraft.
the class TileRockCrusher method update.
@Override
public void update() {
super.update();
if (Game.isHost(getWorld())) {
BlockPos pos = getPos();
double x = pos.getX();
double y = pos.getZ();
double z = pos.getZ();
if (isStructureValid()) {
// TileEntityHopper.getItemsAroundAPointOrSomethingLikeThat
for (EntityItem item : TileEntityHopper.getCaptureItems(getWorld(), x, y + 1, z)) {
if (item != null && useMasterEnergy(SUCKING_POWER_COST, false)) {
ItemStack stack = item.getEntityItem().copy();
InventoryManipulator.get((IInventory) invInput).addStack(stack);
useMasterEnergy(SUCKING_POWER_COST, true);
item.setDead();
}
}
EntityLivingBase entity = MiscTools.getEntityAt(worldObj, EntityLivingBase.class, getPos().up());
if (entity != null && useMasterEnergy(KILLING_POWER_COST, false))
if (entity.attackEntityFrom(RailcraftDamageSource.CRUSHER, 10))
useMasterEnergy(KILLING_POWER_COST, true);
}
if (isMaster()) {
if (clock % 16 == 0)
processActions();
if (paused)
return;
ItemStack input = InvTools.emptyStack();
ICrusherCraftingManager.ICrusherRecipe recipe = null;
for (IInvSlot slot : InventoryIterator.getVanilla((IInventory) invInput)) {
input = slot.getStack();
if (!InvTools.isEmpty(input)) {
recipe = RailcraftCraftingManager.rockCrusher.getRecipe(input);
if (recipe == null)
recipe = RockCrusherCraftingManager.NULL_RECIPE;
break;
}
}
if (recipe != null)
if (processTime >= PROCESS_TIME) {
isWorking = false;
InventoryCopy tempInv = new InventoryCopy(invOutput);
boolean hasRoom = true;
List<ItemStack> outputs = recipe.getProcessedOutputs();
for (ItemStack output : outputs) {
output = InvTools.moveItemStack(output, tempInv);
if (!InvTools.isEmpty(output)) {
hasRoom = false;
break;
}
}
if (hasRoom) {
for (ItemStack output : outputs) {
InvTools.moveItemStack(output, invOutput);
}
InvTools.removeOneItem(invInput, input);
SoundHelper.playSound(worldObj, null, getPos(), SoundEvents.ENTITY_IRONGOLEM_DEATH, SoundCategory.BLOCKS, 1.0f, worldObj.rand.nextFloat() * 0.25F + 0.7F);
processTime = 0;
}
} else {
isWorking = true;
if (energyStorage != null) {
int energy = energyStorage.extractEnergy(CRUSHING_POWER_COST_PER_TICK, true);
if (energy >= CRUSHING_POWER_COST_PER_TICK) {
processTime++;
energyStorage.extractEnergy(CRUSHING_POWER_COST_PER_TICK, false);
}
} else
processTime++;
}
else {
processTime = 0;
isWorking = false;
}
}
}
}
use of mods.railcraft.common.util.inventory.wrappers.InventoryCopy in project Railcraft by Railcraft.
the class RockCrusherLogic method craftAndPush.
@Override
protected boolean craftAndPush() {
final IRockCrusherCrafter.IRecipe recipe = currentRecipe.orElseThrow(NullPointerException::new);
InventoryCopy tempInv = new InventoryCopy(invOutput);
List<ItemStack> outputs = recipe.pollOutputs(random);
boolean hasRoom = outputs.stream().map(tempInv::addStack).allMatch(InvTools::isEmpty);
if (hasRoom) {
outputs.forEach(invOutput::addStack);
crushed = invInput.removeOneItem(recipe.getInput());
SoundHelper.playSound(theWorldAsserted(), null, getPos(), SoundEvents.ENTITY_IRONGOLEM_DEATH, SoundCategory.BLOCKS, 1.0f, random.nextFloat() * 0.25F + 0.7F);
return true;
}
return false;
}
Aggregations