use of com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel in project Create by Creators-of-Create.
the class BasinRecipe method apply.
private static boolean apply(BasinTileEntity basin, Recipe<?> recipe, boolean test) {
boolean isBasinRecipe = recipe instanceof BasinRecipe;
IItemHandler availableItems = basin.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null);
IFluidHandler availableFluids = basin.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).orElse(null);
if (availableItems == null || availableFluids == null)
return false;
HeatLevel heat = BasinTileEntity.getHeatLevelOf(basin.getLevel().getBlockState(basin.getBlockPos().below(1)));
if (isBasinRecipe && !((BasinRecipe) recipe).getRequiredHeat().testBlazeBurner(heat))
return false;
List<ItemStack> recipeOutputItems = new ArrayList<>();
List<FluidStack> recipeOutputFluids = new ArrayList<>();
List<Ingredient> ingredients = new LinkedList<>(recipe.getIngredients());
ingredients.sort(Comparator.comparingInt(i -> i.getItems().length));
List<FluidIngredient> fluidIngredients = isBasinRecipe ? ((BasinRecipe) recipe).getFluidIngredients() : Collections.emptyList();
for (boolean simulate : Iterate.trueAndFalse) {
if (!simulate && test)
return true;
int[] extractedItemsFromSlot = new int[availableItems.getSlots()];
int[] extractedFluidsFromTank = new int[availableFluids.getTanks()];
Ingredients: for (int i = 0; i < ingredients.size(); i++) {
Ingredient ingredient = ingredients.get(i);
for (int slot = 0; slot < availableItems.getSlots(); slot++) {
if (simulate && availableItems.getStackInSlot(slot).getCount() <= extractedItemsFromSlot[slot])
continue;
ItemStack extracted = availableItems.extractItem(slot, 1, true);
if (!ingredient.test(extracted))
continue;
// Catalyst items are never consumed
if (extracted.hasContainerItem() && extracted.getContainerItem().sameItem(extracted))
continue Ingredients;
if (!simulate)
availableItems.extractItem(slot, 1, false);
else if (extracted.hasContainerItem())
recipeOutputItems.add(extracted.getContainerItem().copy());
extractedItemsFromSlot[slot]++;
continue Ingredients;
}
// something wasn't found
return false;
}
boolean fluidsAffected = false;
FluidIngredients: for (int i = 0; i < fluidIngredients.size(); i++) {
FluidIngredient fluidIngredient = fluidIngredients.get(i);
int amountRequired = fluidIngredient.getRequiredAmount();
for (int tank = 0; tank < availableFluids.getTanks(); tank++) {
FluidStack fluidStack = availableFluids.getFluidInTank(tank);
if (simulate && fluidStack.getAmount() <= extractedFluidsFromTank[tank])
continue;
if (!fluidIngredient.test(fluidStack))
continue;
int drainedAmount = Math.min(amountRequired, fluidStack.getAmount());
if (!simulate) {
fluidStack.shrink(drainedAmount);
fluidsAffected = true;
}
amountRequired -= drainedAmount;
if (amountRequired != 0)
continue;
extractedFluidsFromTank[tank] += drainedAmount;
continue FluidIngredients;
}
// something wasn't found
return false;
}
if (fluidsAffected) {
basin.getBehaviour(SmartFluidTankBehaviour.INPUT).forEach(TankSegment::onFluidStackChanged);
basin.getBehaviour(SmartFluidTankBehaviour.OUTPUT).forEach(TankSegment::onFluidStackChanged);
}
if (simulate) {
if (recipe instanceof BasinRecipe) {
recipeOutputItems.addAll(((BasinRecipe) recipe).rollResults());
recipeOutputFluids.addAll(((BasinRecipe) recipe).getFluidResults());
} else
recipeOutputItems.add(recipe.getResultItem());
}
if (!basin.acceptOutputs(recipeOutputItems, recipeOutputFluids, simulate))
return false;
}
return true;
}
use of com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel in project Create by Creators-of-Create.
the class BlazeBurnerTileEntity method getHeatLevelFromFuelType.
protected HeatLevel getHeatLevelFromFuelType(FuelType fuel) {
HeatLevel level = HeatLevel.SMOULDERING;
switch(activeFuel) {
case SPECIAL:
level = HeatLevel.SEETHING;
break;
case NORMAL:
boolean lowPercent = (double) remainingBurnTime / MAX_HEAT_CAPACITY < 0.1;
level = lowPercent ? HeatLevel.FADING : HeatLevel.KINDLED;
break;
default:
case NONE:
break;
}
return level;
}
use of com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel in project Create by Creators-of-Create.
the class BlazeBurnerRenderer method renderSafe.
@Override
protected void renderSafe(BlazeBurnerTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
HeatLevel heatLevel = te.getHeatLevelFromBlock();
if (heatLevel == HeatLevel.NONE)
return;
float renderTick = AnimationTickHolder.getRenderTime(te.getLevel()) + (te.hashCode() % 13) * 16f;
float offset = (Mth.sin((float) ((renderTick / 16f) % (2 * Math.PI))) + .5f) / 16f;
PartialModel blazeModel = AllBlockPartials.BLAZES.get(heatLevel);
SuperByteBuffer blazeBuffer = CachedBufferer.partial(blazeModel, te.getBlockState());
blazeBuffer.rotateCentered(Direction.UP, AngleHelper.rad(te.headAngle.getValue(partialTicks)));
blazeBuffer.translate(0, offset, 0);
blazeBuffer.light(LightTexture.FULL_BRIGHT).renderInto(ms, buffer.getBuffer(RenderType.solid()));
}
use of com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel in project Create by Creators-of-Create.
the class BlazeBurnerTileEntity method setBlockHeat.
protected void setBlockHeat(HeatLevel heat) {
HeatLevel inBlockState = getHeatLevelFromBlock();
if (inBlockState == heat)
return;
level.setBlockAndUpdate(worldPosition, getBlockState().setValue(BlazeBurnerBlock.HEAT_LEVEL, heat));
notifyUpdate();
}
use of com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel in project Create by Creators-of-Create.
the class BlazeBurnerTileEntity method tryUpdateFuel.
/**
* @return true if the heater updated its burn time and an item should be
* consumed
*/
protected boolean tryUpdateFuel(ItemStack itemStack, boolean forceOverflow, boolean simulate) {
if (isCreative)
return false;
FuelType newFuel = FuelType.NONE;
int newBurnTime;
if (AllItemTags.BLAZE_BURNER_FUEL_SPECIAL.matches(itemStack)) {
newBurnTime = 1000;
newFuel = FuelType.SPECIAL;
} else {
newBurnTime = ForgeHooks.getBurnTime(itemStack, null);
if (newBurnTime > 0)
newFuel = FuelType.NORMAL;
else if (AllItemTags.BLAZE_BURNER_FUEL_REGULAR.matches(itemStack)) {
// Same as coal
newBurnTime = 1600;
newFuel = FuelType.NORMAL;
}
}
if (newFuel == FuelType.NONE)
return false;
if (newFuel.ordinal() < activeFuel.ordinal())
return false;
if (activeFuel == FuelType.SPECIAL && remainingBurnTime > 20)
return false;
if (newFuel == activeFuel) {
if (remainingBurnTime + newBurnTime > MAX_HEAT_CAPACITY && !forceOverflow)
return false;
newBurnTime = Mth.clamp(remainingBurnTime + newBurnTime, 0, MAX_HEAT_CAPACITY);
}
if (simulate)
return true;
activeFuel = newFuel;
remainingBurnTime = newBurnTime;
if (level.isClientSide) {
HeatLevel level = getHeatLevelFromFuelType(activeFuel);
for (int i = 0; i < 20; i++) spawnParticles(level, 1 + (.25 * (i / 4)));
} else {
playSound();
updateBlockState();
}
return true;
}
Aggregations