Merge pull request #2152 from abel1502/abel-abilities

Tool abilities GUI
This commit is contained in:
HbmMods 2025-05-21 13:39:14 +02:00 committed by GitHub
commit 411d73ff9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 9291 additions and 8481 deletions

View File

@ -1,67 +1,67 @@
mod_version=1.0.27
# Empty build number makes a release type
mod_build_number=5336
credits=HbMinecraft,\
\ rodolphito (explosion algorithms),\
\ grangerave (explosion algorithms),\
\ Hoboy (textures, models),\
\ Drillgon200 (effects, models, porting),\
\ MartinTheDragon (calculator, chunk-based fallout, bendable cranes, pipe improvements, PWR sounds),\
\ Alcater (GUI textures, porting),\
\ MellowArpeggiation (new animation system, turbine sounds, sound fixes, industrial lights, better particle diodes),\
\ Pheo (textures, various machines, models, weapons),\
\ Vær (gas centrifuges, better worldgen, ZIRNOX, CP-1 parts, starter guide, new cyclotron, weapon animations),\
\ UFFR (RTG pellets, guns, casings, euphemium capacitor, nucleartech.wiki),\
\ LePeep (coilgun model, BDCL QC),\
\ Adam29 (liquid petroleum, ethanol, electric furnace),\
\ Pvndols (thorium fuel recipe, gas turbine),\
\ JamesH2 (blood mechanics, nitric acid, particle emitter),\
\ Lazzzycat (structures),\
\ PastaBaguette (coal horse decal),\
\ Doctor17 (russian localization)),\
\ Pashtet (russian localization),\
\ Bismarck (chinese localization),\
\ Creeper-banner (chinese localization),\
\ 5467864 (chinese localization),\
\ eeeeee0a (chinese localization),\
\ hz0909adc (chinese localization),\
\ LSKLW (chinese localization),\
\ R-Kaenbyou (chinese localization),\
\ scp-000000000 (chinese localization),\
\ UnnameTokiko (chinese localization),\
\ Herobrine 457985 (chinese localization),\
\ xxwinhere (chinese localization),\
\ Maksymisio (polish localization)\
\ el3ctro4ndre (italian localization),\
\ Pu-238 (Tom impact effects),\
\ Frooz (gun models),\
\ VT-6/24 (models, textures),\
\ Nos (models),\
\ WushiThe (models),\
\ Minecreep (models),\
\ 70k (textures, glyphid AI, strand caster, electrolyzer changes, cryolite),\
\ instantnootles (concept artist),\
\ haru315 (spiral point algorithm),\
\ Sten89 (models),\
\ Pixelguru26 (textures),\
\ TheBlueHat (textures),\
\ Burningwater202 (laminate glass),\
\ TehTemmie (reacher radiation function),\
\ Silly541 (config for safe ME drives),\
\ Voxelstice (OpenComputers integration, turbine spinup),\
\ BallOfEnergy1 (OpenComputers integration, RBMK and packet optimization, crate backpacks),\
\ sdddddf80 (recipe configs, chinese localization, custom machine holograms),\
\ Abel1502 (optimization, crate upgrade recipes, strand caster improvements, varous tweaks),\
\ Darek505 (armor rendering compatibility fix),\
\ SuperCraftAlex (tooltips)\
\ Ice-Arrow (research reactor tweaks),\
\ 245tt (anvil GUI improvements),\
\ KoblizekXD (doors),\
\ FOlkvangrField (custom machine parts),\
\ RosaTryp (centrifuge config),\
\ Toshayo (satellite loot system, project settings, gradle curse task),\
\ icomet (refactoring),\
\ martemen (project settings),\
\ OvermindDL1 (project settings),\
\ impbk2002 (project settings)\
mod_version=1.0.27
# Empty build number makes a release type
mod_build_number=5336
credits=HbMinecraft,\
\ rodolphito (explosion algorithms),\
\ grangerave (explosion algorithms),\
\ Hoboy (textures, models),\
\ Drillgon200 (effects, models, porting),\
\ MartinTheDragon (calculator, chunk-based fallout, bendable cranes, pipe improvements, PWR sounds),\
\ Alcater (GUI textures, porting),\
\ MellowArpeggiation (new animation system, turbine sounds, sound fixes, industrial lights, better particle diodes),\
\ Pheo (textures, various machines, models, weapons),\
\ Vær (gas centrifuges, better worldgen, ZIRNOX, CP-1 parts, starter guide, new cyclotron, weapon animations),\
\ UFFR (RTG pellets, guns, casings, euphemium capacitor, nucleartech.wiki),\
\ LePeep (coilgun model, BDCL QC),\
\ Adam29 (liquid petroleum, ethanol, electric furnace),\
\ Pvndols (thorium fuel recipe, gas turbine),\
\ JamesH2 (blood mechanics, nitric acid, particle emitter),\
\ Lazzzycat (structures),\
\ PastaBaguette (coal horse decal),\
\ Doctor17 (russian localization)),\
\ Pashtet (russian localization),\
\ Bismarck (chinese localization),\
\ Creeper-banner (chinese localization),\
\ 5467864 (chinese localization),\
\ eeeeee0a (chinese localization),\
\ hz0909adc (chinese localization),\
\ LSKLW (chinese localization),\
\ R-Kaenbyou (chinese localization),\
\ scp-000000000 (chinese localization),\
\ UnnameTokiko (chinese localization),\
\ Herobrine 457985 (chinese localization),\
\ xxwinhere (chinese localization),\
\ Maksymisio (polish localization)\
\ el3ctro4ndre (italian localization),\
\ Pu-238 (Tom impact effects),\
\ Frooz (gun models),\
\ VT-6/24 (models, textures),\
\ Nos (models),\
\ WushiThe (models),\
\ Minecreep (models),\
\ 70k (textures, glyphid AI, strand caster, electrolyzer changes, cryolite),\
\ instantnootles (concept artist),\
\ haru315 (spiral point algorithm),\
\ Sten89 (models),\
\ Pixelguru26 (textures),\
\ TheBlueHat (textures),\
\ Burningwater202 (laminate glass),\
\ TehTemmie (reacher radiation function),\
\ Silly541 (config for safe ME drives),\
\ Voxelstice (OpenComputers integration, turbine spinup),\
\ BallOfEnergy1 (OpenComputers integration, RBMK and packet optimization, crate backpacks),\
\ sdddddf80 (recipe configs, chinese localization, custom machine holograms),\
\ Abel1502 (abilities GUI, optimization, crate upgrade recipes, strand caster improvements, varous tweaks),\
\ Darek505 (armor rendering compatibility fix),\
\ SuperCraftAlex (tooltips)\
\ Ice-Arrow (research reactor tweaks),\
\ 245tt (anvil GUI improvements),\
\ KoblizekXD (doors),\
\ FOlkvangrField (custom machine parts),\
\ RosaTryp (centrifuge config),\
\ Toshayo (satellite loot system, project settings, gradle curse task),\
\ icomet (refactoring),\
\ martemen (project settings),\
\ OvermindDL1 (project settings),\
\ impbk2002 (project settings)\

View File

