Search in sources :

Example 1 with CrystalAttributes

use of hellfirepvp.astralsorcery.common.crystal.CrystalAttributes in project AstralSorcery by HellFirePvP.

the class MergeCrystalsRecipe method doServerCraftTick.

@Override
public void doServerCraftTick(ItemEntity trigger, World world, BlockPos at) {
    Random r = new Random(MathHelper.getPositionRandom(at));
    if (!world.isRemote() && getAndIncrementCraftingTick(trigger) > 40 + r.nextInt(20)) {
        ItemStack crystalFoundOne, crystalFoundTwo;
        if ((crystalFoundOne = consumeItemEntityInBlock(world, at, 1, stack -> stack.getItem() instanceof ItemCrystalBase)) != null && (crystalFoundTwo = consumeItemEntityInBlock(world, at, 1, stack -> stack.getItem() instanceof ItemCrystalBase)) != null && world.setBlockState(at, Blocks.AIR.getDefaultState(), Constants.BlockFlags.DEFAULT_AND_RERENDER)) {
            ItemCrystalBase crystalOne = (ItemCrystalBase) crystalFoundOne.getItem();
            CrystalAttributes attrOne = crystalOne.getAttributes(crystalFoundOne);
            attrOne = attrOne != null ? attrOne : CrystalAttributes.Builder.newBuilder(false).build();
            ItemCrystalBase crystalTwo = (ItemCrystalBase) crystalFoundTwo.getItem();
            CrystalAttributes attrTwo = crystalTwo.getAttributes(crystalFoundTwo);
            attrTwo = attrTwo != null ? attrTwo : CrystalAttributes.Builder.newBuilder(false).build();
            CrystalAttributes mergeTo = attrOne.getTotalTierLevel() >= attrTwo.getTotalTierLevel() ? attrOne : attrTwo;
            CrystalAttributes mergeFrom = attrOne.getTotalTierLevel() >= attrTwo.getTotalTierLevel() ? attrTwo : attrOne;
            ItemStack resultStack = attrOne.getTotalTierLevel() >= attrTwo.getTotalTierLevel() ? crystalFoundOne.copy() : crystalFoundTwo.copy();
            ItemCrystalBase resultCrystal = (ItemCrystalBase) resultStack.getItem();
            CrystalAttributes.Builder resultBuilder = CrystalAttributes.Builder.newBuilder(false).addAll(mergeTo);
            int freeProperties = resultCrystal.getMaxPropertyTiers() - mergeTo.getTotalTierLevel();
            int copyAmount = Math.min(freeProperties, mergeFrom.getTotalTierLevel());
            int mergeCount = 0;
            for (int i = 0; i < copyAmount; i++) {
                CrystalAttributes.Attribute attr = MiscUtils.getWeightedRandomEntry(mergeFrom.getCrystalAttributes(), rand, CrystalAttributes.Attribute::getTier);
                if (attr != null) {
                    mergeFrom = mergeFrom.modifyLevel(attr.getProperty(), -1);
                    if (rand.nextFloat() <= (1F - Math.min(mergeCount, 3) * 0.25F)) {
                        resultBuilder.addProperty(attr.getProperty(), 1);
                    }
                    mergeCount++;
                }
            }
            resultCrystal.setAttributes(resultStack, resultBuilder.build());
            ItemUtils.dropItemNaturally(world, trigger.getPosX(), trigger.getPosY(), trigger.getPosZ(), resultStack);
        }
    }
}
Also used : Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) Ingredient(net.minecraft.item.crafting.Ingredient) java.util(java.util) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) Constants(net.minecraftforge.common.util.Constants) CraftingConfig(hellfirepvp.astralsorcery.common.data.config.entry.CraftingConfig) Dist(net.minecraftforge.api.distmarker.Dist) ItemStack(net.minecraft.item.ItemStack) EffectTemplatesAS(hellfirepvp.astralsorcery.client.lib.EffectTemplatesAS) AstralSorcery(hellfirepvp.astralsorcery.AstralSorcery) CrystalIngredient(hellfirepvp.astralsorcery.common.crafting.helper.ingredient.CrystalIngredient) MiscUtils(hellfirepvp.astralsorcery.common.util.MiscUtils) VFXAlphaFunction(hellfirepvp.astralsorcery.client.effect.function.VFXAlphaFunction) Entity(net.minecraft.entity.Entity) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) VFXMotionController(hellfirepvp.astralsorcery.client.effect.function.VFXMotionController) EffectHelper(hellfirepvp.astralsorcery.client.effect.handler.EffectHelper) Blocks(net.minecraft.block.Blocks) ItemCrystalBase(hellfirepvp.astralsorcery.common.item.crystal.ItemCrystalBase) CrystalAttributes(hellfirepvp.astralsorcery.common.crystal.CrystalAttributes) VFXColorFunction(hellfirepvp.astralsorcery.client.effect.function.VFXColorFunction) MathHelper(net.minecraft.util.math.MathHelper) ItemEntity(net.minecraft.entity.item.ItemEntity) ItemUtils(hellfirepvp.astralsorcery.common.util.item.ItemUtils) CrystalAttributes(hellfirepvp.astralsorcery.common.crystal.CrystalAttributes) ItemCrystalBase(hellfirepvp.astralsorcery.common.item.crystal.ItemCrystalBase) ItemStack(net.minecraft.item.ItemStack)

