mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-13 00:37:57 +00:00
Some more work on the Terra Shatterer, it actually does stuff now!
This commit is contained in:
1 parent
7b2b53d370
commit
dbc0100d28
4 files changed
+234
-15
No files matched your search
@@ -67,7 +67,7 @@ public class ItemManasteelPick extends ItemPickaxe {
|
||||
|
||||
@Override
|
||||
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entity) {
|
||||
if (block.getBlockHardness(world, x, y, z) != 0F)
|
||||
if(block.getBlockHardness(world, x, y, z) != 0F)
|
||||
ManasteelToolCommons.damageItem(stack, 1, entity, MANA_PER_DAMAGE);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -12,47 +12,120 @@
|
||||
package vazkii.botania.common.item.equipment.tool;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.mana.IManaItem;
|
||||
import vazkii.botania.client.core.helper.IconHelper;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemTerraPick extends ItemManasteelPick {
|
||||
public class ItemTerraPick extends ItemManasteelPick implements IManaItem {
|
||||
|
||||
private static final String TAG_ENABLED = "enabled";
|
||||
|
||||
private static final String TAG_MANA = "mana";
|
||||
|
||||
private static final int MAX_MANA = 1000000000;
|
||||
|
||||
private static final Material[] MATERIALS = new Material[] { Material.rock, Material.iron, Material.ice, Material.glass, Material.piston, Material.anvil, Material.grass, Material.ground, Material.sand, Material.snow, Material.craftedSnow, Material.clay };
|
||||
|
||||
private static final int[] LEVELS = new int[] {
|
||||
0, 10000, 1000000, 10000000, 100000000, 1000000000
|
||||
};
|
||||
|
||||
IIcon iconTool, iconOverlay;
|
||||
|
||||
|
||||
public ItemTerraPick() {
|
||||
super(BotaniaAPI.terrasteelToolMaterial, LibItemNames.TERRA_PICK);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item item, CreativeTabs tab, List list) {
|
||||
for(int level : LEVELS) {
|
||||
ItemStack stack = new ItemStack(item);
|
||||
setMana(stack, level);
|
||||
list.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
|
||||
String rankFormat = StatCollector.translateToLocal("botaniamisc.toolRank");
|
||||
String rank = StatCollector.translateToLocal("botania.rank" + getLevel(par1ItemStack));
|
||||
par3List.add(String.format(rankFormat, rank).replaceAll("&", "\u00a7"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
|
||||
ItemNBTHelper.setBoolean(par1ItemStack, TAG_ENABLED, !isEnabled(par1ItemStack));
|
||||
int level = getLevel(par1ItemStack);
|
||||
if(level != 0)
|
||||
ItemNBTHelper.setBoolean(par1ItemStack, TAG_ENABLED, !isEnabled(par1ItemStack));
|
||||
return par1ItemStack;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
|
||||
if(!isEnabled(stack))
|
||||
return false;
|
||||
|
||||
World world = player.worldObj;
|
||||
Material mat = world.getBlock(x, y, z).getMaterial();
|
||||
if(!ManasteelToolCommons.isRightMaterial(mat, MATERIALS))
|
||||
return false;
|
||||
|
||||
MovingObjectPosition block = ManasteelToolCommons.raytraceFromEntity(world, player, true, 4.5);
|
||||
if(block == null)
|
||||
return false;
|
||||
|
||||
ForgeDirection direction = ForgeDirection.getOrientation(block.sideHit);
|
||||
int fortune = EnchantmentHelper.getFortuneModifier(player);
|
||||
boolean silk = EnchantmentHelper.getSilkTouchModifier(player);
|
||||
boolean doX = direction.offsetX == 0;
|
||||
boolean doY = direction.offsetY == 0;
|
||||
boolean doZ = direction.offsetZ == 0;
|
||||
|
||||
int level = getLevel(stack);
|
||||
int range = Math.max(0, level - 1);
|
||||
int rangeY = Math.max(1, range);
|
||||
|
||||
if(range == 0 && level != 1)
|
||||
return false;
|
||||
|
||||
ManasteelToolCommons.removeBlocksInIteration(player, stack, world, x, y, z, doX ? -range : 0, doY ? -1 : 0, doZ ? -range : 0, doX ? range + 1 : 1, doY ? rangeY * 2 : 1, doZ ? range + 1 : 1, null, MATERIALS, silk, fortune);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister par1IconRegister) {
|
||||
iconTool = IconHelper.forItem(par1IconRegister, this, 0);
|
||||
iconOverlay = IconHelper.forItem(par1IconRegister, this, 1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean requiresMultipleRenderPasses() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(ItemStack stack, int pass) {
|
||||
return pass == 1 && isEnabled(stack) ? iconOverlay : iconTool;
|
||||
@@ -63,12 +136,61 @@ public class ItemTerraPick extends ItemManasteelPick {
|
||||
public int getColorFromItemStack(ItemStack par1ItemStack, int par2) {
|
||||
if(par2 == 0 || !isEnabled(par1ItemStack))
|
||||
return 0xFFFFFF;
|
||||
|
||||
|
||||
return Color.HSBtoRGB(0.375F, (float) Math.min(1F, (Math.sin((double) System.currentTimeMillis() / 200D) * 0.5 + 1F)), 1F);
|
||||
}
|
||||
|
||||
|
||||
boolean isEnabled(ItemStack stack) {
|
||||
return ItemNBTHelper.getBoolean(stack, TAG_ENABLED, false);
|
||||
}
|
||||
|
||||
|
||||
public static void setMana(ItemStack stack, int mana) {
|
||||
ItemNBTHelper.setInt(stack, TAG_MANA, mana);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMana(ItemStack stack) {
|
||||
return ItemNBTHelper.getInt(stack, TAG_MANA, 0);
|
||||
}
|
||||
|
||||
public int getLevel(ItemStack stack) {
|
||||
int mana = getMana(stack);
|
||||
for(int i = 0; i < LEVELS.length; i++) {
|
||||
if(mana > LEVELS[i])
|
||||
continue;
|
||||
return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMana(ItemStack stack) {
|
||||
return MAX_MANA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMana(ItemStack stack, int mana) {
|
||||
setMana(stack, Math.min(getMana(stack) + mana, MAX_MANA));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveManaFromPool(ItemStack stack, TileEntity pool) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveManaFromItem(ItemStack stack, ItemStack otherStack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExportManaToPool(ItemStack stack, TileEntity pool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExportManaToItem(ItemStack stack, ItemStack otherStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,13 +11,26 @@
|
||||
*/
|
||||
package vazkii.botania.common.item.equipment.tool;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
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.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
|
||||
public final class ManasteelToolCommons {
|
||||
|
||||
|
||||
public static void damageItem(ItemStack stack, int dmg, EntityLivingBase entity, int manaPerDamage) {
|
||||
int manaToRequest = dmg * manaPerDamage;
|
||||
int manaRequested = entity instanceof EntityPlayer ? ManaItemHandler.requestMana(stack, (EntityPlayer) entity, manaToRequest, true) : 0;
|
||||
@@ -27,4 +40,79 @@ public final class ManasteelToolCommons {
|
||||
stack.damageItem(finalDamage, entity);
|
||||
}
|
||||
|
||||
public static void removeBlocksInIteration(EntityPlayer player, ItemStack stack, World world, int x, int y, int z, int xs, int ys, int zs, int xe, int ye, int ze, Block block, Material[] materialsListing, boolean silk, int fortune) {
|
||||
float blockHardness = block == null ? 1F : block.getBlockHardness(world, x, y, z);
|
||||
|
||||
for(int x1 = xs; x1 < xe; x1++)
|
||||
for(int y1 = ys; y1 < ye; y1++)
|
||||
for(int z1 = zs; z1 < ze; z1++)
|
||||
if(x != x1 && y != y1 && z != z1)
|
||||
removeBlockWithDrops(player, stack, world, x1 + x, y1 + y, z1 + z, x, y, z, block, materialsListing, silk, fortune,blockHardness);
|
||||
}
|
||||
|
||||
public static boolean isRightMaterial(Material material, Material[] materialsListing) {
|
||||
for(Material mat : materialsListing)
|
||||
if(material == mat)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void removeBlockWithDrops(EntityPlayer player, ItemStack stack, World world, int x, int y, int z, int bx, int by, int bz, Block block, Material[] materialsListing, boolean silk, int fortune,float blockHardness) {
|
||||
if(!world.blockExists(x, y, z))
|
||||
return;
|
||||
|
||||
Block blk = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if(block != null && blk != block)
|
||||
return;
|
||||
|
||||
Material mat = world.getBlock(x, y, z).getMaterial();
|
||||
if(blk != null && !blk.isAir(world, x, y, z) && blk.getPlayerRelativeBlockHardness(player, world, x, y, z) != 0) {
|
||||
List<ItemStack> items = new ArrayList();
|
||||
|
||||
if(!blk.canHarvestBlock(player, meta) || !isRightMaterial(mat, materialsListing))
|
||||
return;
|
||||
|
||||
if(!player.capabilities.isCreativeMode && blk != Blocks.bedrock) {
|
||||
int localMeta = world.getBlockMetadata(x, y, z);
|
||||
if (blk.removedByPlayer(world, player, x, y, z))
|
||||
blk.onBlockDestroyedByPlayer(world, x, y, z, localMeta);
|
||||
|
||||
damageItem(stack, 1, player, 80);
|
||||
blk.harvestBlock(world, player, x, y, z, localMeta);
|
||||
blk.onBlockHarvested(world, x, y, z, localMeta, player);
|
||||
} else world.setBlockToAir(x, y, z);
|
||||
|
||||
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(blk) + (meta << 12));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author mDiyo
|
||||
*/
|
||||
public static MovingObjectPosition raytraceFromEntity(World world, Entity player, boolean par3, double range) {
|
||||
float f = 1.0F;
|
||||
float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f;
|
||||
float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * f;
|
||||
double d0 = player.prevPosX + (player.posX - player.prevPosX) * f;
|
||||
double d1 = player.prevPosY + (player.posY - player.prevPosY) * f;
|
||||
if (!world.isRemote && player instanceof EntityPlayer)
|
||||
d1 += 1.62D;
|
||||
double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * f;
|
||||
Vec3 vec3 = world.getWorldVec3Pool().getVecFromPool(d0, d1, d2);
|
||||
float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI);
|
||||
float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI);
|
||||
float f5 = -MathHelper.cos(-f1 * 0.017453292F);
|
||||
float f6 = MathHelper.sin(-f1 * 0.017453292F);
|
||||
float f7 = f4 * f5;
|
||||
float f8 = f3 * f5;
|
||||
double d3 = range;
|
||||
if (player instanceof EntityPlayerMP)
|
||||
d3 = ((EntityPlayerMP) player).theItemInWorldManager.getBlockReachDistance();
|
||||
Vec3 vec31 = vec3.addVector(f7 * d3, f6 * d3, f8 * d3);
|
||||
return world.rayTraceBlocks(vec3, vec31, par3);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ botaniamisc.filter2=Pickup any items
|
||||
botaniamisc.creativePool0=Creative Mana Pool, has infinite Mana
|
||||
botaniamisc.creativePool1=Worthy of an Egoist
|
||||
botaniamisc.savedByLaurel=Your Golden Laurel Crown shatters, as it saves you from death.
|
||||
botaniamisc.toolRank=%s&7 Rank
|
||||
|
||||
# COLORS
|
||||
botania.color0=White
|
||||
@@ -44,6 +45,14 @@ botania.color14=Red
|
||||
botania.color15=Black
|
||||
botania.color16=Rainbow
|
||||
|
||||
# -- RANKS
|
||||
botania.rank0=&cD
|
||||
botania.rank1=&eC
|
||||
botania.rank2=&bB
|
||||
botania.rank3=&aA
|
||||
botania.rank4=&dS
|
||||
botania.rank5=&6SS
|
||||
|
||||
# BAUBLE TOOLTIPS
|
||||
botania.baubletype.amulet=Equippable in the &aAmulet&7 slot
|
||||
botania.baubletype.ring=Equippable in the &aRing&7 slot
|
||||
|
||||
Reference in new issue
Block a user