mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
mass storages keeping inventory when broken, recipes
This commit is contained in:
parent
8d8116b3d0
commit
f0b211dbff
@ -1,21 +1,31 @@
|
|||||||
package com.hbm.blocks.machine;
|
package com.hbm.blocks.machine;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import com.hbm.blocks.ModBlocks;
|
import com.hbm.blocks.ModBlocks;
|
||||||
import com.hbm.items.ModItems;
|
import com.hbm.items.ModItems;
|
||||||
import com.hbm.items.tool.ItemLock;
|
import com.hbm.items.tool.ItemLock;
|
||||||
import com.hbm.lib.RefStrings;
|
import com.hbm.lib.RefStrings;
|
||||||
import com.hbm.main.MainRegistry;
|
import com.hbm.main.MainRegistry;
|
||||||
|
import com.hbm.tileentity.machine.TileEntityLockableBase;
|
||||||
import com.hbm.tileentity.machine.storage.TileEntityMassStorage;
|
import com.hbm.tileentity.machine.storage.TileEntityMassStorage;
|
||||||
|
|
||||||
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
|
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockContainer;
|
import net.minecraft.block.BlockContainer;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.ISidedInventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.IIcon;
|
import net.minecraft.util.IIcon;
|
||||||
|
import net.minecraft.util.MathHelper;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class BlockMassStorage extends BlockContainer {
|
public class BlockMassStorage extends BlockContainer {
|
||||||
@ -66,4 +76,134 @@ public class BlockMassStorage extends BlockContainer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean dropInv = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
|
||||||
|
|
||||||
|
if(!player.capabilities.isCreativeMode && !world.isRemote && willHarvest) {
|
||||||
|
|
||||||
|
ItemStack drop = new ItemStack(this);
|
||||||
|
ISidedInventory inv = (ISidedInventory)world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
|
NBTTagCompound nbt = new NBTTagCompound();
|
||||||
|
|
||||||
|
if(inv != null) {
|
||||||
|
|
||||||
|
for(int i = 0; i < inv.getSizeInventory(); i++) {
|
||||||
|
|
||||||
|
ItemStack stack = inv.getStackInSlot(i);
|
||||||
|
if(stack == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
NBTTagCompound slot = new NBTTagCompound();
|
||||||
|
stack.writeToNBT(slot);
|
||||||
|
nbt.setTag("slot" + i, slot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(inv instanceof TileEntityLockableBase) {
|
||||||
|
TileEntityLockableBase lockable = (TileEntityLockableBase) inv;
|
||||||
|
|
||||||
|
if(lockable.isLocked()) {
|
||||||
|
nbt.setInteger("lock", lockable.getPins());
|
||||||
|
nbt.setDouble("lockMod", lockable.getMod());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(inv instanceof TileEntityMassStorage) {
|
||||||
|
TileEntityMassStorage storage = (TileEntityMassStorage) inv;
|
||||||
|
nbt.setInteger("stack", storage.getStockpile());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!nbt.hasNoTags()) {
|
||||||
|
drop.stackTagCompound = nbt;
|
||||||
|
}
|
||||||
|
|
||||||
|
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, drop));
|
||||||
|
}
|
||||||
|
|
||||||
|
dropInv = false;
|
||||||
|
boolean flag = world.setBlockToAir(x, y, z);
|
||||||
|
dropInv = true;
|
||||||
|
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
|
||||||
|
|
||||||
|
ISidedInventory inv = (ISidedInventory)world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
|
if(inv != null && stack.hasTagCompound()) {
|
||||||
|
|
||||||
|
for(int i = 0; i < inv.getSizeInventory(); i++) {
|
||||||
|
inv.setInventorySlotContents(i, ItemStack.loadItemStackFromNBT(stack.stackTagCompound.getCompoundTag("slot" + i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(inv instanceof TileEntityMassStorage) {
|
||||||
|
TileEntityMassStorage storage = (TileEntityMassStorage) inv;
|
||||||
|
|
||||||
|
if(stack.stackTagCompound.hasKey("lock")) {
|
||||||
|
storage.setPins(stack.stackTagCompound.getInteger("lock"));
|
||||||
|
storage.setMod(stack.stackTagCompound.getDouble("lockMod"));
|
||||||
|
storage.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
storage.setStockpile(stack.stackTagCompound.getInteger("stack"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onBlockPlacedBy(world, x, y, z, player, stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
|
||||||
|
|
||||||
|
if(dropInv) {
|
||||||
|
ISidedInventory sided = (ISidedInventory) world.getTileEntity(x, y, z);
|
||||||
|
Random rand = world.rand;
|
||||||
|
|
||||||
|
if(sided != null) {
|
||||||
|
for(int i1 = 0; i1 < sided.getSizeInventory(); ++i1) {
|
||||||
|
|
||||||
|
if(i1 == 1) continue; //do NOT drop the filter item
|
||||||
|
|
||||||
|
ItemStack itemstack = sided.getStackInSlot(i1);
|
||||||
|
|
||||||
|
if(itemstack != null) {
|
||||||
|
float f = rand.nextFloat() * 0.8F + 0.1F;
|
||||||
|
float f1 = rand.nextFloat() * 0.8F + 0.1F;
|
||||||
|
float f2 = rand.nextFloat() * 0.8F + 0.1F;
|
||||||
|
|
||||||
|
while(itemstack.stackSize > 0) {
|
||||||
|
int j1 = rand.nextInt(21) + 10;
|
||||||
|
|
||||||
|
if(j1 > itemstack.stackSize) {
|
||||||
|
j1 = itemstack.stackSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemstack.stackSize -= j1;
|
||||||
|
EntityItem entityitem = new EntityItem(world, x + f, y + f1, z + f2, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
|
||||||
|
|
||||||
|
if(itemstack.hasTagCompound()) {
|
||||||
|
entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
|
||||||
|
}
|
||||||
|
|
||||||
|
float f3 = 0.05F;
|
||||||
|
entityitem.motionX = (float) rand.nextGaussian() * f3;
|
||||||
|
entityitem.motionY = (float) rand.nextGaussian() * f3 + 0.2F;
|
||||||
|
entityitem.motionZ = (float) rand.nextGaussian() * f3;
|
||||||
|
world.spawnEntityInWorld(entityitem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
world.func_147453_f(x, y, z, block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.breakBlock(world, x, y, z, block, meta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,10 +42,14 @@ public class ShredderRecipes {
|
|||||||
if(matches == null || matches.isEmpty())
|
if(matches == null || matches.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
//1 ingot unit, metal
|
||||||
generateRecipes("ingot", name, matches, 1);
|
generateRecipes("ingot", name, matches, 1);
|
||||||
generateRecipes("ore", name, matches, 2);
|
generateRecipes("plate", name, matches, 1);
|
||||||
|
//1 ingot unit, crystalline
|
||||||
generateRecipes("gem", name, matches, 1);
|
generateRecipes("gem", name, matches, 1);
|
||||||
generateRecipes("crystal", name, matches, 1);
|
generateRecipes("crystal", name, matches, 1);
|
||||||
|
//2 ingot units, any
|
||||||
|
generateRecipes("ore", name, matches, 2);
|
||||||
|
|
||||||
if(name.length() > 5 && name.substring(0, 5).equals("block")) {
|
if(name.length() > 5 && name.substring(0, 5).equals("block")) {
|
||||||
ItemStack dust = getDustByName(name.substring(5));
|
ItemStack dust = getDustByName(name.substring(5));
|
||||||
|
|||||||
@ -237,6 +237,9 @@ public class CraftingManager {
|
|||||||
addShapelessAuto(new ItemStack(ModItems.toothpicks, 3), new Object[] { KEY_STICK, KEY_STICK, KEY_STICK });
|
addShapelessAuto(new ItemStack(ModItems.toothpicks, 3), new Object[] { KEY_STICK, KEY_STICK, KEY_STICK });
|
||||||
addRecipeAuto(new ItemStack(ModItems.ducttape, 6), new Object[] { "FSF", "SPS", "FSF", 'F', Items.string, 'S', KEY_SLIME, 'P', Items.paper });
|
addRecipeAuto(new ItemStack(ModItems.ducttape, 6), new Object[] { "FSF", "SPS", "FSF", 'F', Items.string, 'S', KEY_SLIME, 'P', Items.paper });
|
||||||
|
|
||||||
|
addRecipeAuto(new ItemStack(ModBlocks.conveyor, 16), new Object[] { "LLL", "I I", "LLL", 'L', Items.leather, 'I', IRON.ingot() });
|
||||||
|
addRecipeAuto(new ItemStack(ModBlocks.conveyor, 64), new Object[] { "LLL", "I I", "LLL", 'L', RUBBER.ingot(), 'I', IRON.ingot() });
|
||||||
|
|
||||||
//addRecipeAuto(new ItemStack(Item.getItemFromBlock(ModBlocks.machine_difurnace_off), 1), new Object[] { "T T", "PHP", "TFT", 'T', W.ingot(), 'P', ModItems.board_copper, 'H', Blocks.hopper, 'F', Blocks.furnace });
|
//addRecipeAuto(new ItemStack(Item.getItemFromBlock(ModBlocks.machine_difurnace_off), 1), new Object[] { "T T", "PHP", "TFT", 'T', W.ingot(), 'P', ModItems.board_copper, 'H', Blocks.hopper, 'F', Blocks.furnace });
|
||||||
addRecipeAuto(new ItemStack(Item.getItemFromBlock(ModBlocks.machine_uf6_tank), 1), new Object[] { "WTW", "WTW", "SRS", 'S', IRON.plate(), 'W', ModItems.coil_tungsten, 'T', ModItems.tank_steel, 'W', ModItems.coil_tungsten,'R', MINGRADE.ingot() });
|
addRecipeAuto(new ItemStack(Item.getItemFromBlock(ModBlocks.machine_uf6_tank), 1), new Object[] { "WTW", "WTW", "SRS", 'S', IRON.plate(), 'W', ModItems.coil_tungsten, 'T', ModItems.tank_steel, 'W', ModItems.coil_tungsten,'R', MINGRADE.ingot() });
|
||||||
addRecipeAuto(new ItemStack(Item.getItemFromBlock(ModBlocks.machine_puf6_tank), 1), new Object[] { "WTW", "WTW", "SRS", 'S', STEEL.plate(), 'W', ModItems.coil_tungsten, 'T', ModItems.tank_steel, 'W', ModItems.coil_tungsten,'R', MINGRADE.ingot() });
|
addRecipeAuto(new ItemStack(Item.getItemFromBlock(ModBlocks.machine_puf6_tank), 1), new Object[] { "WTW", "WTW", "SRS", 'S', STEEL.plate(), 'W', ModItems.coil_tungsten, 'T', ModItems.tank_steel, 'W', ModItems.coil_tungsten,'R', MINGRADE.ingot() });
|
||||||
@ -269,6 +272,7 @@ public class CraftingManager {
|
|||||||
addRecipeAuto(new ItemStack(ModBlocks.crate_desh, 1), new Object[] { " D ", "DSD", " D ", 'D', ModItems.plate_desh, 'S', ModBlocks.crate_steel });
|
addRecipeAuto(new ItemStack(ModBlocks.crate_desh, 1), new Object[] { " D ", "DSD", " D ", 'D', ModItems.plate_desh, 'S', ModBlocks.crate_steel });
|
||||||
addRecipeAuto(new ItemStack(ModBlocks.crate_tungsten, 1), new Object[] { "BPB", "PCP", "BPB", 'B', W.block(), 'P', ModItems.board_copper, 'C', ModBlocks.crate_steel });
|
addRecipeAuto(new ItemStack(ModBlocks.crate_tungsten, 1), new Object[] { "BPB", "PCP", "BPB", 'B', W.block(), 'P', ModItems.board_copper, 'C', ModBlocks.crate_steel });
|
||||||
addRecipeAuto(new ItemStack(ModBlocks.safe, 1), new Object[] { "LAL", "ACA", "LAL", 'L', PB.plate(), 'A', ALLOY.plate(), 'C', ModBlocks.crate_steel });
|
addRecipeAuto(new ItemStack(ModBlocks.safe, 1), new Object[] { "LAL", "ACA", "LAL", 'L', PB.plate(), 'A', ALLOY.plate(), 'C', ModBlocks.crate_steel });
|
||||||
|
addRecipeAuto(new ItemStack(ModBlocks.mass_storage, 1, 0), new Object[] { "ICI", "CLC", "ICI", 'I', TI.ingot(), 'C', ModBlocks.crate_steel, 'L', ModItems.circuit_red_copper });
|
||||||
addRecipeAuto(new ItemStack(ModBlocks.machine_autocrafter, 1), new Object[] { "SCS", "MWM", "SCS", 'S', STEEL.plate(), 'C', ModItems.circuit_copper, 'M', ModItems.motor, 'W', Blocks.crafting_table });
|
addRecipeAuto(new ItemStack(ModBlocks.machine_autocrafter, 1), new Object[] { "SCS", "MWM", "SCS", 'S', STEEL.plate(), 'C', ModItems.circuit_copper, 'M', ModItems.motor, 'W', Blocks.crafting_table });
|
||||||
addRecipeAuto(new ItemStack(ModBlocks.machine_waste_drum, 1), new Object[] { "LRL", "BRB", "LRL", 'L', PB.ingot(), 'B', Blocks.iron_bars, 'R', ModItems.rod_quad_empty });
|
addRecipeAuto(new ItemStack(ModBlocks.machine_waste_drum, 1), new Object[] { "LRL", "BRB", "LRL", 'L', PB.ingot(), 'B', Blocks.iron_bars, 'R', ModItems.rod_quad_empty });
|
||||||
addRecipeAuto(new ItemStack(ModBlocks.machine_press, 1), new Object[] { "IRI", "IPI", "IBI", 'I', IRON.ingot(), 'R', Blocks.furnace, 'B', IRON.block(), 'P', Blocks.piston });
|
addRecipeAuto(new ItemStack(ModBlocks.machine_press, 1), new Object[] { "IRI", "IPI", "IBI", 'I', IRON.ingot(), 'R', Blocks.furnace, 'B', IRON.block(), 'P', Blocks.piston });
|
||||||
|
|||||||
@ -88,6 +88,10 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements INBTPa
|
|||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStockpile(int stack) {
|
||||||
|
this.stack = stack;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(EntityPlayer player) {
|
public boolean hasPermission(EntityPlayer player) {
|
||||||
return Vec3.createVectorHelper(xCoord - player.posX, yCoord - player.posY, zCoord - player.posZ).lengthVector() < 20;
|
return Vec3.createVectorHelper(xCoord - player.posX, yCoord - player.posY, zCoord - player.posZ).lengthVector() < 20;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user