use of hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack in project AstralSorcery by HellFirePvP.
the class ActiveSimpleAltarRecipe method serialize.
@Nonnull
public CompoundNBT serialize() {
CompoundNBT compound = new CompoundNBT();
compound.putString("recipeToCraft", getRecipeToCraft().getId().toString());
compound.putUniqueId("playerCraftingUUID", getPlayerCraftingUUID());
compound.putInt("ticksCrafting", getTicksCrafting());
compound.putInt("totalCraftingTime", getTotalCraftingTime());
compound.putInt("state", getState().ordinal());
compound.put("craftingData", craftingData);
ListNBT list = new ListNBT();
for (CraftingFocusStack stack : this.focusStacks) {
list.add(stack.serialize());
}
compound.put("focusStacks", list);
return compound;
}
use of hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack in project AstralSorcery by HellFirePvP.
the class ActiveSimpleAltarRecipe method consumeInputs.
public void consumeInputs(TileAltar altar) {
TileInventory inv = altar.getInventory();
AltarRecipeGrid grid = this.recipeToCraft.getInputs();
for (int slot = 0; slot < AltarRecipeGrid.MAX_INVENTORY_SIZE; slot++) {
Ingredient input = grid.getIngredient(slot);
if (input instanceof FluidIngredient) {
ItemStack stack = inv.getStackInSlot(slot);
FluidActionResult far = FluidUtil.tryEmptyContainer(stack, VoidFluidHandler.INSTANCE, FluidAttributes.BUCKET_VOLUME, null, true);
if (far.isSuccess()) {
inv.setStackInSlot(slot, far.getResult());
}
} else {
ItemUtils.decrementItem(inv, slot, altar::dropItemOnTop);
}
}
for (CraftingFocusStack input : this.focusStacks) {
TileSpectralRelay tar = MiscUtils.getTileAt(altar.getWorld(), input.getRealPosition(), TileSpectralRelay.class, true);
if (tar != null) {
TileInventory tarInventory = tar.getInventory();
if (input.getInput() != null && input.getInput().getIngredient() instanceof FluidIngredient) {
ItemStack stack = tarInventory.getStackInSlot(0);
FluidActionResult far = FluidUtil.tryEmptyContainer(stack, VoidFluidHandler.INSTANCE, FluidAttributes.BUCKET_VOLUME, null, true);
if (far.isSuccess()) {
tarInventory.setStackInSlot(0, far.getResult());
}
} else {
ItemUtils.decrementItem(tarInventory, 0, altar::dropItemOnTop);
}
}
}
}
use of hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack in project AstralSorcery by HellFirePvP.
the class BuiltInEffectTraitRelayHighlight method onTESR.
@Override
@OnlyIn(Dist.CLIENT)
public void onTESR(TileAltar altar, ActiveSimpleAltarRecipe.CraftingState state, MatrixStack renderStack, IRenderTypeBuffer buffer, float pTicks, int combinedLight) {
ActiveSimpleAltarRecipe activeRecipe = altar.getActiveRecipe();
if (activeRecipe != null) {
List<WrappedIngredient> additionalIngredients = activeRecipe.getRecipeToCraft().getRelayInputs();
List<CraftingFocusStack> focusStacks = activeRecipe.getFocusStacks();
for (CraftingFocusStack stack : focusStacks) {
if (stack.getStackIndex() < 0 || stack.getStackIndex() >= additionalIngredients.size()) {
continue;
}
WrappedIngredient match = additionalIngredients.get(stack.getStackIndex());
BlockPos offset = stack.getRealPosition().subtract(altar.getPos());
TileSpectralRelay relay = MiscUtils.getTileAt(altar.getWorld(), stack.getRealPosition(), TileSpectralRelay.class, false);
if (relay == null || (!match.getIngredient().test(relay.getInventory().getStackInSlot(0)))) {
ItemStack potential = match.getRandomMatchingStack(getClientTick());
renderStack.push();
renderStack.translate(0.5 + offset.getX(), 0.35 + offset.getY(), 0.5 + offset.getZ());
RenderingUtils.renderTranslucentItemStack(potential, renderStack, pTicks);
renderStack.pop();
}
}
}
}
use of hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack in project AstralSorcery by HellFirePvP.
the class BuiltInEffectTraitRelayHighlight method onTick.
@Override
@OnlyIn(Dist.CLIENT)
public void onTick(TileAltar altar, ActiveSimpleAltarRecipe.CraftingState state) {
ActiveSimpleAltarRecipe recipe = altar.getActiveRecipe();
if (recipe != null) {
List<WrappedIngredient> additionalIngredients = recipe.getRecipeToCraft().getRelayInputs();
for (CraftingFocusStack stack : recipe.getFocusStacks()) {
if (stack.getStackIndex() < 0 || stack.getStackIndex() >= additionalIngredients.size()) {
continue;
}
WrappedIngredient match = additionalIngredients.get(stack.getStackIndex());
TileSpectralRelay relay = MiscUtils.getTileAt(altar.getWorld(), stack.getRealPosition(), TileSpectralRelay.class, false);
if (relay != null) {
ItemStack in = relay.getInventory().getStackInSlot(0);
if (!in.isEmpty() && match.getIngredient().test(in)) {
Color color = ColorizationHelper.getColor(in).orElse(ColorsAS.CELESTIAL_CRYSTAL);
playLightbeam(altar, relay, color);
playRelayHighlightParticles(relay, color);
if (rand.nextInt(4) == 0) {
EffectHelper.of(EffectTemplatesAS.GENERIC_PARTICLE).spawn(new Vector3(altar).add(-3 + rand.nextInt(7), 0.02, -3 + rand.nextInt(7))).color(VFXColorFunction.constant(color)).alpha(VFXAlphaFunction.FADE_OUT).setScaleMultiplier(0.15F + rand.nextFloat() * 0.2F);
}
} else {
ItemStack chosen = match.getRandomMatchingStack(getClientTick());
Color color = ColorizationHelper.getColor(chosen).orElse(ColorsAS.CELESTIAL_CRYSTAL);
playLightbeam(altar, relay, color);
playRelayHighlightParticles(relay, color);
}
}
}
}
}
use of hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack in project AstralSorcery by HellFirePvP.
the class ActiveSimpleAltarRecipe method deserialize.
@Nullable
public static ActiveSimpleAltarRecipe deserialize(CompoundNBT compound, @Nullable ActiveSimpleAltarRecipe previous) {
RecipeManager mgr = RecipeHelper.getRecipeManager();
if (mgr == null) {
return null;
}
ResourceLocation recipeKey = new ResourceLocation(compound.getString("recipeToCraft"));
Optional<?> recipe = mgr.getRecipe(recipeKey);
if (!recipe.isPresent() || !(recipe.get() instanceof SimpleAltarRecipe)) {
AstralSorcery.log.info("Recipe with unknown/invalid name found: " + recipeKey);
return null;
}
SimpleAltarRecipe altarRecipe = (SimpleAltarRecipe) recipe.get();
UUID uuidCraft = compound.getUniqueId("playerCraftingUUID");
int tick = compound.getInt("ticksCrafting");
int total = compound.getInt("totalCraftingTime");
CraftingState state = CraftingState.values()[compound.getInt("state")];
List<CraftingFocusStack> stacks = new LinkedList<>();
ListNBT listStacks = compound.getList("focusStacks", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < listStacks.size(); i++) {
stacks.add(new CraftingFocusStack(listStacks.getCompound(i)));
}
ActiveSimpleAltarRecipe task = new ActiveSimpleAltarRecipe(altarRecipe, uuidCraft);
task.ticksCrafting = tick;
task.totalCraftingTime = total;
task.setState(state);
task.craftingData = compound.getCompound("craftingData");
task.focusStacks = stacks;
task.recoverContainedEffects(previous);
return task;
}
Aggregations