@ -1,566 +0,0 @@
package com.hbm.handler;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.hbm.config.ToolConfig;
import com.hbm.explosion.ExplosionNT;
import com.hbm.explosion.ExplosionNT.ExAttrib;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.recipes.CentrifugeRecipes;
import com.hbm.inventory.recipes.CrystallizerRecipes;
import com.hbm.inventory.recipes.CrystallizerRecipes.CrystallizerRecipe;
import com.hbm.inventory.recipes.ShredderRecipes;
import com.hbm.items.ModItems;
import com.hbm.items.tool.IItemAbility;
import com.hbm.util.EnchantmentUtil;
import net.minecraft.block.Block;
import net.minecraft.client.resources.I18n;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
public abstract class ToolAbility {
//how to potentially save this: cancel the event/operation so that ItemInWorldManager's harvest method falls short, then recreate it with a more sensible structure
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) { return false; }
public abstract String getName();
public abstract String getFullName();
public abstract String getExtension();
public abstract boolean isAllowed();
public static class RecursionAbility extends ToolAbility {
int radius;
public RecursionAbility(int radius) {
this.radius = radius;
}
private Set<ThreeInts> pos = new HashSet();
@Override
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
Block b = world.getBlock(x, y, z);
if(b == Blocks.stone && !ToolConfig.recursiveStone)
return false;
if(b == Blocks.netherrack && !ToolConfig.recursiveNetherrack)
return false;
pos.clear();
recurse(world, x, y, z, x, y, z, player, tool, 0);
return false;
}
private static final List<ThreeInts> offsets = new ArrayList<>(3*3*3-1);
static {
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
for (int dz = -1; dz <= 1; dz++) {
if (dx != 0 || dy != 0 || dz != 0) {
offsets.add(new ThreeInts(dx, dy, dz));
}
}
}
}
}
private void recurse(World world, int x, int y, int z, int refX, int refY, int refZ, EntityPlayer player, IItemAbility tool, int depth) {
List<ThreeInts> shuffledOffsets = new ArrayList<>(offsets);
Collections.shuffle(shuffledOffsets);
for(ThreeInts offset : shuffledOffsets) {
breakExtra(world, x + offset.x, y + offset.y, z + offset.z, refX, refY, refZ, player, tool, depth);
}
}
private void breakExtra(World world, int x, int y, int z, int refX, int refY, int refZ, EntityPlayer player, IItemAbility tool, int depth) {
if(pos.contains(new ThreeInts(x, y, z)))
return;
depth += 1;
if(depth > ToolConfig.recursionDepth)
return;
pos.add(new ThreeInts(x, y, z));
//don't lose the ref block just yet
if(x == refX && y == refY && z == refZ)
return;
if(Vec3.createVectorHelper(x - refX, y - refY, z - refZ).lengthVector() > radius)
return;
Block b = world.getBlock(x, y, z);
Block ref = world.getBlock(refX, refY, refZ);
int meta = world.getBlockMetadata(x, y, z);
int refMeta = world.getBlockMetadata(refX, refY, refZ);
if(!isSameBlock(b, ref))
return;
if(meta != refMeta)
return;
if(player.getHeldItem() == null)
return;
tool.breakExtraBlock(world, x, y, z, player, refX, refY, refZ);
recurse(world, x, y, z, refX, refY, refZ, player, tool, depth);
}
private boolean isSameBlock(Block b1, Block b2) {
if(b1 == b2) return true;
if((b1 == Blocks.redstone_ore && b2 == Blocks.lit_redstone_ore) || (b1 == Blocks.lit_redstone_ore && b2 == Blocks.redstone_ore)) return true;
return false;
}
@Override
public String getName() {
return "tool.ability.recursion";
}
@Override
public String getFullName() {
return I18n.format(getName()) + getExtension();
}
@Override
public String getExtension() {
return " (" + radius + ")";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityVein;
}
}
public static class HammerAbility extends ToolAbility {
int range;
public HammerAbility(int range) {
this.range = range;
}
@Override
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
for(int a = x - range; a <= x + range; a++) {
for(int b = y - range; b <= y + range; b++) {
for(int c = z - range; c <= z + range; c++) {
if(a == x && b == y && c == z)
continue;
tool.breakExtraBlock(world, a, b ,c, player, x, y, z);
}
}
}
return false;
}
@Override
public String getName() {
return "tool.ability.hammer";
}
@Override
public String getFullName() {
return I18n.format(getName()) + getExtension();
}
@Override
public String getExtension() {
return " (" + range + ")";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityHammer;
}
}
public static class SilkAbility extends ToolAbility {
@Override
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
if(EnchantmentHelper.getSilkTouchModifier(player) || player.getHeldItem() == null)
return false;
ItemStack stack = player.getHeldItem();
EnchantmentUtil.addEnchantment(stack, Enchantment.silkTouch, 1);
if(player instanceof EntityPlayerMP)
IItemAbility.standardDigPost(world, x, y, z, (EntityPlayerMP) player);
EnchantmentUtil.removeEnchantment(stack, Enchantment.silkTouch);
return true;
}
@Override
public String getName() {
return "tool.ability.silktouch";
}
@Override
public String getFullName() {
return I18n.format(getName());
}
@Override
public String getExtension() {
return "";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilitySilk;
}
}
public static class LuckAbility extends ToolAbility {
int luck;
public LuckAbility(int luck) {
this.luck = luck;
}
@Override
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
if(EnchantmentHelper.getFortuneModifier(player) > 0 || player.getHeldItem() == null)
return false;
ItemStack stack = player.getHeldItem();
EnchantmentUtil.addEnchantment(stack, Enchantment.fortune, luck);
if(player instanceof EntityPlayerMP)
IItemAbility.standardDigPost(world, x, y, z, (EntityPlayerMP) player);
EnchantmentUtil.removeEnchantment(stack, Enchantment.fortune);
return true;
}
@Override
public String getName() {
return "tool.ability.luck";
}
@Override
public String getFullName() {
return I18n.format(getName()) + getExtension();
}
@Override
public String getExtension() {
return " (" + luck + ")";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityLuck;
}
}
public static class SmelterAbility extends ToolAbility {
@Override
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
List<ItemStack> drops = block.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
boolean doesSmelt = false;
for(int i = 0; i < drops.size(); i++) {
ItemStack stack = drops.get(i).copy();
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(stack);
if(result != null) {
result = result.copy();
result.stackSize *= stack.stackSize;
drops.set(i, result);
doesSmelt = true;
}
}
if(doesSmelt) {
world.setBlockToAir(x, y, z);
player.getHeldItem().damageItem(1, player);
for(ItemStack stack : drops)
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, stack.copy()));
}
return false;
}
@Override
public String getName() {
return "tool.ability.smelter";
}
@Override
public String getFullName() {
return I18n.format(getName());
}
@Override
public String getExtension() {
return "";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityFurnace;
}
}
public static class ShredderAbility extends ToolAbility {
@Override
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
//a band-aid on a gaping wound
if(block == Blocks.lit_redstone_ore)
block = Blocks.redstone_ore;
ItemStack stack = new ItemStack(block, 1, meta);
ItemStack result = ShredderRecipes.getShredderResult(stack);
if(result != null && result.getItem() != ModItems.scrap) {
world.setBlockToAir(x, y, z);
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, result.copy()));
player.getHeldItem().damageItem(1, player);
}
return false;
}
@Override
public String getName() {
return "tool.ability.shredder";
}
@Override
public String getFullName() {
return I18n.format(getName());
}
@Override
public String getExtension() {
return "";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityShredder;
}
}
public static class CentrifugeAbility extends ToolAbility {
@Override
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
//a band-aid on a gaping wound
if(block == Blocks.lit_redstone_ore)
block = Blocks.redstone_ore;
ItemStack stack = new ItemStack(block, 1, meta);
ItemStack[] result = CentrifugeRecipes.getOutput(stack);
if(result != null) {
world.setBlockToAir(x, y, z);
player.getHeldItem().damageItem(1, player);
for(ItemStack st : result) {
if(st != null)
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, st.copy()));
}
}
return false;
}
@Override
public String getExtension() {
return "";
}
@Override
public String getName() {
return "tool.ability.centrifuge";
}
@Override
public String getFullName() {
return I18n.format(getName());
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityCentrifuge;
}
}
public static class CrystallizerAbility extends ToolAbility {
@Override
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
//a band-aid on a gaping wound
if(block == Blocks.lit_redstone_ore)
block = Blocks.redstone_ore;
ItemStack stack = new ItemStack(block, 1, meta);
CrystallizerRecipe result = CrystallizerRecipes.getOutput(stack, Fluids.PEROXIDE);
if(result != null) {
world.setBlockToAir(x, y, z);
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, result.output.copy()));
player.getHeldItem().damageItem(1, player);
}
return false;
}
@Override
public String getExtension() {
return "";
}
@Override
public String getName() {
return "tool.ability.crystallizer";
}
@Override
public String getFullName() {
return I18n.format(getName());
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityCrystallizer;
}
}
public static class MercuryAbility extends ToolAbility {
@Override
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
//a band-aid on a gaping wound
if(block == Blocks.lit_redstone_ore)
block = Blocks.redstone_ore;
int mercury = 0;
if(block == Blocks.redstone_ore)
mercury = player.getRNG().nextInt(5) + 4;
if(block == Blocks.redstone_block)
mercury = player.getRNG().nextInt(7) + 8;
if(mercury > 0) {
world.setBlockToAir(x, y, z);
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, new ItemStack(ModItems.ingot_mercury, mercury)));
player.getHeldItem().damageItem(1, player);
}
return false;
}
@Override
public String getExtension() {
return "";
}
@Override
public String getName() {
return "tool.ability.mercury";
}
@Override
public String getFullName() {
return I18n.format(getName());
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityMercury;
}
}
public static class ExplosionAbility extends ToolAbility {
float strength;
public ExplosionAbility(float strength) {
this.strength = strength;
}
@Override
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
ExplosionNT ex = new ExplosionNT(player.worldObj, player, x + 0.5, y + 0.5, z + 0.5, strength);
ex.addAttrib(ExAttrib.ALLDROP);
ex.addAttrib(ExAttrib.NOHURT);
ex.addAttrib(ExAttrib.NOPARTICLE);
ex.doExplosionA();
ex.doExplosionB(false);
player.worldObj.createExplosion(player, x + 0.5, y + 0.5, z + 0.5, 0.1F, false);
return true;
}
@Override
public String getExtension() {
return " (" + strength + ")";
}
@Override
public String getName() {
return "tool.ability.explosion";
}
@Override
public String getFullName() {
return I18n.format(getName()) + getExtension();
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityExplosion;
}
}
}

View File

@ -1,324 +0,0 @@
package com.hbm.handler;
import com.hbm.blocks.ModBlocks;
import com.hbm.blocks.generic.BlockBobble.BobbleType;
import com.hbm.handler.threading.PacketThreading;
import com.hbm.items.ModItems;
import com.hbm.items.tool.IItemAbility;
import com.hbm.packet.toclient.AuxParticlePacketNT;
import com.hbm.potion.HbmPotion;
import com.hbm.util.ContaminationUtil;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import com.hbm.util.ContaminationUtil.ContaminationType;
import com.hbm.util.ContaminationUtil.HazardType;
import net.minecraft.block.Block;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityMagmaCube;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntitySlime;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
public abstract class WeaponAbility {
public abstract void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool);
public abstract String getName();
public abstract String getFullName();
public static class RadiationAbility extends WeaponAbility {
float rad;
public RadiationAbility(float rad) {
this.rad = rad;
}
@Override
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
if(victim instanceof EntityLivingBase)
ContaminationUtil.contaminate((EntityLivingBase)victim, HazardType.RADIATION, ContaminationType.CREATIVE, rad);
}
@Override
public String getName() {
return "weapon.ability.radiation";
}
@Override
public String getFullName() {
return I18n.format(getName()) + " (" + rad + ")";
}
}
public static class VampireAbility extends WeaponAbility {
float amount;
public VampireAbility(float amount) {
this.amount = amount;
}
@Override
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
if(victim instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) victim;
if(living.getHealth() <= 0) return;
living.setHealth(living.getHealth() - amount);
if(living.getHealth() <= 0) living.onDeath(DamageSource.magic);
player.heal(amount);
}
}
@Override
public String getName() {
return "weapon.ability.vampire";
}
@Override
public String getFullName() {
return I18n.format(getName()) + " (" + amount + ")";
}
}
public static class StunAbility extends WeaponAbility {
int duration;
public StunAbility(int duration) {
this.duration = duration;
}
@Override
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
if(victim instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) victim;
living.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, duration * 20, 4));
living.addPotionEffect(new PotionEffect(Potion.weakness.id, duration * 20, 4));
}
}
@Override
public String getName() {
return "weapon.ability.stun";
}
@Override
public String getFullName() {
return I18n.format(getName()) + " (" + duration + ")";
}
}
public static class PhosphorusAbility extends WeaponAbility {
int duration;
public PhosphorusAbility(int duration) {
this.duration = duration;
}
@Override
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
if(victim instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) victim;
living.addPotionEffect(new PotionEffect(HbmPotion.phosphorus.id, duration * 20, 4));
}
}
@Override
public String getName() {
return "weapon.ability.phosphorus";
}
@Override
public String getFullName() {
return I18n.format(getName()) + " (" + duration + ")";
}
}
public static class FireAbility extends WeaponAbility {
int duration;
public FireAbility(int duration) {
this.duration = duration;
}
@Override
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
if(victim instanceof EntityLivingBase) {
victim.setFire(duration);
}
}
@Override
public String getName() {
return "weapon.ability.fire";
}
@Override
public String getFullName() {
return I18n.format(getName()) + " (" + duration + ")";
}
}
public static class ChainsawAbility extends WeaponAbility {
int divider;
public ChainsawAbility(int divider) {
this.divider = divider;
}
@Override
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
if(victim instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) victim;
if(living.getHealth() <= 0.0F) {
int count = Math.min((int)Math.ceil(living.getMaxHealth() / divider), 250); //safeguard to prevent funnies from bosses with obscene health
for(int i = 0; i < count; i++) {
living.entityDropItem(new ItemStack(ModItems.nitra_small), 1);
world.spawnEntityInWorld(new EntityXPOrb(world, living.posX, living.posY, living.posZ, 1));
}
if(player instanceof EntityPlayerMP) {
NBTTagCompound data = new NBTTagCompound();
data.setString("type", "vanillaburst");
data.setInteger("count", count * 4);
data.setDouble("motion", 0.1D);
data.setString("mode", "blockdust");
data.setInteger("block", Block.getIdFromBlock(Blocks.redstone_block));
PacketThreading.createAllAroundThreadedPacket(new AuxParticlePacketNT(data, living.posX, living.posY + living.height * 0.5, living.posZ), new TargetPoint(living.dimension, living.posX, living.posY, living.posZ, 50));
}
world.playSoundEffect(living.posX, living.posY + living.height * 0.5, living.posZ, "hbm:weapon.chainsaw", 0.5F, 1.0F);
}
}
}
@Override
public String getName() {
return "weapon.ability.chainsaw";
}
@Override
public String getFullName() {
return I18n.format(getName()) + " (1:" + divider + ")";
}
}
public static class BeheaderAbility extends WeaponAbility {
@Override
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
if(victim instanceof EntityLivingBase && ((EntityLivingBase) victim).getHealth() <= 0.0F) {
EntityLivingBase living = (EntityLivingBase) victim;
if(living instanceof EntitySkeleton) {
if(((EntitySkeleton)living).getSkeletonType() == 0) {
living.entityDropItem(new ItemStack(Items.skull, 1, 0), 0.0F);
} else {
if(world.rand.nextInt(20) == 0)
living.entityDropItem(new ItemStack(Items.skull, 1, 1), 0.0F);
else
living.entityDropItem(new ItemStack(Items.coal, 3), 0.0F);
}
} else if(living instanceof EntityZombie) {
living.entityDropItem(new ItemStack(Items.skull, 1, 2), 0.0F);
} else if(living instanceof EntityCreeper) {
living.entityDropItem(new ItemStack(Items.skull, 1, 4), 0.0F);
} else if(living instanceof EntityMagmaCube) {
living.entityDropItem(new ItemStack(Items.magma_cream, 3), 0.0F);
} else if(living instanceof EntitySlime) {
living.entityDropItem(new ItemStack(Items.slime_ball, 3), 0.0F);
} else if(living instanceof EntityPlayer) {
ItemStack head = new ItemStack(Items.skull, 1, 3);
head.stackTagCompound = new NBTTagCompound();
head.stackTagCompound.setString("SkullOwner", ((EntityPlayer) living).getDisplayName());
living.entityDropItem(head, 0.0F);
} else {
living.entityDropItem(new ItemStack(Items.rotten_flesh, 3, 0), 0.0F);
living.entityDropItem(new ItemStack(Items.bone, 2, 0), 0.0F);
}
}
}
@Override
public String getName() {
return "weapon.ability.beheader";
}
@Override
public String getFullName() {
return I18n.format(getName());
}
}
public static class BobbleAbility extends WeaponAbility {
@Override
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
if(victim instanceof EntityMob && ((EntityMob) victim).getHealth() <= 0.0F) {
EntityMob mob = (EntityMob) victim;
int chance = 1000;
if(mob.getMaxHealth() > 20) {
chance = 750;
}
if(world.rand.nextInt(chance) == 0)
mob.entityDropItem(new ItemStack(ModBlocks.bobblehead, 1, world.rand.nextInt(BobbleType.values().length - 1) + 1), 0.0F);
}
}
@Override
public String getName() {
return "weapon.ability.bobble";
}
@Override
public String getFullName() {
return I18n.format(getName());
}
}
}

