Search in sources :

Example 1 with ItemCrystalBase

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

the class AttuneCrystalRecipe method isApplicableCrystal.

public static boolean isApplicableCrystal(ItemEntity entity, IConstellation cst) {
    ItemStack stack;
    if (entity.isAlive() && !(stack = entity.getItem()).isEmpty() && stack.getItem() instanceof ItemCrystalBase) {
        if (!(stack.getItem() instanceof ConstellationItem)) {
            return cst instanceof IWeakConstellation;
        } else {
            IWeakConstellation attuned = ((ConstellationItem) stack.getItem()).getAttunedConstellation(stack);
            IMinorConstellation trait = ((ConstellationItem) stack.getItem()).getTraitConstellation(stack);
            if (attuned == null && cst instanceof IWeakConstellation) {
                return true;
            } else if (trait == null && cst instanceof IMinorConstellation) {
                return true;
            }
        }
    }
    return false;
}
Also used : ItemCrystalBase(hellfirepvp.astralsorcery.common.item.crystal.ItemCrystalBase) IMinorConstellation(hellfirepvp.astralsorcery.common.constellation.IMinorConstellation) ItemStack(net.minecraft.item.ItemStack) ConstellationItem(hellfirepvp.astralsorcery.common.constellation.ConstellationItem) IWeakConstellation(hellfirepvp.astralsorcery.common.constellation.IWeakConstellation)

Example 2 with ItemCrystalBase

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

the class ActiveCrystalAttunementRecipe method finishRecipe.

@Override
public void finishRecipe(TileAttunementAltar altar) {
    ItemEntity crystal = this.getEntity(altar.getWorld());
    if (crystal != null) {
        ItemStack stack = crystal.getItem();
        if (!(stack.getItem() instanceof ConstellationItem) && stack.getItem() instanceof ItemCrystalBase) {
            CompoundNBT tag = stack.getTag();
            stack = new ItemStack(((ItemCrystalBase) stack.getItem()).getTunedItemVariant(), stack.getCount());
            stack.setTag(tag);
        }
        if (stack.getItem() instanceof ConstellationItem) {
            IWeakConstellation attuned = ((ConstellationItem) stack.getItem()).getAttunedConstellation(stack);
            IMinorConstellation trait = ((ConstellationItem) stack.getItem()).getTraitConstellation(stack);
            if (attuned == null) {
                if (altar.getActiveConstellation() instanceof IWeakConstellation) {
                    ((ConstellationItem) stack.getItem()).setAttunedConstellation(stack, (IWeakConstellation) altar.getActiveConstellation());
                }
            } else if (trait == null) {
                if (altar.getActiveConstellation() instanceof IMinorConstellation) {
                    ((ConstellationItem) stack.getItem()).setTraitConstellation(stack, (IMinorConstellation) altar.getActiveConstellation());
                }
            }
            crystal.setItem(stack);
            UUID throwerUUID = crystal.getThrowerId();
            if (throwerUUID != null) {
                PlayerEntity thrower = altar.getWorld().getPlayerByUuid(throwerUUID);
                if (thrower instanceof ServerPlayerEntity) {
                    AdvancementsAS.ATTUNE_CRYSTAL.trigger((ServerPlayerEntity) thrower, altar.getActiveConstellation());
                }
            }
        }
    }
}
Also used : ItemEntity(net.minecraft.entity.item.ItemEntity) CompoundNBT(net.minecraft.nbt.CompoundNBT) ItemCrystalBase(hellfirepvp.astralsorcery.common.item.crystal.ItemCrystalBase) IMinorConstellation(hellfirepvp.astralsorcery.common.constellation.IMinorConstellation) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ItemStack(net.minecraft.item.ItemStack) UUID(java.util.UUID) ConstellationItem(hellfirepvp.astralsorcery.common.constellation.ConstellationItem) IWeakConstellation(hellfirepvp.astralsorcery.common.constellation.IWeakConstellation) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 3 with ItemCrystalBase

use of hellfirepvp.astralsorcery.common.item.crystal.ItemCrystalBase 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 4 with ItemCrystalBase

use of hellfirepvp.astralsorcery.common.item.crystal.ItemCrystalBase 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 5 with ItemCrystalBase

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

the class FormCelestialCrystalClusterRecipe method doServerCraftTick.

@Override
public void doServerCraftTick(ItemEntity trigger, World world, BlockPos at) {
    Random r = new Random(MathHelper.getPositionRandom(at));
    if (!world.isRemote() && getAndIncrementCraftingTick(trigger) > 50 + r.nextInt(20)) {
        ItemStack crystalFound;
        if (consumeItemEntityInBlock(world, at, ItemsAS.STARDUST) != null && (crystalFound = consumeItemEntityInBlock(world, at, 1, stack -> stack.getItem() instanceof ItemCrystalBase)) != null) {
            if (world.setBlockState(at, BlocksAS.CELESTIAL_CRYSTAL_CLUSTER.getDefaultState())) {
                TileCelestialCrystals cluster = MiscUtils.getTileAt(world, at, TileCelestialCrystals.class, true);
                if (cluster != null) {
                    CrystalAttributes attr = ((CrystalAttributeItem) crystalFound.getItem()).getAttributes(crystalFound);
                    ItemStack targetCrystal = new ItemStack(ItemsAS.CELESTIAL_CRYSTAL);
                    ((CrystalAttributeItem) crystalFound.getItem()).setAttributes(targetCrystal, attr);
                    cluster.setAttributes(CrystalGenerator.upgradeProperties(targetCrystal));
                }
            }
        }
    }
}
Also used : CrystalAttributes(hellfirepvp.astralsorcery.common.crystal.CrystalAttributes) ItemCrystalBase(hellfirepvp.astralsorcery.common.item.crystal.ItemCrystalBase) ItemStack(net.minecraft.item.ItemStack) CrystalAttributeItem(hellfirepvp.astralsorcery.common.crystal.CrystalAttributeItem) TileCelestialCrystals(hellfirepvp.astralsorcery.common.tile.TileCelestialCrystals)

Aggregations

ItemCrystalBase (hellfirepvp.astralsorcery.common.item.crystal.ItemCrystalBase)7 ItemStack (net.minecraft.item.ItemStack)7 CrystalAttributes (hellfirepvp.astralsorcery.common.crystal.CrystalAttributes)5 ConstellationItem (hellfirepvp.astralsorcery.common.constellation.ConstellationItem)2 IMinorConstellation (hellfirepvp.astralsorcery.common.constellation.IMinorConstellation)2 IWeakConstellation (hellfirepvp.astralsorcery.common.constellation.IWeakConstellation)2 ItemEntity (net.minecraft.entity.item.ItemEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)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 EffectTemplatesAS (hellfirepvp.astralsorcery.client.lib.EffectTemplatesAS)1 CrystalIngredient (hellfirepvp.astralsorcery.common.crafting.helper.ingredient.CrystalIngredient)1 CrystalAttributeItem (hellfirepvp.astralsorcery.common.crystal.CrystalAttributeItem)1 CrystalProperty (hellfirepvp.astralsorcery.common.crystal.CrystalProperty)1 CraftingConfig (hellfirepvp.astralsorcery.common.data.config.entry.CraftingConfig)1 ItemChisel (hellfirepvp.astralsorcery.common.item.ItemChisel)1 TileCelestialCrystals (hellfirepvp.astralsorcery.common.tile.TileCelestialCrystals)1