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;
}
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());
}
}
}
}
}
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);
}
}
}
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;
}
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));
}
}
}
}
}
Aggregations