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