diff options
| author | Draknyte1 <Draknyte1@hotmail.com> | 2016-06-16 03:59:47 +1000 |
|---|---|---|
| committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-06-16 03:59:47 +1000 |
| commit | 51d5db94cfafac652a05f6f121ec2521d62aaf5c (patch) | |
| tree | 8e622e427fa6416b5ca508ed4deb8e10e783f9d1 /src/Java/miscutil/core/item/general | |
| parent | d3f4786befad33f4ec77723bf4470d05f9f862ec (diff) | |
| download | GT5-Unofficial-51d5db94cfafac652a05f6f121ec2521d62aaf5c.tar.gz GT5-Unofficial-51d5db94cfafac652a05f6f121ec2521d62aaf5c.tar.bz2 GT5-Unofficial-51d5db94cfafac652a05f6f121ec2521d62aaf5c.zip | |
Done a lot of work on the NFHG.
Also did some more refactoring beforehand.
Diffstat (limited to 'src/Java/miscutil/core/item/general')
3 files changed, 373 insertions, 0 deletions
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; + } + +} |
