forked from TAIGA/TAIGA
Fixed a Trait where no enchantment effect has been shown after restart. Added beserk trait.
This commit is contained in:
@@ -52,7 +52,9 @@ public class MaterialTraits {
|
||||
public static final AbstractTrait decay = new TraitDecay();
|
||||
public static final AbstractTrait whirl = new TraitWhirl();
|
||||
public static final AbstractTrait superheavy = new TraitSuperHeavy();
|
||||
//public static final AbstractTrait dev = new TraitDevelopement();
|
||||
public static final AbstractTrait dev = new TraitDevelopement();
|
||||
public static final AbstractTrait carousel = new TraitCarousel();
|
||||
public static final AbstractTrait beserk = new TraitBeserk();
|
||||
|
||||
|
||||
/**
|
||||
@@ -86,7 +88,7 @@ public class MaterialTraits {
|
||||
/**
|
||||
* With Dev
|
||||
**/
|
||||
public static Material adamant = new Material("adamant", TextFormatting.GOLD); //.addTrait(dev);
|
||||
public static Material adamant = new Material("adamant", TextFormatting.GOLD).addTrait(beserk); //.addTrait(dev);
|
||||
public static Material dyonite = new Material("dyonite", TextFormatting.GREEN).addTrait(tantrum);
|
||||
public static Material nucleum = new Material("nucleum", TextFormatting.YELLOW).addTrait(decay);
|
||||
public static Material lumix = new Material("lumix", TextFormatting.YELLOW).addTrait(bright, MaterialTypes.HANDLE).addTrait(glimmer, MaterialTypes.HEAD);
|
||||
|
107
src/main/java/com/sosnitzka/taiga/traits/TraitBeserk.java
Normal file
107
src/main/java/com/sosnitzka/taiga/traits/TraitBeserk.java
Normal file
@@ -0,0 +1,107 @@
|
||||
package com.sosnitzka.taiga.traits;
|
||||
|
||||
import com.sosnitzka.taiga.util.Utils;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
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.common.util.FakePlayer;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import slimeknights.tconstruct.library.tools.ToolNBT;
|
||||
import slimeknights.tconstruct.library.utils.TagUtil;
|
||||
import slimeknights.tconstruct.library.utils.TinkerUtil;
|
||||
import slimeknights.tconstruct.library.utils.ToolHelper;
|
||||
|
||||
|
||||
public class TraitBeserk extends TraitProgressiveStats {
|
||||
|
||||
protected static int TICK_PER_STAT = 8;
|
||||
|
||||
public TraitBeserk() {
|
||||
super(TraitBeserk.class.getSimpleName().toLowerCase().substring(5), TextFormatting.RED);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void miningSpeed(ItemStack tool, PlayerInteractEvent.BreakSpeed event) {
|
||||
NBTTagCompound tag = TagUtil.getExtraTag(tool);
|
||||
Utils.GeneralNBTData data = Utils.GeneralNBTData.read(tag);
|
||||
if (!data.active) return;
|
||||
event.setNewSpeed(event.getNewSpeed() * 4);
|
||||
}
|
||||
|
||||
@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);
|
||||
if (!data.active) return newDamage;
|
||||
return newDamage * 4;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack tool, World world, Entity entity, int itemSlot, boolean isSelected) {
|
||||
if (!world.isRemote) {
|
||||
NBTTagCompound tag = TagUtil.getExtraTag(tool);
|
||||
EntityLivingBase player = (EntityLivingBase) entity;
|
||||
Utils.GeneralNBTData data = Utils.GeneralNBTData.read(tag);
|
||||
NBTTagCompound root = TagUtil.getTagSafe(tool);
|
||||
StatNBT distributed = getBonus(root);
|
||||
if (data.active) {
|
||||
TagUtil.setEnchantEffect(root, true);
|
||||
if (entity instanceof FakePlayer) {
|
||||
return;
|
||||
}
|
||||
if (entity.ticksExisted % TICK_PER_STAT > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ToolNBT stat = TagUtil.getToolStats(tool);
|
||||
if (random.nextFloat() > .80f) {
|
||||
stat.durability -= 1;
|
||||
distributed.durability -= 1;
|
||||
} else
|
||||
ToolHelper.damageTool(tool, 1, player);
|
||||
TagUtil.setToolTag(root, stat.get());
|
||||
setBonus(root, distributed);
|
||||
} else TagUtil.setEnchantEffect(root, false);
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
NBTTagCompound root = TagUtil.getTagSafe(tool);
|
||||
StatNBT distributed = getBonus(root);
|
||||
ToolNBT stat = TagUtil.getToolStats(tool);
|
||||
if (data.active) {
|
||||
data.active = false;
|
||||
TagUtil.setEnchantEffect(root, false);
|
||||
TagUtil.setExtraTag(root, tag);
|
||||
data.write(tag);
|
||||
|
||||
} else {
|
||||
stat.durability -= 10;
|
||||
distributed.durability -= 10;
|
||||
TagUtil.setToolTag(root, stat.get());
|
||||
setBonus(root, distributed);
|
||||
data.active = true;
|
||||
data.write(tag);
|
||||
|
||||
TagUtil.setExtraTag(root, tag);
|
||||
data.write(tag);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
25
src/main/java/com/sosnitzka/taiga/traits/TraitCarousel.java
Normal file
25
src/main/java/com/sosnitzka/taiga/traits/TraitCarousel.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.sosnitzka.taiga.traits;
|
||||
|
||||
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.world.World;
|
||||
import slimeknights.tconstruct.library.traits.AbstractTrait;
|
||||
|
||||
|
||||
public class TraitCarousel extends AbstractTrait {
|
||||
|
||||
public static final int TICK = 24;
|
||||
|
||||
public TraitCarousel() {
|
||||
super(TraitCarousel.class.getSimpleName().toLowerCase().substring(5), 0xffcc5511);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterBlockBreak(ItemStack tool, World world, IBlockState state, BlockPos pos, EntityLivingBase player, boolean wasEffective) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -3,6 +3,8 @@ package com.sosnitzka.taiga.traits;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -10,6 +12,7 @@ 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.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -21,7 +24,7 @@ import slimeknights.tconstruct.library.utils.ToolHelper;
|
||||
|
||||
public class TraitCatcher extends AbstractTrait {
|
||||
|
||||
public static int chance = 1;
|
||||
public static int chance = 3;
|
||||
public static float costMulti = 0.25f;
|
||||
|
||||
public TraitCatcher() {
|
||||
@@ -29,25 +32,50 @@ public class TraitCatcher extends AbstractTrait {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean isCritical) {
|
||||
World w = player.worldObj;
|
||||
@SubscribeEvent
|
||||
public void killEntity(LivingDeathEvent event) {
|
||||
if (!(event.getSource().getEntity() instanceof EntityPlayer))
|
||||
return;
|
||||
if (event.getEntityLiving() instanceof EntityPlayer || event.getEntityLiving() instanceof EntityPlayerMP)
|
||||
return;
|
||||
World w = event.getSource().getEntity().getEntityWorld();
|
||||
EntityPlayer p = (EntityPlayer) event.getSource().getEntity();
|
||||
EntityLivingBase target = event.getEntityLiving();
|
||||
NBTTagCompound tag = TagUtil.getExtraTag(p.getHeldItemMainhand());
|
||||
Data data = Data.read(tag);
|
||||
if (!data.mobClass.isEmpty())
|
||||
return;
|
||||
if (!w.isRemote && random.nextInt((int) target.getMaxHealth()) <= chance && target instanceof EntityLiving) {
|
||||
NBTTagCompound tag = TagUtil.getExtraTag(tool);
|
||||
Data data = Data.read(tag);
|
||||
event.setCanceled(true);
|
||||
target.setDropItemsWhenDead(false);
|
||||
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);
|
||||
TagUtil.setExtraTag(p.getHeldItemMainhand(), tag);
|
||||
p.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
|
||||
target.setDropItemsWhenDead(false);
|
||||
target.setDead();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack tool, World world, Entity entity, int itemSlot, boolean isSelected) {
|
||||
if (!world.isRemote) {
|
||||
NBTTagCompound tag = TagUtil.getExtraTag(tool);
|
||||
Data data = Data.read(tag);
|
||||
if (data.mobClass.isEmpty()) {
|
||||
TagUtil.setEnchantEffect(tool, false);
|
||||
} else
|
||||
TagUtil.setEnchantEffect(tool, true);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRightClickItem(PlayerInteractEvent.RightClickItem event) {
|
||||
World w = event.getWorld();
|
||||
@@ -72,7 +100,6 @@ public class TraitCatcher extends AbstractTrait {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@@ -2,11 +2,14 @@ package com.sosnitzka.taiga.traits;
|
||||
|
||||
import net.minecraft.block.BlockStone;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
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 TraitDevelopement extends AbstractTrait {
|
||||
@@ -20,7 +23,8 @@ public class TraitDevelopement extends AbstractTrait {
|
||||
@SubscribeEvent
|
||||
public void onBreak(BlockEvent.BreakEvent e) {
|
||||
IBlockState state = e.getState();
|
||||
if (state.getBlock().equals(net.minecraft.init.Blocks.STONE))
|
||||
ItemStack tool = e.getPlayer().getHeldItemMainhand();
|
||||
if (state.getBlock().equals(net.minecraft.init.Blocks.STONE) && TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier))
|
||||
System.out.println("State.Variant: " + state.getValue(BlockStone.VARIANT));
|
||||
}
|
||||
|
||||
|
@@ -125,6 +125,7 @@ public class Utils {
|
||||
public float radius;
|
||||
public float dfloat;
|
||||
public int dint;
|
||||
public boolean active;
|
||||
|
||||
public static GeneralNBTData read(NBTTagCompound tag) {
|
||||
GeneralNBTData data = new GeneralNBTData();
|
||||
@@ -137,6 +138,7 @@ public class Utils {
|
||||
data.radius = tag.getFloat("radius");
|
||||
data.dfloat = tag.getFloat("dfloat");
|
||||
data.dint = tag.getInteger("dint");
|
||||
data.active = tag.getBoolean("active");
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -150,6 +152,7 @@ public class Utils {
|
||||
tag.setFloat("radius", radius);
|
||||
tag.setInteger("dint", dint);
|
||||
tag.setFloat("dfloat", dfloat);
|
||||
tag.setBoolean("active", active);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user