Make worldgen mines be inactive until a player comes within 25 blocks, this has two effects:

* Far away worldgen mines won't be triggered by mobs
* You can hear an activation beep (once), giving you an indication of their existence
This commit is contained in:
George Paton 2024-02-14 17:21:07 +11:00
parent 82ec052d27
commit 9ff31388c8
4 changed files with 70 additions and 70 deletions

View File

@ -1819,10 +1819,10 @@ public class ModBlocks {
charge_miner = new BlockChargeMiner().setBlockName("charge_miner").setCreativeTab(MainRegistry.nukeTab).setResistance(1.0F);
charge_c4 = new BlockChargeC4().setBlockName("charge_c4").setCreativeTab(MainRegistry.nukeTab).setResistance(1.0F);
charge_semtex = new BlockChargeSemtex().setBlockName("charge_semtex").setCreativeTab(MainRegistry.nukeTab).setResistance(1.0F);
mine_ap = new Landmine(Material.iron).setBlockName("mine_ap").setCreativeTab(MainRegistry.nukeTab).setHardness(1.0F).setBlockTextureName(RefStrings.MODID + ":mine_ap");
mine_he = new Landmine(Material.iron).setBlockName("mine_he").setCreativeTab(MainRegistry.nukeTab).setHardness(1.0F).setBlockTextureName(RefStrings.MODID + ":mine_he");
mine_shrap = new Landmine(Material.iron).setBlockName("mine_shrap").setCreativeTab(MainRegistry.nukeTab).setHardness(1.0F).setBlockTextureName(RefStrings.MODID + ":mine_shrap");
mine_fat = new Landmine(Material.iron).setBlockName("mine_fat").setCreativeTab(MainRegistry.nukeTab).setHardness(1.0F).setBlockTextureName(RefStrings.MODID + ":mine_fat");
mine_ap = new Landmine(Material.iron, 1.5D, 1D).setBlockName("mine_ap").setCreativeTab(MainRegistry.nukeTab).setHardness(1.0F).setBlockTextureName(RefStrings.MODID + ":mine_ap");
mine_he = new Landmine(Material.iron, 2D, 5D).setBlockName("mine_he").setCreativeTab(MainRegistry.nukeTab).setHardness(1.0F).setBlockTextureName(RefStrings.MODID + ":mine_he");
mine_shrap = new Landmine(Material.iron, 1.5D, 1D).setBlockName("mine_shrap").setCreativeTab(MainRegistry.nukeTab).setHardness(1.0F).setBlockTextureName(RefStrings.MODID + ":mine_shrap");
mine_fat = new Landmine(Material.iron, 2.5D, 1D).setBlockName("mine_fat").setCreativeTab(MainRegistry.nukeTab).setHardness(1.0F).setBlockTextureName(RefStrings.MODID + ":mine_fat");
dynamite = new BlockDynamite().setBlockName("dynamite").setStepSound(Block.soundTypeGrass).setCreativeTab(MainRegistry.nukeTab).setHardness(0.0F).setBlockTextureName(RefStrings.MODID + ":dynamite");
tnt = new BlockTNT().setBlockName("tnt_ntm").setStepSound(Block.soundTypeGrass).setCreativeTab(MainRegistry.nukeTab).setHardness(0.0F).setBlockTextureName(RefStrings.MODID + ":tnt");
semtex = new BlockSemtex().setBlockName("semtex").setStepSound(Block.soundTypeGrass).setCreativeTab(MainRegistry.nukeTab).setHardness(0.0F).setBlockTextureName(RefStrings.MODID + ":semtex");

View File

@ -26,8 +26,14 @@ public class Landmine extends BlockContainer implements IBomb {
public static boolean safeMode = false;
public Landmine(Material p_i45386_1_) {
super(p_i45386_1_);
public double range;
public double height;
public Landmine(Material mat, double range, double height) {
super(mat);
this.range = range;
this.height = height;
}
@Override
@ -56,7 +62,7 @@ public class Landmine extends BlockContainer implements IBomb {
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_) {
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
float f = 0.0625F;
if(this == ModBlocks.mine_ap)
this.setBlockBounds(6 * f, 0.0F, 6 * f, 10 * f, 2 * f, 10 * f);
@ -70,15 +76,7 @@ public class Landmine extends BlockContainer implements IBomb {
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
float f = 0.0625F;
if(this == ModBlocks.mine_ap)
this.setBlockBounds(6 * f, 0.0F, 6 * f, 10 * f, 2 * f, 10 * f);
if(this == ModBlocks.mine_he)
this.setBlockBounds(4 * f, 0.0F, 4 * f, 12 * f, 2 * f, 12 * f);
if(this == ModBlocks.mine_shrap)
this.setBlockBounds(4 * f, 0.0F, 4 * f, 12 * f, 2 * f, 12 * f);
if(this == ModBlocks.mine_fat)
this.setBlockBounds(5 * f, 0.0F, 4 * f, 11 * f, 6 * f, 12 * f);
setBlockBoundsBasedOnState(world, x, y, z);
return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
}
@ -92,14 +90,7 @@ public class Landmine extends BlockContainer implements IBomb {
explode(world, x, y, z);
}
boolean flag = false;
if(!World.doesBlockHaveSolidTopSurface(world, x, y - 1, z) && !BlockFence.func_149825_a(world.getBlock(x, y - 1, z))) {
flag = true;
}
if(flag) {
if(!safeMode) {
explode(world, x, y, z);
} else {
@ -157,18 +148,14 @@ public class Landmine extends BlockContainer implements IBomb {
if(this == ModBlocks.mine_ap) {
world.newExplosion(null, x + 0.5, y + 0.5, z + 0.5, 2.5F, false, false);
}
if(this == ModBlocks.mine_he) {
} else if(this == ModBlocks.mine_he) {
ExplosionLarge.explode(world, x + 0.5, y + 0.5, z + 0.5, 3F, true, false, false);
world.newExplosion(null, x + 0.5, y + 2, z + 0.5, 15F, false, false);
}
if(this == ModBlocks.mine_shrap) {
} else if(this == ModBlocks.mine_shrap) {
ExplosionLarge.explode(world, x + 0.5, y + 0.5, z + 0.5, 1, true, false, false);
ExplosionLarge.spawnShrapnelShower(world, x + 0.5, y + 0.5, z + 0.5, 0, 1D, 0, 45, 0.2D);
ExplosionLarge.spawnShrapnels(world, x + 0.5, y + 0.5, z + 0.5, 5);
}
if(this == ModBlocks.mine_fat) {
} else if(this == ModBlocks.mine_fat) {
ExplosionNukeSmall.explode(world, x + 0.5, y + 0.5, z + 0.5, ExplosionNukeSmall.PARAMS_MEDIUM);
}
}

View File

@ -13,6 +13,7 @@ import com.hbm.handler.MultiblockHandlerXR;
import com.hbm.items.ModItems;
import com.hbm.main.MainRegistry;
import com.hbm.saveddata.TomSaveData;
import com.hbm.tileentity.bomb.TileEntityLandmine;
import com.hbm.tileentity.deco.TileEntityLanternBehemoth;
import com.hbm.tileentity.machine.storage.TileEntitySafe;
import com.hbm.tileentity.machine.storage.TileEntitySoyuzCapsule;
@ -152,6 +153,7 @@ public class HbmWorldGen implements IWorldGenerator {
DungeonToolbox.generateOre(world, rand, i, j, WorldConfig.limestoneSpawn, 12, 25, 30, ModBlocks.stone_resource, EnumStoneType.LIMESTONE.ordinal());
if(rand.nextInt(3) == 0) {
@SuppressWarnings("unchecked")
WeightedRandomGeneric<BedrockOreDefinition> item = (WeightedRandomGeneric<BedrockOreDefinition>) WeightedRandom.getRandomItem(rand, BedrockOre.weightedOres);
BedrockOreDefinition def = item.get();
@ -394,6 +396,8 @@ public class HbmWorldGen implements IWorldGenerator {
if(world.getBlock(x, y - 1, z).canPlaceTorchOnTop(world, x, y - 1, z)) {
world.setBlock(x, y, z, ModBlocks.mine_ap);
TileEntityLandmine landmine = (TileEntityLandmine) world.getTileEntity(x, y, z);
landmine.waitingForPlayer = true;
if(GeneralConfig.enableDebugMode)
MainRegistry.logger.info("[Debug] Successfully spawned landmine at " + x + " " + (y) + " " + z);
@ -429,6 +433,8 @@ public class HbmWorldGen implements IWorldGenerator {
int y = world.getHeightValue(x, z);
if(world.getBlock(x, y - 1, z).canPlaceTorchOnTop(world, x, y - 1, z)) {
world.setBlock(x, y, z, ModBlocks.mine_he);
TileEntityLandmine landmine = (TileEntityLandmine) world.getTileEntity(x, y, z);
landmine.waitingForPlayer = true;
}
}
@ -768,6 +774,7 @@ public class HbmWorldGen implements IWorldGenerator {
DungeonToolbox.generateOre(world, rand, i, j, WorldConfig.netherPlutoniumSpawn, 4, 0, 127, ModBlocks.ore_nether_plutonium, Blocks.netherrack);
if(rand.nextInt(10) == 0) {
@SuppressWarnings("unchecked")
WeightedRandomGeneric<BedrockOreDefinition> item = (WeightedRandomGeneric<BedrockOreDefinition>) WeightedRandom.getRandomItem(rand, BedrockOre.weightedOresNether);
BedrockOreDefinition def = item.get();
int randPosX = i + rand.nextInt(2) + 8;

View File

@ -2,13 +2,14 @@ package com.hbm.tileentity.bomb;
import java.util.List;
import com.hbm.blocks.ModBlocks;
import com.hbm.blocks.bomb.Landmine;
import com.hbm.main.MainRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
@ -16,55 +17,59 @@ import net.minecraft.util.AxisAlignedBB;
public class TileEntityLandmine extends TileEntity {
private boolean isPrimed = false;
public boolean waitingForPlayer = false;
public void updateEntity() {
if(worldObj.isRemote) return;
Block block = worldObj.getBlock(xCoord, yCoord, zCoord);
if(!worldObj.isRemote) {
Block block = worldObj.getBlock(xCoord, yCoord, zCoord);
double range = 1;
double height = 1;
if(!(block instanceof Landmine)) return;
Landmine landmine = (Landmine) block;
if (block == ModBlocks.mine_ap) {
range = 1.5D;
}
if (block == ModBlocks.mine_he) {
range = 2;
height = 5;
}
if (block == ModBlocks.mine_shrap) {
range = 1.5D;
}
if (block == ModBlocks.mine_fat) {
range = 2.5D;
}
if(!isPrimed)
range *= 2;
List<Object> list = worldObj.getEntitiesWithinAABBExcludingEntity(null,
AxisAlignedBB.getBoundingBox(xCoord - range, yCoord - height, zCoord - range, xCoord + range + 1, yCoord + height, zCoord + range + 1));
boolean flag = false;
for(Object o : list) {
double range = landmine.range;
double height = landmine.height;
if (waitingForPlayer) {
range = 25;
height = 25;
} else if(!isPrimed) {
range *= 2;
height *= 2;
}
@SuppressWarnings("unchecked")
List<Object> list = worldObj.getEntitiesWithinAABBExcludingEntity(null,
AxisAlignedBB.getBoundingBox(xCoord - range, yCoord - height, zCoord - range, xCoord + range + 1, yCoord + height, zCoord + range + 1));
for(Object o : list) {
if(waitingForPlayer) {
// This mine has been generated by worldgen and is ignoring mobs until a player is close enough
// This is to prevent worldgen mines from detonating well before they become gameplay relevant
if(o instanceof EntityPlayer) {
MainRegistry.logger.info("player is in range, enabling");
waitingForPlayer = false;
return;
}
} else {
if(o instanceof EntityLivingBase) {
flag = true;
if(isPrimed) {
//why did i do it like that?
((Landmine) block).explode(worldObj, xCoord, yCoord, zCoord);
// iunno, you tell me
landmine.explode(worldObj, xCoord, yCoord, zCoord);
}
return;
}
}
}
if(!isPrimed && !flag) {
this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "hbm:weapon.fstbmbStart", 3.0F, 1.0F);
isPrimed = true;
}
// After placing, the mine needs to prime itself in order to not immediately kill the placer
// The mine will prime itself only after all entities have left its trigger radius * 2
// I'm leaving this note because I made a dumb assumption on what this was meant to do
if(!isPrimed && !waitingForPlayer) {
this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "hbm:weapon.fstbmbStart", 3.0F, 1.0F);
isPrimed = true;
}
}
@ -72,18 +77,19 @@ public class TileEntityLandmine extends TileEntity {
super.readFromNBT(nbt);
isPrimed = nbt.getBoolean("primed");
waitingForPlayer = nbt.getBoolean("waiting");
}
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setBoolean("primed", isPrimed);
nbt.setBoolean("waiting", waitingForPlayer);
}
@Override
@SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared()
{
public double getMaxRenderDistanceSquared() {
return 65536.0D;
}
}