From 272bdd53a74b5b24c893e3065759e4d574ec2c27 Mon Sep 17 00:00:00 2001 From: HbmMods Date: Wed, 16 Jan 2019 19:59:33 +0100 Subject: [PATCH] bulletbase framework finished, added syncing util for new bullets --- assets/hbm/textures/gui/potions.png | Bin 2767 -> 2807 bytes .../entity/projectile/EntityBulletBase.java | 58 +++++++++++------- com/hbm/handler/BulletConfigFactory.java | 7 ++- com/hbm/handler/BulletConfigSyncingUtil.java | 45 ++++++++++++++ com/hbm/handler/BulletConfiguration.java | 2 + com/hbm/items/weapon/GunFolly.java | 3 +- com/hbm/items/weapon/GunSMG.java | 7 ++- com/hbm/main/MainRegistry.java | 4 +- 8 files changed, 98 insertions(+), 28 deletions(-) create mode 100644 com/hbm/handler/BulletConfigSyncingUtil.java diff --git a/assets/hbm/textures/gui/potions.png b/assets/hbm/textures/gui/potions.png index 48b24b81a5991b4f96a3e72a15ca0542aee6fd7e..bde3d40aac917e6679ca967edf8ec547093255ef 100644 GIT binary patch delta 2495 zcmV;w2|)JG755d8G=Hv1L_t(|obBCDXdLGq#_?xTL&zaQK6OnmsYO<%fv~Ox*+U)OOq);$l!kD{PU5RBl67hd9O#(c+V=kk}AH zButPI2xLrnd)R%)GrKdpv%9nM+WY;0@XpM;zny)v@1J?!nF2QwvB4JskpeiZ@{74H&bi*gt#xVV&O0dnZh|@JrIa{&u44=VLt2NR@)`DL!w^ zV&zy|Ee!;$kI# zJjo>W27pcl6~L6vngcqlY5Bo+ZQ@leYg$D|k`CywR<&&GcA#4L^ZC4gh7U?N=i)zj z_+Vc7ytL#mHLL{ed4xYZd~8+Al2muB6@@~9N%YbC2;1?`^^8YuGSTPsnVJ|_5^%iH$6{MsbTzlK3`V}09kp$zL=J;4Xx{{ zF3J|H|LENyp?&S@)ks>~0w)>X|9z@`wQ39h4*g0KI;tt1HIpiTngcp)D+Mj;b4}=| zCRJ>7EooGLO>N5MaHE_AZvF8T`2%DjvBk9oKD@oEWliX)B&nne(J_Dqt^durZISJ`ANbPJlH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E0RR9100000 z0000000000004kzMW?L{Lpt4=PP1vCF+2?jbg_+E5r}k1r)oL?000000BDc@1NL`p V7!X435dZ)H2>?k&PDHLkV1gFM;XD8U 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");