View File

@ -0,0 +1,133 @@
package com.hbm.handler.ability;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.google.common.base.Functions;
import com.hbm.main.MainRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.util.EnumChatFormatting;
// All abilities available on a given tool
public class AvailableAbilities {
// Insertion order matters
private HashMap<IBaseAbility, Integer> abilities = new HashMap<IBaseAbility, Integer>();
public AvailableAbilities() {}
public AvailableAbilities addAbility(IBaseAbility ability, int level) {
if (level < 0 || level >= ability.levels()) {
MainRegistry.logger.warn("Illegal level " + level + " for ability " + ability.getName());
level = ability.levels() - 1;
}
if (abilities.containsKey(ability)) {
MainRegistry.logger.warn("Ability " + ability.getName() + " already had level " + abilities.get(ability) + ", overwriting with level " + level);
}
if (ability.isAllowed()) {
abilities.put(ability, level);
}
return this;
}
public AvailableAbilities addToolAbilities() {
addAbility(IToolAreaAbility.NONE, 0);
addAbility(IToolHarvestAbility.NONE, 0);
return this;
}
public AvailableAbilities removeAbility(IBaseAbility ability) {
abilities.remove(ability);
return this;
}
public boolean supportsAbility(IBaseAbility ability) {
return abilities.containsKey(ability);
}
public int maxLevel(IBaseAbility ability) {
return abilities.getOrDefault(ability, -1);
}
public Map<IBaseAbility, Integer> get() {
return Collections.unmodifiableMap(abilities);
}
public Map<IWeaponAbility, Integer> getWeaponAbilities() {
return abilities.keySet().stream().filter(a -> a instanceof IWeaponAbility).collect(Collectors.toMap(a -> (IWeaponAbility)a, a -> abilities.get(a)));
}
public Map<IBaseAbility, Integer> getToolAbilities() {
return abilities.keySet().stream().filter(a -> a instanceof IToolAreaAbility || a instanceof IToolHarvestAbility).collect(Collectors.toMap(a -> a, a -> abilities.get(a)));
}
public Map<IToolAreaAbility, Integer> getToolAreaAbilities() {
return abilities.keySet().stream().filter(a -> a instanceof IToolAreaAbility).collect(Collectors.toMap(a -> (IToolAreaAbility)a, a -> abilities.get(a)));
}
public Map<IToolHarvestAbility, Integer> getToolHarvestAbilities() {
return abilities.keySet().stream().filter(a -> a instanceof IToolHarvestAbility).collect(Collectors.toMap(a -> (IToolHarvestAbility)a, a -> abilities.get(a)));
}
public int size() {
return abilities.size();
}
public boolean isEmpty() {
return abilities.isEmpty();
}
@SideOnly(Side.CLIENT)
public void addInformation(List list) {
List<Map.Entry<IBaseAbility, Integer>> toolAbilities = abilities.entrySet().stream().filter(entry ->
(entry.getKey() instanceof IToolAreaAbility && entry.getKey() != IToolAreaAbility.NONE) ||
(entry.getKey() instanceof IToolHarvestAbility && entry.getKey() != IToolHarvestAbility.NONE)
).sorted(
Comparator
.comparing(Map.Entry<IBaseAbility, Integer>::getKey)
.thenComparing(Map.Entry<IBaseAbility, Integer>::getValue)
).collect(Collectors.toList());
if (!toolAbilities.isEmpty()) {
list.add("Abilities: ");
toolAbilities.forEach(entry -> {
IBaseAbility ability = entry.getKey();
int level = entry.getValue();
list.add(" " + EnumChatFormatting.GOLD + ability.getFullName(level));
});
list.add("Right click to cycle through presets!");
list.add("Sneak-click to go to first preset!");
list.add("Alt-click to open customization GUI!");
}
List<Map.Entry<IBaseAbility, Integer>> weaponAbilities = abilities.entrySet().stream().filter(entry ->
(entry.getKey() instanceof IWeaponAbility && entry.getKey() != IWeaponAbility.NONE)
).sorted(
Comparator
.comparing(Map.Entry<IBaseAbility, Integer>::getKey)
.thenComparing(Map.Entry<IBaseAbility, Integer>::getValue)
).collect(Collectors.toList());
if (!weaponAbilities.isEmpty()) {
list.add("Weapon modifiers: ");
weaponAbilities.forEach(entry -> {
IBaseAbility ability = entry.getKey();
int level = entry.getValue();
list.add(" " + EnumChatFormatting.RED + ability.getFullName(level));
});
}
}
}

View File

@ -0,0 +1,36 @@
package com.hbm.handler.ability;
import net.minecraft.client.resources.I18n;
public interface IBaseAbility extends Comparable<IBaseAbility> {
public String getName();
public default String getExtension(int level) {
return "";
}
public default String getFullName(int level) {
return I18n.format(getName()) + getExtension(level);
}
public default boolean isAllowed() {
return true;
}
// 1 means no support for levels (i.e. the level is always 0).
// The UI only supports levels() between 1 and 10 (inclusive).
// All calls accepting an `int level` parameters must be done
// with a level between 0 and levels()-1 (inclusive).
default int levels() {
return 1;
}
default int sortOrder() {
return hashCode();
}
@Override
default int compareTo(IBaseAbility o) {
return sortOrder() - o.sortOrder();
}
}

View File

@ -0,0 +1,283 @@
package com.hbm.handler.ability;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.hbm.config.ToolConfig;
import com.hbm.explosion.ExplosionNT;
import com.hbm.explosion.ExplosionNT.ExAttrib;
import com.hbm.handler.ThreeInts;
import com.hbm.inventory.OreDictManager;
import com.hbm.items.tool.ItemToolAbility;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
public interface IToolAreaAbility extends IBaseAbility {
// Should call tool.breakExtraBlock on a bunch of blocks.
// The initial block is implicitly broken, so don't call breakExtraBlock on it.
// Returning true skips the reference block from being broken
public boolean onDig(int level, World world, int x, int y, int z, EntityPlayer player, ItemToolAbility tool);
// Whether breakExtraBlock is called at all. Currently only false for explosion
public default boolean allowsHarvest(int level) {
return true;
}
public final static int SORT_ORDER_BASE = 0;
// region handlers
public static final IToolAreaAbility NONE = new IToolAreaAbility() {
@Override
public String getName() {
return "";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 0;
}
@Override
public boolean onDig(int level, World world, int x, int y, int z, EntityPlayer player, ItemToolAbility tool) {
return false;
}
};
public static final IToolAreaAbility RECURSION = new IToolAreaAbility() {
@Override
public String getName() {
return "tool.ability.recursion";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityVein;
}
public final int[] radiusAtLevel = {3, 4, 5, 6, 7, 9, 10};
@Override
public int levels() {
return radiusAtLevel.length;
}
@Override
public String getExtension(int level) {
return " (" + radiusAtLevel[level] + ")";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 1;
}
// Note: if reusing it across different instatces of a tool
// is a problem here, then it had already been one before
// the refactor! The solution is to simply make this a local
// of the onDig method and pass it around as a parameter.
private Set<ThreeInts> pos = new HashSet<>();
@Override
public boolean onDig(int level, World world, int x, int y, int z, EntityPlayer player, ItemToolAbility tool) {
Block b = world.getBlock(x, y, z);
if(b == Blocks.stone && !ToolConfig.recursiveStone) {
return false;
}
if(b == Blocks.netherrack && !ToolConfig.recursiveNetherrack) {
return false;
}
pos.clear();
recurse(world, x, y, z, x, y, z, player, tool, 0, radiusAtLevel[level]);
return false;
}
private final List<ThreeInts> offsets = new ArrayList<ThreeInts>(3*3*3-1) {{
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
for (int dz = -1; dz <= 1; dz++) {
if (dx != 0 || dy != 0 || dz != 0) {
add(new ThreeInts(dx, dy, dz));
}
}
}
}
}};
private void recurse(World world, int x, int y, int z, int refX, int refY, int refZ, EntityPlayer player, ItemToolAbility tool, int depth, int radius) {
List<ThreeInts> shuffledOffsets = new ArrayList<>(offsets);
Collections.shuffle(shuffledOffsets);
for(ThreeInts offset : shuffledOffsets) {
breakExtra(world, x + offset.x, y + offset.y, z + offset.z, refX, refY, refZ, player, tool, depth, radius);
}
}
private void breakExtra(World world, int x, int y, int z, int refX, int refY, int refZ, EntityPlayer player, ItemToolAbility tool, int depth, int radius) {
if(pos.contains(new ThreeInts(x, y, z)))
return;
depth += 1;
if(depth > ToolConfig.recursionDepth)
return;
pos.add(new ThreeInts(x, y, z));
//don't lose the ref block just yet
if(x == refX && y == refY && z == refZ)
return;
if(Vec3.createVectorHelper(x - refX, y - refY, z - refZ).lengthVector() > radius)
return;
Block b = world.getBlock(x, y, z);
Block ref = world.getBlock(refX, refY, refZ);
int meta = world.getBlockMetadata(x, y, z);
int refMeta = world.getBlockMetadata(refX, refY, refZ);
if(!isSameBlock(b, ref))
return;
if(meta != refMeta)
return;
if(player.getHeldItem() == null)
return;
tool.breakExtraBlock(world, x, y, z, player, refX, refY, refZ);
recurse(world, x, y, z, refX, refY, refZ, player, tool, depth, radius);
}
private boolean isSameBlock(Block b1, Block b2) {
if(b1 == b2) return true;
if((b1 == Blocks.redstone_ore && b2 == Blocks.lit_redstone_ore) || (b1 == Blocks.lit_redstone_ore && b2 == Blocks.redstone_ore)) return true;
return false;
}
};
public static final IToolAreaAbility HAMMER = new IToolAreaAbility() {
@Override
public String getName() {
return "tool.ability.hammer";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityHammer;
}
public final int[] rangeAtLevel = {1, 2, 3, 4};
@Override
public int levels() {
return rangeAtLevel.length;
}
@Override
public String getExtension(int level) {
return " (" + rangeAtLevel[level] + ")";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 2;
}
@Override
public boolean onDig(int level, World world, int x, int y, int z, EntityPlayer player, ItemToolAbility tool) {
int range = rangeAtLevel[level];
for(int a = x - range; a <= x + range; a++) {
for(int b = y - range; b <= y + range; b++) {
for(int c = z - range; c <= z + range; c++) {
if (a == x && b == y && c == z)
continue;
tool.breakExtraBlock(world, a, b ,c, player, x, y, z);
}
}
}
return false;
}
};
public static final IToolAreaAbility EXPLOSION = new IToolAreaAbility() {
@Override
public String getName() {
return "tool.ability.explosion";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityExplosion;
}
public final float[] strengthAtLevel = {2.5F, 5F, 10F, 15F};
@Override
public int levels() {
return strengthAtLevel.length;
}
@Override
public String getExtension(int level) {
return " (" + strengthAtLevel[level] + ")";
}
@Override
public boolean allowsHarvest(int level) {
return false;
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 3;
}
@Override
public boolean onDig(int level, World world, int x, int y, int z, EntityPlayer player, ItemToolAbility tool) {
float strength = strengthAtLevel[level];
ExplosionNT ex = new ExplosionNT(player.worldObj, player, x + 0.5, y + 0.5, z + 0.5, strength);
ex.addAttrib(ExAttrib.ALLDROP);
ex.addAttrib(ExAttrib.NOHURT);
ex.addAttrib(ExAttrib.NOPARTICLE);
ex.doExplosionA();
ex.doExplosionB(false);
player.worldObj.createExplosion(player, x + 0.5, y + 0.5, z + 0.5, 0.1F, false);
return true;
}
};
// endregion handlers
static final IToolAreaAbility[] abilities = {NONE, RECURSION, HAMMER, EXPLOSION};
static IToolAreaAbility getByName(String name) {
for(IToolAreaAbility ability : abilities) {
if(ability.getName().equals(name))
return ability;
}
return NONE;
}
}

