From 51d5db94cfafac652a05f6f121ec2521d62aaf5c Mon Sep 17 00:00:00 2001 From: Draknyte1 Date: Thu, 16 Jun 2016 03:59:47 +1000 Subject: Done a lot of work on the NFHG. Also did some more refactoring beforehand. --- src/Java/miscutil/core/item/EntityTeleportFX.java | 236 --------------------- src/Java/miscutil/core/item/ModItems.java | 24 +++ .../core/item/general/NuclearFuelRodBase.java | 210 ++++++++++++++++++ .../core/item/general/fuelrods/FuelRod_Base.java | 150 +++++++++++++ .../item/general/fuelrods/FuelRod_Thorium.java | 13 ++ 5 files changed, 397 insertions(+), 236 deletions(-) delete mode 100644 src/Java/miscutil/core/item/EntityTeleportFX.java create mode 100644 src/Java/miscutil/core/item/general/NuclearFuelRodBase.java create mode 100644 src/Java/miscutil/core/item/general/fuelrods/FuelRod_Base.java create mode 100644 src/Java/miscutil/core/item/general/fuelrods/FuelRod_Thorium.java (limited to 'src/Java/miscutil/core/item') diff --git a/src/Java/miscutil/core/item/EntityTeleportFX.java b/src/Java/miscutil/core/item/EntityTeleportFX.java deleted file mode 100644 index d67ee77968..0000000000 --- a/src/Java/miscutil/core/item/EntityTeleportFX.java +++ /dev/null @@ -1,236 +0,0 @@ -package miscutil.core.item; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class EntityTeleportFX extends Entity -{ - /** 'x' location the eye should float towards. */ - private double targetX; - /** 'y' location the eye should float towards. */ - private double targetY; - /** 'z' location the eye should float towards. */ - private double targetZ; - private int despawnTimer; - private boolean shatterOrDrop; - private static final String __OBFID = "CL_00001716"; - - public EntityTeleportFX(World p_i1757_1_) - { - super(p_i1757_1_); - this.setSize(0.25F, 0.25F); - } - - protected void entityInit() {} - - /** - * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge - * length * 64 * renderDistanceWeight Args: distance - */ - @SideOnly(Side.CLIENT) - public boolean isInRangeToRenderDist(double p_70112_1_) - { - double d1 = this.boundingBox.getAverageEdgeLength() * 4.0D; - d1 *= 64.0D; - return p_70112_1_ < d1 * d1; - } - - public EntityTeleportFX(World p_i1758_1_, double p_i1758_2_, double p_i1758_4_, double p_i1758_6_) - { - super(p_i1758_1_); - this.despawnTimer = 0; - this.setSize(0.25F, 0.25F); - this.setPosition(p_i1758_2_, p_i1758_4_, p_i1758_6_); - this.yOffset = 0.0F; - } - - /** - * The location the eye should float/move towards. Currently used for moving towards the nearest stronghold. Args: - * strongholdX, strongholdY, strongholdZ - */ - public void moveTowards(double p_70220_1_, int p_70220_3_, double p_70220_4_) - { - double d2 = p_70220_1_ - this.posX; - double d3 = p_70220_4_ - this.posZ; - float f = MathHelper.sqrt_double(d2 * d2 + d3 * d3); - - if (f > 12.0F) - { - this.targetX = this.posX + d2 / (double)f * 12.0D; - this.targetZ = this.posZ + d3 / (double)f * 12.0D; - this.targetY = this.posY + 8.0D; - } - else - { - this.targetX = p_70220_1_; - this.targetY = (double)p_70220_3_; - this.targetZ = p_70220_4_; - } - - this.despawnTimer = 0; - this.shatterOrDrop = this.rand.nextInt(5) > 0; - } - - /** - * Sets the velocity to the args. Args: x, y, z - */ - @SideOnly(Side.CLIENT) - public void setVelocity(double p_70016_1_, double p_70016_3_, double p_70016_5_) - { - this.motionX = p_70016_1_; - this.motionY = p_70016_3_; - this.motionZ = p_70016_5_; - - if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) - { - float f = MathHelper.sqrt_double(p_70016_1_ * p_70016_1_ + p_70016_5_ * p_70016_5_); - this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(p_70016_1_, p_70016_5_) * 180.0D / Math.PI); - this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(p_70016_3_, (double)f) * 180.0D / Math.PI); - } - } - - /** - * Called to update the entity's position/logic. - */ - public void onUpdate() - { - this.lastTickPosX = this.posX; - this.lastTickPosY = this.posY; - this.lastTickPosZ = this.posZ; - super.onUpdate(); - this.posX += this.motionX; - this.posY += this.motionY; - this.posZ += this.motionZ; - float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); - this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI); - - for (this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) - { - ; - } - - while (this.rotationPitch - this.prevRotationPitch >= 180.0F) - { - this.prevRotationPitch += 360.0F; - } - - while (this.rotationYaw - this.prevRotationYaw < -180.0F) - { - this.prevRotationYaw -= 360.0F; - } - - while (this.rotationYaw - this.prevRotationYaw >= 180.0F) - { - this.prevRotationYaw += 360.0F; - } - - this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; - this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; - - if (!this.worldObj.isRemote) - { - double d0 = this.targetX - this.posX; - double d1 = this.targetZ - this.posZ; - float f1 = (float)Math.sqrt(d0 * d0 + d1 * d1); - float f2 = (float)Math.atan2(d1, d0); - double d2 = (double)f + (double)(f1 - f) * 0.0025D; - - if (f1 < 1.0F) - { - d2 *= 0.8D; - this.motionY *= 0.8D; - } - - this.motionX = Math.cos((double)f2) * d2; - this.motionZ = Math.sin((double)f2) * d2; - - if (this.posY < this.targetY) - { - this.motionY += (1.0D - this.motionY) * 0.014999999664723873D; - } - else - { - this.motionY += (-1.0D - this.motionY) * 0.014999999664723873D; - } - } - - float f3 = 0.25F; - - if (this.isInWater()) - { - for (int i = 0; i < 4; ++i) - { - this.worldObj.spawnParticle("bubble", this.posX - this.motionX * (double)f3, this.posY - this.motionY * (double)f3, this.posZ - this.motionZ * (double)f3, this.motionX, this.motionY, this.motionZ); - } - } - else - { - this.worldObj.spawnParticle("portal", this.posX - this.motionX * (double)f3 + this.rand.nextDouble() * 0.6D - 0.3D, this.posY - this.motionY * (double)f3 - 0.5D, this.posZ - this.motionZ * (double)f3 + this.rand.nextDouble() * 0.6D - 0.3D, this.motionX, this.motionY, this.motionZ); - } - - if (!this.worldObj.isRemote) - { - this.setPosition(this.posX, this.posY, this.posZ); - ++this.despawnTimer; - - if (this.despawnTimer > 80 && !this.worldObj.isRemote) - { - this.setDead(); - - if (this.shatterOrDrop) - { - this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, new ItemStack(Items.ender_eye))); - } - else - { - this.worldObj.playAuxSFX(2003, (int)Math.round(this.posX), (int)Math.round(this.posY), (int)Math.round(this.posZ), 0); - } - } - } - } - - /** - * (abstract) Protected helper method to write subclass entity data to NBT. - */ - public void writeEntityToNBT(NBTTagCompound p_70014_1_) {} - - /** - * (abstract) Protected helper method to read subclass entity data from NBT. - */ - public void readEntityFromNBT(NBTTagCompound p_70037_1_) {} - - @SideOnly(Side.CLIENT) - public float getShadowSize() - { - return 0.0F; - } - - /** - * Gets how bright this entity is. - */ - public float getBrightness(float p_70013_1_) - { - return 1.0F; - } - - @SideOnly(Side.CLIENT) - public int getBrightnessForRender(float p_70070_1_) - { - return 15728880; - } - - /** - * If returns false, the item will not inflict any damage against entities. - */ - public boolean canAttackWithItem() - { - return false; - } -} \ No newline at end of file diff --git a/src/Java/miscutil/core/item/ModItems.java b/src/Java/miscutil/core/item/ModItems.java index e704ac0365..fbec6a59a3 100644 --- a/src/Java/miscutil/core/item/ModItems.java +++ b/src/Java/miscutil/core/item/ModItems.java @@ -4,6 +4,7 @@ import static miscutil.core.lib.CORE.LOAD_ALL_CONTENT; import miscutil.core.creative.AddToCreativeTab; import miscutil.core.item.effects.RarityUncommon; import miscutil.core.item.general.BufferCore; +import miscutil.core.item.general.fuelrods.FuelRod_Base; import miscutil.core.item.tool.misc.SandstoneHammer; import miscutil.core.item.tool.staballoy.StaballoyAxe; import miscutil.core.item.tool.staballoy.StaballoyPickaxe; @@ -98,6 +99,12 @@ Gold Tool: 22*/ public static Item itemPlateBatteryAlloy; public static Item itemHeliumBlob; public static Item item_PLEASE_FACTOR_ME_4; + + public static Item FuelRod_Empty; + public static Item FuelRod_Thorium; + public static Item FuelRod_Uranium; + public static Item FuelRod_Plutonium; + //@SuppressWarnings("unused") public static final void init(){ @@ -209,6 +216,23 @@ Gold Tool: 22*/ else { Utils.LOG_WARNING("rfTools not Found - Skipping Resources."); } + //IC2 Exp + if (LoadedMods.IndustrialCraft2|| LOAD_ALL_CONTENT){ + Utils.LOG_INFO("IndustrialCraft2 Found - Loading Resources."); + //Item Init + FuelRod_Empty = new FuelRod_Base("itemFuelRod_Empty", "Empty", 0, 1000); + FuelRod_Thorium = new FuelRod_Base("itemFuelRod_Thorium", "Thorium", 1000, 1000); + FuelRod_Uranium = new FuelRod_Base("itemFuelRod_Uranium", "Uranium", 2500, 2500); + FuelRod_Plutonium = new FuelRod_Base("itemFuelRod_Plutonium", "Plutonium", 5000, 5000); + //Registry + GameRegistry.registerItem(FuelRod_Empty, "itemFuelRod_Empty"); + GameRegistry.registerItem(FuelRod_Thorium, "itemFuelRod_Thorium"); + GameRegistry.registerItem(FuelRod_Uranium, "itemFuelRod_Uranium"); + GameRegistry.registerItem(FuelRod_Plutonium, "itemFuelRod_Plutonium"); + } + else { + Utils.LOG_WARNING("IndustrialCraft2 not Found - Skipping Resources."); + } /* * Misc Items */ diff --git a/src/Java/miscutil/core/item/general/NuclearFuelRodBase.java b/src/Java/miscutil/core/item/general/NuclearFuelRodBase.java new file mode 100644 index 0000000000..7de0f93fab --- /dev/null +++ b/src/Java/miscutil/core/item/general/NuclearFuelRodBase.java @@ -0,0 +1,210 @@ +package miscutil.core.item.general; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.FillBucketEvent; +import cpw.mods.fml.common.eventhandler.Event; + +public class NuclearFuelRodBase extends Item +{ + /** field for checking if the bucket has been filled. */ + private Block isFull; + public NuclearFuelRodBase(Block p_i45331_1_) + { + this.maxStackSize = 1; + this.isFull = p_i45331_1_; + this.setCreativeTab(CreativeTabs.tabMisc); + } + + /** + * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer + */ + @Override + public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) + { + boolean flag = this.isFull == Blocks.air; + MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(p_77659_2_, p_77659_3_, flag); + + if (movingobjectposition == null) + { + return p_77659_1_; + } + FillBucketEvent event = new FillBucketEvent(p_77659_3_, p_77659_1_, p_77659_2_, movingobjectposition); + if (MinecraftForge.EVENT_BUS.post(event)) + { + return p_77659_1_; + } + + if (event.getResult() == Event.Result.ALLOW) + { + if (p_77659_3_.capabilities.isCreativeMode) + { + return p_77659_1_; + } + + if (--p_77659_1_.stackSize <= 0) + { + return event.result; + } + + if (!p_77659_3_.inventory.addItemStackToInventory(event.result)) + { + p_77659_3_.dropPlayerItemWithRandomChoice(event.result, false); + } + + return p_77659_1_; + } + if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) + { + int i = movingobjectposition.blockX; + int j = movingobjectposition.blockY; + int k = movingobjectposition.blockZ; + + if (!p_77659_2_.canMineBlock(p_77659_3_, i, j, k)) + { + return p_77659_1_; + } + + if (flag) + { + if (!p_77659_3_.canPlayerEdit(i, j, k, movingobjectposition.sideHit, p_77659_1_)) + { + return p_77659_1_; + } + + Material material = p_77659_2_.getBlock(i, j, k).getMaterial(); + int l = p_77659_2_.getBlockMetadata(i, j, k); + + if (material == Material.water && l == 0) + { + p_77659_2_.setBlockToAir(i, j, k); + return this.func_150910_a(p_77659_1_, p_77659_3_, Items.water_bucket); + } + + if (material == Material.lava && l == 0) + { + p_77659_2_.setBlockToAir(i, j, k); + return this.func_150910_a(p_77659_1_, p_77659_3_, Items.lava_bucket); + } + } + else + { + if (this.isFull == Blocks.air) + { + return new ItemStack(Items.bucket); + } + + if (movingobjectposition.sideHit == 0) + { + --j; + } + + if (movingobjectposition.sideHit == 1) + { + ++j; + } + + if (movingobjectposition.sideHit == 2) + { + --k; + } + + if (movingobjectposition.sideHit == 3) + { + ++k; + } + + if (movingobjectposition.sideHit == 4) + { + --i; + } + + if (movingobjectposition.sideHit == 5) + { + ++i; + } + + if (!p_77659_3_.canPlayerEdit(i, j, k, movingobjectposition.sideHit, p_77659_1_)) + { + return p_77659_1_; + } + + if (this.tryPlaceContainedLiquid(p_77659_2_, i, j, k) && !p_77659_3_.capabilities.isCreativeMode) + { + return new ItemStack(Items.bucket); + } + } + } + + return p_77659_1_; + } + + @SuppressWarnings("static-method") + private ItemStack func_150910_a(ItemStack p_150910_1_, EntityPlayer p_150910_2_, Item p_150910_3_) + { + if (p_150910_2_.capabilities.isCreativeMode) + { + return p_150910_1_; + } + else if (--p_150910_1_.stackSize <= 0) + { + return new ItemStack(p_150910_3_); + } + else + { + if (!p_150910_2_.inventory.addItemStackToInventory(new ItemStack(p_150910_3_))) + { + p_150910_2_.dropPlayerItemWithRandomChoice(new ItemStack(p_150910_3_, 1, 0), false); + } + + return p_150910_1_; + } + } + + /** + * Attempts to place the liquid contained inside the bucket. + */ + public boolean tryPlaceContainedLiquid(World p_77875_1_, int p_77875_2_, int p_77875_3_, int p_77875_4_) + { + if (this.isFull == Blocks.air) + { + return false; + } + Material material = p_77875_1_.getBlock(p_77875_2_, p_77875_3_, p_77875_4_).getMaterial(); + boolean flag = !material.isSolid(); + + if (!p_77875_1_.isAirBlock(p_77875_2_, p_77875_3_, p_77875_4_) && !flag) + { + return false; + } + if (p_77875_1_.provider.isHellWorld && this.isFull == Blocks.flowing_water) + { + p_77875_1_.playSoundEffect((double)((float)p_77875_2_ + 0.5F), (double)((float)p_77875_3_ + 0.5F), (double)((float)p_77875_4_ + 0.5F), "random.fizz", 0.5F, 2.6F + (p_77875_1_.rand.nextFloat() - p_77875_1_.rand.nextFloat()) * 0.8F); + + for (int l = 0; l < 8; ++l) + { + p_77875_1_.spawnParticle("largesmoke", (double)p_77875_2_ + Math.random(), (double)p_77875_3_ + Math.random(), (double)p_77875_4_ + Math.random(), 0.0D, 0.0D, 0.0D); + } + } + else + { + if (!p_77875_1_.isRemote && flag && !material.isLiquid()) + { + p_77875_1_.func_147480_a(p_77875_2_, p_77875_3_, p_77875_4_, true); + } + + p_77875_1_.setBlock(p_77875_2_, p_77875_3_, p_77875_4_, this.isFull, 0, 3); + } + + return true; + } +} \ No newline at end of file diff --git a/src/Java/miscutil/core/item/general/fuelrods/FuelRod_Base.java b/src/Java/miscutil/core/item/general/fuelrods/FuelRod_Base.java new file mode 100644 index 0000000000..aedf91f66a --- /dev/null +++ b/src/Java/miscutil/core/item/general/fuelrods/FuelRod_Base.java @@ -0,0 +1,150 @@ +package miscutil.core.item.general.fuelrods; + +import java.util.List; + +import miscutil.core.creative.AddToCreativeTab; +import miscutil.core.lib.CORE; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +public class FuelRod_Base extends Item{ + + public int fuelRemaining = 0; + public int maximumFuel = 0; + public String fuelType = ""; + public float heat = 0; + public float maxHeat = 5000; + private ItemStack thisStack = null; + private int internalClock = 0; + + public FuelRod_Base(String unlocalizedName, String type, int fuelLeft, int maxFuel) { + this.setUnlocalizedName(unlocalizedName); + this.setTextureName(CORE.MODID + ":" + unlocalizedName); + this.setMaxStackSize(1); + this.setMaxDamage(maxFuel); + this.maximumFuel = maxFuel; + this.fuelRemaining = fuelLeft; + this.fuelType = type; + this.setCreativeTab(AddToCreativeTab.tabMachines); + } + @Override + public boolean onEntityItemUpdate(EntityItem entityItem) { + if (internalClock <= 200){ + internalClock++; + } + else { + if (heat < maxHeat){ + heat++; + } + if (fuelRemaining <= maximumFuel){ + fuelRemaining--; + } + internalClock = 0; + } + return super.onEntityItemUpdate(entityItem); + } + @Override + public void setDamage(ItemStack stack, int damage) { + this.heat=heat+5; + super.setDamage(stack, damage); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(ItemStack stack, EntityPlayer aPlayer, List list, boolean bool) { + thisStack = stack; + String tempHeat = String.valueOf(heat); + String tempFuel = String.valueOf(fuelRemaining); + String formattedType = EnumChatFormatting.DARK_RED+fuelType+EnumChatFormatting.GRAY; + String formattedHeat = EnumChatFormatting.RED+tempHeat+EnumChatFormatting.GRAY; + String formattedFuelLeft = tempFuel+EnumChatFormatting.GRAY; + + int tempMax = maximumFuel; + float tempCurrentHeat = heat; + int tempFuelLeft = fuelRemaining; + if (tempFuelLeft <= maximumFuel/3){ + formattedFuelLeft = EnumChatFormatting.RED+tempFuel+EnumChatFormatting.GRAY; + } + else if (tempFuelLeft >= maximumFuel/3 && tempFuelLeft <= (maximumFuel/3)*2){ + formattedFuelLeft = EnumChatFormatting.YELLOW+tempFuel+EnumChatFormatting.GRAY; + } + else if (tempFuelLeft >= (maximumFuel/3)*2 && tempFuelLeft <= maximumFuel){ + formattedFuelLeft = EnumChatFormatting.GREEN+tempFuel+EnumChatFormatting.GRAY; + } + else { + formattedFuelLeft = EnumChatFormatting.GRAY+tempFuel+EnumChatFormatting.GRAY; + } + if (tempCurrentHeat <= maxHeat/3 && tempCurrentHeat != 0){ + formattedHeat = EnumChatFormatting.GRAY+tempHeat+EnumChatFormatting.GRAY; + } + else if (tempCurrentHeat >= maxHeat/3 && tempMax <= (maxHeat/3)*2 && tempCurrentHeat != 0){ + formattedHeat = EnumChatFormatting.YELLOW+tempHeat+EnumChatFormatting.GRAY; + } + else if (tempCurrentHeat <= (maxHeat/3)*2 && tempMax <= maxHeat && tempCurrentHeat != 0){ + formattedHeat = EnumChatFormatting.RED+tempHeat+EnumChatFormatting.GRAY; + } + else { + formattedHeat = EnumChatFormatting.BLUE+tempHeat+EnumChatFormatting.GRAY; + } + + list.add(EnumChatFormatting.GRAY+"A "+formattedType+" fuel rod."); + list.add(EnumChatFormatting.GRAY+"Running at "+formattedHeat+"K."); + list.add(EnumChatFormatting.GRAY+"Currently there is: "+formattedFuelLeft+"L of fuel left."); + super.addInformation(stack, aPlayer, list, bool); + } + + public String getType(){ + return fuelType; + } + + public int getFuelRemaining(){ + return fuelRemaining; + } + + public int getMaxFuel(){ + return maximumFuel; + } + + public int getFuel(){ + if (thisStack != null){ + int i = thisStack.getItemDamage(); + int r = maximumFuel - i; + return r; + } + return fuelRemaining; + } + + public boolean setFuelRemainingExplicitly(int i){ + int tempFuel = fuelRemaining; + fuelRemaining = i; + if (i != tempFuel){ + return true; + } + return false; + } + + public boolean addFuel(int i){ + int tempFuel = fuelRemaining; + fuelRemaining = tempFuel+i; + if (fuelRemaining != tempFuel){ + return true; + } + return false; + } + + public float getHeat(){ + return heat; + } + + public boolean addHeat(float i){ + float tempFuel = heat; + heat = tempFuel+i; + if (heat != tempFuel){ + return true; + } + return false; + } + +} diff --git a/src/Java/miscutil/core/item/general/fuelrods/FuelRod_Thorium.java b/src/Java/miscutil/core/item/general/fuelrods/FuelRod_Thorium.java new file mode 100644 index 0000000000..0e8230645b --- /dev/null +++ b/src/Java/miscutil/core/item/general/fuelrods/FuelRod_Thorium.java @@ -0,0 +1,13 @@ +package miscutil.core.item.general.fuelrods; + +public class FuelRod_Thorium extends FuelRod_Base{ + + public FuelRod_Thorium(String unlocalizedName, String type, int fuelLeft, int maxFuel) { + super(unlocalizedName, type, fuelLeft, maxFuel); + this.setMaxDamage(maxFuel); + this.maximumFuel = maxFuel; + this.fuelRemaining = fuelLeft; + this.fuelType = type; + } + +} -- cgit