i fucked around, i found out

this shit WORKS
This commit is contained in:
BallOfEnergy 2025-03-19 13:31:56 -05:00
parent 0a59fa86a0
commit c73ec3a0ac
6 changed files with 123 additions and 45 deletions

View File

@ -24,8 +24,6 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityCaveSpider;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
@ -178,21 +176,7 @@ public class BlockStorageCrate extends BlockContainer implements IBlockMulti, IT
if(entity instanceof TileEntityCrateBase && ((TileEntityCrateBase) entity).canAccess(player)) {
FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z);
TileEntityCrateBase crate = (TileEntityCrateBase) entity;
if(crate.hasSpiders) {
Random random = new Random();
int numSpiders = 3; // leave that at 3 for now TODO: maybe a config option or smth
for (int i = 0; i < numSpiders; i++) {
EntityCaveSpider spider = new EntityCaveSpider(crate.getWorldObj()); // lord
spider.setLocationAndAngles(x + random.nextGaussian() * 2, y + 1, z + random.nextGaussian() * 2, random.nextFloat(), 0);
spider.setAttackTarget(player);
world.spawnEntityInWorld(spider);
crate.hasSpiders = false;
}
}
TileEntityCrateBase.spawnSpiders(player, world, crate);
}
return true;
} else {

View File

@ -1,10 +1,8 @@
package com.hbm.inventory.container;
import com.hbm.util.InventoryUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerCrateBase extends ContainerBase {

View File

@ -3,7 +3,7 @@ package com.hbm.items.block;
import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.container.*;
import com.hbm.inventory.gui.*;
import com.hbm.items.ModItems;
import com.hbm.items.tool.ItemKey;
import com.hbm.main.MainRegistry;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.machine.storage.*;
@ -42,16 +42,19 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
for (ItemStack item : player.inventory.mainInventory) {
if(item == null) // Skip if no item.
continue;
if(item.getItem() != ModItems.key || item.stackTagCompound == null) // Skip if item isn't a key or if the NBT is null (wouldn't open it either way).
if(!(item.getItem() instanceof ItemKey)) // Skip if item isn't a key.
continue;
if(item.stackTagCompound == null) // Skip if there is no NBT (wouldn't open it anyway).
continue;
if (item.stackTagCompound.getInteger("pins") == stack.stackTagCompound.getInteger("lock")) { // Check if pins are equal (if it can open it)
TileEntityCrateBase.spawnSpiders(player, world, stack);
player.openGui(MainRegistry.instance, 0, world, 0, 0, 0);
break;
}
}
return stack; // Return early if it was locked.
}
TileEntityCrateBase.spawnSpiders(player, world, stack);
player.openGui(MainRegistry.instance, 0, world, 0, 0, 0); // If there is no lock then don't bother checking.
}
@ -89,6 +92,8 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
public final ItemStack crate;
public ItemStack[] slots;
private boolean toMarkDirty = false;
public InventoryCrate(EntityPlayer player, ItemStack crate) {
this.player = player;
@ -99,9 +104,11 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
crate.stackTagCompound = new NBTTagCompound();
else if(!player.worldObj.isRemote) {
for (int i = 0; i < this.getSizeInventory(); i++)
this.setInventorySlotContents(i, ItemStack.loadItemStackFromNBT(crate.stackTagCompound.getCompoundTag("slot" + i)), false);
this.setInventorySlotContents(i, ItemStack.loadItemStackFromNBT(crate.stackTagCompound.getCompoundTag("slot" + i)));
}
toMarkDirty = true;
this.markDirty();
toMarkDirty = false;
}
@Nonnull
@ -137,7 +144,6 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
if (stack != null) {
if (stack.stackSize > amount) {
stack = stack.splitStack(amount);
markDirty();
} else {
setInventorySlotContents(slot, null);
}
@ -154,18 +160,11 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
setInventorySlotContents(slot, stack, true);
}
public void setInventorySlotContents(int slot, ItemStack stack, boolean markDirty) {
if(stack != null) {
stack.stackSize = Math.min(stack.stackSize, this.getInventoryStackLimit());
}
slots[slot] = stack;
if(markDirty) // This is purely so we don't re-serialize *all* the data when *each* item is loaded during the inventory creation.
markDirty();
}
@Override
@ -181,11 +180,19 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
@Override
public void markDirty() { // I HATE THIS SO MUCH
ItemStack item = new ItemStack(crate.getItem());
if(player.worldObj.isRemote) { // go the fuck away
return;
}
if(!toMarkDirty) { // ok fuck you too
return;
}
NBTTagCompound nbt = new NBTTagCompound();
for(int i = 0; i < this.getSizeInventory(); i++) {
int invSize = this.getSizeInventory();
for(int i = 0; i < invSize; i++) {
ItemStack stack = this.getStackInSlot(i);
if(stack == null)
@ -214,7 +221,7 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
if(abyte.length > 6000) {
player.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.RED + "Warning: Container NBT exceeds 6kB, contents will be ejected!"));
for(int i1 = 0; i1 < this.getSizeInventory(); ++i1) {
for(int i1 = 0; i1 < invSize; ++i1) {
ItemStack itemstack = this.getStackInSlot(i1);
if(itemstack != null) {
@ -244,16 +251,17 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
}
}
}
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
player.closeScreen();
crate.setTagCompound(null); // Wipe tag compound to clear crate.
player.inventory.setInventorySlotContents(player.inventory.currentItem, crate);
return;
}
} catch(IOException ignored) { }
}
item.setTagCompound(nbt);
crate.setTagCompound(nbt);
player.inventory.setInventorySlotContents(player.inventory.currentItem, item);
player.inventory.setInventorySlotContents(player.inventory.currentItem, crate);
}
@Override
@ -268,6 +276,9 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider
@Override
public void closeInventory() {
toMarkDirty = true;
markDirty();
toMarkDirty = false;
player.worldObj.playSoundEffect(player.posX, player.posY, player.posZ, "hbm:block.crateClose", 1.0F, 0.8F);
}

