use of hellfirepvp.astralsorcery.common.tile.TileSpectralRelay 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.tile.TileSpectralRelay 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.tile.TileSpectralRelay 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.tile.TileSpectralRelay in project AstralSorcery by HellFirePvP.
the class TileAltar method nearbyRelays.
@Nonnull
public Set<BlockPos> nearbyRelays() {
Set<BlockPos> eligableRelayOffsets = new HashSet<>();
for (int xx = -3; xx <= 3; xx++) {
for (int zz = -3; zz <= 3; zz++) {
if (xx == 0 && zz == 0) {
// Not that it matters though
continue;
}
BlockPos offset = new BlockPos(xx, 0, zz);
TileSpectralRelay tar = MiscUtils.getTileAt(getWorld(), getPos().add(offset), TileSpectralRelay.class, true);
if (tar != null) {
eligableRelayOffsets.add(getPos().add(offset));
}
}
}
return eligableRelayOffsets;
}
use of hellfirepvp.astralsorcery.common.tile.TileSpectralRelay in project AstralSorcery by HellFirePvP.
the class ActiveSimpleAltarRecipe method tickCraftingRelayInputs.
private boolean tickCraftingRelayInputs(TileAltar altar, List<WrappedIngredient> iIngredients) {
// Start the surrounding stack intake past 66%
int part = totalCraftingTime / 3;
// Every input is evenly spread
int cttPart = part / (iIngredients.size()) + 1;
boolean waitMissingInputs = false;
for (int i = 0; i < iIngredients.size(); i++) {
WrappedIngredient input = iIngredients.get(i);
int index = i;
int offset = part + (index * cttPart);
if (this.ticksCrafting >= offset) {
CraftingFocusStack found = MiscUtils.iterativeSearch(this.focusStacks, fStack -> fStack.getStackIndex() == index);
if (found == null) {
Set<BlockPos> relays = altar.nearbyRelays();
relays.removeIf(pos -> MiscUtils.contains(this.focusStacks, fs -> fs.getRealPosition().equals(pos)));
// No unused relay found for a new focus-stack..
if (relays.isEmpty()) {
waitMissingInputs = true;
continue;
}
BlockPos at = MiscUtils.getRandomEntry(relays, rand);
TileSpectralRelay tar = MiscUtils.getTileAt(altar.getWorld(), at, TileSpectralRelay.class, true);
if (tar == null) {
// We were lied to. lol.
waitMissingInputs = true;
continue;
}
found = new CraftingFocusStack(index, input, at);
this.focusStacks.add(found);
}
TileSpectralRelay tar = MiscUtils.getTileAt(altar.getWorld(), found.getRealPosition(), TileSpectralRelay.class, true);
if (tar == null) {
waitMissingInputs = true;
continue;
}
if (!input.getIngredient().test(tar.getInventory().getStackInSlot(0))) {
waitMissingInputs = true;
}
}
}
return waitMissingInputs;
}
Aggregations