forked from TAIGA/TAIGA
* Developement tests for nbt data in traits * Lot of trait changes and better balancing * Traits reworked a bit, new traits added. * First correction of NBT Data in Trait (Soulbound). Is shown twice. Still needs corrections. * Few fixes in traits and new trait "catcher" * Small fix, needs workaround * fixed some catch issues * Fixed Catcher and Reviving Traits, new Trait: Souleater. Updated build.gradle for new TiC Version. * Splitted SoulEater to get the bad touch to an extra trait "Cursed". Added method for using nbt more easily. Changed declaration names of fluids * Some minor changes in Traits, Registry and Utils. * Iron_nugget is replaced with oreDict Item when not loaded via TAIGA. * Beginning of new material integration. Lot of names changed, lot more work to do here. Many null pointer exceptions and no changes of values up to now. * Some Small changes in names, registry and recipes * Some weird stuff I don't remember :D * fixed some things I missed while merging * Rollback to something * More Stuff * fixed some merging stuff * Fixed some misspelled names. Actually working with lots of restrictions. * Rearranged alloys, tried to add blocks / ingots for non-tinker-materials, but they won't work. * Again tried to fix the melting issue, but non-tinker materials still are not able to be casted as a block, ingot or nugget... * Fixed integration of materials without tools. * changed IMC to direct lib calls * removed more IMC, removed redundant code * some reformatting * Alloy integration reworked, needs to be balanced. * updated deps, renamed some func's, added duplicate material check * some more renaming * some reformatting, fixed wrong import, fixed string cmp's * Added images for blocks, ingots, nuggets and dust. Json changes do not work yet. * some reformatting * Removed old json files. Placeholder needed. * Fixed block json, items not working yet. * Fixed my own derp (missing json files) * Reduced materials to ensure unique traits for most of them. Still 30 though, but reduced by 20 more :'( RIP * Changed some generator stuff, not working properly right now! * rewrote offset generation, added some debug command, fixed some stuff * fixed on-surface-generation, made dependencies more flexible * reverted gen-weight back to its normal value * Meteor generator implemented. * fixed generating on ground * optimized a thing * Replaced Uru with Osram, replaced Meteorite with Uru, added Meteorite again for Hull-Material and late game alloy. * Some changes in generation of ores, not ready yet. * Added Cobble Meteorite. Added debug command. Implemented rest of ore generation. Some minor fixes left for generation including balancing. * Some changes for ore generation. Added 2 separate Generic Blocks for meteorite and their cobble variant. * some cleanup in Generator class, added meteor world save handler * Added Textures. Added blockstates and item models. Fixed fluid rendering. * renamed world save data file to be little more specific, removed a unused method * some preps for the upcoming release * First attempt of well balancing material stats. Renamed TiberiumX to Triberium. * Final changes... ready for beta testing * Added missing alloys. * Corrected balancing of ore generation. Still WIP * removed some last debug out * one last reformat
115 lines
3.9 KiB
Java
115 lines
3.9 KiB
Java
package com.sosnitzka.taiga.traits;
|
|
|
|
import com.google.common.collect.ImmutableList;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.util.text.TextFormatting;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.common.util.FakePlayer;
|
|
import slimeknights.tconstruct.library.materials.HeadMaterialStats;
|
|
import slimeknights.tconstruct.library.tools.ToolNBT;
|
|
import slimeknights.tconstruct.library.utils.TagUtil;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Gives the tool bonus stats on crafting.
|
|
* The bonus stats are distributed over time and are more or less random.
|
|
* The stats that will be rewarded are already designated on the first time the tool is crafted
|
|
*/
|
|
public class TraitDecay extends TraitProgressiveStats {
|
|
|
|
protected static int TICK_PER_STAT = 24;
|
|
protected static int DURABILITY_STEP = 10;
|
|
protected static float SPEED_STEP = 0.05f;
|
|
protected static float ATTACK_STEP = 0.05f;
|
|
|
|
public TraitDecay() {
|
|
super("decay", TextFormatting.GREEN);
|
|
}
|
|
|
|
@Override
|
|
public void applyEffect(NBTTagCompound rootCompound, NBTTagCompound modifierTag) {
|
|
// check if we have stats already distributed, and if not add them
|
|
if (!hasPool(rootCompound)) {
|
|
// ok, we need new stats. Let the fun begin!
|
|
StatNBT data = new StatNBT();
|
|
|
|
int statPoints = 800; // we distribute a whopping X points worth of stats!
|
|
for (; statPoints > 0; statPoints--) {
|
|
switch (random.nextInt(3)) {
|
|
// durability
|
|
case 0:
|
|
data.durability += DURABILITY_STEP;
|
|
break;
|
|
// speed
|
|
case 1:
|
|
data.speed += SPEED_STEP;
|
|
break;
|
|
// attack
|
|
case 2:
|
|
data.attack += ATTACK_STEP;
|
|
break;
|
|
}
|
|
}
|
|
|
|
setPool(rootCompound, data);
|
|
}
|
|
|
|
super.applyEffect(rootCompound, modifierTag);
|
|
}
|
|
|
|
@Override
|
|
public void onUpdate(ItemStack tool, World world, Entity entity, int itemSlot, boolean isSelected) {
|
|
if (entity instanceof FakePlayer || entity.worldObj.isRemote) {
|
|
return;
|
|
}
|
|
// every 3.6 seconds we distribute one stat. This means 1h = 1000 applications
|
|
if (entity.ticksExisted % TICK_PER_STAT > 0) {
|
|
return;
|
|
}
|
|
|
|
// we don't update if the player is currently breaking a block because that'd reset it
|
|
if (playerIsBreakingBlock(entity)) {
|
|
return;
|
|
}
|
|
|
|
NBTTagCompound root = TagUtil.getTagSafe(tool);
|
|
StatNBT distributed = getBonus(root);
|
|
ToolNBT data = TagUtil.getToolStats(tool);
|
|
|
|
// attack
|
|
if (entity.ticksExisted % (TICK_PER_STAT * 3) == 0) {
|
|
float A = ATTACK_STEP * random.nextFloat();
|
|
data.attack -= A;
|
|
distributed.attack -= A;
|
|
}
|
|
// speed
|
|
else if (entity.ticksExisted % (TICK_PER_STAT * 2) == 0) {
|
|
float S = SPEED_STEP * random.nextFloat();
|
|
data.speed -= S;
|
|
distributed.speed -= S;
|
|
}
|
|
// durability
|
|
else {
|
|
int D = random.nextInt(DURABILITY_STEP) + 1;
|
|
data.durability -= D;
|
|
distributed.durability -= D;
|
|
}
|
|
|
|
// update tool stats
|
|
TagUtil.setToolTag(root, data.get());
|
|
// update statistics on distributed stats
|
|
setBonus(root, distributed);
|
|
}
|
|
|
|
@Override
|
|
public List<String> getExtraInfo(ItemStack tool, NBTTagCompound modifierTag) {
|
|
StatNBT pool = getBonus(TagUtil.getTagSafe(tool));
|
|
|
|
return ImmutableList.of(HeadMaterialStats.formatDurability(pool.durability),
|
|
HeadMaterialStats.formatMiningSpeed(pool.speed),
|
|
HeadMaterialStats.formatAttack(pool.attack));
|
|
}
|
|
} |