From bf400c3525ba758f261649e28c5643dda6fddfc5 Mon Sep 17 00:00:00 2001 From: 70000hp <105080577+70000hp@users.noreply.github.com> Date: Mon, 4 Sep 2023 16:31:38 -0400 Subject: [PATCH] Bomber Fixes Added a new helper function to WorldUtil which chunkloads an entity whenever it spawns and uses that helper function in the Airstrike Designator code to help the bombers load properly. Also turned the rancid if chains into switches --- .../com/hbm/items/tool/ItemBombCaller.java | 110 ++++++++++-------- src/main/java/com/hbm/world/WorldUtil.java | 37 +++++- 2 files changed, 95 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/hbm/items/tool/ItemBombCaller.java b/src/main/java/com/hbm/items/tool/ItemBombCaller.java index 9d39a924d..29ec58ced 100644 --- a/src/main/java/com/hbm/items/tool/ItemBombCaller.java +++ b/src/main/java/com/hbm/items/tool/ItemBombCaller.java @@ -7,6 +7,7 @@ import com.hbm.lib.Library; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import com.hbm.world.WorldUtil; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; @@ -23,26 +24,38 @@ public class ItemBombCaller extends Item { } @Override - public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean bool) + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) { list.add("Aim & click to call an airstrike!"); - if(itemstack.getItemDamage() == 0) - list.add("Type: Carpet bombing"); - if(itemstack.getItemDamage() == 1) - list.add("Type: Napalm"); - if(itemstack.getItemDamage() == 2) - list.add("Type: Poison gas"); - if(itemstack.getItemDamage() == 3) - list.add("Type: Agent orange"); - if(itemstack.getItemDamage() == 4) - list.add("Type: Atomic bomb"); - if(itemstack.getItemDamage() == 5) - list.add("Type: VT stinger rockets"); - if(itemstack.getItemDamage() == 6) - list.add("Type: PIP OH GOD"); - if(itemstack.getItemDamage() == 7) - list.add("Type: Cloud the cloud oh god the cloud"); + switch (stack.getItemDamage()) { + + case 1: + list.add("Type: Napalm"); + break; + case 2: + list.add("Type: Poison gas"); + break; + case 3: + list.add("Type: Agent orange"); + break; + case 4: + list.add("Type: Atomic bomb"); + break; + case 5: + list.add("Type: VT stinger rockets"); + break; + case 6: + list.add("Type: PIP OH GOD"); + break; + case 7: + list.add("Type: Cloud the cloud oh god the cloud"); + break; + default: + list.add("Type: Carpet bombing"); + + } + } @Override @@ -53,45 +66,40 @@ public class ItemBombCaller extends Item { int y = pos.blockY; int z = pos.blockZ; - boolean b = false; - if(!world.isRemote) { + switch(stack.getItemDamage()) { + case 1: + WorldUtil.loadAndSpawnEntityInWorld(EntityBomber.statFacNapalm(world, x, y, z)); + break; + case 2: + WorldUtil.loadAndSpawnEntityInWorld(EntityBomber.statFacChlorine(world, x, y, z)); + break; + case 3: + WorldUtil.loadAndSpawnEntityInWorld(EntityBomber.statFacOrange(world, x, y, z)); + break; + case 4: + WorldUtil.loadAndSpawnEntityInWorld(EntityBomber.statFacABomb(world, x, y, z)); + break; + case 5: + WorldUtil.loadAndSpawnEntityInWorld(EntityBomber.statFacStinger(world, x, y, z)); + break; + case 6: + WorldUtil.loadAndSpawnEntityInWorld(EntityBomber.statFacBoxcar(world, x, y, z)); + break; + case 7: + WorldUtil.loadAndSpawnEntityInWorld(EntityBomber.statFacPC(world, x, y, z)); + + default: + WorldUtil.loadAndSpawnEntityInWorld(EntityBomber.statFacCarpet(world, x, y, z)); + } + + player.addChatMessage(new ChatComponentText("Called in airstrike!")); + world.playSoundAtEntity(player, "hbm:item.techBleep", 1.0F, 1.0F); - if(stack.getItemDamage() == 0) - if(world.spawnEntityInWorld(EntityBomber.statFacCarpet(world, x, y, z))) - b = true; - if(stack.getItemDamage() == 1) - if(world.spawnEntityInWorld(EntityBomber.statFacNapalm(world, x, y, z))) - b = true; - if(stack.getItemDamage() == 2) - if(world.spawnEntityInWorld(EntityBomber.statFacChlorine(world, x, y, z))) - b = true; - if(stack.getItemDamage() == 3) - if(world.spawnEntityInWorld(EntityBomber.statFacOrange(world, x, y, z))) - b = true; - if(stack.getItemDamage() == 4) - if(world.spawnEntityInWorld(EntityBomber.statFacABomb(world, x, y, z))) - b = true; - if(stack.getItemDamage() == 5) - if(world.spawnEntityInWorld(EntityBomber.statFacStinger(world, x, y, z))) - b = true; - if(stack.getItemDamage() == 6) - if(world.spawnEntityInWorld(EntityBomber.statFacBoxcar(world, x, y, z))) - b = true; - if(stack.getItemDamage() == 7) - if(world.spawnEntityInWorld(EntityBomber.statFacPC(world, x, y, z))) - b = true; - - if(b) { - player.addChatMessage(new ChatComponentText("Called in airstrike!")); - world.playSoundAtEntity(player, "hbm:item.techBleep", 1.0F, 1.0F); - } else { - world.playSoundAtEntity(player, "hbm:item.techBoop", 1.0F, 1.0F); - } } - stack.stackSize -= b ? 1 : 0; + stack.stackSize -= 1; return stack; } diff --git a/src/main/java/com/hbm/world/WorldUtil.java b/src/main/java/com/hbm/world/WorldUtil.java index 89f1db25e..ec75eee2e 100644 --- a/src/main/java/com/hbm/world/WorldUtil.java +++ b/src/main/java/com/hbm/world/WorldUtil.java @@ -2,12 +2,15 @@ package com.hbm.world; import com.hbm.packet.BiomeSyncPacket; import com.hbm.packet.PacketDispatcher; - import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; +import net.minecraft.entity.Entity; +import net.minecraft.util.MathHelper; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.EntityJoinWorldEvent; public class WorldUtil { @@ -31,6 +34,38 @@ public class WorldUtil { PacketDispatcher.wrapper.sendToAllAround(new BiomeSyncPacket(coord.chunkXPos, coord.chunkZPos, chunk.getBiomeArray()), new TargetPoint(world.provider.dimensionId, coord.getCenterXPos(), 128, coord.getCenterZPosition() /* who named you? */, 1024D)); } + /**Chunkloads the chunk the entity is going to spawn in and then spawns it + * @param entity The entity to be spawned**/ + + /*fun fact: this is based off of joinEntityInSurroundings in World + however, since mojang is staffed by field mice, that function is client side only and half-baked + */ + public static void loadAndSpawnEntityInWorld(Entity entity) + { + World world = entity.worldObj; + int chunkX = MathHelper.floor_double(entity.posX / 16.0D); + int chunkZ = MathHelper.floor_double(entity.posZ / 16.0D); + byte loadRadius = 2; + + for (int k = chunkX - loadRadius; k <= chunkX + loadRadius; ++k) + { + for (int l = chunkZ - loadRadius; l <= chunkZ + loadRadius; ++l) + { + world.getChunkFromChunkCoords(k, l); + } + } + + if (!world.loadedEntityList.contains(entity)) + { + if (!MinecraftForge.EVENT_BUS.post(new EntityJoinWorldEvent(entity, world))) + { + world.getChunkFromChunkCoords(chunkX, chunkZ).addEntity(entity); + world.loadedEntityList.add(entity); + world.onEntityAdded(entity); + } + } + } + public static void syncBiomeChange(World world, int x, int z) { Chunk chunk = world.getChunkFromBlockCoords(x, z); byte biome = chunk.getBiomeArray()[(z & 15) << 4 | (x & 15)];