View File

@ -0,0 +1,341 @@
package com.hbm.handler.ability;
import java.util.List;
import com.hbm.config.ToolConfig;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.recipes.CentrifugeRecipes;
import com.hbm.inventory.recipes.CrystallizerRecipes;
import com.hbm.inventory.recipes.ShredderRecipes;
import com.hbm.inventory.recipes.CrystallizerRecipes.CrystallizerRecipe;
import com.hbm.items.ModItems;
import com.hbm.items.tool.ItemToolAbility;
import com.hbm.util.EnchantmentUtil;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.world.World;
public interface IToolHarvestAbility extends IBaseAbility {
public default void preHarvestAll(int level, World world, EntityPlayer player) {}
public default void postHarvestAll(int level, World world, EntityPlayer player) {}
// You must call harvestBlock to actually break the block.
// If you don't, visual glitches ensue
public default void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) {
harvestBlock(false, world, x, y, z, player);
}
public static void harvestBlock(boolean skipDefaultDrops, World world, int x, int y, int z, EntityPlayer player) {
if (skipDefaultDrops) {
// Emulate the block breaking without drops
world.setBlockToAir(x, y, z);
player.getHeldItem().damageItem(1, player);
} else if (player instanceof EntityPlayerMP) {
// Break the block conventionally
ItemToolAbility.standardDigPost(world, x, y, z, (EntityPlayerMP) player);
}
}
public final static int SORT_ORDER_BASE = 100;
// region handlers
public static final IToolHarvestAbility NONE = new IToolHarvestAbility() {
@Override
public String getName() {
return "";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 0;
}
};
public static final IToolHarvestAbility SILK = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.silktouch";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilitySilk;
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 1;
}
@Override
public void preHarvestAll(int level, World world, EntityPlayer player) {
ItemStack stack = player.getHeldItem();
EnchantmentUtil.addEnchantment(stack, Enchantment.silkTouch, 1);
}
@Override
public void postHarvestAll(int level, World world, EntityPlayer player) {
// ToC-ToU mismatch should be impossible
// because both calls happen on the same tick.
// Even if can be forced somehow, the player doesn't gain any benefit from it.
ItemStack stack = player.getHeldItem();
EnchantmentUtil.removeEnchantment(stack, Enchantment.silkTouch);
}
};
public static final IToolHarvestAbility LUCK = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.luck";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityLuck;
}
public final int[] powerAtLevel = {1, 2, 3, 4, 5, 9};
@Override
public int levels() {
return powerAtLevel.length;
}
@Override
public String getExtension(int level) {
return " (" + powerAtLevel[level] + ")";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 2;
}
@Override
public void preHarvestAll(int level, World world, EntityPlayer player) {
ItemStack stack = player.getHeldItem();
EnchantmentUtil.addEnchantment(stack, Enchantment.fortune, powerAtLevel[level]);
}
@Override
public void postHarvestAll(int level, World world, EntityPlayer player) {
// ToC-ToU mismatch should be impossible
// because both calls happen on the same tick.
// Even if can be forced somehow, the player doesn't gain any benefit from it.
ItemStack stack = player.getHeldItem();
EnchantmentUtil.removeEnchantment(stack, Enchantment.fortune);
}
};
public static final IToolHarvestAbility SMELTER = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.smelter";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityFurnace;
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 3;
}
@Override
public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) {
List<ItemStack> drops = block.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
boolean doesSmelt = false;
for(int i = 0; i < drops.size(); i++) {
ItemStack stack = drops.get(i).copy();
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(stack);
if(result != null) {
result = result.copy();
result.stackSize *= stack.stackSize;
drops.set(i, result);
doesSmelt = true;
}
}
harvestBlock(doesSmelt, world, x, y, z, player);
if(doesSmelt) {
for(ItemStack stack : drops) {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, stack.copy()));
}
}
}
};
public static final IToolHarvestAbility SHREDDER = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.shredder";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityShredder;
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 4;
}
@Override
public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) {
//a band-aid on a gaping wound
if(block == Blocks.lit_redstone_ore)
block = Blocks.redstone_ore;
ItemStack stack = new ItemStack(block, 1, meta);
ItemStack result = ShredderRecipes.getShredderResult(stack);
boolean doesShred = result != null && result.getItem() != ModItems.scrap;
harvestBlock(doesShred, world, x, y, z, player);
if(doesShred) {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, result.copy()));
}
}
};
public static final IToolHarvestAbility CENTRIFUGE = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.centrifuge";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityCentrifuge;
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 5;
}
@Override
public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) {
//a band-aid on a gaping wound
if(block == Blocks.lit_redstone_ore)
block = Blocks.redstone_ore;
ItemStack stack = new ItemStack(block, 1, meta);
ItemStack[] result = CentrifugeRecipes.getOutput(stack);
boolean doesCentrifuge = result != null;
harvestBlock(doesCentrifuge, world, x, y, z, player);
if(doesCentrifuge) {
for(ItemStack st : result) {
if(st != null) {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, st.copy()));
}
}
}
}
};
public static final IToolHarvestAbility CRYSTALLIZER = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.crystallizer";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityCrystallizer;
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 6;
}
@Override
public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) {
//a band-aid on a gaping wound
if(block == Blocks.lit_redstone_ore)
block = Blocks.redstone_ore;
ItemStack stack = new ItemStack(block, 1, meta);
CrystallizerRecipe result = CrystallizerRecipes.getOutput(stack, Fluids.PEROXIDE);
boolean doesCrystallize = result != null;
harvestBlock(doesCrystallize, world, x, y, z, player);
if(doesCrystallize) {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, result.output.copy()));
}
}
};
public static final IToolHarvestAbility MERCURY = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.mercury";
}
@Override
public boolean isAllowed() {
return ToolConfig.abilityMercury;
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 7;
}
@Override
public void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) {
//a band-aid on a gaping wound
if(block == Blocks.lit_redstone_ore)
block = Blocks.redstone_ore;
int mercury = 0;
if(block == Blocks.redstone_ore)
mercury = player.getRNG().nextInt(5) + 4;
if(block == Blocks.redstone_block)
mercury = player.getRNG().nextInt(7) + 8;
boolean doesConvert = mercury > 0;
harvestBlock(doesConvert, world, x, y, z, player);
if(doesConvert) {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, new ItemStack(ModItems.ingot_mercury, mercury)));
}
}
};
// endregion handlers
static final IToolHarvestAbility[] abilities = {NONE, SILK, LUCK, SMELTER, SHREDDER, CENTRIFUGE, CRYSTALLIZER, MERCURY};
static IToolHarvestAbility getByName(String name) {
for(IToolHarvestAbility ability : abilities) {
if(ability.getName().equals(name))
return ability;
}
return NONE;
}
}

View File

