mirror of
https://github.com/GTNewHorizons/IguanaTweaksTConstruct.git
synced 2026-11-25 22:34:38 +00:00
Doing specific things now increases the chance for receiving specific modifiers a bit!
This commit is contained in:
1 parent
52b07c9f9c
commit
fa48bdced5
6 files changed
+157
-37
No files matched your search
@@ -52,10 +52,9 @@ public class LevelingActiveToolMod extends ActiveToolMod {
|
||||
strong = strength >= 1.0f;
|
||||
effective = harvestTool.isEffective(block.getMaterial());
|
||||
|
||||
boolean blockWithDrops = block.quantityDropped(IguanaTweaksTConstruct.random) > 1;
|
||||
boolean blockIsOre = false;
|
||||
// look for an oredict entry that suggests that the block is an ore
|
||||
// todo: might actually be worth it caching this stuff
|
||||
boolean blockIsOre = false;
|
||||
ItemStack blockStack = new ItemStack(Item.getItemFromBlock(block), 1, meta);
|
||||
for(int id : OreDictionary.getOreIDs(blockStack))
|
||||
if(OreDictionary.getOreName(id).startsWith("ore"))
|
||||
@@ -68,14 +67,34 @@ public class LevelingActiveToolMod extends ActiveToolMod {
|
||||
if(harvestable && effective && strong) {
|
||||
int xp = 1;
|
||||
// bonus xp for mining ores!
|
||||
if(blockWithDrops || blockIsOre)
|
||||
if(blockIsOre)
|
||||
xp++;
|
||||
LevelingLogic.addXP(stack, (EntityPlayer) entity, xp);
|
||||
|
||||
// bonus-chances for lapis when mining blocks with drops!
|
||||
if(block.quantityDropped(IguanaTweaksTConstruct.random) > 1)
|
||||
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.LAPIS, 1, tags);
|
||||
// or redstone!
|
||||
else
|
||||
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.REDSTONE, 1, tags);
|
||||
|
||||
// block was next to lava or hot liquid in general?
|
||||
boolean itsHotInHere = false;
|
||||
itsHotInHere |= entity.worldObj.getBlock(x+1, y, z).getMaterial() == Material.lava;
|
||||
itsHotInHere |= entity.worldObj.getBlock(x-1, y, z).getMaterial() == Material.lava;
|
||||
itsHotInHere |= entity.worldObj.getBlock(x, y+1, z).getMaterial() == Material.lava;
|
||||
itsHotInHere |= entity.worldObj.getBlock(x, y-1, z).getMaterial() == Material.lava;
|
||||
itsHotInHere |= entity.worldObj.getBlock(x, y, z+1).getMaterial() == Material.lava;
|
||||
itsHotInHere |= entity.worldObj.getBlock(x, y, z-1).getMaterial() == Material.lava;
|
||||
// it only took 7 lines to make this pun
|
||||
if(itsHotInHere)
|
||||
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.AUTOSMELT, 1, tags);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean afterBlockBreak() {
|
||||
Log.info("afterBlockBreak is implemented. Somebody tell me that so I can update xp giving.");
|
||||
|
||||
@@ -255,13 +255,18 @@ public abstract class LevelingLogic {
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
World world = player.worldObj;
|
||||
|
||||
// Add random bonuses on leveling up?
|
||||
// this is done first so the extra-chance can be incorporated correctly
|
||||
if (Config.toolLevelingRandomBonuses)
|
||||
{
|
||||
RandomBonuses.tryModifying(player, stack);
|
||||
}
|
||||
|
||||
// *ding* levelup!
|
||||
int level = getLevel(tags);
|
||||
level++;
|
||||
tags.setInteger(TAG_LEVEL, level);
|
||||
|
||||
boolean isTool = stack.getItem() instanceof HarvestTool;
|
||||
|
||||
// reset tool xp to 0, since we're at a new level now
|
||||
tags.setLong(TAG_EXP, 0L);
|
||||
|
||||
@@ -300,13 +305,6 @@ public abstract class LevelingLogic {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add random bonuses on leveling up?
|
||||
if (Config.toolLevelingRandomBonuses)
|
||||
{
|
||||
RandomBonuses.tryModifying(player, stack);
|
||||
}
|
||||
}
|
||||
|
||||
public static void levelUpMiningLevel(ItemStack stack, EntityPlayer player, boolean leveled)
|
||||
|
||||
@@ -22,22 +22,21 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/*
|
||||
todo:
|
||||
On doing stuff, add data what was done. Apply data to weights. Basically on action add an NBT tag that knows how much.
|
||||
- Redstone: mining a regular block
|
||||
- Luck: mining a block that drops stuff. Maybe miningan ore. Hitting an enemy (simply assume every enemy drops stuff for simplicity)
|
||||
On doing stuff, add data what was done. Apply data to weights. Basically on action add an NBT tag that knows how much.
|
||||
! - Redstone: mining a regular block
|
||||
! - Luck: mining a block that drops stuff. Maybe mining an ore. Hitting an enemy (simply assume every enemy drops stuff for simplicity)
|
||||
- autosmelt: ...hitting furnaces maybe? No, digging blocks that are submerged in lava! :D
|
||||
- silktouch: nope. we don't a higher silktouch chance.
|
||||
- diamond: this is probably not useful enough to warrant an increased chance. leave it at base chance.
|
||||
- emerald: same as diamond
|
||||
- repair: repairing the tool maybe? meh. Should probably simply have a good base chance and maybe decrease it once we get one level of it
|
||||
- attack: critting? or simply doing damage in general?
|
||||
- blaze: hitting a blaze
|
||||
- smite: hitting a zombie
|
||||
- bane: hitting a spider
|
||||
- beheading: hitting an enderman
|
||||
- lifesteal: hitting a skeleton (witherskeleton only?)
|
||||
- knockback: spring+hitting enemies
|
||||
! - attack: critting? or simply doing damage in general?
|
||||
! - blaze: hitting a blaze
|
||||
! - smite: hitting a zombie
|
||||
! - bane: hitting a spider
|
||||
! - beheading: hitting an enderman
|
||||
! - lifesteal: hitting a wither skelly or pigman
|
||||
! - knockback: spring+hitting enemies
|
||||
|
||||
maybe.. add a critical strike modifier, only obtainable through levelup :>
|
||||
*/
|
||||
@@ -71,6 +70,17 @@ public class RandomBonuses {
|
||||
else
|
||||
chances[i] = 0;
|
||||
|
||||
// calculate extra bonus chance
|
||||
if(chances[i] > 0 && tags.hasKey(String.format("Extra%s", mod.toString()))) {
|
||||
float bonus = tags.getInteger(String.format("Extra%s", mod.toString()));
|
||||
// relativize bonus to xp. It matters how much you've done X during the levelup after all, not in total. We don't want +100% chance :P
|
||||
// basically if we didn't do this, the higher the xp required, the higher the chance.
|
||||
bonus /= (float)LevelingLogic.getRequiredXp(tool, tags);
|
||||
// maximal bonus obtainable should be ~20
|
||||
bonus *= 20;
|
||||
chances[i] += bonus;
|
||||
}
|
||||
|
||||
total += chances[i];
|
||||
i++;
|
||||
}
|
||||
@@ -132,6 +142,21 @@ public class RandomBonuses {
|
||||
}
|
||||
}
|
||||
|
||||
if(Config.logBonusExtraChance && tags.hasKey(String.format("Extra%s", choice.toString()))) {
|
||||
// same as above
|
||||
float bonus = tags.getInteger(String.format("Extra%s", choice.toString()));
|
||||
bonus /= (float)LevelingLogic.getRequiredXp(tool, tags);
|
||||
bonus *= 20;
|
||||
|
||||
// now relativize the weight bonus to the total.
|
||||
Log.debug(String.format("Bonus weight for getting %s was %f", choice.toString(), bonus));
|
||||
Log.debug(String.format("Bonus chance for getting %s was %f %%", choice.toString(), 100f*bonus/(float)total));
|
||||
}
|
||||
|
||||
|
||||
// remove the extra chance for the received modifier
|
||||
resetModifierExtraWeight(choice, tags);
|
||||
|
||||
// restore modifiers
|
||||
tags.setInteger("Modifiers", modifiers);
|
||||
|
||||
@@ -315,6 +340,34 @@ public class RandomBonuses {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used to add an extra chance for getting a specific modifier.
|
||||
* @param modifier The modifier which gains extra chance
|
||||
* @param amount How much weight shall be added
|
||||
* @param tags The InfiTool tagcompound of the tool
|
||||
*/
|
||||
public static void addModifierExtraWeight(Modifier modifier, int amount, NBTTagCompound tags)
|
||||
{
|
||||
String key = "Extra" + modifier.toString();
|
||||
int old = 0;
|
||||
if(tags.hasKey(key))
|
||||
old = tags.getInteger(key);
|
||||
|
||||
tags.setInteger(key, old + amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the extra chance for a modifier.
|
||||
* @param modifier The modifier which loses its extra chance
|
||||
* @param tags The InfiTool tagcompound of the tool
|
||||
*/
|
||||
public static void resetModifierExtraWeight(Modifier modifier, NBTTagCompound tags)
|
||||
{
|
||||
String key = "Extra" + modifier.toString();
|
||||
if(tags.hasKey(key))
|
||||
tags.removeTag(key);
|
||||
}
|
||||
|
||||
/* Modifier weights */
|
||||
private static int getToolModifierWeight(Modifier mod)
|
||||
{
|
||||
@@ -444,6 +497,8 @@ public class RandomBonuses {
|
||||
LIFESTEAL,
|
||||
KNOCKBACK;
|
||||
|
||||
// !!! DO NOT CHANGE THESE !!!
|
||||
// They're used for NBTTags and Configs. Changing them would break compatibility
|
||||
@Override
|
||||
public String toString() {
|
||||
switch(this) {
|
||||
|
||||
+59
-14
@@ -5,8 +5,10 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import iguanaman.iguanatweakstconstruct.leveling.LevelingLogic;
|
||||
import iguanaman.iguanatweakstconstruct.leveling.LevelingTooltips;
|
||||
import iguanaman.iguanatweakstconstruct.leveling.RandomBonuses;
|
||||
import iguanaman.iguanatweakstconstruct.reference.Config;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.monster.*;
|
||||
import net.minecraft.entity.passive.EntityAnimal;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -29,23 +31,66 @@ public class LevelingEventHandler {
|
||||
@SubscribeEvent
|
||||
public void onHurt (LivingHurtEvent event)
|
||||
{
|
||||
if (event.source.damageType.equals("player") || event.source.damageType.equals("arrow"))
|
||||
if (event.source.getEntity() instanceof EntityPlayer)
|
||||
{
|
||||
EntityPlayer player = (EntityPlayer) event.source.getEntity();
|
||||
// fake player?
|
||||
if(!(player instanceof FakePlayer))
|
||||
{
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
if (stack != null && stack.hasTagCompound())
|
||||
if (stack.getItem() instanceof Weapon || stack.getItem() instanceof Battleaxe || stack.getItem() instanceof Shortbow && event.source.damageType.equals("arrow")) {
|
||||
long xp = Math.round(event.ammount);
|
||||
if (event.entityLiving instanceof EntityAnimal) xp = Math.round(event.ammount / 4f);
|
||||
// only player caused damage
|
||||
if (!(event.source.damageType.equals("player") || event.source.damageType.equals("arrow")))
|
||||
return;
|
||||
|
||||
if (xp > 0) LevelingLogic.addXP(stack, player, xp);
|
||||
}
|
||||
// only players
|
||||
if (!(event.source.getEntity() instanceof EntityPlayer))
|
||||
return;
|
||||
EntityPlayer player = (EntityPlayer) event.source.getEntity();
|
||||
// but no fake players
|
||||
if(player instanceof FakePlayer)
|
||||
return;
|
||||
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
if (stack == null || !stack.hasTagCompound())
|
||||
return;
|
||||
|
||||
// is a weapon?
|
||||
if (stack.getItem() instanceof Weapon || stack.getItem() instanceof Battleaxe || stack.getItem() instanceof Shortbow && event.source.damageType.equals("arrow")) {
|
||||
long xp = Math.round(event.ammount);
|
||||
if (event.entityLiving instanceof EntityAnimal) xp = Math.round(event.ammount / 4f);
|
||||
|
||||
if (xp > 0)
|
||||
{
|
||||
LevelingLogic.addXP(stack, player, xp);
|
||||
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
|
||||
// bonus chance for luck if hitting passive mob
|
||||
if(event.entityLiving instanceof EntityAnimal)
|
||||
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.LAPIS, 5, tags);
|
||||
// otherwise damage chance
|
||||
else
|
||||
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.ATTACK, 1, tags);
|
||||
|
||||
// spiders also increase bane chance
|
||||
if(event.entityLiving instanceof EntitySpider)
|
||||
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.BANE, 1, tags);
|
||||
// blazes give fiery chance (yes, blizz gives fiery :P)
|
||||
else if(event.entityLiving instanceof EntityBlaze)
|
||||
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.BLAZE, 1, tags);
|
||||
// zombie pigman gives lifesteal
|
||||
else if(event.entityLiving instanceof EntityPigZombie)
|
||||
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.LIFESTEAL, 1, tags);
|
||||
// zombie gives smite
|
||||
else if(event.entityLiving instanceof EntityZombie)
|
||||
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.SMITE, 1, tags);
|
||||
// wither skeleton gives lifesteal
|
||||
else if(event.entityLiving instanceof EntitySkeleton) {
|
||||
if (((EntitySkeleton) event.entityLiving).getSkeletonType() != 0)
|
||||
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.LIFESTEAL, 2, tags);
|
||||
}
|
||||
// enderman gives beheading
|
||||
else if(event.entityLiving instanceof EntityEnderman)
|
||||
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.BEHEADING, 3, tags);
|
||||
|
||||
// knocking back enemies with spriting gives knockback chance
|
||||
if(player.isSprinting())
|
||||
RandomBonuses.addModifierExtraWeight(RandomBonuses.Modifier.KNOCKBACK, 2, tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -73,6 +73,7 @@ public class Config {
|
||||
public static boolean logHarvestLevelChanges;
|
||||
public static boolean logMiningLevelChanges;
|
||||
public static boolean logToolMaterialChanges;
|
||||
public static boolean logBonusExtraChance;
|
||||
|
||||
|
||||
public void init(File file) {
|
||||
@@ -195,6 +196,7 @@ public class Config {
|
||||
logHarvestLevelChanges = configfile.getBoolean("logBlockHarvestLevelChange", CATEGORY_Debug, true, "Logs when the harvest level of a block is changed");
|
||||
logMiningLevelChanges = configfile.getBoolean("logToolMiningLevelChange", CATEGORY_Debug, true, "Logs when the mining level of a (non-tinker) tool is changed");
|
||||
logToolMaterialChanges = configfile.getBoolean("logTinkerMaterialChange", CATEGORY_Debug, true, "Logs when the mining level of a tinkers tool material is changed");
|
||||
logBonusExtraChance = configfile.getBoolean("logBonusExtraChance", CATEGORY_Debug, true, "Logs how much the extra-chance from doing stuff you had when getting a random bonus on levelup.");
|
||||
|
||||
|
||||
/** not implemented anymore **/
|
||||
|
||||
+1
@@ -13,6 +13,7 @@ public class VanillaToolNerfHandler {
|
||||
@SubscribeEvent
|
||||
public void breakSpeed(PlayerEvent.BreakSpeed event)
|
||||
{
|
||||
event.newSpeed *= 10;
|
||||
if(event.entityPlayer == null)
|
||||
return;
|
||||
|
||||
|
||||
Reference in new issue
Block a user