View File

@ -1,19 +1,27 @@
package com.hbm.items.tool;
import java.util.List;
import java.util.Random;
import com.hbm.blocks.ModBlocks;
import com.hbm.config.GeneralConfig;
import com.hbm.explosion.vanillant.ExplosionVNT;
import com.hbm.explosion.vanillant.standard.BlockAllocatorStandard;
import com.hbm.itempool.ItemPool;
import com.hbm.itempool.ItemPoolsSingle;
import com.hbm.lib.HbmWorldGen;
import com.hbm.lib.Library;
import com.hbm.main.MainRegistry;
import com.hbm.particle.helper.ExplosionCreator;
import com.hbm.tileentity.machine.storage.TileEntityCrateBase;
import com.hbm.tileentity.machine.storage.TileEntitySafe;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraft.world.World;
public class ItemWandD extends Item {
@ -28,6 +36,42 @@ public class ItemWandD extends Item {
if(pos != null) {
int y = world.getHeightValue(pos.blockX, pos.blockZ);
Random rand = new Random();
if(world.getBlock(pos.blockX, y - 1, pos.blockZ).canPlaceTorchOnTop(world, pos.blockX, y - 1, pos.blockZ)) {
world.setBlock(pos.blockX, y, pos.blockZ, ModBlocks.safe, rand.nextInt(4) + 2, 2);
TileEntitySafe safe = (TileEntitySafe) world.getTileEntity(pos.blockX, y, pos.blockZ);
switch(rand.nextInt(10)) {
case 0: case 1: case 2: case 3:
safe.setMod(1);
WeightedRandomChestContent.generateChestContents(rand, ItemPool.getPool(ItemPoolsSingle.POOL_VAULT_RUSTY), safe, rand.nextInt(4) + 3);
break;
case 4: case 5: case 6:
safe.setMod(0.1);
WeightedRandomChestContent.generateChestContents(rand, ItemPool.getPool(ItemPoolsSingle.POOL_VAULT_STANDARD), safe, rand.nextInt(3) + 2);
break;
case 7: case 8:
safe.setMod(0.02);
WeightedRandomChestContent.generateChestContents(rand, ItemPool.getPool(ItemPoolsSingle.POOL_VAULT_REINFORCED), safe, rand.nextInt(3) + 1);
break;
case 9:
safe.setMod(0.0);
WeightedRandomChestContent.generateChestContents(rand, ItemPool.getPool(ItemPoolsSingle.POOL_VAULT_UNBREAKABLE), safe, rand.nextInt(2) + 1);
break;
}
safe.setPins(rand.nextInt(999) + 1);
safe.lock();
safe.fillWithSpiders(); // debug
if(GeneralConfig.enableDebugMode)
MainRegistry.logger.info("[Debug] Successfully spawned safe at " + pos.blockX + " " + (y + 1) +" " + pos.blockZ);
}
/*ExplosionVNT vnt = new ExplosionVNT(world, pos.hitVec.xCoord, pos.hitVec.yCoord, pos.hitVec.zCoord, 7);
vnt.setBlockAllocator(new BlockAllocatorBulkie(60));
vnt.setBlockProcessor(new BlockProcessorStandard().withBlockEffect(new BlockMutatorBulkie(ModBlocks.block_slag)).setNoDrop());

View File

@ -513,7 +513,7 @@ public class HbmWorldGen implements IWorldGenerator {
safe.setPins(rand.nextInt(999) + 1);
safe.lock();
if(rand.nextInt(10) < 3) // 30% chance
if(rand.nextInt(10) < 3) // 30% chance; those safes have been sitting there for ages, they gotta have some spiders in them
safe.fillWithSpiders();
if(GeneralConfig.enableDebugMode)
@ -706,8 +706,8 @@ public class HbmWorldGen implements IWorldGenerator {
int d = 16 + rand.nextInt(96);
for(int y = d - 5; y <= d; y++)
if(world.getBlock(x, y + 1, z) == Blocks.air && world.getBlock(x, y, z) == Blocks.netherrack)
world.setBlock(x, y, z, ModBlocks.ore_nether_smoldering);
if(world.getBlock(x, y + 1, z) == Blocks.air && world.getBlock(x, y, z) == Blocks.netherrack)
world.setBlock(x, y, z, ModBlocks.ore_nether_smoldering);
}
for(int k = 0; k < 1; k++){
@ -716,8 +716,8 @@ public class HbmWorldGen implements IWorldGenerator {
int d = 16 + rand.nextInt(96);
for(int y = d - 5; y <= d; y++)
if(world.getBlock(x, y + 1, z) == Blocks.air && world.getBlock(x, y, z) == Blocks.netherrack)
world.setBlock(x, y, z, ModBlocks.geysir_nether);
if(world.getBlock(x, y + 1, z) == Blocks.air && world.getBlock(x, y, z) == Blocks.netherrack)
world.setBlock(x, y, z, ModBlocks.geysir_nether);
}
}

View File

@ -3,15 +3,19 @@ package com.hbm.tileentity.machine.storage;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.machine.TileEntityLockableBase;
import net.minecraft.entity.monster.EntityCaveSpider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import java.util.Random;
public abstract class TileEntityCrateBase extends TileEntityLockableBase implements ISidedInventory, IGUIProvider {
protected ItemStack slots[];
protected ItemStack[] slots;
public String customName;
public boolean hasSpiders = false;
@ -52,7 +56,7 @@ public abstract class TileEntityCrateBase extends TileEntityLockableBase impleme
@Override
public boolean hasCustomInventoryName() {
return this.customName != null && this.customName.length() > 0;
return this.customName != null && !this.customName.isEmpty();
}
public void setCustomName(String name) {
@ -164,4 +168,41 @@ public abstract class TileEntityCrateBase extends TileEntityLockableBase impleme
public void fillWithSpiders() {
this.hasSpiders = true;
}
private static final int numSpiders = 3; // leave that at 3 for now TODO: maybe a config option or smth
/// For when opening from a TileEntity.
public static void spawnSpiders(EntityPlayer player, World worldObj, TileEntityCrateBase crate) {
if(crate.hasSpiders) {
Random random = new Random();
for (int i = 0; i < numSpiders; i++) {
EntityCaveSpider spider = new EntityCaveSpider(worldObj); // lord
spider.setLocationAndAngles(crate.xCoord + random.nextGaussian() * 2, crate.yCoord + 1, crate.zCoord + random.nextGaussian() * 2, random.nextFloat(), 0);
spider.setAttackTarget(player);
worldObj.spawnEntityInWorld(spider);
}
crate.hasSpiders = false;
crate.markDirty();
}
}
/// For when opening from a player's inventory.
public static void spawnSpiders(EntityPlayer player, World worldObj, ItemStack crate) {
if(crate.getTagCompound().getBoolean("spiders")) {
Random random = new Random();
for (int i = 0; i < numSpiders; i++) {
EntityCaveSpider spider = new EntityCaveSpider(worldObj);
spider.setLocationAndAngles(player.posX + random.nextGaussian() * 2, player.posY + 1, player.posZ + random.nextGaussian() * 2, random.nextFloat(), 0);
spider.setAttackTarget(player);
worldObj.spawnEntityInWorld(spider);
}
crate.getTagCompound().removeTag("spiders");
}
}
}