@ -0,0 +1,367 @@
package com.hbm.handler.ability;
import com.hbm.blocks.ModBlocks;
import com.hbm.blocks.generic.BlockBobble.BobbleType;
import com.hbm.handler.threading.PacketThreading;
import com.hbm.items.ModItems;
import com.hbm.lib.ModDamageSource;
import com.hbm.packet.toclient.AuxParticlePacketNT;
import com.hbm.potion.HbmPotion;
import com.hbm.util.ContaminationUtil;
import com.hbm.util.ContaminationUtil.ContaminationType;
import com.hbm.util.ContaminationUtil.HazardType;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityMagmaCube;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntitySlime;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
public interface IWeaponAbility extends IBaseAbility {
// Note: tool is currently unused in weapon abilities
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool);
public final static int SORT_ORDER_BASE = 200;
// region handlers
public static final IWeaponAbility NONE = new IWeaponAbility() {
@Override
public String getName() {
return "";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 0;
}
@Override
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {}
};
public static final IWeaponAbility RADIATION = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.radiation";
}
public final float[] radAtLevel = {15F, 50F, 500F};
@Override
public int levels() {
return radAtLevel.length;
}
@Override
public String getExtension(int level) {
return " (" + radAtLevel[level] + ")";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 1;
}
@Override
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
if(victim instanceof EntityLivingBase)
ContaminationUtil.contaminate((EntityLivingBase)victim, HazardType.RADIATION, ContaminationType.CREATIVE, radAtLevel[level]);
}
};
public static final IWeaponAbility VAMPIRE = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.vampire";
}
public final float[] amountAtLevel = {2F, 3F, 5F, 10F, 50F};
@Override
public int levels() {
return amountAtLevel.length;
}
@Override
public String getExtension(int level) {
return " (" + amountAtLevel[level] + ")";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 2;
}
@Override
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
float amount = amountAtLevel[level];
if(victim instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) victim;
if(living.getHealth() <= 0) return;
living.setHealth(living.getHealth() - amount);
if(living.getHealth() <= 0) living.onDeath(DamageSource.magic);
player.heal(amount);
}
}
};
public static final IWeaponAbility STUN = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.stun";
}
public final int[] durationAtLevel = {2, 3, 5, 10, 15};
@Override
public int levels() {
return durationAtLevel.length;
}
@Override
public String getExtension(int level) {
return " (" + durationAtLevel[level] + ")";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 3;
}
@Override
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
int duration = durationAtLevel[level];
if(victim instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) victim;
living.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, duration * 20, 4));
living.addPotionEffect(new PotionEffect(Potion.weakness.id, duration * 20, 4));
}
}
};
public static final IWeaponAbility PHOSPHORUS = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.phosphorus";
}
public final int[] durationAtLevel = {60, 90};
@Override
public int levels() {
return durationAtLevel.length;
}
@Override
public String getExtension(int level) {
return " (" + durationAtLevel[level] + ")";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 4;
}
@Override
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
int duration = durationAtLevel[level];
if(victim instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) victim;
living.addPotionEffect(new PotionEffect(HbmPotion.phosphorus.id, duration * 20, 4));
}
}
};
public static final IWeaponAbility FIRE = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.fire";
}
public final int[] durationAtLevel = {5, 10};
@Override
public int levels() {
return durationAtLevel.length;
}
@Override
public String getExtension(int level) {
return " (" + durationAtLevel[level] + ")";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 6;
}
@Override
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
if(victim instanceof EntityLivingBase) {
victim.setFire(durationAtLevel[level]);
}
}
};
public static final IWeaponAbility CHAINSAW = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.chainsaw";
}
public final int[] dividerAtLevel = {15, 10};
@Override
public int levels() {
return dividerAtLevel.length;
}
@Override
public String getExtension(int level) {
return " (1:" + dividerAtLevel[level] + ")";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 7;
}
@Override
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
int divider = dividerAtLevel[level];
if(victim instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) victim;
if(living.getHealth() <= 0.0F) {
int count = Math.min((int)Math.ceil(living.getMaxHealth() / divider), 250); //safeguard to prevent funnies from bosses with obscene health
for(int i = 0; i < count; i++) {
living.entityDropItem(new ItemStack(ModItems.nitra_small), 1);
world.spawnEntityInWorld(new EntityXPOrb(world, living.posX, living.posY, living.posZ, 1));
}
if(player instanceof EntityPlayerMP) {
NBTTagCompound data = new NBTTagCompound();
data.setString("type", "vanillaburst");
data.setInteger("count", count * 4);
data.setDouble("motion", 0.1D);
data.setString("mode", "blockdust");
data.setInteger("block", Block.getIdFromBlock(Blocks.redstone_block));
PacketThreading.createAllAroundThreadedPacket(new AuxParticlePacketNT(data, living.posX, living.posY + living.height * 0.5, living.posZ), new TargetPoint(living.dimension, living.posX, living.posY, living.posZ, 50));
}
world.playSoundEffect(living.posX, living.posY + living.height * 0.5, living.posZ, "hbm:weapon.chainsaw", 0.5F, 1.0F);
}
}
}
};
public static final IWeaponAbility BEHEADER = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.beheader";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 8;
}
@Override
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
if(victim instanceof EntityLivingBase && ((EntityLivingBase) victim).getHealth() <= 0.0F) {
EntityLivingBase living = (EntityLivingBase) victim;
if(living instanceof EntitySkeleton) {
if(((EntitySkeleton)living).getSkeletonType() == 0) {
living.entityDropItem(new ItemStack(Items.skull, 1, 0), 0.0F);
} else {
if(world.rand.nextInt(20) == 0)
living.entityDropItem(new ItemStack(Items.skull, 1, 1), 0.0F);
else
living.entityDropItem(new ItemStack(Items.coal, 3), 0.0F);
}
} else if(living instanceof EntityZombie) {
living.entityDropItem(new ItemStack(Items.skull, 1, 2), 0.0F);
} else if(living instanceof EntityCreeper) {
living.entityDropItem(new ItemStack(Items.skull, 1, 4), 0.0F);
} else if(living instanceof EntityMagmaCube) {
living.entityDropItem(new ItemStack(Items.magma_cream, 3), 0.0F);
} else if(living instanceof EntitySlime) {
living.entityDropItem(new ItemStack(Items.slime_ball, 3), 0.0F);
} else if(living instanceof EntityPlayer) {
ItemStack head = new ItemStack(Items.skull, 1, 3);
head.stackTagCompound = new NBTTagCompound();
head.stackTagCompound.setString("SkullOwner", ((EntityPlayer) living).getDisplayName());
living.entityDropItem(head, 0.0F);
} else {
living.entityDropItem(new ItemStack(Items.rotten_flesh, 3, 0), 0.0F);
living.entityDropItem(new ItemStack(Items.bone, 2, 0), 0.0F);
}
}
}
};
public static final IWeaponAbility BOBBLE = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.bobble";
}
@Override
public int sortOrder() {
return SORT_ORDER_BASE + 9;
}
@Override
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
if(victim instanceof EntityMob && ((EntityMob) victim).getHealth() <= 0.0F) {
EntityMob mob = (EntityMob) victim;
int chance = 1000;
if(mob.getMaxHealth() > 20) {
chance = 750;
}
if(world.rand.nextInt(chance) == 0)
mob.entityDropItem(new ItemStack(ModBlocks.bobblehead, 1, world.rand.nextInt(BobbleType.values().length - 1) + 1), 0.0F);
}
}
};
// endregion handlers
static final IWeaponAbility[] abilities = {NONE, RADIATION, VAMPIRE, STUN, PHOSPHORUS, FIRE, CHAINSAW, BEHEADER, BOBBLE};
static IWeaponAbility getByName(String name) {
for(IWeaponAbility ability : abilities) {
if(ability.getName().equals(name))
return ability;
}
return NONE;
}
}

View File

@ -0,0 +1,99 @@
package com.hbm.handler.ability;
import com.hbm.util.ChatBuilder;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
public class ToolPreset {
public IToolAreaAbility areaAbility = IToolAreaAbility.NONE;
public int areaAbilityLevel = 0;
public IToolHarvestAbility harvestAbility = IToolHarvestAbility.NONE;
public int harvestAbilityLevel = 0;
public ToolPreset() {}
public ToolPreset(IToolAreaAbility areaAbility, IToolHarvestAbility harvestAbility) {
this.areaAbility = areaAbility;
this.harvestAbility = harvestAbility;
}
public ToolPreset(IToolAreaAbility areaAbility, int areaAbilityLevel, IToolHarvestAbility harvestAbility, int harvestAbilityLevel) {
this.areaAbility = areaAbility;
this.areaAbilityLevel = areaAbilityLevel;
this.harvestAbility = harvestAbility;
this.harvestAbilityLevel = harvestAbilityLevel;
}
public ChatComponentText getMessage() {
if (isNone())
return ChatBuilder.start("[Tool ability deactivated]").color(EnumChatFormatting.GOLD).flush();
String areaPart = areaAbility.getFullName(areaAbilityLevel);
String harvestPart = harvestAbility.getFullName(harvestAbilityLevel);
ChatBuilder builder = ChatBuilder.start("[Enabled ");
if (!areaPart.isEmpty())
builder.next(areaPart);
if (!areaPart.isEmpty() && !harvestPart.isEmpty())
builder.next(" + ");
if (!harvestPart.isEmpty())
builder.next(harvestPart);
return builder.colorAll(EnumChatFormatting.YELLOW).flush();
}
public boolean isNone() {
return areaAbility == IToolAreaAbility.NONE && harvestAbility == IToolHarvestAbility.NONE;
}
public void writeToNBT(NBTTagCompound nbt) {
nbt.setString("area", areaAbility.getName());
nbt.setInteger("areaLevel", areaAbilityLevel);
nbt.setString("harvest", harvestAbility.getName());
nbt.setInteger("harvestLevel", harvestAbilityLevel);
}
public void readFromNBT(NBTTagCompound nbt) {
areaAbility = IToolAreaAbility.getByName(nbt.getString("area"));
areaAbilityLevel = nbt.getInteger("areaLevel");
harvestAbility = IToolHarvestAbility.getByName(nbt.getString("harvest"));
harvestAbilityLevel = nbt.getInteger("harvestLevel");
areaAbilityLevel = Math.min(areaAbilityLevel, areaAbility.levels() - 1);
harvestAbilityLevel = Math.min(harvestAbilityLevel, harvestAbility.levels() - 1);
}
public void restrictTo(AvailableAbilities availableAbilities) {
int maxAreaLevel = availableAbilities.maxLevel(areaAbility);
if (maxAreaLevel == -1) {
areaAbility = IToolAreaAbility.NONE;
areaAbilityLevel = 0;
} else if (areaAbilityLevel > maxAreaLevel) {
areaAbilityLevel = maxAreaLevel;
} else if (areaAbilityLevel < 0) {
areaAbilityLevel = 0;
}
if (!areaAbility.allowsHarvest(areaAbilityLevel)) {
harvestAbility = IToolHarvestAbility.NONE;
harvestAbilityLevel = 0;
}
int maxHarvestLevel = availableAbilities.maxLevel(harvestAbility);
if (maxHarvestLevel == -1) {
harvestAbility = IToolHarvestAbility.NONE;
harvestAbilityLevel = 0;
} else if (harvestAbilityLevel > maxHarvestLevel) {
harvestAbilityLevel = maxHarvestLevel;
} else if (harvestAbilityLevel < 0) {
harvestAbilityLevel = 0;
}
}
}

View File