Example 2 with CrystalAttributes

use of hellfirepvp.astralsorcery.common.crystal.CrystalAttributes in project AstralSorcery by HellFirePvP.

the class EntityCrystal method hitByEntity.

@Override
public boolean hitByEntity(Entity entity) {
    if (!this.getEntityWorld().isRemote() && entity instanceof ServerPlayerEntity) {
        ItemStack held = ((ServerPlayerEntity) entity).getHeldItem(Hand.MAIN_HAND);
        if (!held.isEmpty() && held.getItem() instanceof ItemChisel) {
            ItemStack thisStack = this.getItem();
            if (!thisStack.isEmpty() && thisStack.getItem() instanceof ItemCrystalBase) {
                CrystalAttributes thisAttributes = ((ItemCrystalBase) thisStack.getItem()).getAttributes(thisStack);
                if (thisAttributes != null) {
                    // TODO chipping sound ?
                    boolean doDamage = false;
                    if (rand.nextFloat() < 0.35F) {
                        int fortuneLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, held);
                        doDamage = this.splitCrystal(thisAttributes, fortuneLevel);
                    }
                    if (doDamage || rand.nextFloat() < 0.35F) {
                        held.damageItem(1, (PlayerEntity) entity, (player) -> player.sendBreakAnimation(Hand.MAIN_HAND));
                    }
                }
            }
        }
    }
    return true;
}
Also used : CrystalAttributes(hellfirepvp.astralsorcery.common.crystal.CrystalAttributes) ItemChisel(hellfirepvp.astralsorcery.common.item.ItemChisel) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ItemCrystalBase(hellfirepvp.astralsorcery.common.item.crystal.ItemCrystalBase) ItemStack(net.minecraft.item.ItemStack)

Example 3 with CrystalAttributes

use of hellfirepvp.astralsorcery.common.crystal.CrystalAttributes in project AstralSorcery by HellFirePvP.

the class BlockCollectorCrystal method addInformation.

@Override
@OnlyIn(Dist.CLIENT)
public void addInformation(ItemStack stack, @Nullable IBlockReader world, List<ITextComponent> toolTip, ITooltipFlag flag) {
    super.addInformation(stack, world, toolTip, flag);
    CrystalAttributes attr = CrystalAttributes.getCrystalAttributes(stack);
    CrystalAttributes.TooltipResult result = null;
    if (attr != null) {
        result = attr.addTooltip(toolTip, CalculationContext.Builder.withSource(new AttunedSourceInstance(CrystalPropertiesAS.Sources.SOURCE_TILE_COLLECTOR_CRYSTAL, ((ConstellationItem) stack.getItem()).getAttunedConstellation(stack))).addUsage(CrystalPropertiesAS.Usages.USE_COLLECTOR_CRYSTAL).addUsage(CrystalPropertiesAS.Usages.USE_LENS_TRANSFER).build());
    }
    if (result != null) {
        PlayerProgress clientProgress = ResearchHelper.getClientProgress();
        ProgressionTier tier = clientProgress.getTierReached();
        boolean addedMissing = result != CrystalAttributes.TooltipResult.ADDED_ALL;
        IWeakConstellation c = ((ConstellationItem) stack.getItem()).getAttunedConstellation(stack);
        if (c != null) {
            if (GatedKnowledge.COLLECTOR_TYPE.canSee(tier) && clientProgress.hasConstellationDiscovered(c)) {
                toolTip.add(new TranslationTextComponent("crystal.info.astralsorcery.collect.type", c.getConstellationName().mergeStyle(TextFormatting.BLUE)).mergeStyle(TextFormatting.GRAY));
            } else if (!addedMissing) {
                toolTip.add(new TranslationTextComponent("astralsorcery.progress.missing.knowledge").mergeStyle(TextFormatting.GRAY));
            }
        }
        IMinorConstellation tr = ((ConstellationItem) stack.getItem()).getTraitConstellation(stack);
        if (tr != null) {
            if (GatedKnowledge.CRYSTAL_TRAIT.canSee(tier) && clientProgress.hasConstellationDiscovered(tr)) {
                toolTip.add(new TranslationTextComponent("crystal.info.astralsorcery.trait", tr.getConstellationName().mergeStyle(TextFormatting.BLUE)).mergeStyle(TextFormatting.GRAY));
            } else if (!addedMissing) {
                toolTip.add(new TranslationTextComponent("astralsorcery.progress.missing.knowledge").mergeStyle(TextFormatting.GRAY));
            }
        }
    }
}
Also used : CrystalAttributes(hellfirepvp.astralsorcery.common.crystal.CrystalAttributes) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) AttunedSourceInstance(hellfirepvp.astralsorcery.common.crystal.source.AttunedSourceInstance) IMinorConstellation(hellfirepvp.astralsorcery.common.constellation.IMinorConstellation) PlayerProgress(hellfirepvp.astralsorcery.common.data.research.PlayerProgress) ProgressionTier(hellfirepvp.astralsorcery.common.data.research.ProgressionTier) IWeakConstellation(hellfirepvp.astralsorcery.common.constellation.IWeakConstellation) ConstellationItem(hellfirepvp.astralsorcery.common.constellation.ConstellationItem) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 4 with CrystalAttributes

