From 3eb8c7a8fca3f22475d53e30f0b90a6737f313fa Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 24 May 2018 15:53:20 -0400 Subject: Initial commit --- .../fyresmodjam/entities/EntityMysteryPotion.java | 253 +++++++++++++++++++++ .../entities/renderers/RenderMysteryPotion.java | 100 ++++++++ 2 files changed, 353 insertions(+) create mode 100755 YWD/src/main/java/fyresmodjam/entities/EntityMysteryPotion.java create mode 100755 YWD/src/main/java/fyresmodjam/entities/renderers/RenderMysteryPotion.java (limited to 'YWD/src/main/java/fyresmodjam/entities') diff --git a/YWD/src/main/java/fyresmodjam/entities/EntityMysteryPotion.java b/YWD/src/main/java/fyresmodjam/entities/EntityMysteryPotion.java new file mode 100755 index 0000000..6c4eef5 --- /dev/null +++ b/YWD/src/main/java/fyresmodjam/entities/EntityMysteryPotion.java @@ -0,0 +1,253 @@ +package fyresmodjam.entities; + +import java.util.Iterator; +import java.util.List; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import fyresmodjam.ModjamMod; +import fyresmodjam.blessings.BlessingUtils; +import fyresmodjam.handlers.CommonTickHandler; +import fyresmodjam.handlers.NewPacketHandler; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; + +public class EntityMysteryPotion extends EntityThrowable { + + public EntityMysteryPotion(World par1World) { + super(par1World); + } + + public EntityMysteryPotion(World par1World, + EntityLivingBase par2EntityLivingBase, int par3) { + this(par1World, par2EntityLivingBase, null); + } + + public EntityMysteryPotion(World par1World, + EntityLivingBase par2EntityLivingBase, + ItemStack par4ItemStack) { + super(par1World, par2EntityLivingBase); + + if (par4ItemStack != null) { + int damage = par4ItemStack.getItemDamage(); + dataWatcher.updateObject(24, damage); + if (damage % 13 < 12) { + dataWatcher.updateObject(25, + CommonTickHandler.worldData.potionDurations[damage + % 13]); + } + } + } + + @Override + public void entityInit() { + super.entityInit(); + + dataWatcher.addObject(24, 0); + dataWatcher.addObject(25, 0); + } + + @SideOnly(Side.CLIENT) + public EntityMysteryPotion(World par1World, double par2, + double par4, double par6, int par8) { + this(par1World, par2, par4, par6, + new ItemStack(Items.potionitem, 1, par8)); + } + + public EntityMysteryPotion(World par1World, double par2, + double par4, double par6, + ItemStack par4ItemStack) { + super(par1World, par2, par4, par6); + + if (par4ItemStack != null) { + int damage = par4ItemStack.getItemDamage(); + dataWatcher.updateObject(24, damage); + dataWatcher.updateObject(25, + CommonTickHandler.worldData.potionDurations[damage + % 13]); + } + } + + @Override + protected float getGravityVelocity() { + return 0.05F; + } + + @Override + protected float func_70182_d() { + return 0.5F; + } + + @Override + protected float func_70183_g() { + return -20.0F; + } + + @Override + @SuppressWarnings("rawtypes") + protected void onImpact( + MovingObjectPosition par1MovingObjectPosition) { + if (!worldObj.isRemote) { + AxisAlignedBB axisalignedbb = boundingBox + .expand(4.0D, 2.0D, 4.0D); + List list1 = worldObj.getEntitiesWithinAABB( + EntityLivingBase.class, + axisalignedbb); + + if (list1 != null && !list1.isEmpty()) { + int type = getDataWatcher() + .getWatchableObjectInt(24) + % 13; + int j = type >= 12 + ? (5 + ModjamMod.r.nextInt( + 26)) + : getDataWatcher() + .getWatchableObjectInt( + 25); + + int damage = 0; + + if (type >= 12 || (BlessingUtils + .hasBlessing(getThrower(), + "BlessingAlchemist"))) { + damage = ModjamMod.r.nextInt( + Potion.potionTypes.length); + while (Potion.potionTypes[damage] == null) { + damage = ModjamMod.r + .nextInt(Potion.potionTypes.length); + } + } else { + damage = CommonTickHandler.worldData.potionValues[type]; + } + + Iterator iterator = list1.iterator(); + + while (iterator.hasNext()) { + EntityLivingBase entitylivingbase = (EntityLivingBase) iterator + .next(); + double d0 = getDistanceSqToEntity( + entitylivingbase); + + if (d0 < 16.0D) { + if (Potion.potionTypes[damage] + .isInstant()) { + Potion.potionTypes[damage] + .affectEntity(getThrower(), + entitylivingbase, + 1, + 1); + } else { + entitylivingbase.addPotionEffect( + new PotionEffect( + damage, + j * 20, + 1, + false)); + } + } + } + + if (getThrower() instanceof EntityPlayer) { + EntityPlayer par3EntityPlayer = (EntityPlayer) getThrower(); + + if (type < 12 && (!BlessingUtils + .hasBlessing(getThrower(), + "BlessingAlchemist"))) { + if (!par3EntityPlayer + .getEntityData() + .hasKey("PotionKnowledge")) { + par3EntityPlayer.getEntityData() + .setIntArray("PotionKnowledge", + new int[] { + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1 + }); + } + + if (par3EntityPlayer + .getEntityData() + .getIntArray("PotionKnowledge")[type] == -1) { + par3EntityPlayer.getEntityData() + .getIntArray("PotionKnowledge")[type] = 1; + + NewPacketHandler.UPDATE_POTION_KNOWLEDGE + .sendToPlayer(par3EntityPlayer, + par3EntityPlayer.getEntityData() + .getIntArray("PotionKnowledge")); + + Potion potion = Potion.potionTypes[CommonTickHandler.worldData.potionValues[type]]; + String name = StatCollector + .translateToLocal( + potion.getName()) + + " Potion"; + + if (!potion.isInstant()) { + int time = CommonTickHandler.worldData.potionDurations[type]; + name += " (" + time + + " seconds)"; + } + + NewPacketHandler.SEND_MESSAGE + .sendToPlayer(par3EntityPlayer, + "\u00A7oYou learnt Mystery Potion #" + + (type + 1) + + " was a " + + name + + "!"); + } + } else { + Potion potion = Potion.potionTypes[damage]; + String name = StatCollector + .translateToLocal( + potion.getName()) + + " Potion"; + if (!potion.isInstant()) { + name += " (" + j + " seconds)"; + } + + NewPacketHandler.SEND_MESSAGE + .sendToPlayer(par3EntityPlayer, + "\u00A7oYou threw a " + + name + + "."); + } + } + } + + worldObj.playAuxSFX(2002, (int) Math.round(posX), + (int) Math.round(posY), + (int) Math.round(posZ), 1); + setDead(); + } + } + + @Override + public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { + super.readEntityFromNBT(par1NBTTagCompound); + } + + @Override + public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) { + super.writeEntityToNBT(par1NBTTagCompound); + } +} diff --git a/YWD/src/main/java/fyresmodjam/entities/renderers/RenderMysteryPotion.java b/YWD/src/main/java/fyresmodjam/entities/renderers/RenderMysteryPotion.java new file mode 100755 index 0000000..ea79e25 --- /dev/null +++ b/YWD/src/main/java/fyresmodjam/entities/renderers/RenderMysteryPotion.java @@ -0,0 +1,100 @@ +package fyresmodjam.entities.renderers; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import fyresmodjam.entities.EntityMysteryPotion; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.Entity; +import net.minecraft.entity.projectile.EntityPotion; +import net.minecraft.item.Item; +import net.minecraft.item.ItemPotion; +import net.minecraft.potion.PotionHelper; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; + +@SideOnly(Side.CLIENT) +public class RenderMysteryPotion extends Render { + private Item field_94151_a; + + public RenderMysteryPotion(Item par1Item) { + field_94151_a = par1Item; + } + + @Override + public void doRender(Entity par1Entity, double par2, double par4, + double par6, float par8, float par9) { + IIcon icon = (par1Entity instanceof EntityMysteryPotion) + ? field_94151_a.getIconFromDamage( + par1Entity.getDataWatcher() + .getWatchableObjectInt( + 24)) + : field_94151_a.getIconFromDamage(0); + + if (icon != null) { + GL11.glPushMatrix(); + GL11.glTranslatef((float) par2, (float) par4, + (float) par6); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glScalef(0.5F, 0.5F, 0.5F); + bindEntityTexture(par1Entity); + Tessellator tessellator = Tessellator.instance; + + if (icon == ItemPotion + .func_94589_d("bottle_splash")) { + int i = PotionHelper.func_77915_a( + ((EntityPotion) par1Entity) + .getPotionDamage(), + false); + float f2 = (i >> 16 & 255) / 255.0F; + float f3 = (i >> 8 & 255) / 255.0F; + float f4 = (i & 255) / 255.0F; + GL11.glColor3f(f2, f3, f4); + GL11.glPushMatrix(); + func_77026_a(tessellator, ItemPotion + .func_94589_d("overlay")); + GL11.glPopMatrix(); + GL11.glColor3f(1.0F, 1.0F, 1.0F); + } + + func_77026_a(tessellator, icon); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + GL11.glPopMatrix(); + } + } + + @Override + protected ResourceLocation getEntityTexture(Entity par1Entity) { + return TextureMap.locationItemsTexture; + } + + private void func_77026_a(Tessellator par1Tessellator, + IIcon par2Icon) { + float f = par2Icon.getMinU(); + float f1 = par2Icon.getMaxU(); + float f2 = par2Icon.getMinV(); + float f3 = par2Icon.getMaxV(); + float f4 = 1.0F; + float f5 = 0.5F; + float f6 = 0.25F; + GL11.glRotatef(180.0F - renderManager.playerViewY, 0.0F, + 1.0F, 0.0F); + GL11.glRotatef(-renderManager.playerViewX, 1.0F, 0.0F, + 0.0F); + par1Tessellator.startDrawingQuads(); + par1Tessellator.setNormal(0.0F, 1.0F, 0.0F); + par1Tessellator.addVertexWithUV(0.0F - f5, 0.0F - f6, 0.0D, + f, f3); + par1Tessellator.addVertexWithUV(f4 - f5, 0.0F - f6, 0.0D, + f1, f3); + par1Tessellator.addVertexWithUV(f4 - f5, f4 - f6, 0.0D, f1, + f2); + par1Tessellator.addVertexWithUV(0.0F - f5, f4 - f6, 0.0D, + f, f2); + par1Tessellator.draw(); + } +} -- cgit v1.2.3