[1.2] Material rework (#60)

* 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
This commit is contained in:
Giovanni Harting
2016-12-05 20:34:02 +01:00
committed by GitHub
parent 9554b56931
commit 826ab1cf3a
625 changed files with 3540 additions and 3279 deletions

View File

@@ -43,7 +43,7 @@ public class TraitAnalysing extends AbstractTrait {
@SubscribeEvent
public void onMobDrops(LivingDropsEvent event) {
World w = event.getEntity().getEntityWorld();
if (event.getSource().getEntity() instanceof EntityPlayer) {
if (random.nextFloat() < .1f && event.getSource().getEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.getSource().getEntity();
if (!w.isRemote && event.getEntity() instanceof EntityMob && TinkerUtil.hasTrait(TagUtil.getTagSafe(player.getHeldItemMainhand()), identifier)) {
event.getDrops().clear();
@@ -52,13 +52,13 @@ public class TraitAnalysing extends AbstractTrait {
}
private int getUpdateXP(int xp) {
float exp = random.nextFloat() * random.nextFloat() * random.nextFloat() * (xp + 18) * 50;
float exp = random.nextFloat() * random.nextFloat() * random.nextFloat() * (xp + random.nextInt(xp) * (1 + random.nextFloat()));
return Math.round(exp);
}
@Override
public void blockHarvestDrops(ItemStack tool, BlockEvent.HarvestDropsEvent event) {
if (random.nextFloat() < 0.85) {
if (random.nextFloat() < 0.1) {
event.getDrops().clear();
}
}

View File

@@ -1,12 +1,19 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
import slimeknights.tconstruct.library.utils.ToolHelper;
import static com.sosnitzka.taiga.util.Utils.isNight;
@@ -15,21 +22,36 @@ public class TraitArcane extends AbstractTrait {
public TraitArcane() {
super("arcane", TextFormatting.DARK_PURPLE);
MinecraftForge.EVENT_BUS.register(this);
}
@Override
public void afterBlockBreak(ItemStack tool, World world, IBlockState state, BlockPos pos, EntityLivingBase player, boolean wasEffective) {
int time = (int) world.getWorldTime();
if (random.nextFloat() <= 0.1 && isNight(time)) {
ToolHelper.healTool(tool, random.nextInt(15) + 1, null);
if (random.nextFloat() <= 0.05 && isNight(time)) {
ToolHelper.healTool(tool, random.nextInt(8) + 1, null);
}
}
@Override
public void afterHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean wasCritical, boolean wasHit) {
int time = (int) player.getEntityWorld().getWorldTime();
if (random.nextFloat() <= 0.1 && isNight(time)) {
ToolHelper.healTool(tool, random.nextInt(15) + 1, null);
if (random.nextFloat() <= 0.05 && isNight(time)) {
ToolHelper.healTool(tool, random.nextInt(8) + 1, null);
}
}
@SubscribeEvent
public void onEntityKill(LivingDeathEvent e) {
World w = e.getEntity().getEntityWorld();
if (!w.isRemote && e.getSource().getEntity() != null) {
if (e.getSource().getEntity() instanceof EntityPlayer && e.getEntity() instanceof EntityCreature) {
ItemStack tool = ((EntityPlayer) e.getSource().getEntity()).getHeldItemMainhand();
if (isNight((int) w.getWorldTime()) && random.nextFloat() < 0.1 && TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier)) {
ToolHelper.healTool(tool, random.nextInt(16), null);
}
}
}
}
}

View File

@@ -21,7 +21,7 @@ public class TraitBlind extends AbstractTrait {
@Override
public void afterBlockBreak(ItemStack tool, World world, IBlockState state, BlockPos pos, EntityLivingBase player, boolean wasEffective) {
int time = (int) world.getWorldTime();
if (random.nextFloat() <= 0.05 || (random.nextFloat() <= 0.1 && isNight(time))) {
if (random.nextFloat() <= 0.01 || (random.nextFloat() <= 0.03 && isNight(time))) {
if (random.nextBoolean())
player.addPotionEffect(new PotionEffect(MobEffects.BLINDNESS, random.nextInt(200) + 100));
else
@@ -32,7 +32,7 @@ public class TraitBlind extends AbstractTrait {
@Override
public void afterHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean wasCritical, boolean wasHit) {
int time = (int) player.getEntityWorld().getWorldTime();
if (random.nextFloat() <= 0.05 || (random.nextFloat() <= 0.1 && isNight(time))) {
if (random.nextFloat() <= 0.01 || (random.nextFloat() <= 0.03 && isNight(time))) {
if (random.nextBoolean())
player.addPotionEffect(new PotionEffect(MobEffects.BLINDNESS, random.nextInt(400) + 200));
else

View File

@@ -1,22 +1,22 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.entity.Entity;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
import static com.sosnitzka.taiga.util.Utils.isNight;
import static net.minecraft.init.MobEffects.GLOWING;
public class TraitBright extends AbstractTrait {
private static final float chance = 0.90f;
public TraitBright() {
super("bright", TextFormatting.DARK_GRAY);
}
@@ -25,19 +25,16 @@ public class TraitBright extends AbstractTrait {
public float damage(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, float newDamage, boolean isCritical) {
int time = (int) target.getEntityWorld().getWorldTime();
if (!isNight(time)) {
newDamage += damage / 2f;
}
newDamage = damage * (1 + random.nextFloat() / 2f);
} else newDamage = damage / (1 + random.nextFloat() / 3f);
return super.damage(tool, player, target, damage, newDamage, isCritical);
}
@Override
public void onUpdate(ItemStack item, World world, Entity entity, int i, boolean b) {
if (entity instanceof EntityPlayer) {
EntityPlayer e = (EntityPlayer) entity;
if (TinkerUtil.hasTrait(TagUtil.getTagSafe(e.getHeldItemMainhand()), identifier)) {
e.addPotionEffect(new PotionEffect(MobEffects.GLOWING, 100));
}
public void afterBlockBreak(ItemStack tool, World world, IBlockState state, BlockPos pos, EntityLivingBase player, boolean wasEffective) {
if (random.nextFloat() >= chance) {
player.addPotionEffect(new PotionEffect(GLOWING, 200));
}
}
}

View File

@@ -36,7 +36,7 @@ public class TraitCascade extends AbstractTrait {
sx = x = nextBlock.getX();
sy = y = nextBlock.getY();
sz = z = nextBlock.getZ();
ToolHelper.damageTool(tool, random.nextInt(2), player);
ToolHelper.damageTool(tool, 1, player);
} else {
x = sx;
y = sy;

View File

@@ -0,0 +1,113 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
import slimeknights.tconstruct.library.utils.ToolHelper;
public class TraitCatcher extends AbstractTrait {
public static int chance = 1;
public static float costMulti = 0.25f;
public TraitCatcher() {
super(TraitCatcher.class.getSimpleName().toLowerCase().substring(5), TextFormatting.RED);
MinecraftForge.EVENT_BUS.register(this);
}
@Override
public void onHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean isCritical) {
World w = player.worldObj;
if (!w.isRemote && random.nextInt((int) target.getMaxHealth()) <= chance && target instanceof EntityLiving) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Data data = Data.read(tag);
if (data.mobClass.isEmpty()) {
data.mobClass = target.getClass().getName();
data.mobName = target.getName();
data.write(tag);
TagUtil.setEnchantEffect(tool, true);
TagUtil.setExtraTag(tool, tag);
player.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
target.setDropItemsWhenDead(false);
target.setDead();
}
}
}
@SubscribeEvent
public void onRightClickItem(PlayerInteractEvent.RightClickItem event) {
World w = event.getWorld();
BlockPos pos = event.getEntityPlayer().getPosition();
ItemStack tool = event.getEntityPlayer().getHeldItemMainhand();
if (!w.isRemote && TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier)) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Data data = Data.read(tag);
if (!data.mobClass.isEmpty()) {
Entity ent = null;
try {
ent = (Entity) Class.forName(data.mobClass).getConstructor(World.class).newInstance(w);
} catch (Exception e) {
System.out.println(e.toString());
}
if (ent != null) {
ent.setPosition(pos.getX(), pos.getY(), pos.getZ()); // TODO: set to player view target
w.spawnEntityInWorld(ent);
event.getEntityPlayer().playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
data.mobClass = "";
data.mobName = "";
data.write(tag);
TagUtil.setExtraTag(tool, tag);
TagUtil.setEnchantEffect(tool, false);
ToolHelper.damageTool(tool, random.nextInt((int) (ToolHelper.getCurrentDurability(tool) * costMulti)), event.getEntityPlayer());
}
}
}
}
@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent e) {
ItemStack tool = e.getItemStack();
if (TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier)) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Data data = Data.read(tag);
if (!data.mobClass.isEmpty())
e.getToolTip().add(TextFormatting.DARK_PURPLE + "Captured: " + TextFormatting.LIGHT_PURPLE + data.mobName);
}
}
public static class Data {
String mobClass;
String mobName;
public static Data read(NBTTagCompound tag) {
Data data = new Data();
data.mobName = tag.getString("mobName");
data.mobClass = tag.getString("mobClass");
return data;
}
public void write(NBTTagCompound tag) {
tag.setString("mobClass", mobClass);
tag.setString("mobName", mobName);
}
}
}

View File

@@ -0,0 +1,78 @@
package com.sosnitzka.taiga.traits;
import com.sosnitzka.taiga.util.Utils;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
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.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
public class TraitCongenial extends AbstractTrait {
public TraitCongenial() {
super(TraitCongenial.class.getSimpleName().toLowerCase().substring(5), TextFormatting.RED);
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onEntityKill(LivingDeathEvent e) {
if (e.getSource().getEntity() instanceof EntityPlayer && !e.getSource().getEntity().worldObj.isRemote && e.getEntity() instanceof EntityCreature) {
if (TinkerUtil.hasTrait(TagUtil.getTagSafe(((EntityPlayer) e.getSource().getEntity()).getHeldItemMainhand()), identifier)) {
ItemStack tool = ((EntityPlayer) e.getSource().getEntity()).getHeldItemMainhand();
String name = e.getEntity().getName();
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Utils.GeneralNBTData data = Utils.GeneralNBTData.read(tag);
if (!data.name.isEmpty()) {
return;
}
data.name = name;
data.write(tag);
assert tool != null;
TagUtil.setExtraTag(tool, tag);
}
}
}
@Override
public float damage(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, float newDamage, boolean isCritical) {
World w = player.getEntityWorld();
if (!w.isRemote) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Utils.GeneralNBTData data = Utils.GeneralNBTData.read(tag);
if (data.name.isEmpty()) {
return damage;
}
if (!data.name.equals(target.getName())) {
return damage / (random.nextInt(5) + 5);
}
float x = (1 + random.nextFloat() * 9);
return damage * x;
}
return damage;
}
@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent e) {
ItemStack tool = e.getItemStack();
if (TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier)) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Utils.GeneralNBTData data = Utils.GeneralNBTData.read(tag);
if (data.name.isEmpty()) e.getToolTip().add(TextFormatting.LIGHT_PURPLE + "Unbound");
else {
e.getToolTip().add(TextFormatting.DARK_PURPLE + "Bound to: " + TextFormatting.LIGHT_PURPLE + data.name);
}
}
}
}

View File

@@ -0,0 +1,58 @@
package com.sosnitzka.taiga.traits;
import com.sosnitzka.taiga.util.Utils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
public class TraitCursed extends AbstractTrait {
private static int chance = 60 * 1000;
public TraitCursed() {
super(TraitCursed.class.getSimpleName().toLowerCase().substring(5), TextFormatting.RED);
MinecraftForge.EVENT_BUS.register(this);
}
@Override
public void onUpdate(ItemStack tool, World world, Entity entity, int itemSlot, boolean isSelected) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Utils.GeneralNBTData data = Utils.GeneralNBTData.read(tag);
if (random.nextInt((chance + data.curse) / (data.curse + 1)) == 1) {
if (isSelected) data.curse += 10;
else data.curse++;
entity.attackEntityFrom(new DamageSource("Curse"), random.nextFloat() * ((EntityPlayer) entity).getHealth() / 2);
}
data.write(tag);
TagUtil.setExtraTag(tool, tag);
}
@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent e) {
ItemStack tool = e.getItemStack();
if (TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier)) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Utils.GeneralNBTData data = Utils.GeneralNBTData.read(tag);
if (data.curse != 0) {
e.getToolTip().add(TextFormatting.DARK_PURPLE + "Curse: " + TextFormatting.WHITE + data.curse);
}
}
}
}

View File

@@ -1,5 +1,7 @@
package com.sosnitzka.taiga.traits;
import com.google.common.collect.Lists;
import com.sosnitzka.taiga.util.Utils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
@@ -10,76 +12,74 @@ import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
import java.util.List;
public class TraitCurvature extends AbstractTrait {
public static int chance = 5;
public static int distance = 10;
public TraitCurvature() {
super("curvature", TextFormatting.BLACK);
super("curvature", TextFormatting.DARK_PURPLE);
MinecraftForge.EVENT_BUS.register(this);
}
@Override
public void afterBlockBreak(ItemStack tool, World world, IBlockState state, BlockPos pos, EntityLivingBase player, boolean wasEffective) {
if (player.worldObj.isRemote) {
return;
}
if (random.nextFloat() <= 0.01 && world.provider.getDimension() != -1) {
teleport(player, world);
player.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
public void blockHarvestDrops(ItemStack tool, BlockEvent.HarvestDropsEvent event) {
if (!event.getWorld().isRemote && random.nextFloat() < 0.05) {
List<IBlockState> blockstates = Lists.newArrayList(Blocks.STONE.getDefaultState(), Blocks.NETHERRACK.getDefaultState(), Blocks.END_STONE.getDefaultState(), Blocks.AIR.getDefaultState(), Blocks.DIRT.getDefaultState());
IBlockState mainstate = event.getState();
if (blockstates.contains(mainstate)) return;
for (int i = 0; i < chance; i++) {
int x = event.getPos().getX() + Utils.nextInt(random, -distance, distance);
int y = event.getPos().getY() + Utils.nextInt(random, -distance, distance);
int z = event.getPos().getZ() + Utils.nextInt(random, -distance, distance);
BlockPos cPos = new BlockPos(x, y, z);
IBlockState state = event.getWorld().getBlockState(cPos);
if (blockstates.contains(state)) {
event.getDrops().clear();
event.getWorld().setBlockState(cPos, mainstate);
event.getHarvester().playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
event.getHarvester().addChatComponentMessage(new TextComponentString("Teleported to: " + x + " " + y + " " + z));
return;
}
}
}
}
@Override
public void afterHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean wasCritical, boolean wasHit) {
if (random.nextFloat() <= 0.3) {
if (random.nextFloat() <= 0.15) {
target.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
changePos(player, target);
}
}
@SubscribeEvent
public void onMobDrops(LivingDropsEvent event) {
World w = event.getEntity().getEntityWorld();
if (!w.isRemote && event.getSource().getEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.getSource().getEntity();
if (event.getEntity() instanceof EntityMob && TinkerUtil.hasTrait(TagUtil.getTagSafe(player.getHeldItemMainhand()), identifier)) {
ItemStack i = new ItemStack(Items.ENDER_PEARL, random.nextInt(3));
ItemStack i = new ItemStack(Items.ENDER_PEARL, random.nextInt(2));
event.getDrops().add(0, new EntityItem(w, event.getEntity().posX, event.getEntity().posY, event.getEntity().posZ, i));
}
}
}
private void teleport(EntityLivingBase e, World w) {
int x = e.getPosition().getX() + random.nextInt(250) - 125;
int y = e.getPosition().getY();
int z = e.getPosition().getZ() + random.nextInt(250) - 125;
// TODO: Make this a proper search for top block (if there is one)
while (w.getBlockState(new BlockPos(x, y, z)).getBlock() != Blocks.AIR) {
y++;
}
while (w.getBlockState(new BlockPos(x, y - 1, z)).getBlock() == Blocks.AIR) {
if (y <= 0) {
y = 1;
break;
}
y--;
}
e.setPosition(x, y, z);
}
private void changePos(EntityLivingBase player, EntityLivingBase target) {
BlockPos pp = new BlockPos(player.getPosition());
BlockPos tp = new BlockPos(target.getPosition());

View File

@@ -18,9 +18,8 @@ public class TraitDark extends AbstractTrait {
public float damage(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, float newDamage, boolean isCritical) {
int time = (int) target.getEntityWorld().getWorldTime();
if (isNight(time)) {
newDamage += damage / 2f;
}
newDamage = damage * (1 + random.nextFloat() / 2f);
} else newDamage = damage / (1 + random.nextFloat() / 3f);
return super.damage(tool, player, target, damage, newDamage, isCritical);
}
}

View File

@@ -0,0 +1,115 @@
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));
}
}

View File

@@ -1,13 +1,12 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.living.LivingExperienceDropEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
@@ -21,20 +20,11 @@ public class TraitDiffuse extends AbstractTrait {
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onXpDrop(LivingExperienceDropEvent event) {
EntityPlayer player = event.getAttackingPlayer();
if (!event.getEntity().getEntityWorld().isRemote && player != null && TinkerUtil.hasTrait(TagUtil.getTagSafe(player.getHeldItemMainhand()), this.identifier)) {
event.setDroppedExperience(0);
}
}
@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent event) {
EntityPlayer player = event.getPlayer();
if (!player.getEntityWorld().isRemote && TinkerUtil.hasTrait(TagUtil.getTagSafe(player.getHeldItemMainhand()), this.identifier)) {
event.setExpToDrop(this.getUpdateXP(event.getExpToDrop()));
event.setExpToDrop((int) this.getUpdateXP(event.getExpToDrop()));
}
}
@@ -43,22 +33,22 @@ public class TraitDiffuse extends AbstractTrait {
World w = event.getEntity().getEntityWorld();
if (!w.isRemote && event.getSource().getEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.getSource().getEntity();
if (event.getEntity() instanceof EntityMob && TinkerUtil.hasTrait(TagUtil.getTagSafe(player.getHeldItemMainhand()), identifier)) {
if (event.getEntity() instanceof EntityCreature && TinkerUtil.hasTrait(TagUtil.getTagSafe(player.getHeldItemMainhand()), identifier)) {
event.getDrops().clear();
}
}
}
private int getUpdateXP(int xp) {
float exp = random.nextFloat() * random.nextFloat() * random.nextFloat() * (xp + random.nextInt(10));
if (random.nextBoolean())
return Math.round(exp);
private float getUpdateXP(int xp) {
float exp = random.nextFloat() * random.nextFloat() * random.nextFloat() * (xp + random.nextFloat() * xp);
if (random.nextFloat() <= 0.25)
return exp;
else return 0;
}
@Override
public void blockHarvestDrops(ItemStack tool, BlockEvent.HarvestDropsEvent event) {
if (random.nextFloat() < 0.75) {
if (random.nextFloat() < 0.35) {
event.getDrops().clear();
}
}

View File

@@ -18,16 +18,18 @@ public class TraitDissolving extends AbstractTrait {
}
// high chance to remove XP, low chance to double,triple or quatruple dropped Experience
@SubscribeEvent
public void onXpDrop(LivingExperienceDropEvent event) {
if (!event.getEntity().getEntityWorld().isRemote) {
EntityPlayer player = event.getAttackingPlayer();
float r = random.nextFloat();
if (r <= 0.75 && player != null && TinkerUtil.hasTrait(TagUtil.getTagSafe(player.getHeldItemMainhand()), this.identifier)) {
event.setDroppedExperience(0);
}
if (r > 0.95 && player != null && TinkerUtil.hasTrait(TagUtil.getTagSafe(player.getHeldItemMainhand()), this.identifier)) {
event.setDroppedExperience(event.getDroppedExperience() * (random.nextInt(3) + 2));
if (player != null && TinkerUtil.hasTrait(TagUtil.getTagSafe(player.getHeldItemMainhand()), this.identifier)) {
if (r <= 0.80) {
event.setDroppedExperience(0);
} else {
event.setDroppedExperience(event.getDroppedExperience() * (random.nextInt(3) + 2));
}
}
}
}

View File

@@ -24,6 +24,7 @@ public class TraitFragile extends AbstractTrait {
float b = 0.99F * calcBonus(tool);
if (!world.isRemote && tool.canHarvestBlock(state) && f <= b) {
if (random.nextBoolean()) ToolHelper.damageTool(tool, random.nextInt(3), player);
else ToolHelper.healTool(tool, random.nextInt(3), player);
}
} else {
float f = random.nextFloat();
@@ -41,20 +42,18 @@ public class TraitFragile extends AbstractTrait {
if (r == 2) z += d;
BlockPos nextBlock = new BlockPos(x, y, z);
if (world.getBlockState(nextBlock) == world.getBlockState(pos)) {
Block block = Blocks.STONE;
int ib = random.nextInt(3);
Block block = null;
int ib = random.nextInt(2);
switch (ib) {
case 0:
block = Blocks.COBBLESTONE;
break;
case 1:
block = Blocks.MOSSY_COBBLESTONE;
break;
case 2:
block = Blocks.GRAVEL;
break;
if (random.nextFloat() <= 0.9) block = Blocks.GRAVEL;
else block = Blocks.MOSSY_COBBLESTONE;
}
f = random.nextFloat();
assert block != null;
if (f < 0.85) {
world.setBlockState(nextBlock, block.getDefaultState());
} else if (f > 95) {

View File

@@ -18,8 +18,6 @@ import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
import slimeknights.tconstruct.library.utils.ToolHelper;
import static com.sosnitzka.taiga.Items.*;
public class TraitGarishly extends AbstractTrait {
public TraitGarishly() {
@@ -34,7 +32,7 @@ public class TraitGarishly extends AbstractTrait {
EntityPlayer player = (EntityPlayer) event.getSource().getEntity();
if (event.getEntity() instanceof EntityMob && TinkerUtil.hasTrait(TagUtil.getTagSafe(player.getHeldItemMainhand()), identifier)) {
int r = random.nextInt(6);
int r = random.nextInt(2);
ItemStack i = null;
switch (r) {
case 0:
@@ -44,17 +42,8 @@ public class TraitGarishly extends AbstractTrait {
i = new ItemStack(Items.BLAZE_ROD, random.nextInt(3));
break;
case 2:
i = new ItemStack(glimmerstone_dust, random.nextInt(3));
break;
case 3:
i = new ItemStack(luminar_dust, random.nextInt(3));
break;
case 4:
i = new ItemStack(Items.COAL, random.nextInt(3));
break;
case 5:
i = new ItemStack(lignite, random.nextInt(3));
break;
}
assert i != null;
event.getDrops().add(0, new EntityItem(w, event.getEntity().posX, event.getEntity().posY, event.getEntity().posZ, i));
@@ -65,8 +54,8 @@ public class TraitGarishly extends AbstractTrait {
@Override
public void blockHarvestDrops(ItemStack tool, BlockEvent.HarvestDropsEvent event) {
float r = random.nextFloat();
if (r > 0.5f) event.getDrops().clear();
else if (r < 0.1 && event.getWorld().getBlockState(event.getPos()).getMaterial() == Material.ROCK) {
if (random.nextBoolean()) event.getDrops().clear();
else if (r < 0.25 && event.getWorld().getBlockState(event.getPos()).getMaterial() == Material.ROCK) {
@SuppressWarnings("ConstantConditions") ItemStack stack = new ItemStack(Item.getItemFromBlock(event.getWorld().getBlockState(event.getPos()).getBlock()), random.nextInt(3));
event.getDrops().add(0, stack);
ToolHelper.damageTool(tool, random.nextInt(6) + 1, event.getHarvester());

View File

@@ -34,14 +34,14 @@ public class TraitGlimmer extends AbstractTrait {
@Override
public void afterBlockBreak(ItemStack tool, World world, IBlockState state, BlockPos pos, EntityLivingBase player, boolean wasEffective) {
if (random.nextFloat() <= 0.08) {
if (random.nextFloat() <= 0.05) {
player.addPotionEffect(new PotionEffect(MobEffects.NIGHT_VISION, random.nextInt(600) + 300));
}
}
@Override
public void afterHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean wasCritical, boolean wasHit) {
if (random.nextFloat() <= 0.08) {
if (random.nextFloat() <= 0.05) {
player.addPotionEffect(new PotionEffect(MobEffects.NIGHT_VISION, random.nextInt(600) + 300));
}
}

View File

@@ -1,37 +0,0 @@
package com.sosnitzka.taiga.traits;
import com.sosnitzka.taiga.util.EntityAIPermanentPanic;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.*;
import net.minecraft.entity.passive.*;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.MinecraftForge;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import static com.sosnitzka.taiga.util.Utils.isNight;
public class TraitHaunted extends AbstractTrait {
public TraitHaunted() {
super("haunted", TextFormatting.DARK_GRAY);
MinecraftForge.EVENT_BUS.register(this);
}
// Just several tested Vanilla-Mobs, e.g. no ghasts, bats or skeletons
@Override
public void onHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean isCritical) {
int time = (int) player.getEntityWorld().getWorldTime();
if (random.nextFloat() <= 0.1 || (random.nextFloat() <= 0.3 && isNight(time)))
if (target instanceof EntityCow || target instanceof EntityZombie || target instanceof EntityWolf || target instanceof EntityPig || target instanceof EntitySpider ||
target instanceof EntityVillager || target instanceof EntitySheep || target instanceof EntityEnderman || target instanceof EntityEndermite ||
target instanceof EntityBlaze || target instanceof EntityWitch || target instanceof EntityHorse) {
((EntityLiving) target).tasks.taskEntries.clear();
((EntityLiving) target).targetTasks.taskEntries.clear();
((EntityLiving) target).tasks.addTask(0, new EntityAIPermanentPanic((EntityCreature) target, target.getAIMoveSpeed() + 3.5D));
}
}
}

View File

@@ -19,6 +19,6 @@ public class TraitHeroic extends AbstractTrait {
float calc = newDamage + (newDamage / 2) / (durability * durabilitymax / (durabilitymax - durability - 1));
if ((float) durability < (float) (0.10 * durabilitymax) || player.getHealth() < player.getMaxHealth() / 8 || (target.getHealth() == target.getMaxHealth() && random.nextFloat() > 0.8)) {
return super.damage(tool, player, target, damage, calc, isCritical);
} else return super.damage(tool, player, target, damage, newDamage, isCritical);
} else return super.damage(tool, player, target, damage, newDamage * 0.9f, isCritical);
}
}

View File

@@ -28,10 +28,10 @@ public class TraitHollow extends AbstractTrait {
@Override
public void onHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean isCritical) {
int time = (int) player.getEntityWorld().getWorldTime();
if (random.nextFloat() <= 0.2 || (random.nextFloat() <= 0.2 && isNight(time))) {
if (random.nextFloat() <= 0.01 || (random.nextFloat() <= 0.03 && isNight(time))) {
((EntityLiving) target).setNoAI(true);
target.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
if (target.getMaxHealth() < 200) {
if (target.getMaxHealth() < 250) {
target.setHealth(target.getMaxHealth() * (1.8f - random.nextFloat() * 0.4f));
}
}

View File

@@ -36,7 +36,7 @@ public class TraitInstable extends AbstractTrait {
explode(world, player, pos.getX(), pos.getY(), pos.getZ());
} else explode(world, null, pos.getX(), pos.getY(), pos.getZ());
}
ToolHelper.damageTool(tool, 11 + random.nextInt(10), player);
ToolHelper.damageTool(tool, random.nextInt(10) + 2, player);
}
}
@@ -49,17 +49,17 @@ public class TraitInstable extends AbstractTrait {
explode(player.getEntityWorld(), player, pos.getX(), pos.getY(), pos.getZ());
} else explode(player.getEntityWorld(), target, pos.getX(), pos.getY(), pos.getZ());
}
ToolHelper.damageTool(tool, 3 + random.nextInt(18), player);
ToolHelper.damageTool(tool, 2 + random.nextInt(10), player);
}
}
@SubscribeEvent
public void onMobDrops(LivingDropsEvent event) {
World w = event.getEntity().getEntityWorld();
if (!w.isRemote && event.getSource().getEntity() instanceof EntityPlayer) {
if (random.nextFloat() < 0.05 && !w.isRemote && event.getSource().getEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.getSource().getEntity();
if (event.getEntity() instanceof EntityMob && TinkerUtil.hasTrait(TagUtil.getTagSafe(player.getHeldItemMainhand()), identifier)) {
ItemStack i = new ItemStack(Items.GUNPOWDER, random.nextInt(4));
ItemStack i = new ItemStack(Items.GUNPOWDER, random.nextInt(2));
event.getDrops().add(0, new EntityItem(w, event.getEntity().posX, event.getEntity().posY, event.getEntity().posZ, i));
}
}

View File

@@ -2,24 +2,31 @@ package com.sosnitzka.taiga.traits;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
public class TraitMelting extends AbstractTrait {
public TraitMelting() {
super("melting", TextFormatting.YELLOW);
MinecraftForge.EVENT_BUS.register(this);
}
@Override
public void blockHarvestDrops(ItemStack tool, BlockEvent.HarvestDropsEvent event) {
float r = random.nextFloat();
Block b = event.getWorld().getBlockState(event.getPos()).getBlock();
if (r <= 0.01 && (b == Blocks.STONE || b == Blocks.COBBLESTONE || b == Blocks.NETHERRACK)) {
event.getWorld().setBlockState(event.getPos(), Blocks.LAVA.getDefaultState());
@SubscribeEvent
public void blockbreak(BlockEvent.BreakEvent e) {
Block b = e.getWorld().getBlockState(e.getPos()).getBlock();
if (TinkerUtil.hasTrait(TagUtil.getTagSafe(e.getPlayer().getHeldItemMainhand()), identifier)) {
if (!e.getWorld().isRemote && random.nextFloat() <= 0.025 && (b == Blocks.STONE || b == Blocks.COBBLESTONE || b == Blocks.NETHERRACK || b == Blocks.OBSIDIAN)) {
e.setCanceled(true);
e.getWorld().setBlockState(e.getPos(), Blocks.LAVA.getDefaultState());
}
}
}
}

View File

@@ -1,19 +1,13 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
import slimeknights.tconstruct.library.utils.ToolHelper;
@@ -26,26 +20,19 @@ public class TraitNatureBound extends AbstractTrait {
@Override
public int onToolHeal(ItemStack tool, int amount, int newAmount, EntityLivingBase entity) {
// 5% less durability repaired!
return newAmount - amount * 5 / 100;
// 10% less durability repaired!
return newAmount - amount * 10 / 100;
}
@Override
public void onUpdate(ItemStack tool, World world, Entity entity, int itemSlot, boolean isSelected) {
// *20 because 20 ticks in a second
int chance = 20;
if (!world.isRemote && entity instanceof EntityLivingBase && random.nextInt(30 * chance) == 0) {
ToolHelper.healTool(tool, random.nextInt(9) + 1, (EntityLivingBase) entity);
}
}
@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent e) {
Block b = e.getWorld().getBlockState(e.getPos()).getBlock();
if (!e.getWorld().isRemote && TinkerUtil.hasTrait(TagUtil.getTagSafe(e.getPlayer().getHeldItemMainhand()), identifier) && random.nextFloat() <= .07 && (b == Blocks.DIRT || b == Blocks.GRASS || b == Blocks.LOG || b == Blocks.LOG2 || b == Blocks.STONE)) {
e.setCanceled(true);
e.getPlayer().playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
// * 20 because 20 ticks in a second
int chance = 20 * 20;
Material m = world.getBlockState(entity.getPosition().down()).getMaterial();
if (!world.isRemote && entity instanceof EntityLivingBase && random.nextInt(chance) == 0) {
if (m.equals(Material.GRASS) || m.equals(Material.LEAVES)) {
ToolHelper.healTool(tool, random.nextInt(2) + 1, (EntityLivingBase) entity);
} else ToolHelper.damageTool(tool, 1, (EntityLivingBase) entity);
}
}
}

View File

@@ -1,29 +0,0 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.ToolHelper;
public class TraitOrganizing extends AbstractTrait {
private static final float chance = 0.02f;
public TraitOrganizing() {
super("organizing", TextFormatting.GREEN);
}
@Override
public void afterBlockBreak(ItemStack tool, World world, IBlockState state, BlockPos pos, EntityLivingBase player, boolean wasEffective) {
if (!world.isRemote && (state.getMaterial() == Material.ROCK) && random.nextFloat() < chance) {
world.setBlockState(pos, Blocks.LOG.getDefaultState());
ToolHelper.healTool(tool, random.nextInt(5), player);
}
}
}

View File

@@ -0,0 +1,67 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
import slimeknights.tconstruct.library.utils.ToolHelper;
public class TraitPorted extends AbstractTrait {
public static int distance = 10;
public TraitPorted() {
super("ported", TextFormatting.DARK_PURPLE);
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onItemRightClick(PlayerInteractEvent.RightClickItem e) {
ItemStack tool = e.getEntityPlayer().getHeldItemMainhand();
if (TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier))
teleport(e.getEntityPlayer(), e.getWorld());
}
@Override
public void afterBlockBreak(ItemStack tool, World world, IBlockState state, BlockPos pos, EntityLivingBase player, boolean wasEffective) {
if (random.nextFloat() <= 0.005) {
player.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
teleport(player, world);
}
}
@Override
public void afterHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean wasCritical, boolean wasHit) {
if (random.nextFloat() <= 0.005) {
target.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
teleport(player, player.getEntityWorld());
}
}
private void teleport(EntityLivingBase e, World w) {
BlockPos tPos = new BlockPos(e.getPosition().up(distance));
if (e.getPosition().getY() >= 128) {
return;
}
while (!w.getBlockState(tPos).equals(Blocks.AIR.getDefaultState()) && tPos.getY() <= 128) {
tPos = tPos.up();
}
if (!w.getBlockState(tPos).equals(Blocks.AIR.getDefaultState())) {
return;
}
e.setPosition(tPos.getX(), tPos.getY(), tPos.getZ());
ToolHelper.damageTool(e.getHeldItemMainhand(), ToolHelper.getCurrentDurability(e.getHeldItemMainhand()) / 2 + 1, e);
}
}

View File

@@ -0,0 +1,115 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.text.TextFormatting;
import slimeknights.tconstruct.library.modifiers.ModifierNBT;
import slimeknights.tconstruct.library.tools.ToolNBT;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
/**
* Base class for tools that progressively gain/award stats.
* The modifier persists 2 different stat-data on the tool:
* - A 'pool' of stats to award
* - A 'bonus' of already awarded stats
* <p>
* The modifier reapplies the 'bonus' stats on application.
* The pool is not touched inheritly but only provided for the logic of the deriving trait.
*/
public abstract class TraitProgressiveStats extends AbstractTrait {
protected final String pool_key; // Key to the tag that contains the free unassigned
protected final String applied_key; // Key to the tag that contains the already applied bonus stats
public TraitProgressiveStats(String identifier, TextFormatting color) {
super(identifier, color);
pool_key = identifier + "StatPool";
applied_key = identifier + "StatBonus";
}
public TraitProgressiveStats(String identifier, int color) {
super(identifier, color);
pool_key = identifier + "StatPool";
applied_key = identifier + "StatBonus";
}
/* Modifier management */
protected static StatNBT getStats(NBTTagCompound root, String key) {
return ModifierNBT.readTag(TagUtil.getTagSafe(TagUtil.getExtraTag(root), key), StatNBT.class);
}
protected static void setStats(NBTTagCompound root, StatNBT data, String key) {
NBTTagCompound extra = TagUtil.getExtraTag(root);
NBTTagCompound tag = new NBTTagCompound();
data.write(tag);
extra.setTag(key, tag);
TagUtil.setExtraTag(root, extra);
}
@Override
public void applyEffect(NBTTagCompound rootCompound, NBTTagCompound modifierTag) {
super.applyEffect(rootCompound, modifierTag);
// called on tool loading only
// we just apply the saved bonus stats
ToolNBT data = TagUtil.getToolStats(rootCompound);
StatNBT bonus = getBonus(rootCompound);
data.durability += bonus.durability;
data.speed += bonus.speed;
data.attack += bonus.attack;
TagUtil.setToolTag(rootCompound, data.get());
}
protected boolean hasPool(NBTTagCompound root) {
return TagUtil.getExtraTag(root).hasKey(pool_key);
}
protected StatNBT getPool(NBTTagCompound root) {
return getStats(root, pool_key);
}
protected void setPool(NBTTagCompound root, StatNBT data) {
setStats(root, data, pool_key);
}
protected StatNBT getBonus(NBTTagCompound root) {
return getStats(root, applied_key);
}
protected void setBonus(NBTTagCompound root, StatNBT data) {
setStats(root, data, applied_key);
}
protected boolean playerIsBreakingBlock(Entity entity) {
return false;
}
public static class StatNBT extends ModifierNBT {
// statpool
public int durability;
public float attack;
public float speed;
@Override
public void read(NBTTagCompound tag) {
super.read(tag);
durability = tag.getInteger("durability");
attack = tag.getFloat("attack");
speed = tag.getFloat("speed");
}
@Override
public void write(NBTTagCompound tag) {
super.write(tag);
tag.setInteger("durability", durability);
tag.setFloat("attack", attack);
tag.setFloat("speed", speed);
}
}
}

View File

@@ -16,16 +16,15 @@ public class TraitPulverizing extends AbstractTrait {
@Override
public void miningSpeed(ItemStack tool, PlayerEvent.BreakSpeed event) {
if (ToolHelper.isToolEffective2(tool, event.getState())) {
event.setNewSpeed((float) (event.getNewSpeed() + calcBonus(tool)));
event.setNewSpeed((float) (event.getNewSpeed() * calcBonus(tool)));
}
}
private double calcBonus(ItemStack tool) {
int durability = ToolHelper.getCurrentDurability(tool);
int maxDurability = ToolHelper.getMaxDurability(tool);
float speed = ToolHelper.getMiningSpeedStat(tool);
tool.setItemDamage(tool.getItemDamage() + 1);
return speed * (maxDurability - maxDurability / 10) / (durability);
return (1 + .9f * (maxDurability - durability) / maxDurability);
// Min 1.0; Max 1.9
}
@Override

View File

@@ -1,177 +0,0 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.entity.monster.*;
import net.minecraft.entity.passive.*;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.world.BlockEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.ToolHelper;
import slimeknights.tconstruct.world.entity.EntityBlueSlime;
import static com.sosnitzka.taiga.Blocks.*;
import static slimeknights.tconstruct.shared.TinkerCommons.oreArdite;
import static slimeknights.tconstruct.shared.TinkerCommons.oreCobalt;
public class TraitRandomize extends AbstractTrait {
public TraitRandomize() {
super("randomize", TextFormatting.DARK_RED);
}
@Override
public void miningSpeed(ItemStack tool, PlayerEvent.BreakSpeed event) {
if (ToolHelper.isToolEffective2(tool, event.getState())) {
event.setNewSpeed(event.getNewSpeed() + random.nextFloat() * 2);
}
}
@Override
public void onHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean isCritical) {
if (random.nextFloat() <= .15 && target instanceof EntityLiving) {
World w = player.getEntityWorld();
Entity e = new EntityCow(w);
target.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
if (!w.isRemote) {
int i = random.nextInt(22);
switch (i) {
case 0:
e = new EntityCow(w);
break;
case 1:
e = new EntityPig(w);
break;
case 2:
e = new EntityHorse(w);
break;
case 3:
e = new EntityChicken(w);
break;
case 4:
e = new EntityVillager(w);
break;
case 5:
e = new EntityEnderman(w);
break;
case 6:
e = new EntityPolarBear(w);
break;
case 7:
e = new EntityIronGolem(w);
break;
case 8:
e = new EntitySilverfish(w);
break;
case 9:
e = new EntityCaveSpider(w);
break;
case 10:
e = new EntityWolf(w);
break;
case 11:
e = new EntityWitch(w);
break;
case 12:
e = new EntityTNTPrimed(w);
break;
case 13:
e = new EntityGhast(w);
break;
case 14:
e = new EntitySpider(w);
break;
case 15:
e = new EntitySkeleton(w);
break;
case 16:
e = new EntityMagmaCube(w);
break;
case 17:
e = new EntitySlime(w);
break;
case 18:
e = new EntityBlueSlime(w);
break;
case 19:
e = new EntityBat(w);
break;
case 20:
e = new EntityPigZombie(w);
break;
case 21:
e = new EntityBlaze(w);
break;
}
e.setPosition(target.getPosition().getX(), target.getPosition().getY() + 0.1f, target.getPosition().getZ());
e.setCustomNameTag("Missingno");
if (e instanceof EntityLiving)
((EntityLiving) e).setHealth(((EntityLiving) e).getHealth() * (random.nextInt(5) + 1));
w.spawnEntityInWorld(e);
target.setDead();
}
}
}
@SuppressWarnings("ConstantConditions")
@Override
public void blockHarvestDrops(ItemStack tool, BlockEvent.HarvestDropsEvent event) {
float r = random.nextFloat();
if (r > 0.95f) event.getDrops().clear();
if (event.getDrops() != null) {
if (r < 0.4f && (event.getDrops().get(0).getItem() == Item.getItemFromBlock(Blocks.IRON_ORE) || event.getDrops().get(0).getItem() == Item.getItemFromBlock(Blocks.GOLD_ORE))) {
ItemStack change = new ItemStack(Item.getItemFromBlock(Blocks.IRON_ORE));
int i = random.nextInt(12);
switch (i) {
case 0:
change = new ItemStack(Item.getItemFromBlock(Blocks.GOLD_ORE));
break;
case 1:
change = new ItemStack(Item.getItemFromBlock(Blocks.REDSTONE_ORE));
break;
case 2:
change = new ItemStack(Item.getItemFromBlock(Blocks.LAPIS_ORE));
break;
case 3:
change = new ItemStack(Item.getItemFromBlock(Blocks.DIAMOND_ORE));
break;
case 4:
change = new ItemStack(Item.getItemFromBlock(Blocks.QUARTZ_ORE));
break;
case 5:
change = new ItemStack(oreCobalt.getItem());
break;
case 6:
change = new ItemStack(oreArdite.getItem());
break;
case 7:
change = new ItemStack(titaniteOre);
break;
case 8:
change = new ItemStack(bismuthOre);
break;
case 9:
change = new ItemStack(tiberiumOre);
break;
case 10:
change = new ItemStack(eterniteOre);
break;
case 11:
change = new ItemStack(Item.getItemFromBlock(Blocks.IRON_ORE));
break;
}
event.getDrops().set(0, change);
}
}
}
}

View File

@@ -8,14 +8,16 @@ import slimeknights.tconstruct.library.traits.AbstractTrait;
public class TraitResonance extends AbstractTrait {
public static float chance = 0.33f;
public TraitResonance() {
super("resonance", TextFormatting.AQUA);
}
@Override
public void afterHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean wasCritical, boolean wasHit) {
if (random.nextFloat() <= .33) {
target.knockBack(target, random.nextFloat() * random.nextFloat() * 12, player.posX - target.posX, player.posZ - target.posZ);
if (random.nextFloat() <= chance) {
target.knockBack(target, random.nextFloat() * random.nextFloat() * 10, player.posX - target.posX, player.posZ - target.posZ);
}
}
}

View File

@@ -1,13 +1,11 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
@@ -17,13 +15,13 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
import slimeknights.tconstruct.library.utils.ToolHelper;
import static com.sosnitzka.taiga.util.Utils.isNight;
public class TraitReviving extends AbstractTrait {
public final float chance = 0.15f;
public TraitReviving() {
super("reviving", TextFormatting.DARK_PURPLE);
MinecraftForge.EVENT_BUS.register(this);
@@ -35,36 +33,19 @@ public class TraitReviving extends AbstractTrait {
World w = e.getEntity().getEntityWorld();
if (!w.isRemote && e.getSource().getEntity() != null) {
if (e.getSource().getEntity() instanceof EntityPlayer && e.getEntity() instanceof EntityCreature) {
if (isNight((int) w.getWorldTime()) && random.nextFloat() > 0.85 && TinkerUtil.hasTrait(TagUtil.getTagSafe(((EntityPlayer) e.getSource().getEntity()).getHeldItemMainhand()), identifier)) {
if (random.nextFloat() <= chance && TinkerUtil.hasTrait(TagUtil.getTagSafe(((EntityPlayer) e.getSource().getEntity()).getHeldItemMainhand()), identifier)) {
String name = EntityList.getEntityString(e.getEntity());
Entity ent = EntityList.createEntityByName(name, w);
if (ent != null) {
if (ent instanceof EntitySkeleton && e.getEntity() instanceof EntitySkeleton) {
((EntitySkeleton) ent).setSkeletonType(((EntitySkeleton) e.getEntity()).getSkeletonType());
}
ent.setPosition(pos.getX(), pos.getY(), pos.getZ());
w.spawnEntityInWorld(ent);
e.getSource().getEntity().playSound(SoundEvents.AMBIENT_CAVE, 1.0F, 1.0F);
}
}
}
}
}
@Override
public void afterBlockBreak(ItemStack tool, World world, IBlockState state, BlockPos pos, EntityLivingBase player, boolean wasEffective) {
int time = (int) world.getWorldTime();
if (random.nextFloat() <= 0.1 && isNight(time)) {
ToolHelper.healTool(tool, random.nextInt(15) + 1, null);
}
}
@Override
public void afterHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean wasCritical, boolean wasHit) {
int time = (int) player.getEntityWorld().getWorldTime();
if (random.nextFloat() <= 0.1 && isNight(time)) {
ToolHelper.healTool(tool, random.nextInt(15) + 1, null);
}
}
}

View File

@@ -1,28 +1,49 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
import slimeknights.tconstruct.library.utils.ToolHelper;
public class TraitSofty extends AbstractTrait {
private static final float chance = 0.2f;
private static final float chance = 0.1f;
private static final float speedmulti = 1.3f;
public TraitSofty() {
super("softy", TextFormatting.AQUA);
super("softy", TextFormatting.GRAY);
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void blockbreak(BlockEvent.BreakEvent e) {
float r = random.nextFloat();
float hardness = e.getWorld().getBlockState(e.getPos()).getBlockHardness(e.getWorld(), e.getPos());
if (TinkerUtil.hasTrait(TagUtil.getTagSafe(e.getPlayer().getHeldItemMainhand()), identifier)) {
if (!e.getWorld().isRemote && r <= chance && hardness >= 1.0f) {
e.setCanceled(true);
ToolHelper.damageTool(e.getPlayer().getHeldItemMainhand(), random.nextInt(3) + 1, e.getPlayer());
}
}
}
@Override
public void afterBlockBreak(ItemStack tool, World world, IBlockState state, BlockPos pos, EntityLivingBase player, boolean wasEffective) {
if (!world.isRemote && state.getMaterial().equals(Material.GROUND) && random.nextFloat() < chance) {
ToolHelper.healTool(tool, random.nextInt(10), player);
public void miningSpeed(ItemStack tool, PlayerEvent.BreakSpeed event) {
World w = event.getEntity().getEntityWorld();
IBlockState state = w.getBlockState(event.getPos());
float speed = event.getOriginalSpeed();
if (!w.isRemote) {
if (state.getBlockHardness(w, event.getPos()) <= 1.0f) {
event.setNewSpeed(speed * speedmulti);
}
}
}
}

View File

@@ -0,0 +1,70 @@
package com.sosnitzka.taiga.traits;
import com.sosnitzka.taiga.util.Utils;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
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.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
public class TraitSoulEater extends AbstractTrait {
private static float divisor = 20000f;
public TraitSoulEater() {
super(TraitSoulEater.class.getSimpleName().toLowerCase().substring(5), TextFormatting.RED);
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onTargetKilled(LivingDeathEvent event) {
if (event.getSource().getEntity() instanceof EntityPlayer && event.getEntity() instanceof EntityLiving) {
World w = event.getSource().getEntity().worldObj;
ItemStack tool = ((EntityPlayer) event.getSource().getEntity()).getHeldItemMainhand();
if (!w.isRemote && TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier)) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Utils.GeneralNBTData data = Utils.GeneralNBTData.read(tag);
float health = ((EntityLiving) event.getEntity()).getMaxHealth();
data.killcount += 1;
data.health = health;
float bonus = Math.round(random.nextFloat() * health * 100) / divisor;
data.bonus += bonus;
data.bonus = (float) Math.round(data.bonus * 100f) / 100f;
data.write(tag);
TagUtil.setExtraTag(tool, tag);
}
}
}
@Override
public float damage(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, float newDamage, boolean isCritical) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Utils.GeneralNBTData data = Utils.GeneralNBTData.read(tag);
float bonus = data.bonus;
return newDamage + bonus;
}
@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent e) {
ItemStack tool = e.getItemStack();
if (TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier)) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Utils.GeneralNBTData data = Utils.GeneralNBTData.read(tag);
if (data.killcount != 0) {
e.getToolTip().add(TextFormatting.WHITE + "Killed: " + TextFormatting.WHITE + data.killcount);
e.getToolTip().add(TextFormatting.WHITE + "Bonus: " + TextFormatting.WHITE + data.bonus);
}
}
}
}

View File

@@ -0,0 +1,105 @@
package com.sosnitzka.taiga.traits;
import com.sosnitzka.taiga.util.Utils;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.common.Sounds;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
import static com.sosnitzka.taiga.Blocks.tiberiumOre;
public class TraitTantrum extends AbstractTrait {
/*
* Collects tiberium, to release it for an explosion
*/
public static float max_charges = 12f;
public static float max_power = 5;
public TraitTantrum() {
super("tantrum", TextFormatting.RED);
MinecraftForge.EVENT_BUS.register(this);
}
@Override
public void blockHarvestDrops(ItemStack tool, BlockEvent.HarvestDropsEvent event) {
World w = event.getWorld();
if (!w.isRemote) {
if (event.getState().getBlock().equals(tiberiumOre)) {
event.getDrops().clear();
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Data data = Data.read(tag);
if (data.amount >= max_charges) {
return;
}
data.amount += (0.25f + Utils.round2(random.nextDouble() / 4));
if (data.amount >= max_charges) {
TagUtil.setEnchantEffect(tool, true);
if (event.getHarvester() instanceof EntityPlayerMP) {
Sounds.PlaySoundForPlayer(event.getHarvester(), Sounds.shocking_discharge, 1f, 0.8f + .2f * random.nextFloat());
}
}
data.write(tag);
TagUtil.setExtraTag(tool, tag);
}
}
}
@SubscribeEvent
public void RightClickItem(PlayerInteractEvent.RightClickItem event) {
World w = event.getWorld();
BlockPos pos = event.getPos();
ItemStack tool = event.getEntityPlayer().getHeldItemMainhand();
if (!w.isRemote && TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier)) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Data data = Data.read(tag);
if (data.amount > 1f) {
double d = Math.min(Utils.round2(random.nextDouble() * data.amount), max_power);
w.newExplosion(event.getEntityPlayer(), pos.getX(), pos.getY(), pos.getZ(), (float) Math.pow((double) 1.2f, d), false, true);
data.amount -= d;
data.write(tag);
TagUtil.setExtraTag(tool, tag);
TagUtil.setEnchantEffect(tool, false);
}
}
}
@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent e) {
ItemStack tool = e.getItemStack();
if (TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier)) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Data data = Data.read(tag);
e.getToolTip().add(TextFormatting.RED + "Charge: " + data.amount);
}
}
public static class Data {
float amount;
public static Data read(NBTTagCompound tag) {
Data data = new Data();
data.amount = tag.getFloat("amount");
return data;
}
public void write(NBTTagCompound tag) {
tag.setFloat("amount", amount);
}
}
}

View File

@@ -0,0 +1,17 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.MinecraftForge;
import slimeknights.tconstruct.library.traits.AbstractTrait;
public class TraitTemplate extends AbstractTrait {
public TraitTemplate() {
super(TraitTemplate.class.getSimpleName().toLowerCase().substring(5), TextFormatting.RED);
MinecraftForge.EVENT_BUS.register(this);
}
}

View File

@@ -1,14 +1,49 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
public class TraitTraditional extends AbstractTrait {
public TraitTraditional() {
super("traditional", TextFormatting.GREEN);
super("traditional", 0xff33ff);
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onEntityKill(LivingDeathEvent e) {
World w = e.getEntity().getEntityWorld();
if (!w.isRemote && e.getSource().getEntity() instanceof EntityPlayer && e.getEntity() instanceof EntityCreature) {
if (TinkerUtil.hasTrait(TagUtil.getTagSafe(((EntityPlayer) e.getSource().getEntity()).getHeldItemMainhand()), identifier)) {
String name = EntityList.getEntityString(e.getEntity());
}
}
}
public static class Data {
String mobname;
public static Data read(NBTTagCompound tag) {
Data data = new Data();
data.mobname = tag.getString("mob");
return data;
}
public void write(NBTTagCompound tag) {
tag.setString("amount", mobname);
}
}
}

View File

@@ -1,79 +1,15 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
import slimeknights.tconstruct.library.utils.ToolHelper;
import static com.sosnitzka.taiga.Items.glimmerstone_dust;
import static com.sosnitzka.taiga.Items.tiberiumShardInstable;
import static com.sosnitzka.taiga.Items.tiberium_nugget;
public class TraitUncertain extends AbstractTrait {
public TraitUncertain() {
super("uncertain", TextFormatting.RED);
super(TraitUncertain.class.getName().toLowerCase().substring(4), TextFormatting.RED);
MinecraftForge.EVENT_BUS.register(this);
}
@Override
public void afterBlockBreak(ItemStack tool, World world, IBlockState state, BlockPos pos, EntityLivingBase player, boolean wasEffective) {
if (random.nextFloat() <= 0.05) {
if (!world.isRemote) {
if (random.nextFloat() > 0.1f) {
explode(world, player, pos.getX(), pos.getY(), pos.getZ());
} else explode(world, null, pos.getX(), pos.getY(), pos.getZ());
}
ToolHelper.damageTool(tool, random.nextInt(5) + 1, null);
}
}
@SubscribeEvent
public void onMobDrops(LivingDropsEvent event) {
World w = event.getEntity().getEntityWorld();
if (!w.isRemote && event.getSource().getEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.getSource().getEntity();
if (event.getEntity() instanceof EntityMob && TinkerUtil.hasTrait(TagUtil.getTagSafe(player.getHeldItemMainhand()), identifier)) {
ItemStack i = new ItemStack(Items.COAL, random.nextInt(4));
if (random.nextBoolean()) {
int r = random.nextInt(4);
switch (r) {
case 0:
i = new ItemStack(Items.GUNPOWDER, random.nextInt(4));
break;
case 1:
i = new ItemStack(tiberiumShardInstable, random.nextInt(4));
break;
case 2:
i = new ItemStack(tiberium_nugget, random.nextInt(12));
break;
case 3:
i = new ItemStack(glimmerstone_dust, random.nextInt(4));
break;
}
}
event.getDrops().add(0, new EntityItem(w, event.getEntity().posX, event.getEntity().posY, event.getEntity().posZ, i));
}
}
}
private void explode(World w, Entity e, double x, double y, double z) {
w.newExplosion(e, x, y, z, 1.2f + random.nextFloat() * 4, random.nextBoolean(), true);
}
}

View File

@@ -0,0 +1,17 @@
package com.sosnitzka.taiga.traits;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.MinecraftForge;
import slimeknights.tconstruct.library.traits.AbstractTrait;
public class TraitVortex extends AbstractTrait {
public TraitVortex() {
super(TraitVortex.class.getSimpleName().toLowerCase().substring(5), TextFormatting.DARK_PURPLE);
MinecraftForge.EVENT_BUS.register(this);
}
}

View File

@@ -0,0 +1,98 @@
package com.sosnitzka.taiga.traits;
import com.sosnitzka.taiga.util.Utils;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.traits.AbstractTrait;
import slimeknights.tconstruct.library.utils.TagUtil;
import slimeknights.tconstruct.library.utils.TinkerUtil;
import slimeknights.tconstruct.library.utils.ToolHelper;
public class TraitWhirl extends AbstractTrait {
protected static int TICK_PER_STAT = 36;
public TraitWhirl() {
super(TraitWhirl.class.getSimpleName().toLowerCase().substring(5), TextFormatting.DARK_BLUE);
MinecraftForge.EVENT_BUS.register(this);
}
@Override
public void onUpdate(ItemStack tool, World world, Entity entity, int itemSlot, boolean isSelected) {
if (entity instanceof FakePlayer || entity.worldObj.isRemote) {
return;
}
if (entity.ticksExisted % TICK_PER_STAT > 0) {
return;
}
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Utils.GeneralNBTData data = Utils.GeneralNBTData.read(tag);
data.radius += random.nextFloat() * 0.5f;
if (data.radius >= 1) {
TagUtil.setEnchantEffect(tool, true);
}
data.write(tag);
TagUtil.setExtraTag(tool, tag);
}
@SubscribeEvent
public void onRightClickItem(PlayerInteractEvent.RightClickItem event) {
World w = event.getWorld();
ItemStack tool = event.getEntityPlayer().getHeldItemMainhand();
if (!w.isRemote && TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier)) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Utils.GeneralNBTData data = Utils.GeneralNBTData.read(tag);
if ((int) data.radius >= 1) {
int r = Math.min((int) data.radius, 8);
for (int x = -r; x <= r; x++) {
for (int y = -r; y <= r; y++) {
for (int z = -r; z <= r; z++) {
if (MathHelper.sqrt_double(x * x + y * y + z * z) > r) {
continue;
}
BlockPos nPos = new BlockPos(event.getPos().getX() + x, event.getPos().getY() + y, event.getPos().getZ() + z);
if (!(event.getWorld().getBlockState(nPos).equals(Blocks.WATER.getDefaultState()) || event.getWorld().getBlockState(nPos).equals(Blocks.FLOWING_WATER.getDefaultState())))
continue;
event.getWorld().destroyBlock(nPos, false);
}
}
}
data.radius -= r;
data.write(tag);
TagUtil.setExtraTag(tool, tag);
TagUtil.setEnchantEffect(tool, false);
ToolHelper.damageTool(tool, 2 * r, event.getEntityPlayer());
}
}
}
@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent e) {
ItemStack tool = e.getItemStack();
if (TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier)) {
NBTTagCompound tag = TagUtil.getExtraTag(tool);
Utils.GeneralNBTData data = Utils.GeneralNBTData.read(tag);
if (data.radius > 0) {
e.getToolTip().add(TextFormatting.BLUE + "Actual Radius: " + TextFormatting.WHITE + Math.round(data.radius * 100) / 100);
}
}
}
}