diff --git a/src/main/java/vazkii/botania/client/render/item/RenderLens.java b/src/main/java/vazkii/botania/client/render/item/RenderLens.java index 21da42eef..18715ddc8 100644 --- a/src/main/java/vazkii/botania/client/render/item/RenderLens.java +++ b/src/main/java/vazkii/botania/client/render/item/RenderLens.java @@ -24,7 +24,7 @@ import net.minecraftforge.client.IItemRenderer; import org.lwjgl.opengl.GL11; import vazkii.botania.api.mana.ILens; -import vazkii.botania.common.item.ItemLens; +import vazkii.botania.common.item.lens.ItemLens; public class RenderLens implements IItemRenderer { diff --git a/src/main/java/vazkii/botania/common/crafting/recipe/CompositeLensRecipe.java b/src/main/java/vazkii/botania/common/crafting/recipe/CompositeLensRecipe.java index f116546f8..dad1a328a 100644 --- a/src/main/java/vazkii/botania/common/crafting/recipe/CompositeLensRecipe.java +++ b/src/main/java/vazkii/botania/common/crafting/recipe/CompositeLensRecipe.java @@ -17,8 +17,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.world.World; import vazkii.botania.api.mana.ILens; -import vazkii.botania.common.item.ItemLens; import vazkii.botania.common.item.ModItems; +import vazkii.botania.common.item.lens.ItemLens; public class CompositeLensRecipe implements IRecipe { diff --git a/src/main/java/vazkii/botania/common/crafting/recipe/LensDyingRecipe.java b/src/main/java/vazkii/botania/common/crafting/recipe/LensDyingRecipe.java index 430d6663a..9faa67d95 100644 --- a/src/main/java/vazkii/botania/common/crafting/recipe/LensDyingRecipe.java +++ b/src/main/java/vazkii/botania/common/crafting/recipe/LensDyingRecipe.java @@ -21,8 +21,8 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.world.World; import net.minecraftforge.oredict.OreDictionary; import vazkii.botania.api.mana.ILens; -import vazkii.botania.common.item.ItemLens; import vazkii.botania.common.item.ModItems; +import vazkii.botania.common.item.lens.ItemLens; import vazkii.botania.common.lib.LibOreDict; public class LensDyingRecipe implements IRecipe { diff --git a/src/main/java/vazkii/botania/common/item/ItemLens.java b/src/main/java/vazkii/botania/common/item/ItemLens.java deleted file mode 100644 index dffcc7a67..000000000 --- a/src/main/java/vazkii/botania/common/item/ItemLens.java +++ /dev/null @@ -1,636 +0,0 @@ -/** - * This class was created by . It's distributed as - * part of the Botania Mod. Get the Source Code in github: - * https://github.com/Vazkii/Botania - * - * Botania is Open Source and distributed under a - * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License - * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) - * - * File Created @ [Jan 31, 2014, 3:02:58 PM (GMT)] - */ -package vazkii.botania.common.item; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import net.minecraft.block.Block; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityFallingBlock; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.item.EntityXPOrb; -import net.minecraft.entity.passive.EntitySheep; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.projectile.EntityArrow; -import net.minecraft.entity.projectile.EntityThrowable; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.ChunkCoordinates; -import net.minecraft.util.DamageSource; -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 net.minecraftforge.oredict.RecipeSorter; -import net.minecraftforge.oredict.RecipeSorter.Category; -import vazkii.botania.api.internal.IManaBurst; -import vazkii.botania.api.mana.BurstProperties; -import vazkii.botania.api.mana.ILens; -import vazkii.botania.api.mana.IManaBlock; -import vazkii.botania.api.mana.IManaReceiver; -import vazkii.botania.client.core.helper.IconHelper; -import vazkii.botania.common.Botania; -import vazkii.botania.common.block.ModBlocks; -import vazkii.botania.common.block.tile.TileManaFlame; -import vazkii.botania.common.core.handler.ConfigHandler; -import vazkii.botania.common.core.helper.ItemNBTHelper; -import vazkii.botania.common.core.helper.MathHelper; -import vazkii.botania.common.core.helper.Vector3; -import vazkii.botania.common.crafting.recipe.CompositeLensRecipe; -import vazkii.botania.common.crafting.recipe.LensDyingRecipe; -import vazkii.botania.common.lib.LibItemNames; -import cpw.mods.fml.common.registry.GameRegistry; - -public class ItemLens extends ItemMod implements ILens { - - private static final int NORMAL = 0, - SPEED = 1, - POWER = 2, - TIME = 3, - EFFICIENCY = 4, - BOUNCE = 5, - GRAVITY = 6, - MINE = 7, - DAMAGE = 8, - PHANTOM = 9, - MAGNET = 10, - EXPLOSIVE = 11, - INFLUENCE = 12, - WEIGHT = 13, - PAINT = 14, - FIRE = 15, - PISTON = 16, - LIGHT = 17; - - private static final int PROP_NONE = 0, - PROP_POWER = 1, - PROP_ORIENTATION = 1 << 1, - PROP_TOUCH = 1 << 2, - PROP_INTERACTION = 1 << 3, - PROP_DAMAGE = 1 << 4; - - private static final Map props = new HashMap(); - - static { - setProps(NORMAL, PROP_NONE); - setProps(SPEED, PROP_NONE); - setProps(POWER, PROP_POWER); - setProps(TIME, PROP_NONE); - setProps(EFFICIENCY, PROP_NONE); - setProps(BOUNCE, PROP_TOUCH); - setProps(GRAVITY, PROP_ORIENTATION); - setProps(MINE, PROP_TOUCH | PROP_INTERACTION); - setProps(DAMAGE, PROP_DAMAGE); - setProps(PHANTOM, PROP_TOUCH); - setProps(MAGNET, PROP_ORIENTATION); - setProps(EXPLOSIVE, PROP_DAMAGE | PROP_TOUCH | PROP_INTERACTION); - setProps(INFLUENCE, PROP_NONE); - setProps(WEIGHT, PROP_TOUCH | PROP_INTERACTION); - setProps(PAINT, PROP_TOUCH | PROP_INTERACTION); - setProps(FIRE, PROP_DAMAGE | PROP_TOUCH | PROP_INTERACTION); - setProps(PISTON, PROP_TOUCH | PROP_INTERACTION); - setProps(LIGHT, PROP_TOUCH | PROP_INTERACTION); - } - - static final List paintableBlocks = new ArrayList() {{ - add(Blocks.stained_glass); - add(Blocks.stained_glass_pane); - add(Blocks.stained_hardened_clay); - add(Blocks.wool); - add(Blocks.carpet); - add(ModBlocks.unstableBlock); - add(ModBlocks.manaBeacon); - } - }; - - private static final String TAG_COLOR = "color"; - private static final String TAG_COMPOSITE_LENS = "compositeLens"; - - public static IIcon iconGlass; - - public static final int SUBTYPES = 18; - IIcon[] ringIcons; - - public ItemLens() { - super(); - setUnlocalizedName(LibItemNames.LENS); - setMaxStackSize(1); - setHasSubtypes(true); - - GameRegistry.addRecipe(new CompositeLensRecipe()); - GameRegistry.addRecipe(new LensDyingRecipe()); - RecipeSorter.register("botania:compositeLens", CompositeLensRecipe.class, Category.SHAPELESS, ""); - RecipeSorter.register("botania:lensDying", CompositeLensRecipe.class, Category.SHAPELESS, ""); - } - - @Override - public void registerIcons(IIconRegister par1IconRegister) { - iconGlass = IconHelper.forName(par1IconRegister, "lensInside"); - - ringIcons = new IIcon[SUBTYPES]; - for(int i = 0; i < ringIcons.length; i++) - ringIcons[i] = IconHelper.forName(par1IconRegister, LibItemNames.LENS_NAMES[i]); - } - - @Override - public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) { - for(int i = 0; i < SUBTYPES; i++) - par3List.add(new ItemStack(par1, 1, i)); - } - - @Override - public boolean requiresMultipleRenderPasses() { - return true; - } - - @Override - public IIcon getIconFromDamageForRenderPass(int par1, int par2) { - return par2 == 1 ? ringIcons[Math.min(SUBTYPES - 1, par1)] : iconGlass; - } - - @Override - public IIcon getIconFromDamage(int par1) { - return getIconFromDamageForRenderPass(par1, 0); - } - - @Override - public int getColorFromItemStack(ItemStack par1ItemStack, int par2) { - return par2 == 0 ? getLensColor(par1ItemStack) : 0xFFFFFF; - } - - @Override - public String getUnlocalizedName(ItemStack par1ItemStack) { - return "item." + LibItemNames.LENS_NAMES[Math.min(SUBTYPES - 1, par1ItemStack.getItemDamage())]; - } - - @Override - public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { - int storedColor = getStoredColor(par1ItemStack); - if(storedColor != -1) - par3List.add(String.format(StatCollector.translateToLocal("botaniamisc.color"), StatCollector.translateToLocal("botania.color" + storedColor))); - } - - - public String getItemShortTermName(ItemStack stack) { - return StatCollector.translateToLocal(stack.getUnlocalizedName().replaceAll("item.", "item.botania:") + ".short"); - } - - @Override - public String getItemStackDisplayName(ItemStack stack) { - ItemStack compositeLens = getCompositeLens(stack); - if(compositeLens == null) - return super.getItemStackDisplayName(stack); - return String.format(StatCollector.translateToLocal("item.botania:compositeLens.name"), getItemShortTermName(stack), getItemShortTermName(compositeLens)); - } - - @Override - public void apply(ItemStack stack, BurstProperties props) { - int storedColor = getStoredColor(stack); - if(storedColor != -1) - props.color = getLensColor(stack); - - switch(stack.getItemDamage()) { - case SPEED : { - props.motionModifier *= 2F; - props.maxMana *= 0.75F; - props.ticksBeforeManaLoss /= 3F; - props.manaLossPerTick *= 2F; - break; - } - case POWER : { - props.maxMana *= 2; - props.motionModifier *= 0.85F; - props.manaLossPerTick *= 2F; - break; - } - case TIME : { - props.ticksBeforeManaLoss *= 2.25F; - props.motionModifier *= 0.8F; - break; - } - case EFFICIENCY : { - props.manaLossPerTick /= 5F; - props.ticksBeforeManaLoss *= 1.1F; - break; - } - case GRAVITY : { - props.gravity = 0.0015F; - props.ticksBeforeManaLoss *= 1.2F; - break; - } - } - - ItemStack compositeLens = getCompositeLens(stack); - if(compositeLens != null && compositeLens.getItem() instanceof ILens) - ((ILens) compositeLens.getItem()).apply(compositeLens, props); - } - - @Override - public boolean collideBurst(IManaBurst burst, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { - EntityThrowable entity = (EntityThrowable) burst; - - switch(stack.getItemDamage()) { - case BOUNCE : { - if(!isManaBlock && pos.entityHit == null) { - ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates(); - if(coords.posX != pos.blockX || coords.posY != pos.blockY || coords.posZ != pos.blockZ) { - Vector3 currentMovementVec = new Vector3(entity.motionX, entity.motionY, entity.motionZ); - ForgeDirection dir = ForgeDirection.getOrientation(pos.sideHit); - Vector3 normalVector = new Vector3(dir.offsetX, dir.offsetY, dir.offsetZ).normalize(); - Vector3 movementVec = normalVector.multiply(-2 * currentMovementVec.dotProduct(normalVector)).add(currentMovementVec); - - burst.setMotion(movementVec.x, movementVec.y, movementVec.z); - dead = false; - } - } - break; - } - case MINE : { - World world = entity.worldObj; - int x = pos.blockX; - int y = pos.blockY; - int z = pos.blockZ; - Block block = world.getBlock(x, y, z); - TileEntity tile = world.getTileEntity(x, y, z); - - int meta = world.getBlockMetadata(x, y, z); - float hardness = block.getBlockHardness(world, x, y, z); - int mana = burst.getMana(); - - ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates(); - if((coords.posX != x || coords.posY != y || coords.posZ != z) && !(tile instanceof IManaBlock) && block != null && hardness != -1 && hardness < 50F && (burst.isFake() || mana >= 24)) { - List items = new ArrayList(); - - items.addAll(block.getDrops(world, x, y, z, meta, 0)); - - if(!burst.hasAlreadyCollidedAt(x, y, z)) { - if(!burst.isFake() && !entity.worldObj.isRemote) { - world.setBlockToAir(x, y, z); - if(ConfigHandler.blockBreakParticles) - entity.worldObj.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12)); - - for(ItemStack stack_ : items) - world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, stack_)); - burst.setMana(mana - 24); - } - } - - dead = false; - } - break; - } - case PHANTOM : { - if(!isManaBlock) { - dead = false; - burst.setMinManaLoss(Math.max(0, burst.getMinManaLoss() - 4)); - } - break; - } - case EXPLOSIVE : { - if(!burst.isFake()) { - ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates(); - if(!entity.worldObj.isRemote && pos.entityHit == null && !isManaBlock && (pos.blockX != coords.posX || pos.blockY != coords.posY || pos.blockZ != coords.posZ)) - entity.worldObj.createExplosion(entity, entity.posX, entity.posY, entity.posZ, burst.getMana() / 50F, true); - } else dead = false; - break; - } - case WEIGHT : { - if(!burst.isFake()) { - int x = pos.blockX; - int y = pos.blockY; - int z = pos.blockZ; - Block block = entity.worldObj.getBlock(x, y, z); - Block blockBelow = entity.worldObj.getBlock(x, y - 1, z); - if(blockBelow.isAir(entity.worldObj, x, y - 1, z) && block.getBlockHardness(entity.worldObj, x, y, z) != -1 && entity.worldObj.getTileEntity(x, y, z) == null) { - EntityFallingBlock falling = new EntityFallingBlock(entity.worldObj, x + 0.5, y + 0.5, z + 0.5, block, entity.worldObj.getBlockMetadata(x, y, z)); - if(!entity.worldObj.isRemote) - entity.worldObj.spawnEntityInWorld(falling); - } - } - break; - } - case PAINT : { - int storedColor = getStoredColor(stack); - if(!burst.isFake() && storedColor > -1 && storedColor < 17) { - if(pos.entityHit != null && pos.entityHit instanceof EntitySheep) { - int r = 20; - int sheepColor = ((EntitySheep) pos.entityHit).getFleeceColor(); - List sheepList = entity.worldObj.getEntitiesWithinAABB(EntitySheep.class, AxisAlignedBB.getBoundingBox(pos.entityHit.posX - r, pos.entityHit.posY - r, pos.entityHit.posZ - r, pos.entityHit.posX + r, pos.entityHit.posY + r, pos.entityHit.posZ + r)); - for(EntitySheep sheep : sheepList) { - if(sheep.getFleeceColor() == sheepColor) - sheep.setFleeceColor(storedColor == 16 ? sheep.worldObj.rand.nextInt(16) : storedColor); - } - dead = true; - } else { - Block block = entity.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ); - if(paintableBlocks.contains(block)) { - int meta = entity.worldObj.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ); - List coordsToPaint = new ArrayList(); - List coordsFound = new ArrayList(); - - ChunkCoordinates theseCoords = new ChunkCoordinates(pos.blockX, pos.blockY, pos.blockZ); - coordsFound.add(theseCoords); - - do { - List iterCoords = new ArrayList(coordsFound); - for(ChunkCoordinates coords : iterCoords) { - coordsFound.remove(coords); - coordsToPaint.add(coords); - - for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { - Block block_ = entity.worldObj.getBlock(coords.posX + dir.offsetX, coords.posY + dir.offsetY, coords.posZ + dir.offsetZ); - int meta_ = entity.worldObj.getBlockMetadata(coords.posX + dir.offsetX, coords.posY + dir.offsetY, coords.posZ + dir.offsetZ); - ChunkCoordinates coords_ = new ChunkCoordinates(coords.posX + dir.offsetX, coords.posY + dir.offsetY, coords.posZ + dir.offsetZ); - if(block_ == block && meta_ == meta && !coordsFound.contains(coords_) && !coordsToPaint.contains(coords_)) - coordsFound.add(coords_); - } - } - } while(!coordsFound.isEmpty() && coordsToPaint.size() < 1000); - - for(ChunkCoordinates coords : coordsToPaint) { - int placeColor = storedColor == 16 ? entity.worldObj.rand.nextInt(16) : storedColor; - int metaThere = entity.worldObj.getBlockMetadata(coords.posX, coords.posY, coords.posZ); - - if(metaThere != placeColor) { - if(!entity.worldObj.isRemote) - entity.worldObj.setBlockMetadataWithNotify(coords.posX, coords.posY, coords.posZ, placeColor, 2); - float[] color = EntitySheep.fleeceColorTable[placeColor]; - float r = color[0]; - float g = color[1]; - float b = color[2]; - for(int i = 0; i < 4; i++) - Botania.proxy.sparkleFX(entity.worldObj, coords.posX + (float) Math.random(), coords.posY + (float) Math.random(), coords.posZ + (float) Math.random(), r, g, b, 0.6F + (float) Math.random() * 0.3F, 5); - - } - } - } - } - } - break; - } - case FIRE : { - ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates(); - if((coords.posX != pos.blockX || coords.posY != pos.blockY || coords.posZ != pos.blockZ) && !burst.isFake() && !isManaBlock) { - ForgeDirection dir = ForgeDirection.getOrientation(pos.sideHit); - - int x = pos.blockX + dir.offsetX; - int y = pos.blockY + dir.offsetY; - int z = pos.blockZ + dir.offsetZ; - - Block blockAt = entity.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ); - Block blockAt_ = entity.worldObj.getBlock(x, y, z); - - if(blockAt == Blocks.portal) - entity.worldObj.setBlock(pos.blockX, pos.blockY, pos.blockZ, Blocks.air); - else if(blockAt_.isAir(entity.worldObj, x, y, z)) - entity.worldObj.setBlock(x, y, z, Blocks.fire); - } - - break; - } - case PISTON : { - ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates(); - if((coords.posX != pos.blockX || coords.posY != pos.blockY || coords.posZ != pos.blockZ) && !burst.isFake() && !isManaBlock && !entity.worldObj.isRemote) { - ForgeDirection dir = ForgeDirection.getOrientation(pos.sideHit).getOpposite(); - int x = pos.blockX + dir.offsetX; - int y = pos.blockY + dir.offsetY; - int z = pos.blockZ + dir.offsetZ; - - if(entity.worldObj.isAirBlock(x, y, z) || entity.worldObj.getBlock(x, y, z).isReplaceable(entity.worldObj, x, y, z)) { - Block block = entity.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ); - int meta = entity.worldObj.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ); - TileEntity tile = entity.worldObj.getTileEntity(pos.blockX, pos.blockY, pos.blockZ); - - if(block.getMobilityFlag() == 0 && block != Blocks.obsidian && tile == null) { - entity.worldObj.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ); - entity.worldObj.setBlock(x, y, z, block, meta, 1 | 2); - entity.worldObj.playAuxSFX(2001, pos.blockX, pos.blockY, pos.blockZ, Block.getIdFromBlock(block) + (meta << 12)); - } - } - } - break; - } - case LIGHT : { - ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates(); - if((coords.posX != pos.blockX || coords.posY != pos.blockY || coords.posZ != pos.blockZ) && !burst.isFake() && !isManaBlock) { - ForgeDirection dir = ForgeDirection.getOrientation(pos.sideHit); - - int x = pos.blockX + dir.offsetX; - int y = pos.blockY + dir.offsetY; - int z = pos.blockZ + dir.offsetZ; - - Block blockAt = entity.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ); - Block blockAt_ = entity.worldObj.getBlock(x, y, z); - - if(blockAt == ModBlocks.manaFlame) - entity.worldObj.setBlock(pos.blockX, pos.blockY, pos.blockZ, Blocks.air); - else if(blockAt_.isAir(entity.worldObj, x, y, z)) { - entity.worldObj.setBlock(x, y, z, ModBlocks.manaFlame); - TileEntity tile = entity.worldObj.getTileEntity(x, y, z); - - if(tile instanceof TileManaFlame) - ((TileManaFlame) tile).setColor(burst.getColor()); - } - } - - break; - } - } - - ItemStack compositeLens = getCompositeLens(stack); - if(compositeLens != null && compositeLens.getItem() instanceof ILens) - dead = ((ILens) compositeLens.getItem()).collideBurst(burst, pos, isManaBlock, dead, compositeLens); - - return dead; - } - - @Override - public void updateBurst(IManaBurst burst, ItemStack stack) { - EntityThrowable entity = (EntityThrowable) burst; - int storedColor = getStoredColor(stack); - - if(storedColor == 16 && entity.worldObj.isRemote) - burst.setColor(getLensColor(stack)); - - boolean magnetized = entity.getEntityData().hasKey("Botania:Magnetized"); - switch(stack.getItemDamage()) { - case DAMAGE : { - AxisAlignedBB axis = AxisAlignedBB.getBoundingBox(entity.posX, entity.posY, entity.posZ, entity.lastTickPosX, entity.lastTickPosY, entity.lastTickPosZ).expand(1, 1, 1); - List entities = entity.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axis); - for(EntityLivingBase living : entities) { - if(living instanceof EntityPlayer) - continue; - - if(living.hurtTime == 0) { - int mana = burst.getMana(); - if(mana >= 16) { - burst.setMana(mana - 16); - if(!burst.isFake() && !entity.worldObj.isRemote) - living.attackEntityFrom(DamageSource.magic, 4); - break; - } - } - } - break; - } - case MAGNET : { - int x = (int) entity.posX; - int y = (int) entity.posY; - int z = (int) entity.posZ; - int range = 3; - - magnetize : { - for(int i = -range; i < range; i++) - for(int j = -range; j < range; j++) - for(int k = -range; k < range; k++) - if(entity.worldObj.getTileEntity(i + x, j + y, k + z) instanceof IManaReceiver) { - TileEntity tile = entity.worldObj.getTileEntity(i + x, j + y, k + z); - - if(magnetized) { - int magX = entity.getEntityData().getInteger("Botania:MagnetizedX"); - int magY = entity.getEntityData().getInteger("Botania:MagnetizedY"); - int magZ = entity.getEntityData().getInteger("Botania:MagnetizedZ"); - if(tile.xCoord != magX || tile.yCoord != magY || tile.zCoord != magZ) - continue; - } - - IManaReceiver receiver = (IManaReceiver) tile; - - ChunkCoordinates srcCoords = burst.getBurstSourceChunkCoordinates(); - - if(MathHelper.pointDistanceSpace(tile.xCoord, tile.yCoord, tile.zCoord, srcCoords.posX, srcCoords.posY, srcCoords.posZ) > 3 && receiver.canRecieveManaFromBursts() && !receiver.isFull()) { - Vector3 burstVec = Vector3.fromEntity(entity); - Vector3 tileVec = Vector3.fromTileEntityCenter(tile).add(0, -0.1, 0); - Vector3 motionVec = new Vector3(entity.motionX, entity.motionY, entity.motionZ); - - Vector3 normalMotionVec = motionVec.copy().normalize(); - Vector3 magnetVec = tileVec.sub(burstVec).normalize(); - Vector3 differenceVec = normalMotionVec.sub(magnetVec).multiply(motionVec.mag() * 0.1); - - Vector3 finalMotionVec = motionVec.sub(differenceVec); - if(!magnetized) { - finalMotionVec.multiply(0.75); - entity.getEntityData().setBoolean("Botania:Magnetized", true); - entity.getEntityData().setInteger("Botania:MagnetizedX", tile.xCoord); - entity.getEntityData().setInteger("Botania:MagnetizedY", tile.yCoord); - entity.getEntityData().setInteger("Botania:MagnetizedZ", tile.zCoord); - } - - burst.setMotion(finalMotionVec.x, finalMotionVec.y, finalMotionVec.z); - break magnetize; - } - } - } - break; - } - case INFLUENCE : { - if(!burst.isFake()) { - double range = 3.5; - List movables = entity.worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range)); - movables.addAll(entity.worldObj.getEntitiesWithinAABB(EntityXPOrb.class, AxisAlignedBB.getBoundingBox(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); - movables.addAll(entity.worldObj.getEntitiesWithinAABB(EntityArrow.class, AxisAlignedBB.getBoundingBox(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); - movables.addAll(entity.worldObj.getEntitiesWithinAABB(EntityFallingBlock.class, AxisAlignedBB.getBoundingBox(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); - - for(Entity movable : movables) { - movable.motionX = entity.motionX; - movable.motionY = entity.motionY; - movable.motionZ = entity.motionZ; - } - } - - break; - } - } - - ItemStack compositeLens = getCompositeLens(stack); - if(compositeLens != null && compositeLens.getItem() instanceof ILens) - ((ILens) compositeLens.getItem()).updateBurst(burst, compositeLens); - } - - @Override - public int getLensColor(ItemStack stack) { - int storedColor = getStoredColor(stack); - - if(storedColor == -1) - return 0xFFFFFF; - - if(storedColor == 16) - return Color.HSBtoRGB(Botania.proxy.getWorldElapsedTicks() * 2 % 360 / 360F, 1F, 1F); - - float[] color = EntitySheep.fleeceColorTable[storedColor]; - return new Color(color[0], color[1], color[2]).getRGB(); - } - - public static int getStoredColor(ItemStack stack) { - return ItemNBTHelper.getInt(stack, TAG_COLOR, -1); - } - - public static ItemStack setLensColor(ItemStack stack, int color) { - ItemNBTHelper.setInt(stack, TAG_COLOR, color); - return stack; - } - - @Override - public boolean doParticles(IManaBurst burst, ItemStack stack) { - return true; - } - - public static void setProps(int lens, int props_) { - props.put(lens, props_); - } - - public static boolean isBlacklisted(int lens1, int lens2) { - return (props.get(lens1) & props.get(lens2)) != 0; - } - - @Override - public boolean canCombineLenses(ItemStack sourceLens, ItemStack compositeLens) { - if(sourceLens.getItemDamage() == compositeLens.getItemDamage()) - return false; - - if(sourceLens.getItemDamage() == NORMAL || compositeLens.getItemDamage() == NORMAL) - return false; - - if(isBlacklisted(sourceLens.getItemDamage(), compositeLens.getItemDamage())) - return false; - - return true; - } - - @Override - public ItemStack getCompositeLens(ItemStack stack) { - NBTTagCompound cmp = ItemNBTHelper.getCompound(stack, TAG_COMPOSITE_LENS, false); - ItemStack lens = ItemStack.loadItemStackFromNBT(cmp); - return lens; - } - - @Override - public ItemStack setCompositeLens(ItemStack sourceLens, ItemStack compositeLens) { - NBTTagCompound cmp = new NBTTagCompound(); - compositeLens.writeToNBT(cmp); - ItemNBTHelper.setCompound(sourceLens, TAG_COMPOSITE_LENS, cmp); - - return sourceLens; - } -} diff --git a/src/main/java/vazkii/botania/common/item/ModItems.java b/src/main/java/vazkii/botania/common/item/ModItems.java index d28e58dc7..4787cf2cd 100644 --- a/src/main/java/vazkii/botania/common/item/ModItems.java +++ b/src/main/java/vazkii/botania/common/item/ModItems.java @@ -71,6 +71,7 @@ import vazkii.botania.common.item.interaction.thaumcraft.ItemElementiumHelmRevea import vazkii.botania.common.item.interaction.thaumcraft.ItemManaInkwell; import vazkii.botania.common.item.interaction.thaumcraft.ItemManasteelHelmRevealing; import vazkii.botania.common.item.interaction.thaumcraft.ItemTerrasteelHelmRevealing; +import vazkii.botania.common.item.lens.ItemLens; import vazkii.botania.common.item.material.ItemDye; import vazkii.botania.common.item.material.ItemManaPetal; import vazkii.botania.common.item.material.ItemManaResource; diff --git a/src/main/java/vazkii/botania/common/item/lens/ItemLens.java b/src/main/java/vazkii/botania/common/item/lens/ItemLens.java new file mode 100644 index 000000000..b73912ed5 --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/ItemLens.java @@ -0,0 +1,310 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 31, 2014, 3:02:58 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import java.awt.Color; +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.passive.EntitySheep; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.StatCollector; +import net.minecraftforge.oredict.RecipeSorter; +import net.minecraftforge.oredict.RecipeSorter.Category; +import vazkii.botania.api.internal.IManaBurst; +import vazkii.botania.api.mana.BurstProperties; +import vazkii.botania.api.mana.ILens; +import vazkii.botania.client.core.helper.IconHelper; +import vazkii.botania.common.Botania; +import vazkii.botania.common.core.helper.ItemNBTHelper; +import vazkii.botania.common.crafting.recipe.CompositeLensRecipe; +import vazkii.botania.common.crafting.recipe.LensDyingRecipe; +import vazkii.botania.common.item.ItemMod; +import vazkii.botania.common.lib.LibItemNames; +import cpw.mods.fml.common.registry.GameRegistry; + +public class ItemLens extends ItemMod implements ILens { + + public static final int SUBTYPES = 18; + + private static final int NORMAL = 0, + SPEED = 1, + POWER = 2, + TIME = 3, + EFFICIENCY = 4, + BOUNCE = 5, + GRAVITY = 6, + MINE = 7, + DAMAGE = 8, + PHANTOM = 9, + MAGNET = 10, + EXPLOSIVE = 11, + INFLUENCE = 12, + WEIGHT = 13, + PAINT = 14, + FIRE = 15, + PISTON = 16, + LIGHT = 17; + + private static final int PROP_NONE = 0, + PROP_POWER = 1, + PROP_ORIENTATION = 1 << 1, + PROP_TOUCH = 1 << 2, + PROP_INTERACTION = 1 << 3, + PROP_DAMAGE = 1 << 4; + + private static final int[] props = new int[SUBTYPES]; + private static final Lens[] lenses = new Lens[SUBTYPES]; + private static Lens fallbackLens = new Lens(); + + static { + setProps(NORMAL, PROP_NONE); + setProps(SPEED, PROP_NONE); + setProps(POWER, PROP_POWER); + setProps(TIME, PROP_NONE); + setProps(EFFICIENCY, PROP_NONE); + setProps(BOUNCE, PROP_TOUCH); + setProps(GRAVITY, PROP_ORIENTATION); + setProps(MINE, PROP_TOUCH | PROP_INTERACTION); + setProps(DAMAGE, PROP_DAMAGE); + setProps(PHANTOM, PROP_TOUCH); + setProps(MAGNET, PROP_ORIENTATION); + setProps(EXPLOSIVE, PROP_DAMAGE | PROP_TOUCH | PROP_INTERACTION); + setProps(INFLUENCE, PROP_NONE); + setProps(WEIGHT, PROP_TOUCH | PROP_INTERACTION); + setProps(PAINT, PROP_TOUCH | PROP_INTERACTION); + setProps(FIRE, PROP_DAMAGE | PROP_TOUCH | PROP_INTERACTION); + setProps(PISTON, PROP_TOUCH | PROP_INTERACTION); + setProps(LIGHT, PROP_TOUCH | PROP_INTERACTION); + + setLens(NORMAL, fallbackLens); + setLens(SPEED, new LensSpeed()); + setLens(POWER, new LensPower()); + setLens(TIME, new LensTime()); + setLens(EFFICIENCY, new LensEfficiency()); + setLens(BOUNCE, new LensBounce()); + setLens(GRAVITY, new LensGravity()); + setLens(MINE, new LensMine()); + setLens(DAMAGE, new LensDamage()); + setLens(PHANTOM, new LensPhantom()); + setLens(MAGNET, new LensMagnet()); + setLens(EXPLOSIVE, new LensExplosive()); + setLens(INFLUENCE, new LensInfluence()); + setLens(WEIGHT, new LensWeight()); + setLens(PAINT, new LensPaint()); + setLens(FIRE, new LensFire()); + setLens(PISTON, new LensPiston()); + setLens(LIGHT, new LensLight()); + } + + private static final String TAG_COLOR = "color"; + private static final String TAG_COMPOSITE_LENS = "compositeLens"; + + public static IIcon iconGlass; + + IIcon[] ringIcons; + + public ItemLens() { + super(); + setUnlocalizedName(LibItemNames.LENS); + setMaxStackSize(1); + setHasSubtypes(true); + + GameRegistry.addRecipe(new CompositeLensRecipe()); + GameRegistry.addRecipe(new LensDyingRecipe()); + RecipeSorter.register("botania:compositeLens", CompositeLensRecipe.class, Category.SHAPELESS, ""); + RecipeSorter.register("botania:lensDying", CompositeLensRecipe.class, Category.SHAPELESS, ""); + } + + @Override + public void registerIcons(IIconRegister par1IconRegister) { + iconGlass = IconHelper.forName(par1IconRegister, "lensInside"); + + ringIcons = new IIcon[SUBTYPES]; + for(int i = 0; i < ringIcons.length; i++) + ringIcons[i] = IconHelper.forName(par1IconRegister, LibItemNames.LENS_NAMES[i]); + } + + @Override + public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) { + for(int i = 0; i < SUBTYPES; i++) + par3List.add(new ItemStack(par1, 1, i)); + } + + @Override + public boolean requiresMultipleRenderPasses() { + return true; + } + + @Override + public IIcon getIconFromDamageForRenderPass(int par1, int par2) { + return par2 == 1 ? ringIcons[Math.min(SUBTYPES - 1, par1)] : iconGlass; + } + + @Override + public IIcon getIconFromDamage(int par1) { + return getIconFromDamageForRenderPass(par1, 0); + } + + @Override + public int getColorFromItemStack(ItemStack par1ItemStack, int par2) { + return par2 == 0 ? getLensColor(par1ItemStack) : 0xFFFFFF; + } + + @Override + public String getUnlocalizedName(ItemStack par1ItemStack) { + return "item." + LibItemNames.LENS_NAMES[Math.min(SUBTYPES - 1, par1ItemStack.getItemDamage())]; + } + + @Override + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { + int storedColor = getStoredColor(par1ItemStack); + if(storedColor != -1) + par3List.add(String.format(StatCollector.translateToLocal("botaniamisc.color"), StatCollector.translateToLocal("botania.color" + storedColor))); + } + + + public String getItemShortTermName(ItemStack stack) { + return StatCollector.translateToLocal(stack.getUnlocalizedName().replaceAll("item.", "item.botania:") + ".short"); + } + + @Override + public String getItemStackDisplayName(ItemStack stack) { + ItemStack compositeLens = getCompositeLens(stack); + if(compositeLens == null) + return super.getItemStackDisplayName(stack); + return String.format(StatCollector.translateToLocal("item.botania:compositeLens.name"), getItemShortTermName(stack), getItemShortTermName(compositeLens)); + } + + @Override + public void apply(ItemStack stack, BurstProperties props) { + int storedColor = getStoredColor(stack); + if(storedColor != -1) + props.color = getLensColor(stack); + + getLens(stack.getItemDamage()).apply(stack, props); + + ItemStack compositeLens = getCompositeLens(stack); + if(compositeLens != null && compositeLens.getItem() instanceof ILens) + ((ILens) compositeLens.getItem()).apply(compositeLens, props); + } + + @Override + public boolean collideBurst(IManaBurst burst, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { + EntityThrowable entity = (EntityThrowable) burst; + + dead = getLens(stack.getItemDamage()).collideBurst(burst, entity, pos, isManaBlock, dead, stack); + + ItemStack compositeLens = getCompositeLens(stack); + if(compositeLens != null && compositeLens.getItem() instanceof ILens) + dead = ((ILens) compositeLens.getItem()).collideBurst(burst, pos, isManaBlock, dead, compositeLens); + + return dead; + } + + @Override + public void updateBurst(IManaBurst burst, ItemStack stack) { + EntityThrowable entity = (EntityThrowable) burst; + int storedColor = getStoredColor(stack); + + if(storedColor == 16 && entity.worldObj.isRemote) + burst.setColor(getLensColor(stack)); + + getLens(stack.getItemDamage()).updateBurst(burst, entity, stack); + + ItemStack compositeLens = getCompositeLens(stack); + if(compositeLens != null && compositeLens.getItem() instanceof ILens) + ((ILens) compositeLens.getItem()).updateBurst(burst, compositeLens); + } + + @Override + public int getLensColor(ItemStack stack) { + int storedColor = getStoredColor(stack); + + if(storedColor == -1) + return 0xFFFFFF; + + if(storedColor == 16) + return Color.HSBtoRGB(Botania.proxy.getWorldElapsedTicks() * 2 % 360 / 360F, 1F, 1F); + + float[] color = EntitySheep.fleeceColorTable[storedColor]; + return new Color(color[0], color[1], color[2]).getRGB(); + } + + public static int getStoredColor(ItemStack stack) { + return ItemNBTHelper.getInt(stack, TAG_COLOR, -1); + } + + public static ItemStack setLensColor(ItemStack stack, int color) { + ItemNBTHelper.setInt(stack, TAG_COLOR, color); + return stack; + } + + @Override + public boolean doParticles(IManaBurst burst, ItemStack stack) { + return true; + } + + public static void setProps(int lens, int props_) { + props[lens] = props_; + } + + public static void setLens(int index, Lens lens) { + lenses[index] = lens; + } + + public static boolean isBlacklisted(int lens1, int lens2) { + return (props[lens1] & props[lens2]) != 0; + } + + public static Lens getLens(int index) { + Lens lens = lenses[index]; + return lens == null ? fallbackLens : lens; + } + + @Override + public boolean canCombineLenses(ItemStack sourceLens, ItemStack compositeLens) { + if(sourceLens.getItemDamage() == compositeLens.getItemDamage()) + return false; + + if(sourceLens.getItemDamage() == NORMAL || compositeLens.getItemDamage() == NORMAL) + return false; + + if(isBlacklisted(sourceLens.getItemDamage(), compositeLens.getItemDamage())) + return false; + + return true; + } + + @Override + public ItemStack getCompositeLens(ItemStack stack) { + NBTTagCompound cmp = ItemNBTHelper.getCompound(stack, TAG_COMPOSITE_LENS, false); + ItemStack lens = ItemStack.loadItemStackFromNBT(cmp); + return lens; + } + + @Override + public ItemStack setCompositeLens(ItemStack sourceLens, ItemStack compositeLens) { + NBTTagCompound cmp = new NBTTagCompound(); + compositeLens.writeToNBT(cmp); + ItemNBTHelper.setCompound(sourceLens, TAG_COMPOSITE_LENS, cmp); + + return sourceLens; + } +} diff --git a/src/main/java/vazkii/botania/common/item/lens/Lens.java b/src/main/java/vazkii/botania/common/item/lens/Lens.java new file mode 100644 index 000000000..f2b34fdf2 --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/Lens.java @@ -0,0 +1,34 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:31:16 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import vazkii.botania.api.internal.IManaBurst; +import vazkii.botania.api.mana.BurstProperties; + +public class Lens { + + public void apply(ItemStack stack, BurstProperties props) { + // NO-OP + } + + public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { + return dead; + } + + public void updateBurst(IManaBurst burst, EntityThrowable entity, ItemStack stack) { + // NO-OP + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensBounce.java b/src/main/java/vazkii/botania/common/item/lens/LensBounce.java new file mode 100644 index 000000000..dc525b17c --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensBounce.java @@ -0,0 +1,42 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:34:29 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.MovingObjectPosition; +import net.minecraftforge.common.util.ForgeDirection; +import vazkii.botania.api.internal.IManaBurst; +import vazkii.botania.common.core.helper.Vector3; + +public class LensBounce extends Lens { + + @Override + public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { + if(!isManaBlock && pos.entityHit == null) { + ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates(); + if(coords.posX != pos.blockX || coords.posY != pos.blockY || coords.posZ != pos.blockZ) { + Vector3 currentMovementVec = new Vector3(entity.motionX, entity.motionY, entity.motionZ); + ForgeDirection dir = ForgeDirection.getOrientation(pos.sideHit); + Vector3 normalVector = new Vector3(dir.offsetX, dir.offsetY, dir.offsetZ).normalize(); + Vector3 movementVec = normalVector.multiply(-2 * currentMovementVec.dotProduct(normalVector)).add(currentMovementVec); + + burst.setMotion(movementVec.x, movementVec.y, movementVec.z); + dead = false; + } + } + + return dead; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensDamage.java b/src/main/java/vazkii/botania/common/item/lens/LensDamage.java new file mode 100644 index 000000000..1a5629954 --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensDamage.java @@ -0,0 +1,46 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:37:33 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import java.util.List; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; +import vazkii.botania.api.internal.IManaBurst; + +public class LensDamage extends Lens { + + @Override + public void updateBurst(IManaBurst burst, EntityThrowable entity, ItemStack stack) { + AxisAlignedBB axis = AxisAlignedBB.getBoundingBox(entity.posX, entity.posY, entity.posZ, entity.lastTickPosX, entity.lastTickPosY, entity.lastTickPosZ).expand(1, 1, 1); + List entities = entity.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axis); + for(EntityLivingBase living : entities) { + if(living instanceof EntityPlayer) + continue; + + if(living.hurtTime == 0) { + int mana = burst.getMana(); + if(mana >= 16) { + burst.setMana(mana - 16); + if(!burst.isFake() && !entity.worldObj.isRemote) + living.attackEntityFrom(DamageSource.magic, 4); + break; + } + } + } + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensEfficiency.java b/src/main/java/vazkii/botania/common/item/lens/LensEfficiency.java new file mode 100644 index 000000000..eb0da3f2b --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensEfficiency.java @@ -0,0 +1,25 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:34:06 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.item.ItemStack; +import vazkii.botania.api.mana.BurstProperties; + +public class LensEfficiency extends Lens { + + @Override + public void apply(ItemStack stack, BurstProperties props) { + props.manaLossPerTick /= 5F; + props.ticksBeforeManaLoss *= 1.1F; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensExplosive.java b/src/main/java/vazkii/botania/common/item/lens/LensExplosive.java new file mode 100644 index 000000000..38d1ef523 --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensExplosive.java @@ -0,0 +1,35 @@ +/** + * This class was created by + . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:41:44 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.MovingObjectPosition; +import vazkii.botania.api.internal.IManaBurst; +import vazkii.botania.api.mana.BurstProperties; + +public class LensExplosive extends Lens { + + @Override + public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { + if(!burst.isFake()) { + ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates(); + if(!entity.worldObj.isRemote && pos.entityHit == null && !isManaBlock && (pos.blockX != coords.posX || pos.blockY != coords.posY || pos.blockZ != coords.posZ)) + entity.worldObj.createExplosion(entity, entity.posX, entity.posY, entity.posZ, burst.getMana() / 50F, true); + } else dead = false; + + return dead; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensFire.java b/src/main/java/vazkii/botania/common/item/lens/LensFire.java new file mode 100644 index 000000000..c2248386f --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensFire.java @@ -0,0 +1,47 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:46:03 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.block.Block; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.MovingObjectPosition; +import net.minecraftforge.common.util.ForgeDirection; +import vazkii.botania.api.internal.IManaBurst; + +public class LensFire extends Lens { + + @Override + public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { + ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates(); + if((coords.posX != pos.blockX || coords.posY != pos.blockY || coords.posZ != pos.blockZ) && !burst.isFake() && !isManaBlock) { + ForgeDirection dir = ForgeDirection.getOrientation(pos.sideHit); + + int x = pos.blockX + dir.offsetX; + int y = pos.blockY + dir.offsetY; + int z = pos.blockZ + dir.offsetZ; + + Block blockAt = entity.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ); + Block blockAt_ = entity.worldObj.getBlock(x, y, z); + + if(blockAt == Blocks.portal) + entity.worldObj.setBlock(pos.blockX, pos.blockY, pos.blockZ, Blocks.air); + else if(blockAt_.isAir(entity.worldObj, x, y, z)) + entity.worldObj.setBlock(x, y, z, Blocks.fire); + } + + return dead; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensGravity.java b/src/main/java/vazkii/botania/common/item/lens/LensGravity.java new file mode 100644 index 000000000..b00863b7b --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensGravity.java @@ -0,0 +1,25 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:35:52 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.item.ItemStack; +import vazkii.botania.api.mana.BurstProperties; + +public class LensGravity extends Lens { + + @Override + public void apply(ItemStack stack, BurstProperties props) { + props.gravity = 0.0015F; + props.ticksBeforeManaLoss *= 1.2F; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensInfluence.java b/src/main/java/vazkii/botania/common/item/lens/LensInfluence.java new file mode 100644 index 000000000..ab5255763 --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensInfluence.java @@ -0,0 +1,45 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:42:33 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityFallingBlock; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.item.EntityXPOrb; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import vazkii.botania.api.internal.IManaBurst; + +public class LensInfluence extends Lens { + + @Override + public void updateBurst(IManaBurst burst, EntityThrowable entity, ItemStack stack) { + if(!burst.isFake()) { + double range = 3.5; + List movables = entity.worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range)); + movables.addAll(entity.worldObj.getEntitiesWithinAABB(EntityXPOrb.class, AxisAlignedBB.getBoundingBox(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); + movables.addAll(entity.worldObj.getEntitiesWithinAABB(EntityArrow.class, AxisAlignedBB.getBoundingBox(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); + movables.addAll(entity.worldObj.getEntitiesWithinAABB(EntityFallingBlock.class, AxisAlignedBB.getBoundingBox(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); + + for(Entity movable : movables) { + movable.motionX = entity.motionX; + movable.motionY = entity.motionY; + movable.motionZ = entity.motionZ; + } + } + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensLight.java b/src/main/java/vazkii/botania/common/item/lens/LensLight.java new file mode 100644 index 000000000..7746d6a0c --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensLight.java @@ -0,0 +1,55 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:47:20 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.block.Block; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.MovingObjectPosition; +import net.minecraftforge.common.util.ForgeDirection; +import vazkii.botania.api.internal.IManaBurst; +import vazkii.botania.common.block.ModBlocks; +import vazkii.botania.common.block.tile.TileManaFlame; + +public class LensLight extends Lens { + + @Override + public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { + ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates(); + if((coords.posX != pos.blockX || coords.posY != pos.blockY || coords.posZ != pos.blockZ) && !burst.isFake() && !isManaBlock) { + ForgeDirection dir = ForgeDirection.getOrientation(pos.sideHit); + + int x = pos.blockX + dir.offsetX; + int y = pos.blockY + dir.offsetY; + int z = pos.blockZ + dir.offsetZ; + + Block blockAt = entity.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ); + Block blockAt_ = entity.worldObj.getBlock(x, y, z); + + if(blockAt == ModBlocks.manaFlame) + entity.worldObj.setBlock(pos.blockX, pos.blockY, pos.blockZ, Blocks.air); + else if(blockAt_.isAir(entity.worldObj, x, y, z)) { + entity.worldObj.setBlock(x, y, z, ModBlocks.manaFlame); + TileEntity tile = entity.worldObj.getTileEntity(x, y, z); + + if(tile instanceof TileManaFlame) + ((TileManaFlame) tile).setColor(burst.getColor()); + } + } + + return dead; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensMagnet.java b/src/main/java/vazkii/botania/common/item/lens/LensMagnet.java new file mode 100644 index 000000000..a894c0d9e --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensMagnet.java @@ -0,0 +1,82 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:39:58 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChunkCoordinates; +import vazkii.botania.api.internal.IManaBurst; +import vazkii.botania.api.mana.IManaReceiver; +import vazkii.botania.common.core.helper.MathHelper; +import vazkii.botania.common.core.helper.Vector3; + +public class LensMagnet extends Lens { + + private static final String TAG_MAGNETIZED = "Botania:Magnetized"; + private static final String TAG_MAGNETIZED_X = "Botania:MagnetizedX"; + private static final String TAG_MAGNETIZED_Y = "Botania:MagnetizedY"; + private static final String TAG_MAGNETIZED_Z = "Botania:MagnetizedZ"; + + @Override + public void updateBurst(IManaBurst burst, EntityThrowable entity, ItemStack stack) { + int x = (int) entity.posX; + int y = (int) entity.posY; + int z = (int) entity.posZ; + boolean magnetized = entity.getEntityData().hasKey(TAG_MAGNETIZED); + int range = 3; + + magnetize : { + for(int i = -range; i < range; i++) + for(int j = -range; j < range; j++) + for(int k = -range; k < range; k++) + if(entity.worldObj.getTileEntity(i + x, j + y, k + z) instanceof IManaReceiver) { + TileEntity tile = entity.worldObj.getTileEntity(i + x, j + y, k + z); + + if(magnetized) { + int magX = entity.getEntityData().getInteger(TAG_MAGNETIZED_X); + int magY = entity.getEntityData().getInteger(TAG_MAGNETIZED_Y); + int magZ = entity.getEntityData().getInteger(TAG_MAGNETIZED_Z); + if(tile.xCoord != magX || tile.yCoord != magY || tile.zCoord != magZ) + continue; + } + + IManaReceiver receiver = (IManaReceiver) tile; + + ChunkCoordinates srcCoords = burst.getBurstSourceChunkCoordinates(); + + if(MathHelper.pointDistanceSpace(tile.xCoord, tile.yCoord, tile.zCoord, srcCoords.posX, srcCoords.posY, srcCoords.posZ) > 3 && receiver.canRecieveManaFromBursts() && !receiver.isFull()) { + Vector3 burstVec = Vector3.fromEntity(entity); + Vector3 tileVec = Vector3.fromTileEntityCenter(tile).add(0, -0.1, 0); + Vector3 motionVec = new Vector3(entity.motionX, entity.motionY, entity.motionZ); + + Vector3 normalMotionVec = motionVec.copy().normalize(); + Vector3 magnetVec = tileVec.sub(burstVec).normalize(); + Vector3 differenceVec = normalMotionVec.sub(magnetVec).multiply(motionVec.mag() * 0.1); + + Vector3 finalMotionVec = motionVec.sub(differenceVec); + if(!magnetized) { + finalMotionVec.multiply(0.75); + entity.getEntityData().setBoolean(TAG_MAGNETIZED, true); + entity.getEntityData().setInteger(TAG_MAGNETIZED_X, tile.xCoord); + entity.getEntityData().setInteger(TAG_MAGNETIZED_Y, tile.yCoord); + entity.getEntityData().setInteger(TAG_MAGNETIZED_Z, tile.zCoord); + } + + burst.setMotion(finalMotionVec.x, finalMotionVec.y, finalMotionVec.z); + break magnetize; + } + } + } + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensMine.java b/src/main/java/vazkii/botania/common/item/lens/LensMine.java new file mode 100644 index 000000000..70dd6cbc7 --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensMine.java @@ -0,0 +1,69 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:36:20 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import vazkii.botania.api.internal.IManaBurst; +import vazkii.botania.api.mana.BurstProperties; +import vazkii.botania.api.mana.IManaBlock; +import vazkii.botania.common.core.handler.ConfigHandler; + +public class LensMine extends Lens { + + @Override + public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { + World world = entity.worldObj; + int x = pos.blockX; + int y = pos.blockY; + int z = pos.blockZ; + Block block = world.getBlock(x, y, z); + TileEntity tile = world.getTileEntity(x, y, z); + + int meta = world.getBlockMetadata(x, y, z); + float hardness = block.getBlockHardness(world, x, y, z); + int mana = burst.getMana(); + + ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates(); + if((coords.posX != x || coords.posY != y || coords.posZ != z) && !(tile instanceof IManaBlock) && block != null && hardness != -1 && hardness < 50F && (burst.isFake() || mana >= 24)) { + List items = new ArrayList(); + + items.addAll(block.getDrops(world, x, y, z, meta, 0)); + + if(!burst.hasAlreadyCollidedAt(x, y, z)) { + if(!burst.isFake() && !entity.worldObj.isRemote) { + world.setBlockToAir(x, y, z); + if(ConfigHandler.blockBreakParticles) + entity.worldObj.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12)); + + for(ItemStack stack_ : items) + world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, stack_)); + burst.setMana(mana - 24); + } + } + + dead = false; + } + + return dead; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensPaint.java b/src/main/java/vazkii/botania/common/item/lens/LensPaint.java new file mode 100644 index 000000000..1a7958ce9 --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensPaint.java @@ -0,0 +1,105 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:44:01 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.passive.EntitySheep; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.MovingObjectPosition; +import net.minecraftforge.common.util.ForgeDirection; +import vazkii.botania.api.internal.IManaBurst; +import vazkii.botania.common.Botania; +import vazkii.botania.common.block.ModBlocks; + +public class LensPaint extends Lens { + + static final List paintableBlocks = new ArrayList() {{ + add(Blocks.stained_glass); + add(Blocks.stained_glass_pane); + add(Blocks.stained_hardened_clay); + add(Blocks.wool); + add(Blocks.carpet); + add(ModBlocks.unstableBlock); + add(ModBlocks.manaBeacon); + } + }; + + @Override + public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { + int storedColor = ItemLens.getStoredColor(stack); + if(!burst.isFake() && storedColor > -1 && storedColor < 17) { + if(pos.entityHit != null && pos.entityHit instanceof EntitySheep) { + int r = 20; + int sheepColor = ((EntitySheep) pos.entityHit).getFleeceColor(); + List sheepList = entity.worldObj.getEntitiesWithinAABB(EntitySheep.class, AxisAlignedBB.getBoundingBox(pos.entityHit.posX - r, pos.entityHit.posY - r, pos.entityHit.posZ - r, pos.entityHit.posX + r, pos.entityHit.posY + r, pos.entityHit.posZ + r)); + for(EntitySheep sheep : sheepList) { + if(sheep.getFleeceColor() == sheepColor) + sheep.setFleeceColor(storedColor == 16 ? sheep.worldObj.rand.nextInt(16) : storedColor); + } + dead = true; + } else { + Block block = entity.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ); + if(paintableBlocks.contains(block)) { + int meta = entity.worldObj.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ); + List coordsToPaint = new ArrayList(); + List coordsFound = new ArrayList(); + + ChunkCoordinates theseCoords = new ChunkCoordinates(pos.blockX, pos.blockY, pos.blockZ); + coordsFound.add(theseCoords); + + do { + List iterCoords = new ArrayList(coordsFound); + for(ChunkCoordinates coords : iterCoords) { + coordsFound.remove(coords); + coordsToPaint.add(coords); + + for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { + Block block_ = entity.worldObj.getBlock(coords.posX + dir.offsetX, coords.posY + dir.offsetY, coords.posZ + dir.offsetZ); + int meta_ = entity.worldObj.getBlockMetadata(coords.posX + dir.offsetX, coords.posY + dir.offsetY, coords.posZ + dir.offsetZ); + ChunkCoordinates coords_ = new ChunkCoordinates(coords.posX + dir.offsetX, coords.posY + dir.offsetY, coords.posZ + dir.offsetZ); + if(block_ == block && meta_ == meta && !coordsFound.contains(coords_) && !coordsToPaint.contains(coords_)) + coordsFound.add(coords_); + } + } + } while(!coordsFound.isEmpty() && coordsToPaint.size() < 1000); + + for(ChunkCoordinates coords : coordsToPaint) { + int placeColor = storedColor == 16 ? entity.worldObj.rand.nextInt(16) : storedColor; + int metaThere = entity.worldObj.getBlockMetadata(coords.posX, coords.posY, coords.posZ); + + if(metaThere != placeColor) { + if(!entity.worldObj.isRemote) + entity.worldObj.setBlockMetadataWithNotify(coords.posX, coords.posY, coords.posZ, placeColor, 2); + float[] color = EntitySheep.fleeceColorTable[placeColor]; + float r = color[0]; + float g = color[1]; + float b = color[2]; + for(int i = 0; i < 4; i++) + Botania.proxy.sparkleFX(entity.worldObj, coords.posX + (float) Math.random(), coords.posY + (float) Math.random(), coords.posZ + (float) Math.random(), r, g, b, 0.6F + (float) Math.random() * 0.3F, 5); + + } + } + } + } + } + + return dead; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensPhantom.java b/src/main/java/vazkii/botania/common/item/lens/LensPhantom.java new file mode 100644 index 000000000..eba830e96 --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensPhantom.java @@ -0,0 +1,31 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:39:24 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import vazkii.botania.api.internal.IManaBurst; + +public class LensPhantom extends Lens { + + @Override + public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { + if(!isManaBlock) { + dead = false; + burst.setMinManaLoss(Math.max(0, burst.getMinManaLoss() - 4)); + } + + return dead; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensPiston.java b/src/main/java/vazkii/botania/common/item/lens/LensPiston.java new file mode 100644 index 000000000..ae8c6635a --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensPiston.java @@ -0,0 +1,52 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:46:39 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.block.Block; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.MovingObjectPosition; +import net.minecraftforge.common.util.ForgeDirection; +import vazkii.botania.api.internal.IManaBurst; +import vazkii.botania.api.mana.BurstProperties; + +public class LensPiston extends Lens { + + @Override + public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { + ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates(); + if((coords.posX != pos.blockX || coords.posY != pos.blockY || coords.posZ != pos.blockZ) && !burst.isFake() && !isManaBlock && !entity.worldObj.isRemote) { + ForgeDirection dir = ForgeDirection.getOrientation(pos.sideHit).getOpposite(); + int x = pos.blockX + dir.offsetX; + int y = pos.blockY + dir.offsetY; + int z = pos.blockZ + dir.offsetZ; + + if(entity.worldObj.isAirBlock(x, y, z) || entity.worldObj.getBlock(x, y, z).isReplaceable(entity.worldObj, x, y, z)) { + Block block = entity.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ); + int meta = entity.worldObj.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ); + TileEntity tile = entity.worldObj.getTileEntity(pos.blockX, pos.blockY, pos.blockZ); + + if(block.getMobilityFlag() == 0 && block != Blocks.obsidian && tile == null) { + entity.worldObj.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ); + entity.worldObj.setBlock(x, y, z, block, meta, 1 | 2); + entity.worldObj.playAuxSFX(2001, pos.blockX, pos.blockY, pos.blockZ, Block.getIdFromBlock(block) + (meta << 12)); + } + } + } + + return dead; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensPower.java b/src/main/java/vazkii/botania/common/item/lens/LensPower.java new file mode 100644 index 000000000..a4cec94ae --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensPower.java @@ -0,0 +1,26 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:33:14 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.item.ItemStack; +import vazkii.botania.api.mana.BurstProperties; + +public class LensPower extends Lens { + + @Override + public void apply(ItemStack stack, BurstProperties props) { + props.maxMana *= 2; + props.motionModifier *= 0.85F; + props.manaLossPerTick *= 2F; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensSpeed.java b/src/main/java/vazkii/botania/common/item/lens/LensSpeed.java new file mode 100644 index 000000000..235c9b2cc --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensSpeed.java @@ -0,0 +1,27 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:32:47 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.item.ItemStack; +import vazkii.botania.api.mana.BurstProperties; + +public class LensSpeed extends Lens { + + @Override + public void apply(ItemStack stack, BurstProperties props) { + props.motionModifier *= 2F; + props.maxMana *= 0.75F; + props.ticksBeforeManaLoss /= 3F; + props.manaLossPerTick *= 2F; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensTime.java b/src/main/java/vazkii/botania/common/item/lens/LensTime.java new file mode 100644 index 000000000..13fad9dd9 --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensTime.java @@ -0,0 +1,25 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:33:41 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.item.ItemStack; +import vazkii.botania.api.mana.BurstProperties; + +public class LensTime extends Lens { + + @Override + public void apply(ItemStack stack, BurstProperties props) { + props.ticksBeforeManaLoss *= 2.25F; + props.motionModifier *= 0.8F; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/lens/LensWeight.java b/src/main/java/vazkii/botania/common/item/lens/LensWeight.java new file mode 100644 index 000000000..d4edfd10a --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensWeight.java @@ -0,0 +1,41 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 24, 2015, 4:43:16 PM (GMT)] + */ +package vazkii.botania.common.item.lens; + +import net.minecraft.block.Block; +import net.minecraft.entity.item.EntityFallingBlock; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import vazkii.botania.api.internal.IManaBurst; + +public class LensWeight extends Lens { + + @Override + public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) { + if(!burst.isFake()) { + int x = pos.blockX; + int y = pos.blockY; + int z = pos.blockZ; + Block block = entity.worldObj.getBlock(x, y, z); + Block blockBelow = entity.worldObj.getBlock(x, y - 1, z); + if(blockBelow.isAir(entity.worldObj, x, y - 1, z) && block.getBlockHardness(entity.worldObj, x, y, z) != -1 && entity.worldObj.getTileEntity(x, y, z) == null) { + EntityFallingBlock falling = new EntityFallingBlock(entity.worldObj, x + 0.5, y + 0.5, z + 0.5, block, entity.worldObj.getBlockMetadata(x, y, z)); + if(!entity.worldObj.isRemote) + entity.worldObj.spawnEntityInWorld(falling); + } + } + + return dead; + } + +}