use of hellfirepvp.astralsorcery.common.crystal.CrystalAttributes in project AstralSorcery by HellFirePvP.

the class ConstellationBaseMergeStatsRecipe method setStats.

private void setStats(ItemStack out, Iterable<ItemStack> inventoryContents) {
    if (!(out.getItem() instanceof CrystalAttributeItem)) {
        return;
    }
    CrystalAttributes.Builder builder = CrystalAttributes.Builder.newBuilder(true);
    for (ItemStack stack : inventoryContents) {
        if (stack.getItem() instanceof CrystalAttributeItem) {
            CrystalAttributes attr = ((CrystalAttributeItem) stack.getItem()).getAttributes(stack);
            if (attr != null) {
                builder.addAll(attr);
            }
        }
    }
    CrystalAttributes attr = builder.build();
    if (!attr.isEmpty()) {
        ((CrystalAttributeItem) out.getItem()).setAttributes(out, attr);
    }
}
Also used : CrystalAttributes(hellfirepvp.astralsorcery.common.crystal.CrystalAttributes) CrystalAttributeItem(hellfirepvp.astralsorcery.common.crystal.CrystalAttributeItem) ItemStack(net.minecraft.item.ItemStack)

Example 5 with CrystalAttributes

use of hellfirepvp.astralsorcery.common.crystal.CrystalAttributes in project AstralSorcery by HellFirePvP.

the class ItemCrystalTierItem method getDestroySpeed.

@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
    float str = super.getDestroySpeed(stack, state);
    if (getToolTypes(stack).stream().noneMatch(state::isToolEffective) && !isToolEfficientAgainst(state) && !this.effectiveMaterials.contains(state.getMaterial())) {
        return str;
    }
    str *= CrystalToolTier.getInstance().getEfficiency();
    CrystalAttributes attr = getAttributes(stack);
    if (attr != null) {
        return CrystalCalculations.getToolEfficiency(str, stack);
    }
    return str;
}
Also used : CrystalAttributes(hellfirepvp.astralsorcery.common.crystal.CrystalAttributes)

Aggregations

CrystalAttributes (hellfirepvp.astralsorcery.common.crystal.CrystalAttributes)23 ItemStack (net.minecraft.item.ItemStack)9 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)8 CrystalAttributeItem (hellfirepvp.astralsorcery.common.crystal.CrystalAttributeItem)5 ItemCrystalBase (hellfirepvp.astralsorcery.common.item.crystal.ItemCrystalBase)5 IWeakConstellation (hellfirepvp.astralsorcery.common.constellation.IWeakConstellation)3 CrystalAttributeGenItem (hellfirepvp.astralsorcery.common.crystal.CrystalAttributeGenItem)3 BlockPos (net.minecraft.util.math.BlockPos)3 CrystalProperty (hellfirepvp.astralsorcery.common.crystal.CrystalProperty)2 Vector3 (hellfirepvp.astralsorcery.common.util.data.Vector3)2 AstralSorcery (hellfirepvp.astralsorcery.AstralSorcery)1 VFXAlphaFunction (hellfirepvp.astralsorcery.client.effect.function.VFXAlphaFunction)1 VFXColorFunction (hellfirepvp.astralsorcery.client.effect.function.VFXColorFunction)1 VFXMotionController (hellfirepvp.astralsorcery.client.effect.function.VFXMotionController)1 EffectHelper (hellfirepvp.astralsorcery.client.effect.handler.EffectHelper)1 FXSpritePlane (hellfirepvp.astralsorcery.client.effect.vfx.FXSpritePlane)1 EffectTemplatesAS (hellfirepvp.astralsorcery.client.lib.EffectTemplatesAS)1 ConstellationItem (hellfirepvp.astralsorcery.common.constellation.ConstellationItem)1 IMinorConstellation (hellfirepvp.astralsorcery.common.constellation.IMinorConstellation)1 ConstellationEffect (hellfirepvp.astralsorcery.common.constellation.effect.ConstellationEffect)1