mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Begin ability refactor, rewrite tool harvest abilities
This commit is contained in:
parent
caf416a27d
commit
2982dd1f58
@ -15,7 +15,7 @@ import com.hbm.inventory.recipes.CrystallizerRecipes;
|
|||||||
import com.hbm.inventory.recipes.CrystallizerRecipes.CrystallizerRecipe;
|
import com.hbm.inventory.recipes.CrystallizerRecipes.CrystallizerRecipe;
|
||||||
import com.hbm.inventory.recipes.ShredderRecipes;
|
import com.hbm.inventory.recipes.ShredderRecipes;
|
||||||
import com.hbm.items.ModItems;
|
import com.hbm.items.ModItems;
|
||||||
import com.hbm.items.tool.IItemAbility;
|
import com.hbm.items.tool.IItemWithAbility;
|
||||||
import com.hbm.util.EnchantmentUtil;
|
import com.hbm.util.EnchantmentUtil;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
@ -33,7 +33,7 @@ import net.minecraft.world.World;
|
|||||||
|
|
||||||
public abstract class ToolAbility {
|
public abstract class ToolAbility {
|
||||||
|
|
||||||
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) { return false; }
|
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemWithAbility tool) { return false; }
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
public abstract String getFullName();
|
public abstract String getFullName();
|
||||||
public abstract String getExtension();
|
public abstract String getExtension();
|
||||||
@ -50,7 +50,7 @@ public abstract class ToolAbility {
|
|||||||
private Set<ThreeInts> pos = new HashSet();
|
private Set<ThreeInts> pos = new HashSet();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
|
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemWithAbility tool) {
|
||||||
|
|
||||||
Block b = world.getBlock(x, y, z);
|
Block b = world.getBlock(x, y, z);
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ public abstract class ToolAbility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recurse(World world, int x, int y, int z, int refX, int refY, int refZ, EntityPlayer player, IItemAbility tool, int depth) {
|
private void recurse(World world, int x, int y, int z, int refX, int refY, int refZ, EntityPlayer player, IItemWithAbility tool, int depth) {
|
||||||
|
|
||||||
List<ThreeInts> shuffledOffsets = new ArrayList<>(offsets);
|
List<ThreeInts> shuffledOffsets = new ArrayList<>(offsets);
|
||||||
Collections.shuffle(shuffledOffsets);
|
Collections.shuffle(shuffledOffsets);
|
||||||
@ -90,7 +90,7 @@ public abstract class ToolAbility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void breakExtra(World world, int x, int y, int z, int refX, int refY, int refZ, EntityPlayer player, IItemAbility tool, int depth) {
|
private void breakExtra(World world, int x, int y, int z, int refX, int refY, int refZ, EntityPlayer player, IItemWithAbility tool, int depth) {
|
||||||
|
|
||||||
if(pos.contains(new ThreeInts(x, y, z)))
|
if(pos.contains(new ThreeInts(x, y, z)))
|
||||||
return;
|
return;
|
||||||
@ -166,7 +166,7 @@ public abstract class ToolAbility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
|
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemWithAbility tool) {
|
||||||
|
|
||||||
for(int a = x - range; a <= x + range; a++) {
|
for(int a = x - range; a <= x + range; a++) {
|
||||||
for(int b = y - range; b <= y + range; b++) {
|
for(int b = y - range; b <= y + range; b++) {
|
||||||
@ -213,7 +213,7 @@ public abstract class ToolAbility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
|
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemWithAbility tool) {
|
||||||
if(EnchantmentHelper.getSilkTouchModifier(player) || player.getHeldItem() == null)
|
if(EnchantmentHelper.getSilkTouchModifier(player) || player.getHeldItem() == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ public abstract class ToolAbility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(player instanceof EntityPlayerMP)
|
if(player instanceof EntityPlayerMP)
|
||||||
IItemAbility.standardDigPost(world, x, y, z, (EntityPlayerMP) player);
|
IItemWithAbility.standardDigPost(world, x, y, z, (EntityPlayerMP) player);
|
||||||
|
|
||||||
EnchantmentUtil.removeEnchantment(stack, Enchantment.silkTouch);
|
EnchantmentUtil.removeEnchantment(stack, Enchantment.silkTouch);
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ public abstract class ToolAbility {
|
|||||||
public static class SilkAbility extends ToolAbility {
|
public static class SilkAbility extends ToolAbility {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
|
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemWithAbility tool) {
|
||||||
|
|
||||||
if(EnchantmentHelper.getSilkTouchModifier(player) || player.getHeldItem() == null)
|
if(EnchantmentHelper.getSilkTouchModifier(player) || player.getHeldItem() == null)
|
||||||
return false;
|
return false;
|
||||||
@ -273,7 +273,7 @@ public abstract class ToolAbility {
|
|||||||
EnchantmentUtil.addEnchantment(stack, Enchantment.silkTouch, 1);
|
EnchantmentUtil.addEnchantment(stack, Enchantment.silkTouch, 1);
|
||||||
|
|
||||||
if(player instanceof EntityPlayerMP)
|
if(player instanceof EntityPlayerMP)
|
||||||
IItemAbility.standardDigPost(world, x, y, z, (EntityPlayerMP) player);
|
IItemWithAbility.standardDigPost(world, x, y, z, (EntityPlayerMP) player);
|
||||||
|
|
||||||
EnchantmentUtil.removeEnchantment(stack, Enchantment.silkTouch);
|
EnchantmentUtil.removeEnchantment(stack, Enchantment.silkTouch);
|
||||||
|
|
||||||
@ -310,7 +310,7 @@ public abstract class ToolAbility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
|
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemWithAbility tool) {
|
||||||
|
|
||||||
if(EnchantmentHelper.getFortuneModifier(player) > 0 || player.getHeldItem() == null)
|
if(EnchantmentHelper.getFortuneModifier(player) > 0 || player.getHeldItem() == null)
|
||||||
return false;
|
return false;
|
||||||
@ -319,7 +319,7 @@ public abstract class ToolAbility {
|
|||||||
EnchantmentUtil.addEnchantment(stack, Enchantment.fortune, luck);
|
EnchantmentUtil.addEnchantment(stack, Enchantment.fortune, luck);
|
||||||
|
|
||||||
if(player instanceof EntityPlayerMP)
|
if(player instanceof EntityPlayerMP)
|
||||||
IItemAbility.standardDigPost(world, x, y, z, (EntityPlayerMP) player);
|
IItemWithAbility.standardDigPost(world, x, y, z, (EntityPlayerMP) player);
|
||||||
|
|
||||||
EnchantmentUtil.removeEnchantment(stack, Enchantment.fortune);
|
EnchantmentUtil.removeEnchantment(stack, Enchantment.fortune);
|
||||||
|
|
||||||
@ -350,7 +350,7 @@ public abstract class ToolAbility {
|
|||||||
public static class SmelterAbility extends ToolAbility {
|
public static class SmelterAbility extends ToolAbility {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
|
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemWithAbility tool) {
|
||||||
|
|
||||||
List<ItemStack> drops = block.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
|
List<ItemStack> drops = block.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
|
||||||
|
|
||||||
@ -403,7 +403,7 @@ public abstract class ToolAbility {
|
|||||||
public static class ShredderAbility extends ToolAbility {
|
public static class ShredderAbility extends ToolAbility {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
|
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemWithAbility tool) {
|
||||||
|
|
||||||
//a band-aid on a gaping wound
|
//a band-aid on a gaping wound
|
||||||
if(block == Blocks.lit_redstone_ore)
|
if(block == Blocks.lit_redstone_ore)
|
||||||
@ -445,7 +445,7 @@ public abstract class ToolAbility {
|
|||||||
public static class CentrifugeAbility extends ToolAbility {
|
public static class CentrifugeAbility extends ToolAbility {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
|
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemWithAbility tool) {
|
||||||
|
|
||||||
//a band-aid on a gaping wound
|
//a band-aid on a gaping wound
|
||||||
if(block == Blocks.lit_redstone_ore)
|
if(block == Blocks.lit_redstone_ore)
|
||||||
@ -491,7 +491,7 @@ public abstract class ToolAbility {
|
|||||||
public static class CrystallizerAbility extends ToolAbility {
|
public static class CrystallizerAbility extends ToolAbility {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
|
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemWithAbility tool) {
|
||||||
|
|
||||||
//a band-aid on a gaping wound
|
//a band-aid on a gaping wound
|
||||||
if(block == Blocks.lit_redstone_ore)
|
if(block == Blocks.lit_redstone_ore)
|
||||||
@ -533,7 +533,7 @@ public abstract class ToolAbility {
|
|||||||
public static class MercuryAbility extends ToolAbility {
|
public static class MercuryAbility extends ToolAbility {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
|
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemWithAbility tool) {
|
||||||
|
|
||||||
//a band-aid on a gaping wound
|
//a band-aid on a gaping wound
|
||||||
if(block == Blocks.lit_redstone_ore)
|
if(block == Blocks.lit_redstone_ore)
|
||||||
@ -585,7 +585,7 @@ public abstract class ToolAbility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemAbility tool) {
|
public boolean onDig(World world, int x, int y, int z, EntityPlayer player, Block block, int meta, IItemWithAbility tool) {
|
||||||
|
|
||||||
ExplosionNT ex = new ExplosionNT(player.worldObj, player, x + 0.5, y + 0.5, z + 0.5, strength);
|
ExplosionNT ex = new ExplosionNT(player.worldObj, player, x + 0.5, y + 0.5, z + 0.5, strength);
|
||||||
ex.addAttrib(ExAttrib.ALLDROP);
|
ex.addAttrib(ExAttrib.ALLDROP);
|
||||||
|
|||||||
@ -4,7 +4,8 @@ import com.hbm.blocks.ModBlocks;
|
|||||||
import com.hbm.blocks.generic.BlockBobble.BobbleType;
|
import com.hbm.blocks.generic.BlockBobble.BobbleType;
|
||||||
import com.hbm.handler.threading.PacketThreading;
|
import com.hbm.handler.threading.PacketThreading;
|
||||||
import com.hbm.items.ModItems;
|
import com.hbm.items.ModItems;
|
||||||
import com.hbm.items.tool.IItemAbility;
|
import com.hbm.items.tool.IItemWithAbility;
|
||||||
|
import com.hbm.lib.ModDamageSource;
|
||||||
import com.hbm.packet.toclient.AuxParticlePacketNT;
|
import com.hbm.packet.toclient.AuxParticlePacketNT;
|
||||||
import com.hbm.potion.HbmPotion;
|
import com.hbm.potion.HbmPotion;
|
||||||
import com.hbm.util.ContaminationUtil;
|
import com.hbm.util.ContaminationUtil;
|
||||||
@ -38,7 +39,7 @@ import net.minecraft.world.World;
|
|||||||
|
|
||||||
public abstract class WeaponAbility {
|
public abstract class WeaponAbility {
|
||||||
|
|
||||||
public abstract void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool);
|
public abstract void onHit(World world, EntityPlayer player, Entity victim, IItemWithAbility tool);
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
public abstract String getFullName();
|
public abstract String getFullName();
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ public abstract class WeaponAbility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
|
public void onHit(World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||||
|
|
||||||
if(victim instanceof EntityLivingBase)
|
if(victim instanceof EntityLivingBase)
|
||||||
ContaminationUtil.contaminate((EntityLivingBase)victim, HazardType.RADIATION, ContaminationType.CREATIVE, rad);
|
ContaminationUtil.contaminate((EntityLivingBase)victim, HazardType.RADIATION, ContaminationType.CREATIVE, rad);
|
||||||
@ -77,7 +78,7 @@ public abstract class WeaponAbility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
|
public void onHit(World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||||
|
|
||||||
if(victim instanceof EntityLivingBase) {
|
if(victim instanceof EntityLivingBase) {
|
||||||
|
|
||||||
@ -109,7 +110,7 @@ public abstract class WeaponAbility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
|
public void onHit(World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||||
|
|
||||||
if(victim instanceof EntityLivingBase) {
|
if(victim instanceof EntityLivingBase) {
|
||||||
|
|
||||||
@ -130,6 +131,50 @@ public abstract class WeaponAbility {
|
|||||||
return I18n.format(getName()) + " (" + duration + ")";
|
return I18n.format(getName()) + " (" + duration + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class BlendAbility extends WeaponAbility {
|
||||||
|
|
||||||
|
int divider;
|
||||||
|
|
||||||
|
public BlendAbility(int divider) {
|
||||||
|
this.divider = divider;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHit(World world, EntityPlayer player, Entity victim, IItemWithAbility 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
|
||||||
|
world.playSoundEffect(living.posX, living.posY + living.height * 0.5, living.posZ, "mob.zombie.woodbreak", 0.5F, 1.0F);
|
||||||
|
victim.attackEntityFrom(ModDamageSource.turbofan, 100);
|
||||||
|
NBTTagCompound data = new NBTTagCompound();
|
||||||
|
data.setString("type", "giblets");
|
||||||
|
data.setInteger("count", count * 4);
|
||||||
|
data.setInteger("ent", victim.getEntityId());
|
||||||
|
data.setInteger("cDiv", 5);
|
||||||
|
PacketThreading.createAllAroundThreadedPacket(new AuxParticlePacketNT(data, victim.posX, victim.posY + victim.height * 0.5, victim.posZ), new TargetPoint(victim.dimension, victim.posX, victim.posY + victim.height * 0.5, victim.posZ, 150));
|
||||||
|
living.entityDropItem(new ItemStack(ModItems.flesh, 10, 0), 0.0F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "weapon.ability.blender";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFullName() {
|
||||||
|
return I18n.format(getName()) + " (1:" + divider + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class PhosphorusAbility extends WeaponAbility {
|
public static class PhosphorusAbility extends WeaponAbility {
|
||||||
|
|
||||||
@ -140,7 +185,7 @@ public abstract class WeaponAbility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
|
public void onHit(World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||||
|
|
||||||
if(victim instanceof EntityLivingBase) {
|
if(victim instanceof EntityLivingBase) {
|
||||||
|
|
||||||
@ -170,7 +215,7 @@ public abstract class WeaponAbility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
|
public void onHit(World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||||
|
|
||||||
if(victim instanceof EntityLivingBase) {
|
if(victim instanceof EntityLivingBase) {
|
||||||
victim.setFire(duration);
|
victim.setFire(duration);
|
||||||
@ -197,7 +242,7 @@ public abstract class WeaponAbility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
|
public void onHit(World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||||
|
|
||||||
if(victim instanceof EntityLivingBase) {
|
if(victim instanceof EntityLivingBase) {
|
||||||
|
|
||||||
@ -241,7 +286,7 @@ public abstract class WeaponAbility {
|
|||||||
public static class BeheaderAbility extends WeaponAbility {
|
public static class BeheaderAbility extends WeaponAbility {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
|
public void onHit(World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||||
|
|
||||||
if(victim instanceof EntityLivingBase && ((EntityLivingBase) victim).getHealth() <= 0.0F) {
|
if(victim instanceof EntityLivingBase && ((EntityLivingBase) victim).getHealth() <= 0.0F) {
|
||||||
|
|
||||||
@ -294,7 +339,7 @@ public abstract class WeaponAbility {
|
|||||||
public static class BobbleAbility extends WeaponAbility {
|
public static class BobbleAbility extends WeaponAbility {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHit(World world, EntityPlayer player, Entity victim, IItemAbility tool) {
|
public void onHit(World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||||
|
|
||||||
if(victim instanceof EntityMob && ((EntityMob) victim).getHealth() <= 0.0F) {
|
if(victim instanceof EntityMob && ((EntityMob) victim).getHealth() <= 0.0F) {
|
||||||
|
|
||||||
|
|||||||
27
src/main/java/com/hbm/handler/ability/IBaseAbility.java
Normal file
27
src/main/java/com/hbm/handler/ability/IBaseAbility.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package com.hbm.handler.ability;
|
||||||
|
|
||||||
|
import net.minecraft.client.resources.I18n;
|
||||||
|
|
||||||
|
public interface IBaseAbility {
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
default String getExtension(int level) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
default String getFullName(int level) {
|
||||||
|
return I18n.format(getName()) + getExtension(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/main/java/com/hbm/handler/ability/IToolAreaAbility.java
Normal file
14
src/main/java/com/hbm/handler/ability/IToolAreaAbility.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package com.hbm.handler.ability;
|
||||||
|
|
||||||
|
import com.hbm.items.tool.IItemWithAbility;
|
||||||
|
import com.jcraft.jorbis.Block;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public interface IToolAreaAbility extends IBaseAbility {
|
||||||
|
// Should call tool.breakExtraBlock on a bunch of blocks.
|
||||||
|
// The initial block is always implicitly broken and shouldn't be included.
|
||||||
|
// TODO: Explosion needs it not to be broken, as it bypasses the harvest ability
|
||||||
|
void onDig(int level, World world, int x, int y, int z, EntityPlayer player, IItemWithAbility tool);
|
||||||
|
}
|
||||||
321
src/main/java/com/hbm/handler/ability/IToolHarvestAbility.java
Normal file
321
src/main/java/com/hbm/handler/ability/IToolHarvestAbility.java
Normal file
@ -0,0 +1,321 @@
|
|||||||
|
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.IItemWithAbility;
|
||||||
|
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 {
|
||||||
|
default void preHarvestAll(int level, World world, EntityPlayer player) {}
|
||||||
|
|
||||||
|
default void postHarvestAll(int level, World world, EntityPlayer player) {}
|
||||||
|
|
||||||
|
boolean skipDefaultDrops(int level);
|
||||||
|
|
||||||
|
// Call IToolHarvestAbility.super.onHarvestBlock to emulate the actual block breaking
|
||||||
|
default void onHarvestBlock(int level, World world, int x, int y, int z, EntityPlayer player, Block block, int meta) {
|
||||||
|
if (skipDefaultDrops(level)) {
|
||||||
|
// 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
|
||||||
|
IItemWithAbility.standardDigPost(world, x, y, z, (EntityPlayerMP) player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum HarvestAbility {
|
||||||
|
None(
|
||||||
|
new IToolHarvestAbility() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
// TODO: null? empty? otherwise i18n
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean skipDefaultDrops(int level) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
|
||||||
|
Silk(new IToolHarvestAbility() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "tool.ability.silktouch";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAllowed() {
|
||||||
|
return ToolConfig.abilitySilk;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean skipDefaultDrops(int level) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
Luck(new IToolHarvestAbility() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "tool.ability.luck";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAllowed() {
|
||||||
|
return ToolConfig.abilityLuck;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 boolean skipDefaultDrops(int level) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
Smelter(new IToolHarvestAbility() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "tool.ability.smelter";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAllowed() {
|
||||||
|
return ToolConfig.abilityFurnace;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean skipDefaultDrops(int level) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(doesSmelt) {
|
||||||
|
IToolHarvestAbility.super.onHarvestBlock(level, world, x, y, z, player, block, meta);
|
||||||
|
|
||||||
|
for(ItemStack stack : drops)
|
||||||
|
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, stack.copy()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
Shredder(new IToolHarvestAbility() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "tool.ability.shredder";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAllowed() {
|
||||||
|
return ToolConfig.abilityShredder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean skipDefaultDrops(int level) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
|
||||||
|
if(result != null && result.getItem() != ModItems.scrap) {
|
||||||
|
IToolHarvestAbility.super.onHarvestBlock(level, world, x, y, z, player, block, meta);
|
||||||
|
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, result.copy()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
Centrifuge(new IToolHarvestAbility() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "tool.ability.centrifuge";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAllowed() {
|
||||||
|
return ToolConfig.abilityCentrifuge;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean skipDefaultDrops(int level) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
|
||||||
|
if(result != null) {
|
||||||
|
IToolHarvestAbility.super.onHarvestBlock(level, world, x, y, z, player, block, meta);
|
||||||
|
|
||||||
|
for(ItemStack st : result) {
|
||||||
|
if(st != null)
|
||||||
|
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, st.copy()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
Crystallizer(new IToolHarvestAbility() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "tool.ability.crystallizer";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAllowed() {
|
||||||
|
return ToolConfig.abilityCrystallizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean skipDefaultDrops(int level) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
|
||||||
|
if(result != null) {
|
||||||
|
IToolHarvestAbility.super.onHarvestBlock(level, world, x, y, z, player, block, meta);
|
||||||
|
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, result.output.copy()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
Mercury(new IToolHarvestAbility() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "tool.ability.mercury";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAllowed() {
|
||||||
|
return ToolConfig.abilityMercury;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean skipDefaultDrops(int level) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
|
if(mercury > 0) {
|
||||||
|
IToolHarvestAbility.super.onHarvestBlock(level, world, x, y, z, player, block, meta);
|
||||||
|
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, new ItemStack(ModItems.ingot_mercury, mercury)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
public IToolHarvestAbility handler;
|
||||||
|
|
||||||
|
HarvestAbility(IToolHarvestAbility handler) {
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/main/java/com/hbm/handler/ability/IWeaponAbility.java
Normal file
12
src/main/java/com/hbm/handler/ability/IWeaponAbility.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package com.hbm.handler.ability;
|
||||||
|
|
||||||
|
import javax.swing.text.html.parser.Entity;
|
||||||
|
|
||||||
|
import com.hbm.items.tool.IItemWithAbility;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public interface IWeaponAbility extends IBaseAbility {
|
||||||
|
void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool);
|
||||||
|
}
|
||||||
@ -22,7 +22,7 @@ import net.minecraftforge.common.ForgeHooks;
|
|||||||
import net.minecraftforge.common.IShearable;
|
import net.minecraftforge.common.IShearable;
|
||||||
import net.minecraftforge.event.world.BlockEvent;
|
import net.minecraftforge.event.world.BlockEvent;
|
||||||
|
|
||||||
public interface IItemAbility {
|
public interface IItemWithAbility {
|
||||||
|
|
||||||
public boolean canHarvestBlock(Block par1Block, ItemStack itemStack);
|
public boolean canHarvestBlock(Block par1Block, ItemStack itemStack);
|
||||||
public boolean isShears(ItemStack stack);
|
public boolean isShears(ItemStack stack);
|
||||||
@ -19,7 +19,7 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.item.ItemSword;
|
import net.minecraft.item.ItemSword;
|
||||||
import net.minecraft.util.EnumChatFormatting;
|
import net.minecraft.util.EnumChatFormatting;
|
||||||
|
|
||||||
public class ItemSwordAbility extends ItemSword implements IItemAbility {
|
public class ItemSwordAbility extends ItemSword implements IItemWithAbility {
|
||||||
|
|
||||||
private EnumRarity rarity = EnumRarity.common;
|
private EnumRarity rarity = EnumRarity.common;
|
||||||
// was there a reason for this to be private?
|
// was there a reason for this to be private?
|
||||||
|
|||||||
@ -40,7 +40,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.util.EnumChatFormatting;
|
import net.minecraft.util.EnumChatFormatting;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRockTool, IGUIProvider {
|
public class ItemToolAbility extends ItemTool implements IItemWithAbility, IDepthRockTool, IGUIProvider {
|
||||||
|
|
||||||
protected boolean isShears = false;
|
protected boolean isShears = false;
|
||||||
protected EnumToolType toolType;
|
protected EnumToolType toolType;
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
Loading…
x
Reference in New Issue
Block a user