@ -0,0 +1,418 @@
package com.hbm.inventory.gui;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import com.hbm.handler.ability.AvailableAbilities;
import com.hbm.handler.ability.IBaseAbility;
import com.hbm.handler.ability.IToolAreaAbility;
import com.hbm.handler.ability.IToolHarvestAbility;
import com.hbm.handler.ability.ToolPreset;
import com.hbm.items.tool.ItemToolAbility;
import com.hbm.lib.RefStrings;
import com.hbm.main.MainRegistry;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.toserver.NBTItemControlPacket;
import com.hbm.util.EnumUtil;
import com.hbm.util.I18nUtil;
import com.hbm.util.Tuple.Pair;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
public class GUIScreenToolAbility extends GuiScreen {
public static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/tool/gui_tool_ability.png");
protected int guiLeft;
protected int guiTop;
protected int xSize;
protected int ySize;
protected int insetWidth;
public static class AbilityInfo {
public IBaseAbility ability;
public int textureU, textureV;
public AbilityInfo(IBaseAbility ability, int textureU, int textureV) {
this.ability = ability;
this.textureU = textureU;
this.textureV = textureV;
}
}
public static final List<AbilityInfo> abilitiesArea = new ArrayList<>();
public static final List<AbilityInfo> abilitiesHarvest = new ArrayList<>();
static {
abilitiesArea.add(new AbilityInfo(IToolAreaAbility.NONE, 0, 91));
abilitiesArea.add(new AbilityInfo(IToolAreaAbility.RECURSION, 32, 91));
abilitiesArea.add(new AbilityInfo(IToolAreaAbility.HAMMER, 64, 91));
abilitiesArea.add(new AbilityInfo(IToolAreaAbility.EXPLOSION, 96, 91));
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.NONE, 0, 107));
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.SILK, 32, 107));
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.LUCK, 64, 107));
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.SMELTER, 96, 107));
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.SHREDDER, 128, 107));
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.CENTRIFUGE, 160, 107));
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.CRYSTALLIZER, 192, 107));
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.MERCURY, 224, 107));
}
protected ItemStack toolStack;
protected AvailableAbilities availableAbilities;
protected ItemToolAbility.Configuration config;
protected int hoverIdxHarvest = -1;
protected int hoverIdxArea = -1;
protected int hoverIdxExtraBtn = -1;
public GUIScreenToolAbility(AvailableAbilities availableAbilities) {
super();
this.availableAbilities = availableAbilities;
this.xSize = 186; // Note: increased dynamically
this.ySize = 76;
this.insetWidth = 20 * Math.max(abilitiesArea.size() - 4, abilitiesHarvest.size() - 8);
this.xSize += insetWidth;
}
@Override
public void initGui() {
this.toolStack = this.mc.thePlayer.getHeldItem();
if(this.toolStack == null) {
doClose();
}
this.config = ((ItemToolAbility) this.toolStack.getItem()).getConfiguration(this.toolStack);
guiLeft = (width - xSize) / 2;
guiTop = (height - ySize) / 2;
}
@Override
public void drawScreen(int mouseX, int mouseY, float f) {
this.drawDefaultBackground();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
// Draw window background
drawStretchedRect(guiLeft, guiTop, 0, 0, xSize, xSize - insetWidth, ySize, 74, 87);
// Draw the switches
ToolPreset activePreset = config.getActivePreset();
hoverIdxArea = drawSwitches(abilitiesArea, activePreset.areaAbility, activePreset.areaAbilityLevel, guiLeft + 15, guiTop + 25, mouseX, mouseY);
hoverIdxHarvest = drawSwitches(abilitiesHarvest, activePreset.harvestAbility, activePreset.harvestAbilityLevel, guiLeft + 15, guiTop + 45, mouseX, mouseY);
// Draw preset indicator
drawNumber(config.currentPreset + 1, guiLeft + insetWidth + 115, guiTop + 25);
drawNumber(config.presets.size(), guiLeft + insetWidth + 149, guiTop + 25);
// Draw extra buttons hover highlights
int extraBtnsX = guiLeft + xSize - 86;
hoverIdxExtraBtn = -1;
for (int i = 0; i < 7; ++i) {
if (isInAABB(mouseX, mouseY, extraBtnsX + i * 11, guiTop + 11, 9, 9)) {
hoverIdxExtraBtn = i;
drawTexturedModalRect(extraBtnsX + i * 11, guiTop + 11, 193 + i * 9, 0, 9, 9);
}
}
// Draw tooltip
String tooltipValue = "";
if (hoverIdxArea != -1) {
int level = 0;
if (abilitiesArea.get(hoverIdxArea).ability == activePreset.areaAbility) {
level = activePreset.areaAbilityLevel;
}
tooltipValue = abilitiesArea.get(hoverIdxArea).ability.getFullName(level);
} else if (hoverIdxHarvest != -1) {
int level = 0;
if (abilitiesHarvest.get(hoverIdxHarvest).ability == activePreset.harvestAbility) {
level = activePreset.harvestAbilityLevel;
}
tooltipValue = abilitiesHarvest.get(hoverIdxHarvest).ability.getFullName(level);
} else if (hoverIdxExtraBtn != -1) {
switch (hoverIdxExtraBtn) {
case 0: tooltipValue = "Reset all presets"; break;
case 1: tooltipValue = "Delete current preset"; break;
case 2: tooltipValue = "Add new preset"; break;
case 3: tooltipValue = "Select first preset"; break;
case 4: tooltipValue = "Next preset"; break;
case 5: tooltipValue = "Previous preset"; break;
case 6: tooltipValue = "Close window"; break;
}
}
if (!tooltipValue.isEmpty()) {
int tooltipWidth = Math.max(6, fontRendererObj.getStringWidth(tooltipValue));
int tooltipX = guiLeft + xSize / 2 - tooltipWidth / 2;
int tooltipY = guiTop + ySize + 1 + 4;
drawStretchedRect(tooltipX - 5, tooltipY - 4, 0, 76, tooltipWidth + 10, 186, 15, 3, 3);
fontRendererObj.drawString(tooltipValue, tooltipX, tooltipY, 0xffffffff);
}
}
protected void drawStretchedRect(int x, int y, int u, int v, int realWidth, int width, int height, int keepLeft, int keepRight) {
int midWidth = width - keepLeft - keepRight;
int realMidWidth = realWidth - keepLeft - keepRight;
drawTexturedModalRect(x, y, u, v, keepLeft, height);
for (int i = 0; i < realMidWidth; i += midWidth) {
drawTexturedModalRect(x + keepLeft + i, y, u + keepLeft, v, Math.min(midWidth, realMidWidth - i), height);
}
drawTexturedModalRect(x + keepLeft + realMidWidth, y, u + keepLeft + midWidth, v, keepRight, height);
}
protected int drawSwitches(List<AbilityInfo> abilities, IBaseAbility selectedAbility, int selectedLevel, int x, int y, int mouseX, int mouseY) {
int hoverIdx = -1;
for (int i = 0; i < abilities.size(); ++i) {
AbilityInfo abilityInfo = abilities.get(i);
boolean available = abilityAvailable(abilityInfo.ability);
boolean selected = abilityInfo.ability == selectedAbility;
// Draw switch
drawTexturedModalRect(x + 20 * i, y, abilityInfo.textureU + (available ? 16 : 0), abilityInfo.textureV, 16, 16);
// Draw level LEDs
if (abilityInfo.ability.levels() > 1) {
int level = 0;
if (selected) {
level = selectedLevel + 1;
}
// Note: only visual effect for the LEDs
// int maxLevel = Math.min(abilityInfo.ability.levels(), 5);
int maxLevel = 5;
if (level > 10 || level < 0) {
// All-red LEDs for invalid levels
level = -1;
}
drawTexturedModalRect(x + 20 * i + 17, y + 1, 188 + level * 2, maxLevel * 14, 2, 14);
}
boolean isHovered = isInAABB(mouseX, mouseY, x + 20 * i, y, 16, 16);
if (isHovered) {
hoverIdx = i;
}
if (selected) {
// Draw selection highlight
drawTexturedModalRect(x + 20 * i - 1, y - 1, 220, 9, 18, 18);
} else if (available && isHovered) {
// Draw hover highlight
drawTexturedModalRect(x + 20 * i - 1, y - 1, 238, 9, 18, 18);
}
}
return hoverIdx;
}
protected void drawNumber(int number, int x, int y) {
number += 100; // Against accidental negatives
drawDigit((number / 10) % 10, x, y);
drawDigit(number % 10, x + 12, y);
}
protected void drawDigit(int digit, int x, int y) {
drawTexturedModalRect(x, y, digit * 10, 123, 10, 15);
}
private boolean isInAABB(int mouseX, int mouseY, int x, int y, int width, int height) {
return x <= mouseX && x + width > mouseX && y <= mouseY && y + height > mouseY;
}
private boolean abilityAvailable(IBaseAbility ability) {
if (!availableAbilities.supportsAbility(ability)) {
return false;
}
ToolPreset activePreset = config.getActivePreset();
if (ability instanceof IToolHarvestAbility && ability != IToolHarvestAbility.NONE && !activePreset.areaAbility.allowsHarvest(activePreset.areaAbilityLevel)) {
return false;
}
return true;
}
// Note: This spuriously trigger way too often, and I can't see why. I'll disable it altogether, I guess
// @Override
// public void updateScreen() {
// EntityPlayer player = this.mc.thePlayer;
//
// if(player.getHeldItem() == null || player.getHeldItem().getItem() != toolStack.getItem()) {
// // TODO: Remove
// MainRegistry.logger.warn("GUIScreenToolAbility.updateScreen: toolStack changed!");
// player.closeScreen();
// }
// }
@Override
public void handleMouseInput() {
super.handleMouseInput();
if(Mouse.getEventButton() == -1) {
int scroll = Mouse.getEventDWheel();
if(scroll < 0) doPrevPreset(true);
if(scroll > 0) doNextPreset(true);
}
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int button) {
ToolPreset activePreset = config.getActivePreset();
// Process switches
Pair<IBaseAbility, Integer> clickResult;
clickResult = handleSwitchesClicked(abilitiesArea, activePreset.areaAbility, activePreset.areaAbilityLevel, hoverIdxArea, mouseX, mouseY);
activePreset.areaAbility = (IToolAreaAbility)clickResult.key;
activePreset.areaAbilityLevel = clickResult.value;
clickResult = handleSwitchesClicked(abilitiesHarvest, activePreset.harvestAbility, activePreset.harvestAbilityLevel, hoverIdxHarvest, mouseX, mouseY);
activePreset.harvestAbility = (IToolHarvestAbility)clickResult.key;
activePreset.harvestAbilityLevel = clickResult.value;
if (!activePreset.areaAbility.allowsHarvest(activePreset.areaAbilityLevel)) {
activePreset.harvestAbility = IToolHarvestAbility.NONE;
activePreset.harvestAbilityLevel = 0;
}
// Process extra buttons
if (hoverIdxExtraBtn != -1) {
switch (hoverIdxExtraBtn) {
case 0: doResetPresets(); break;
case 1: doDelPreset(); break;
case 2: doAddPreset(); break;
case 3: doZeroPreset(); break;
case 4: doNextPreset(false); break;
case 5: doPrevPreset(false); break;
case 6: doClose(); break;
}
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 0.5F));
}
// Allow quick-closing
if (!isInAABB(mouseX, mouseY, guiLeft, guiTop, xSize, ySize)) {
MainRegistry.logger.info("GUIScreenToolAbility.mouseClicked: Clicked outside GUI, closing...");
doClose();
}
}
protected Pair<IBaseAbility, Integer> handleSwitchesClicked(List<AbilityInfo> abilities, IBaseAbility selectedAbility, int selectedLevel, int hoverIdx, int mouseX, int mouseY) {
if (hoverIdx != -1) {
IBaseAbility hoveredAbility = abilities.get(hoverIdx).ability;
boolean available = abilityAvailable(hoveredAbility);
if (available) {
int availableLevels = availableAbilities.maxLevel(hoveredAbility) + 1;
if (hoveredAbility != selectedAbility || availableLevels > 1) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("hbm:item.techBoop"), 2F));
}
if (hoveredAbility == selectedAbility) {
selectedLevel = (selectedLevel + 1) % availableLevels;
} else {
selectedLevel = 0;
}
selectedAbility = hoveredAbility;
}
}
return new Pair<>(selectedAbility, selectedLevel);
}
@Override
protected void keyTyped(char c, int key) {
if(key == 1 || key == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
doClose();
return;
}
super.keyTyped(c, key);
}
@Override
public boolean doesGuiPauseGame() {
return false;
}
protected void doResetPresets() {
config.reset(availableAbilities);
}
protected void doDelPreset() {
if (config.presets.size() <= 1) {
return;
}
config.presets.remove(config.currentPreset);
config.currentPreset = Math.min(config.currentPreset, config.presets.size() - 1);
}
protected void doAddPreset() {
if (config.presets.size() >= 99) {
return;
}
config.presets.add(config.currentPreset + 1, new ToolPreset());
config.currentPreset += 1;
}
protected void doZeroPreset() {
config.currentPreset = 0;
}
protected void doNextPreset(boolean bound) {
if (bound) {
if (config.currentPreset < config.presets.size() - 1) {
config.currentPreset += 1;
}
} else {
config.currentPreset = (config.currentPreset + 1) % config.presets.size();
}
}
protected void doPrevPreset(boolean bound) {
if (bound) {
if (config.currentPreset > 0) {
config.currentPreset -= 1;
}
} else {
config.currentPreset = (config.currentPreset + config.presets.size() - 1) % config.presets.size();
}
}
protected void doClose() {
// A bit messy, but I suppose it works
((ItemToolAbility) this.toolStack.getItem()).setConfiguration(toolStack, config);
PacketDispatcher.wrapper.sendToServer(new NBTItemControlPacket(this.toolStack.getTagCompound()));
this.mc.thePlayer.closeScreen();
MainRegistry.proxy.displayTooltip(config.getActivePreset().getMessage().getFormattedText(), MainRegistry.proxy.ID_TOOLABILITY);
this.mc.theWorld.playSoundAtEntity(this.mc.thePlayer, "random.orb", 0.25F, config.getActivePreset().isNone() ? 0.75F : 1.25F);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,181 +0,0 @@
package com.hbm.items.tool;
import java.util.ArrayList;
import java.util.Random;
import com.hbm.blocks.ModBlocks;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.C07PacketPlayerDigging;
import net.minecraft.network.play.server.S23PacketBlockChange;
import net.minecraft.stats.StatList;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.event.world.BlockEvent;
public interface IItemAbility {
public boolean canHarvestBlock(Block par1Block, ItemStack itemStack);
public boolean isShears(ItemStack stack);
public default boolean canShearBlock(Block block, ItemStack stack, World world, int x, int y, int z) {
return this.isShears(stack) && block instanceof IShearable && ((IShearable) block).isShearable(stack, world, x, y, z);
}
public default void breakExtraBlock(World world, int x, int y, int z, EntityPlayer playerEntity, int refX, int refY, int refZ) {
if(world.isAirBlock(x, y, z))
return;
if(!(playerEntity instanceof EntityPlayerMP))
return;
EntityPlayerMP player = (EntityPlayerMP) playerEntity;
ItemStack stack = player.getHeldItem();
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if(!(canHarvestBlock(block, stack) || canShearBlock(block, stack, world, x, y, z)) || block == Blocks.bedrock || block == ModBlocks.stone_keyhole)
return;
Block refBlock = world.getBlock(refX, refY, refZ);
float refStrength = ForgeHooks.blockStrength(refBlock, player, world, refX, refY, refZ);
float strength = ForgeHooks.blockStrength(block, player, world, x, y, z);
if(!ForgeHooks.canHarvestBlock(block, player, meta) || refStrength / strength > 10f || refBlock.getBlockHardness(world, refX, refY, refZ) < 0)
return;
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, player.theItemInWorldManager.getGameType(), player, x, y, z);
if(event.isCanceled())
return;
if(player.capabilities.isCreativeMode) {
block.onBlockHarvested(world, x, y, z, meta, player);
if(block.removedByPlayer(world, player, x, y, z, false))
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
if(!world.isRemote) {
player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
}
return;
}
player.getCurrentEquippedItem().func_150999_a(world, block, x, y, z, player);
if(!world.isRemote) {
if(canShearBlock(block, stack, world, x, y, z)) {
shearBlock(world, x, y, z, block, player);
}
block.onBlockHarvested(world, x, y, z, meta, player);
if(block.removedByPlayer(world, player, x, y, z, true)) {
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
block.harvestBlock(world, player, x, y, z, meta);
block.dropXpOnBlockBreak(world, x, y, z, event.getExpToDrop());
}
player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
} else {
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
if(block.removedByPlayer(world, player, x, y, z, true)) {
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
}
ItemStack itemstack = player.getCurrentEquippedItem();
if(itemstack != null) {
itemstack.func_150999_a(world, block, x, y, z, player);
if(itemstack.stackSize == 0) {
player.destroyCurrentEquippedItem();
}
}
Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit));
}
}
/** Assumes a canShearBlock check has passed, will most likely crash otherwise! */
public static void shearBlock(World world, int x, int y, int z, Block block, EntityPlayer player) {
ItemStack held = player.getHeldItem();
IShearable target = (IShearable) block;
if(target.isShearable(held, player.worldObj, x, y, z)) {
ArrayList<ItemStack> drops = target.onSheared(held, player.worldObj, x, y, z, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, held));
Random rand = new Random();
for(ItemStack stack : drops) {
float f = 0.7F;
double d = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d1 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d2 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
EntityItem entityitem = new EntityItem(player.worldObj, (double) x + d, (double) y + d1, (double) z + d2, stack);
entityitem.delayBeforeCanPickup = 10;
player.worldObj.spawnEntityInWorld(entityitem);
}
held.damageItem(1, player);
player.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(block)], 1);
}
}
public static void standardDigPost(World world, int x, int y, int z, EntityPlayerMP player) {
Block block = world.getBlock(x, y, z);
int l = world.getBlockMetadata(x, y, z);
world.playAuxSFXAtEntity(player, 2001, x, y, z, Block.getIdFromBlock(block) + (world.getBlockMetadata(x, y, z) << 12));
boolean flag = false;
if(player.capabilities.isCreativeMode) {
flag = removeBlock(world, x, y, z, false, player);
player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
} else {
ItemStack itemstack = player.getCurrentEquippedItem();
boolean flag1 = block.canHarvestBlock(player, l);
if(itemstack != null) {
itemstack.func_150999_a(world, block, x, y, z, player);
if(itemstack.stackSize == 0) {
player.destroyCurrentEquippedItem();
}
}
flag = removeBlock(world, x, y, z, flag1, player);
if(flag && flag1) {
block.harvestBlock(world, player, x, y, z, l);
}
}
/*
* // Drop experience if (!player.capabilities.isCreativeMode && flag &&
* event != null) { block.dropXpOnBlockBreak(world, x, y, z,
* event.getExpToDrop()); }
*/
}
public static boolean removeBlock(World world, int x, int y, int z, boolean canHarvest, EntityPlayerMP player) {
Block block = world.getBlock(x, y, z);
int l = world.getBlockMetadata(x, y, z);
block.onBlockHarvested(world, x, y, z, l, player);
boolean flag = block.removedByPlayer(world, player, x, y, z, canHarvest);
if(flag) {
block.onBlockDestroyedByPlayer(world, x, y, z, l);
}
return flag;
}
}

