diff --git a/assets/hbm/textures/gui/potions.png b/assets/hbm/textures/gui/potions.png index 48b24b81a..bde3d40aa 100644 Binary files a/assets/hbm/textures/gui/potions.png and b/assets/hbm/textures/gui/potions.png differ diff --git a/com/hbm/entity/projectile/EntityBulletBase.java b/com/hbm/entity/projectile/EntityBulletBase.java index 69fa3342d..1ee3fd1ca 100644 --- a/com/hbm/entity/projectile/EntityBulletBase.java +++ b/com/hbm/entity/projectile/EntityBulletBase.java @@ -1,5 +1,6 @@ package com.hbm.entity.projectile; +import com.hbm.handler.BulletConfigSyncingUtil; import com.hbm.handler.BulletConfiguration; import cpw.mods.fml.relauncher.Side; @@ -22,16 +23,18 @@ public class EntityBulletBase extends Entity implements IProjectile { this.setSize(0.5F, 0.5F); } - public EntityBulletBase(World world, BulletConfiguration config) { + public EntityBulletBase(World world, int config) { super(world); - this.config = config; + this.config = BulletConfigSyncingUtil.pullConfig(config); + this.dataWatcher.updateObject(18, config); this.renderDistanceWeight = 10.0D; this.setSize(0.5F, 0.5F); } - public EntityBulletBase(World world, BulletConfiguration config, EntityLivingBase entity, float vel) { + public EntityBulletBase(World world, int config, EntityLivingBase entity) { super(world); - this.config = config; + this.config = BulletConfigSyncingUtil.pullConfig(config); + this.dataWatcher.updateObject(18, config); shooter = entity; this.setLocationAndAngles(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ, entity.rotationYaw, entity.rotationPitch); @@ -48,25 +51,22 @@ public class EntityBulletBase extends Entity implements IProjectile { this.renderDistanceWeight = 10.0D; this.setSize(0.5F, 0.5F); - this.dataWatcher.updateObject(16, (byte)config.style); - this.dataWatcher.updateObject(17, (byte)config.trail); + this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, 1.0F, this.config.spread); + + this.dataWatcher.updateObject(16, (byte)this.config.style); + this.dataWatcher.updateObject(17, (byte)this.config.trail); } @Override public void setThrowableHeading(double moX, double moY, double moZ, float mult1, float mult2) { - float deviation = 0; - - if(config != null) - deviation = config.spread; - float f2 = MathHelper.sqrt_double(moX * moX + moY * moY + moZ * moZ); moX /= f2; moY /= f2; moZ /= f2; - moX += this.rand.nextGaussian() * /*(this.rand.nextBoolean() ? -1 : 1) **/ deviation * mult2; - moY += this.rand.nextGaussian() * /*(this.rand.nextBoolean() ? -1 : 1) **/ deviation * mult2; - moZ += this.rand.nextGaussian() * /*(this.rand.nextBoolean() ? -1 : 1) **/ deviation * mult2; + moX += this.rand.nextGaussian() * /*(this.rand.nextBoolean() ? -1 : 1) **/ mult2; + moY += this.rand.nextGaussian() * /*(this.rand.nextBoolean() ? -1 : 1) **/ mult2; + moZ += this.rand.nextGaussian() * /*(this.rand.nextBoolean() ? -1 : 1) **/ mult2; moX *= mult1; moY *= mult1; moZ *= mult1; @@ -109,6 +109,8 @@ public class EntityBulletBase extends Entity implements IProjectile { this.dataWatcher.addObject(16, Byte.valueOf((byte) 0)); //trail this.dataWatcher.addObject(17, Byte.valueOf((byte) 0)); + //bullet config sync + this.dataWatcher.addObject(18, Integer.valueOf((int) 0)); } @Override @@ -117,18 +119,25 @@ public class EntityBulletBase extends Entity implements IProjectile { super.onUpdate(); if(config == null) - return; + config = BulletConfigSyncingUtil.pullConfig(dataWatcher.getWatchableObjectInt(18)); if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI); this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f) * 180.0D / Math.PI); } + + /// ZONE 1 START /// + //entity and block collision, plinking + + + + /// ZONE 1 END /// motionY -= config.gravity; - this.posX += this.motionX; - this.posY += this.motionY; - this.posZ += this.motionZ; + this.posX += this.motionX * this.config.velocity; + this.posY += this.motionY * this.config.velocity; + this.posZ += this.motionZ * this.config.velocity; this.setPosition(this.posX, this.posY, this.posZ); float f2; @@ -157,15 +166,20 @@ public class EntityBulletBase extends Entity implements IProjectile { } @Override - protected void readEntityFromNBT(NBTTagCompound p_70037_1_) { - // TODO Auto-generated method stub + protected void readEntityFromNBT(NBTTagCompound nbt) { + int cfg = nbt.getInteger("config"); + this.config = BulletConfigSyncingUtil.pullConfig(cfg); + this.dataWatcher.updateObject(18, cfg); + + this.dataWatcher.updateObject(16, (byte)this.config.style); + this.dataWatcher.updateObject(17, (byte)this.config.trail); } @Override - protected void writeEntityToNBT(NBTTagCompound p_70014_1_) { - // TODO Auto-generated method stub + protected void writeEntityToNBT(NBTTagCompound nbt) { + nbt.setInteger("config", dataWatcher.getWatchableObjectInt(18)); } } diff --git a/com/hbm/handler/BulletConfigFactory.java b/com/hbm/handler/BulletConfigFactory.java index 952435f2d..49cb2a866 100644 --- a/com/hbm/handler/BulletConfigFactory.java +++ b/com/hbm/handler/BulletConfigFactory.java @@ -4,12 +4,15 @@ import com.hbm.items.ModItems; public class BulletConfigFactory { - public static BulletConfiguration getTestConfig() { + /// configs should never be loaded manually due to syncing issues: use the syncing util and pass the UID in the DW of the bullet to make the client load the config correctly //// + + protected static BulletConfiguration getTestConfig() { BulletConfiguration bullet = new BulletConfiguration(); bullet.ammo = ModItems.gun_revolver_lead_ammo; - bullet.spread = 0F; + bullet.velocity = 5.0F; + bullet.spread = 0.05F; bullet.dmgMin = 15; bullet.dmgMax = 17; bullet.gravity = 0D; diff --git a/com/hbm/handler/BulletConfigSyncingUtil.java b/com/hbm/handler/BulletConfigSyncingUtil.java new file mode 100644 index 000000000..022a77000 --- /dev/null +++ b/com/hbm/handler/BulletConfigSyncingUtil.java @@ -0,0 +1,45 @@ +package com.hbm.handler; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class BulletConfigSyncingUtil { + + private static List configSet = new ArrayList(); + + /// it's like a hashmap, but easier /// + public static class ConfigKeyPair { + + BulletConfiguration config; + int key; + + public ConfigKeyPair() { } + + public ConfigKeyPair(BulletConfiguration c, int i) { + config = c; + key = i; + } + } + + /// dupicate ids will cause wrong configs to be loaded /// + public static final int TEST_CONFIG = 0x00; + + public static void loadConfigsForSync() { + + configSet.add(new ConfigKeyPair(BulletConfigFactory.getTestConfig(), TEST_CONFIG)); + } + + public static BulletConfiguration pullConfig(int key) { + + for(int i = 0; i < configSet.size(); i++) { + + if(configSet.get(i).key == key) + return configSet.get(i).config; + } + + return null;//configSet.get(TEST_CONFIG).config; + } + +} diff --git a/com/hbm/handler/BulletConfiguration.java b/com/hbm/handler/BulletConfiguration.java index 28aeb6394..2f98bb45a 100644 --- a/com/hbm/handler/BulletConfiguration.java +++ b/com/hbm/handler/BulletConfiguration.java @@ -9,6 +9,8 @@ public class BulletConfiguration { //what item this specific configuration consumes public Item ammo; + //how fast the bullet is (in sanics per second, or sps) + public float velocity; //spread of bullets in gaussian range public float spread; //weapon durability reduced (centered around 10) diff --git a/com/hbm/items/weapon/GunFolly.java b/com/hbm/items/weapon/GunFolly.java index 7f03be684..c6315cf4a 100644 --- a/com/hbm/items/weapon/GunFolly.java +++ b/com/hbm/items/weapon/GunFolly.java @@ -5,6 +5,7 @@ import com.hbm.entity.particle.EntitySSmokeFX; import com.hbm.entity.projectile.EntityBullet; import com.hbm.entity.projectile.EntityBulletBase; import com.hbm.handler.BulletConfigFactory; +import com.hbm.handler.BulletConfigSyncingUtil; import com.hbm.interfaces.IHoldableWeapon; import com.hbm.items.ModItems; import com.hbm.render.misc.RenderScreenOverlay.Crosshair; @@ -65,7 +66,7 @@ public class GunFolly extends Item implements IHoldableWeapon { player.motionZ -= player.getLookVec().zCoord * mult; if (!world.isRemote) { - EntityBulletBase bullet = new EntityBulletBase(world, BulletConfigFactory.getTestConfig(), player, 3.0F); + EntityBulletBase bullet = new EntityBulletBase(world, BulletConfigSyncingUtil.TEST_CONFIG, player); world.spawnEntityInWorld(bullet); for(int i = 0; i < 25; i++) { diff --git a/com/hbm/items/weapon/GunSMG.java b/com/hbm/items/weapon/GunSMG.java index 9e7e9c7a4..a61209495 100644 --- a/com/hbm/items/weapon/GunSMG.java +++ b/com/hbm/items/weapon/GunSMG.java @@ -7,6 +7,7 @@ import com.google.common.collect.Multimap; import com.hbm.entity.projectile.EntityBullet; import com.hbm.entity.projectile.EntityBulletBase; import com.hbm.handler.BulletConfigFactory; +import com.hbm.handler.BulletConfigSyncingUtil; import com.hbm.items.ModItems; import net.minecraft.enchantment.Enchantment; @@ -14,6 +15,7 @@ import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -58,8 +60,9 @@ public class GunSMG extends Item { || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0; if ((player.capabilities.isCreativeMode || player.inventory.hasItem(ModItems.gun_mp40_ammo)) && count % 2 == 0) { - - EntityBulletBase bullet = new EntityBulletBase(world, BulletConfigFactory.getTestConfig(), player, 3.0F); + + EntityBulletBase bullet = new EntityBulletBase(world, BulletConfigSyncingUtil.TEST_CONFIG, player); + //EntityArrow bullet = new EntityArrow(world, player, 3.0F); //world.playSoundAtEntity(player, "random.explode", 1.0F, 1.5F + (rand.nextFloat() / 4)); world.playSoundAtEntity(player, "hbm:weapon.rifleShoot", 1.0F, 0.8F + (rand.nextFloat() * 0.4F)); diff --git a/com/hbm/main/MainRegistry.java b/com/hbm/main/MainRegistry.java index d7e9031f0..a2fbb9646 100644 --- a/com/hbm/main/MainRegistry.java +++ b/com/hbm/main/MainRegistry.java @@ -192,6 +192,7 @@ import com.hbm.entity.projectile.EntityRubble; import com.hbm.entity.projectile.EntitySchrab; import com.hbm.entity.projectile.EntityShrapnel; import com.hbm.entity.projectile.EntitySparkBeam; +import com.hbm.handler.BulletConfigSyncingUtil; import com.hbm.handler.FluidTypeHandler.FluidType; import com.hbm.handler.FuelHandler; import com.hbm.handler.GUIHandler; @@ -590,7 +591,8 @@ public class MainRegistry HbmWorld.mainRegistry(); GameRegistry.registerFuelHandler(new FuelHandler()); HbmPotion.init(); - + BulletConfigSyncingUtil.loadConfigsForSync(); + Library.superuser.add("192af5d7-ed0f-48d8-bd89-9d41af8524f8"); Library.superuser.add("5aee1e3d-3767-4987-a222-e7ce1fbdf88e"); Library.superuser.add("937c9804-e11f-4ad2-a5b1-42e62ac73077");