View File

@ -1,11 +1,11 @@
package com.hbm.items.tool;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.hbm.handler.WeaponAbility;
import com.hbm.handler.ability.AvailableAbilities;
import com.hbm.handler.ability.IWeaponAbility;
import com.hbm.items.ModItems;
import cpw.mods.fml.relauncher.Side;
@ -19,13 +19,13 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.util.EnumChatFormatting;
public class ItemSwordAbility extends ItemSword implements IItemAbility {
public class ItemSwordAbility extends ItemSword {
private EnumRarity rarity = EnumRarity.common;
// was there a reason for this to be private?
protected float damage;
protected double movement;
private List<WeaponAbility> hitAbility = new ArrayList();
private AvailableAbilities abilities = new AvailableAbilities();
public ItemSwordAbility(float damage, double movement, ToolMaterial material) {
super(material);
@ -33,8 +33,8 @@ public class ItemSwordAbility extends ItemSword implements IItemAbility {
this.movement = movement;
}
public ItemSwordAbility addHitAbility(WeaponAbility weaponAbility) {
this.hitAbility.add(weaponAbility);
public ItemSwordAbility addAbility(IWeaponAbility weaponAbility, int level) {
this.abilities.addAbility(weaponAbility, level);
return this;
}
@ -50,15 +50,15 @@ public class ItemSwordAbility extends ItemSword implements IItemAbility {
public boolean hitEntity(ItemStack stack, EntityLivingBase victim, EntityLivingBase attacker) {
if(!attacker.worldObj.isRemote && !this.hitAbility.isEmpty() && attacker instanceof EntityPlayer && canOperate(stack)) {
if(!attacker.worldObj.isRemote && attacker instanceof EntityPlayer && canOperate(stack)) {
// hacky hacky hack
if(this == ModItems.mese_gavel)
attacker.worldObj.playSoundAtEntity(victim, "hbm:weapon.whack", 3.0F, 1.F);
for(WeaponAbility ability : this.hitAbility) {
ability.onHit(attacker.worldObj, (EntityPlayer) attacker, victim, this);
}
this.abilities.getWeaponAbilities().forEach((ability, level) -> {
ability.onHit(level, attacker.worldObj, (EntityPlayer) attacker, victim, this);
});
}
stack.damageItem(1, attacker);
@ -77,23 +77,10 @@ public class ItemSwordAbility extends ItemSword implements IItemAbility {
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
if(!this.hitAbility.isEmpty()) {
list.add("Weapon modifiers: ");
for(WeaponAbility ability : this.hitAbility) {
list.add(" " + EnumChatFormatting.RED + ability.getFullName());
}
}
abilities.addInformation(list);
}
protected boolean canOperate(ItemStack stack) {
return true;
}
@Override
public boolean isShears(ItemStack stack) {
return false;
}
}

View File

@ -1,41 +1,64 @@
package com.hbm.items.tool;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import java.util.Set;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.hbm.handler.ToolAbility;
import com.hbm.handler.ToolAbility.*;
import com.hbm.inventory.gui.GUIScreenToolAbility;
import com.hbm.items.IItemControlReceiver;
import com.hbm.handler.HbmKeybinds;
import com.hbm.blocks.ModBlocks;
import com.hbm.extprop.HbmPlayerProps;
import com.hbm.handler.ability.AvailableAbilities;
import com.hbm.handler.ability.IBaseAbility;
import com.hbm.handler.ability.IToolAreaAbility;
import com.hbm.handler.ability.IToolHarvestAbility;
import com.hbm.handler.ability.ToolPreset;
import com.hbm.main.MainRegistry;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.toclient.PlayerInformPacket;
import com.hbm.util.ChatBuilder;
import com.hbm.handler.WeaponAbility;
import com.hbm.packet.toserver.NBTItemControlPacket;
import com.hbm.tileentity.IGUIProvider;
import api.hbm.item.IDepthRockTool;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.Container;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.play.client.C07PacketPlayerDigging;
import net.minecraft.network.play.server.S23PacketBlockChange;
import net.minecraft.stats.StatList;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.event.world.BlockEvent;
public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRockTool {
public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIProvider, IItemControlReceiver {
protected boolean isShears = false;
protected EnumToolType toolType;
@ -43,9 +66,9 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc
//was there a reason for this to be private?
protected float damage;
protected double movement;
protected List<ToolAbility> breakAbility = new ArrayList() {{ add(null); }};
protected List<WeaponAbility> hitAbility = new ArrayList();
protected AvailableAbilities availableAbilities = new AvailableAbilities().addToolAbilities();
protected boolean rockBreaker = false;
public static enum EnumToolType {
PICKAXE(
@ -97,13 +120,14 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc
}
}
public ItemToolAbility addBreakAbility(ToolAbility breakAbility) {
this.breakAbility.add(breakAbility);
public ItemToolAbility addAbility(IBaseAbility ability, int level) {
this.availableAbilities.addAbility(ability, level);
return this;
}
public ItemToolAbility addHitAbility(WeaponAbility weaponAbility) {
this.hitAbility.add(weaponAbility);
public ItemToolAbility setDepthRockBreaker() {
this.rockBreaker = true;
return this;
}
@ -119,14 +143,14 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc
public boolean hitEntity(ItemStack stack, EntityLivingBase victim, EntityLivingBase attacker) {
if(!attacker.worldObj.isRemote && !this.hitAbility.isEmpty() && attacker instanceof EntityPlayer && canOperate(stack)) {
if(!attacker.worldObj.isRemote && attacker instanceof EntityPlayer && canOperate(stack)) {
for(WeaponAbility ability : this.hitAbility) {
ability.onHit(attacker.worldObj, (EntityPlayer) attacker, victim, this);
}
this.availableAbilities.getWeaponAbilities().forEach((ability, level) -> {
ability.onHit(level, attacker.worldObj, (EntityPlayer) attacker, victim, this);
});
}
stack.damageItem(2, attacker);
stack.damageItem(1, attacker);
return true;
}
@ -136,10 +160,23 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc
World world = player.worldObj;
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if(!world.isRemote && (canHarvestBlock(block, stack) || canShearBlock(block, stack, world, x, y, z)) && this.getCurrentAbility(stack) != null && canOperate(stack))
return this.getCurrentAbility(stack).onDig(world, x, y, z, player, block, meta, this);
if(!world.isRemote && (canHarvestBlock(block, stack) || canShearBlock(block, stack, world, x, y, z)) && canOperate(stack)) {
Configuration config = getConfiguration(stack);
ToolPreset preset = config.getActivePreset();
preset.harvestAbility.preHarvestAll(preset.harvestAbilityLevel, world, player);
boolean skipRef = preset.areaAbility.onDig(preset.areaAbilityLevel, world, x, y, z, player, this);
if (!skipRef) {
breakExtraBlock(world, x, y, z, player, x, y, z);
}
preset.harvestAbility.postHarvestAll(preset.harvestAbilityLevel, world, player);
return true;
}
return false;
}
@ -164,18 +201,35 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc
return super.getDigSpeed(stack, block, meta);
}
public boolean canOperate(ItemStack stack) {
return true;
}
@Override
public boolean canHarvestBlock(Block block, ItemStack stack) {
if(!canOperate(stack))
return false;
if(this.getCurrentAbility(stack) instanceof SilkAbility)
if(this.getConfiguration(stack).getActivePreset().harvestAbility == IToolHarvestAbility.SILK)
return true;
return getDigSpeed(stack, block, 0) > 1;
}
@Override
public boolean canBreakRock(World world, EntityPlayer player, ItemStack tool, Block block, int x, int y, int z) {
return canOperate(tool) && this.rockBreaker;
}
public boolean canShearBlock(Block block, ItemStack stack, World world, int x, int y, int z) {
return this.isShears(stack) && block instanceof IShearable && ((IShearable) block).isShearable(stack, world, x, y, z);
}
public boolean isShears(ItemStack stack) {
return this.isShears;
}
@Override
public Multimap getItemAttributeModifiers() {
@ -187,38 +241,13 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack) {
return getCurrentAbility(stack) != null || stack.isItemEnchanted();
return stack.isItemEnchanted() || !getConfiguration(stack).getActivePreset().isNone();
}
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
if(this.breakAbility.size() > 1) {
list.add("Abilities: ");
for(ToolAbility ability : this.breakAbility) {
if(ability != null) {
if(getCurrentAbility(stack) == ability)
list.add(" >" + EnumChatFormatting.GOLD + ability.getFullName());
else
list.add(" " + EnumChatFormatting.GOLD + ability.getFullName());
}
}
list.add("Right click to cycle through abilities!");
list.add("Sneak-click to turn ability off!");
}
if(!this.hitAbility.isEmpty()) {
list.add("Weapon modifiers: ");
for(WeaponAbility ability : this.hitAbility) {
list.add(" " + EnumChatFormatting.RED + ability.getFullName());
}
}
availableAbilities.addInformation(list);
if(this.rockBreaker) {
list.add("");
@ -228,76 +257,276 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if(world.isRemote || this.breakAbility.size() < 2 || !canOperate(stack))
if(!canOperate(stack))
return super.onItemRightClick(stack, world, player);
int i = getAbility(stack);
i++;
if(player.isSneaking())
i = 0;
setAbility(stack, i % this.breakAbility.size());
while(getCurrentAbility(stack) != null && !getCurrentAbility(stack).isAllowed()) {
PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(ChatBuilder.start("[Ability ").nextTranslation(getCurrentAbility(stack).getName()).next(getCurrentAbility(stack).getExtension() + " is blacklisted!]").colorAll(EnumChatFormatting.RED).flush(), MainRegistry.proxy.ID_TOOLABILITY), (EntityPlayerMP) player);
i++;
setAbility(stack, i % this.breakAbility.size());
if(HbmPlayerProps.getData(player).getKeyPressed(HbmKeybinds.EnumKeybind.TOOL_ALT)) {
if(world.isRemote) player.openGui(MainRegistry.instance, 0, world, 0, 0, 0);
return stack;
}
Configuration config = getConfiguration(stack);
if(getCurrentAbility(stack) != null) {
PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(ChatBuilder.start("[Enabled ").nextTranslation(getCurrentAbility(stack).getName()).next(getCurrentAbility(stack).getExtension() + "]").colorAll(EnumChatFormatting.YELLOW).flush(), MainRegistry.proxy.ID_TOOLABILITY), (EntityPlayerMP) player);
if(config.presets.size() < 2 || world.isRemote)
return super.onItemRightClick(stack, world, player);
if(player.isSneaking()) {
config.currentPreset = 0;
} else {
PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(ChatBuilder.start("[Tool ability deactivated]").color(EnumChatFormatting.GOLD).flush(), MainRegistry.proxy.ID_TOOLABILITY), (EntityPlayerMP) player);
config.currentPreset = (config.currentPreset + 1) % config.presets.size();
}
world.playSoundAtEntity(player, "random.orb", 0.25F, getCurrentAbility(stack) == null ? 0.75F : 1.25F);
setConfiguration(stack, config);
PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(config.getActivePreset().getMessage(), MainRegistry.proxy.ID_TOOLABILITY), (EntityPlayerMP) player);
world.playSoundAtEntity(player, "random.orb", 0.25F, config.getActivePreset().isNone() ? 0.75F : 1.25F);
return stack;
}
private ToolAbility getCurrentAbility(ItemStack stack) {
int ability = getAbility(stack) % this.breakAbility.size();
return this.breakAbility.get(ability);
public void breakExtraBlock(World world, int x, int y, int z, EntityPlayer playerEntity, int refX, int refY, int refZ) {
if(world.isAirBlock(x, y, z))
return;
if(!(playerEntity instanceof EntityPlayerMP))
return;
EntityPlayerMP player = (EntityPlayerMP) playerEntity;
ItemStack stack = player.getHeldItem();
if (stack == null) {
return;
}
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if(!(canHarvestBlock(block, stack) || canShearBlock(block, stack, world, x, y, z)) || block == Blocks.bedrock || block == ModBlocks.stone_keyhole)
return;
Block refBlock = world.getBlock(refX, refY, refZ);
float refStrength = ForgeHooks.blockStrength(refBlock, player, world, refX, refY, refZ);
float strength = ForgeHooks.blockStrength(block, player, world, x, y, z);
if(!ForgeHooks.canHarvestBlock(block, player, meta) || refStrength / strength > 10f || refBlock.getBlockHardness(world, refX, refY, refZ) < 0)
return;
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, player.theItemInWorldManager.getGameType(), player, x, y, z);
if(event.isCanceled())
return;
Configuration config = getConfiguration(stack);
ToolPreset preset = config.getActivePreset();
preset.harvestAbility.onHarvestBlock(preset.harvestAbilityLevel, world, x, y, z, player, block, meta);
}
private int getAbility(ItemStack stack) {
/** Assumes a canShearBlock check has passed, will most likely crash otherwise! */
public static void shearBlock(World world, int x, int y, int z, Block block, EntityPlayer player) {
ItemStack held = player.getHeldItem();
if(stack.hasTagCompound())
return stack.stackTagCompound.getInteger("ability");
IShearable target = (IShearable) block;
if(target.isShearable(held, player.worldObj, x, y, z)) {
ArrayList<ItemStack> drops = target.onSheared(held, player.worldObj, x, y, z, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, held));
Random rand = new Random();
return 0;
for(ItemStack stack : drops) {
float f = 0.7F;
double d = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d1 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d2 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
EntityItem entityitem = new EntityItem(player.worldObj, (double) x + d, (double) y + d1, (double) z + d2, stack);
entityitem.delayBeforeCanPickup = 10;
player.worldObj.spawnEntityInWorld(entityitem);
}
held.damageItem(1, player);
player.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(block)], 1);
}
}
private void setAbility(ItemStack stack, int ability) {
public static void standardDigPost(World world, int x, int y, int z, EntityPlayerMP player) {
if(!stack.hasTagCompound())
Block block = world.getBlock(x, y, z);
int l = world.getBlockMetadata(x, y, z);
world.playAuxSFXAtEntity(player, 2001, x, y, z, Block.getIdFromBlock(block) + (world.getBlockMetadata(x, y, z) << 12));
boolean flag = false;
if(player.capabilities.isCreativeMode) {
flag = removeBlock(world, x, y, z, false, player);
player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
} else {
ItemStack itemstack = player.getCurrentEquippedItem();
boolean flag1 = block.canHarvestBlock(player, l);
flag = removeBlock(world, x, y, z, flag1, player);
if(itemstack != null) {
itemstack.func_150999_a(world, block, x, y, z, player);
if(itemstack.stackSize == 0) {
player.destroyCurrentEquippedItem();
}
}
// TODO: Missing from other method, may be unneeded
if(flag && flag1) {
block.harvestBlock(world, player, x, y, z, l);
}
// TODO: Added from other method, may be unneeded
Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit));
}
// Why was this commented out?
// Drop experience
// if (!player.capabilities.isCreativeMode && flag && event != null) {
// block.dropXpOnBlockBreak(world, x, y, z, event.getExpToDrop());
// }
}
public static boolean removeBlock(World world, int x, int y, int z, boolean canHarvest, EntityPlayerMP player) {
Block block = world.getBlock(x, y, z);
int l = world.getBlockMetadata(x, y, z);
block.onBlockHarvested(world, x, y, z, l, player);
boolean flag = block.removedByPlayer(world, player, x, y, z, canHarvest);
if(flag) {
block.onBlockDestroyedByPlayer(world, x, y, z, l);
}
return flag;
}
public static class Configuration {
public List<ToolPreset> presets;
public int currentPreset;
public Configuration() {
this.presets = null;
this.currentPreset = 0;
}
public Configuration(List<ToolPreset> presets, int currentPreset) {
this.presets = presets;
this.currentPreset = currentPreset;
}
public void writeToNBT(NBTTagCompound nbt) {
nbt.setInteger("ability", currentPreset);
NBTTagList nbtPresets = new NBTTagList();
for(ToolPreset preset : presets) {
NBTTagCompound nbtPreset = new NBTTagCompound();
preset.writeToNBT(nbtPreset);
nbtPresets.appendTag(nbtPreset);
}
nbt.setTag("abilityPresets", nbtPresets);
}
public void readFromNBT(NBTTagCompound nbt) {
currentPreset = nbt.getInteger("ability");
NBTTagList nbtPresets = nbt.getTagList("abilityPresets", 10);
int numPresets = Math.min(nbtPresets.tagCount(), 99);
presets = new ArrayList<ToolPreset>(numPresets);
for(int i = 0; i < numPresets; i++) {
NBTTagCompound nbtPreset = nbtPresets.getCompoundTagAt(i);
ToolPreset preset = new ToolPreset();
preset.readFromNBT(nbtPreset);
presets.add(preset);
}
currentPreset = Math.max(0, Math.min(currentPreset, presets.size() - 1));
}
public void reset(AvailableAbilities availableAbilities) {
currentPreset = 0;
presets = new ArrayList<ToolPreset>(availableAbilities.size());
presets.add(new ToolPreset());
availableAbilities.getToolAreaAbilities().forEach((ability, level) -> {
if (ability == IToolAreaAbility.NONE)
return;
presets.add(new ToolPreset(ability, level, IToolHarvestAbility.NONE, 0));
});
availableAbilities.getToolHarvestAbilities().forEach((ability, level) -> {
if (ability == IToolHarvestAbility.NONE)
return;
presets.add(new ToolPreset(IToolAreaAbility.NONE, 0, ability, level));
});
presets.sort(
Comparator
.comparing((ToolPreset p) -> p.harvestAbility)
.thenComparingInt(p -> p.harvestAbilityLevel)
.thenComparing(p -> p.areaAbility)
.thenComparingInt(p -> p.areaAbilityLevel)
);
}
public void restrictTo(AvailableAbilities availableAbilities) {
for (ToolPreset preset : presets) {
preset.restrictTo(availableAbilities);
}
}
public ToolPreset getActivePreset() {
return presets.get(currentPreset);
}
}
public Configuration getConfiguration(ItemStack stack) {
Configuration config = new Configuration();
if(stack == null || !stack.hasTagCompound() || !stack.stackTagCompound.hasKey("ability") || !stack.stackTagCompound.hasKey("abilityPresets")) {
config.reset(availableAbilities);
return config;
}
config.readFromNBT(stack.stackTagCompound);
config.restrictTo(availableAbilities);
return config;
}
public void setConfiguration(ItemStack stack, Configuration config) {
if (stack == null) {
return;
}
if (!stack.hasTagCompound()) {
stack.stackTagCompound = new NBTTagCompound();
}
stack.stackTagCompound.setInteger("ability", ability);
}
public boolean canOperate(ItemStack stack) {
return true;
}
public ItemToolAbility setDepthRockBreaker() {
this.rockBreaker = true;
return this;
}
private boolean rockBreaker = false;
@Override
public boolean canBreakRock(World world, EntityPlayer player, ItemStack tool, Block block, int x, int y, int z) {
return canOperate(tool) && this.rockBreaker;
config.writeToNBT(stack.stackTagCompound);
}
@Override
public boolean isShears(ItemStack stack) {
return this.isShears;
public void receiveControl(ItemStack stack, NBTTagCompound data) {
Configuration config = new Configuration();
config.readFromNBT(data);
config.restrictTo(availableAbilities);
setConfiguration(stack, config);
}
@Override
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
return null;
}
@Override
@SideOnly(Side.CLIENT)
public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUIScreenToolAbility(this.availableAbilities);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB