Working on cleanup

This commit is contained in:
DarkGuardsman 2014-01-08 18:55:59 -05:00
parent 84a023c66c
commit bb781a6685
39 changed files with 29 additions and 1925 deletions

View file

@ -6,9 +6,7 @@ import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.Configuration;
import com.builtbroken.minecraft.prefab.BlockMulti;
import calclavia.lib.multiblock.link.BlockMulti;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;

View file

@ -21,9 +21,9 @@ import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fluids.IFluidHandler;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.utility.AutoCraftingManager;
import com.builtbroken.common.Pair;
import com.builtbroken.minecraft.recipes.AutoCraftingManager;
public class FluidHelper
{

View file

@ -1,13 +0,0 @@
package com.builtbroken.minecraft.interfaces;
import net.minecraft.entity.player.EntityPlayer;
/** Used re relay an activation event from a block or entity to a tile or another entity */
public interface IBlockActivated
{
/**
* Called when activated. Use angle from tile to get side. and getHeldItem to get the item the
* player is using
*/
public boolean onActivated(EntityPlayer entityPlayer);
}

View file

@ -1,15 +0,0 @@
package com.builtbroken.minecraft.interfaces;
import universalelectricity.api.vector.Vector3;
/**
* Interface to be applied to tile entity blocks that occupies more than one block space. Useful for
* large machines.
*
* @author Calclavia
*/
public interface IMultiBlock
{
/** @return An array of Vector3 containing the multiblock relative coordinates to be constructed. */
public Vector3[] getMultiBlockVectors();
}

View file

@ -9,7 +9,7 @@ import net.minecraftforge.common.ForgeDirection;
*
* @author DarkGuardsman
*/
public interface IToolReadOut
public interface IReadOut
{
/**
* Grabs the message displayed to the user on right click of the machine with the given tool

View file

@ -1,18 +0,0 @@
package com.builtbroken.minecraft.network;
import java.io.DataOutputStream;
import java.io.IOException;
import com.google.common.io.ByteArrayDataInput;
/**
* Used for object that only have one set of data to send and receive
*
* @author DarkGuardsman
*/
public interface IPacketLoad
{
public void readPacket(ByteArrayDataInput data);
public void loadPacket(DataOutputStream data) throws IOException;
}

View file

@ -1,190 +0,0 @@
package com.builtbroken.minecraft.prefab;
import java.lang.reflect.Method;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
/** An advanced block class that is to be extended for wrenching capabilities. */
public abstract class BlockAdvanced extends Block
{
public BlockAdvanced(int id, Material material)
{
super(id, material);
this.setHardness(0.6f);
}
/**
* DO NOT OVERRIDE THIS FUNCTION! Called when the block is right clicked by the player. This
* modified version detects electric items and wrench actions on your machine block. Do not
* override this function. Use onMachineActivated instead! (It does the same thing)
*
* @param world The World Object.
* @param x , y, z The coordinate of the block.
* @param side The side the player clicked on.
* @param hitX , hitY, hitZ The position the player clicked on relative to the block.
*/
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
int metadata = world.getBlockMetadata(x, y, z);
/**
* Check if the player is holding a wrench or an electric item. If so, call the wrench
* event.
*/
if (this.isUsableWrench(entityPlayer, entityPlayer.inventory.getCurrentItem(), x, y, z))
{
this.damageWrench(entityPlayer, entityPlayer.inventory.getCurrentItem(), x, y, z);
if (entityPlayer.isSneaking())
{
if (this.onSneakUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ))
{
return true;
}
}
if (this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ))
{
return true;
}
}
if (entityPlayer.isSneaking())
{
if (this.onSneakMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ))
{
return true;
}
}
return this.onMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ);
}
/**
* A function that denotes if an itemStack is a wrench that can be used. Override this for more
* wrench compatibility. Compatible with Buildcraft and IC2 wrench API via reflection.
*
* @return True if it is a wrench.
*/
public boolean isUsableWrench(EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z)
{
if (entityPlayer != null && itemStack != null)
{
Class wrenchClass = itemStack.getItem().getClass();
/** UE and Buildcraft */
try
{
Method methodCanWrench = wrenchClass.getMethod("canWrench", EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE);
return (Boolean) methodCanWrench.invoke(itemStack.getItem(), entityPlayer, x, y, z);
}
catch (NoClassDefFoundError e)
{
}
catch (Exception e)
{
}
/** Industrialcraft */
try
{
if (wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrench") || wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrenchElectric"))
{
return itemStack.getItemDamage() < itemStack.getMaxDamage();
}
}
catch (Exception e)
{
}
}
return false;
}
/**
* This function damages a wrench. Works with Buildcraft and Industrialcraft wrenches.
*
* @return True if damage was successfull.
*/
public boolean damageWrench(EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z)
{
if (this.isUsableWrench(entityPlayer, itemStack, x, y, z))
{
Class wrenchClass = itemStack.getItem().getClass();
/** UE and Buildcraft */
try
{
Method methodWrenchUsed = wrenchClass.getMethod("wrenchUsed", EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE);
methodWrenchUsed.invoke(itemStack.getItem(), entityPlayer, x, y, z);
return true;
}
catch (Exception e)
{
}
/** Industrialcraft */
try
{
if (wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrench") || wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrenchElectric"))
{
Method methodWrenchDamage = wrenchClass.getMethod("damage", ItemStack.class, Integer.TYPE, EntityPlayer.class);
methodWrenchDamage.invoke(itemStack.getItem(), itemStack, 1, entityPlayer);
return true;
}
}
catch (Exception e)
{
}
}
return false;
}
/**
* Called when the machine is right clicked by the player
*
* @return True if something happens
*/
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
return false;
}
/**
* Called when the machine is being wrenched by a player while sneaking.
*
* @return True if something happens
*/
public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
return false;
}
/**
* Called when a player uses a wrench on the machine
*
* @return True if some happens
*/
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
return false;
}
/**
* Called when a player uses a wrench on the machine while sneaking. Only works with the UE
* wrench.
*
* @return True if some happens
*/
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
return this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ);
}
}

View file

@ -18,6 +18,7 @@ import net.minecraftforge.common.Configuration;
import net.minecraftforge.oredict.OreDictionary;
import calclavia.lib.access.AccessUser;
import calclavia.lib.access.ISpecialAccess;
import calclavia.lib.prefab.block.BlockTile;
import com.builtbroken.common.Pair;
import com.builtbroken.minecraft.DarkCore;

View file

@ -1,161 +0,0 @@
package com.builtbroken.minecraft.prefab;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import universalelectricity.api.UniversalElectricity;
import universalelectricity.api.vector.Vector3;
import com.builtbroken.minecraft.DarkCore;
import com.builtbroken.minecraft.interfaces.IMultiBlock;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockMulti extends BlockContainer
{
public String textureName = null;
public BlockMulti()
{
super(DarkCore.CONFIGURATION.getBlock("multiBlock", DarkCore.getNextID()).getInt(), UniversalElectricity.machine);
this.setHardness(0.8F);
this.setUnlocalizedName("multiBlock");
}
@Override
public BlockMulti setTextureName(String name)
{
this.textureName = name;
return this;
}
public void createMultiBlockStructure(IMultiBlock tile)
{
TileEntity tileEntity = (TileEntity) tile;
Vector3[] positions = tile.getMultiBlockVectors();
for (Vector3 position : positions)
{
makeFakeBlock(tileEntity.worldObj, new Vector3(tileEntity).translate(position), new Vector3(tileEntity));
}
}
public void destroyMultiBlockStructure(IMultiBlock tile)
{
TileEntity tileEntity = (TileEntity) tile;
Vector3[] positions = tile.getMultiBlockVectors();
for (Vector3 position : positions)
{
new Vector3(tileEntity).translate(position).setBlock(tileEntity.worldObj, 0);
}
new Vector3(tileEntity).setBlock(tileEntity.worldObj, 0);
}
public void makeFakeBlock(World worldObj, Vector3 position, Vector3 mainBlock)
{
// Creates a fake block, then sets the relative main block position.
worldObj.setBlock(position.intX(), position.intY(), position.intZ(), this.blockID);
((TileEntityMulti) worldObj.getBlockTileEntity(position.intX(), position.intY(), position.intZ())).setMainBlock(mainBlock);
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IconRegister iconRegister)
{
if (this.textureName != null)
{
this.blockIcon = iconRegister.registerIcon(this.textureName);
}
else
{
super.registerIcons(iconRegister);
}
}
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileEntityMulti)
{
((TileEntityMulti) tileEntity).onBlockRemoval(this);
}
super.breakBlock(world, x, y, z, par5, par6);
}
/**
* Called when the block is right clicked by the player. This modified version detects electric
* items and wrench actions on your machine block. Do not override this function. Use
* machineActivated instead! (It does the same thing)
*/
@Override
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
TileEntityMulti tileEntity = (TileEntityMulti) par1World.getBlockTileEntity(x, y, z);
return tileEntity.onBlockActivated(par1World, x, y, z, par5EntityPlayer);
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random par1Random)
{
return 0;
}
@Override
public int getRenderType()
{
return -1;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityMulti();
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World par1World, int x, int y, int z)
{
TileEntity tileEntity = par1World.getBlockTileEntity(x, y, z);
Vector3 mainBlockPosition = ((TileEntityMulti) tileEntity).getMainBlock();
if (mainBlockPosition != null)
{
int mainBlockID = par1World.getBlockId(mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ());
if (mainBlockID > 0)
{
return Block.blocksList[mainBlockID].getPickBlock(target, par1World, mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ());
}
}
return null;
}
}

View file

@ -1,122 +0,0 @@
package com.builtbroken.minecraft.prefab;
import java.util.Random;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
/**
* An advanced block class that is to be extended for wrenching capabilities.
*/
public abstract class BlockTile extends BlockAdvanced implements ITileEntityProvider
{
public BlockTile(int id, Material material)
{
super(id, material);
this.isBlockContainer = true;
}
/**
* Called whenever the block is added into the world. Args: world, x, y, z
*/
@Override
public void onBlockAdded(World par1World, int par2, int par3, int par4)
{
super.onBlockAdded(par1World, par2, par3, par4);
}
/**
* ejects contained items into the world, and notifies neighbours of an update, as appropriate
*/
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
{
this.dropEntireInventory(world, x, y, z, par5, par6);
super.breakBlock(world, x, y, z, par5, par6);
world.removeBlockTileEntity(x, y, z);
}
/**
* Called when the block receives a BlockEvent - see World.addBlockEvent. By default, passes it
* on to the tile entity at this location. Args: world, x, y, z, blockID, EventID, event
* parameter
*/
@Override
public boolean onBlockEventReceived(World par1World, int par2, int par3, int par4, int par5, int par6)
{
super.onBlockEventReceived(par1World, par2, par3, par4, par5, par6);
TileEntity tileentity = par1World.getBlockTileEntity(par2, par3, par4);
return tileentity != null ? tileentity.receiveClientEvent(par5, par6) : false;
}
/**
* Override this if you don't need it. This will eject all items out of this machine if it has
* an inventory.
*/
public void dropEntireInventory(World world, int x, int y, int z, int par5, int par6)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity != null)
{
if (tileEntity instanceof IInventory)
{
IInventory inventory = (IInventory) tileEntity;
for (int var6 = 0; var6 < inventory.getSizeInventory(); ++var6)
{
ItemStack var7 = inventory.getStackInSlot(var6);
if (var7 != null)
{
Random random = new Random();
float var8 = random.nextFloat() * 0.8F + 0.1F;
float var9 = random.nextFloat() * 0.8F + 0.1F;
float var10 = random.nextFloat() * 0.8F + 0.1F;
while (var7.stackSize > 0)
{
int var11 = random.nextInt(21) + 10;
if (var11 > var7.stackSize)
{
var11 = var7.stackSize;
}
var7.stackSize -= var11;
EntityItem var12 = new EntityItem(world, (x + var8), (y + var9), (z + var10), new ItemStack(var7.itemID, var11, var7.getItemDamage()));
if (var7.hasTagCompound())
{
var12.getEntityItem().setTagCompound((NBTTagCompound) var7.getTagCompound().copy());
}
float var13 = 0.05F;
var12.motionX = ((float) random.nextGaussian() * var13);
var12.motionY = ((float) random.nextGaussian() * var13 + 0.2F);
var12.motionZ = ((float) random.nextGaussian() * var13);
world.spawnEntityInWorld(var12);
}
}
}
}
}
}
/**
* Returns the TileEntity used by this block. You should use the metadata sensitive version of
* this to get the maximum optimization!
*/
@Override
public TileEntity createNewTileEntity(World var1)
{
return null;
}
}

View file

@ -1,20 +0,0 @@
package com.builtbroken.minecraft.prefab;
import net.minecraft.item.Item;
import net.minecraftforge.common.Configuration;
import com.builtbroken.minecraft.DarkCore;
public class ItemBasic extends Item
{
public ItemBasic(int itemID, String name, Configuration config)
{
super(config.getItem(name, itemID).getInt());
this.setUnlocalizedName(name);
}
public ItemBasic(String name, Configuration config)
{
this(DarkCore.getNextID(), name, config);
}
}

View file

@ -1,32 +0,0 @@
package com.builtbroken.minecraft.prefab;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
/**
* Simple itemBlock class for quick use with a block for controlling metadata
*
* @author Darkguardsman
*/
public class ItemBlockHolder extends ItemBlock
{
public ItemBlockHolder(int id)
{
super(id);
this.setMaxDamage(0);
this.setHasSubtypes(true);
}
@Override
public int getMetadata(int damage)
{
return damage;
}
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
return Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage();
}
}

View file

@ -1,57 +0,0 @@
package com.builtbroken.minecraft.prefab;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
/**
* A TileEntity with some pre-added functionalities.
*
* @author Calclavia
*/
public abstract class TileEntityAdvanced extends TileEntity
{
protected long ticks = 0;
@Override
public void updateEntity()
{
if (this.ticks == 0)
{
this.initiate();
}
if (this.ticks >= Long.MAX_VALUE)
{
this.ticks = 1;
}
this.ticks++;
}
/** Called on the TileEntity's first tick. */
public void initiate()
{
}
@Override
public int getBlockMetadata()
{
if (this.blockMetadata == -1)
{
this.blockMetadata = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord);
}
return this.blockMetadata;
}
@Override
public Block getBlockType()
{
if (this.blockType == null)
{
this.blockType = Block.blocksList[this.worldObj.getBlockId(this.xCoord, this.yCoord, this.zCoord)];
}
return this.blockType;
}
}

View file

@ -16,6 +16,7 @@ import calclavia.lib.access.AccessUser;
import calclavia.lib.access.GroupRegistry;
import calclavia.lib.access.ISpecialAccess;
import calclavia.lib.access.Nodes;
import calclavia.lib.prefab.tile.TileAdvanced;
import com.builtbroken.minecraft.interfaces.IExternalInv;
import com.builtbroken.minecraft.interfaces.IInvBox;
@ -27,7 +28,7 @@ import com.builtbroken.minecraft.tilenetwork.prefab.NetworkTileEntities;
*
* @author Darkguardsman
*/
public class TileEntityInv extends TileEntityAdvanced implements IExternalInv, ISidedInventory, ISpecialAccess
public class TileEntityInv extends TileAdvanced implements IExternalInv, ISidedInventory, ISpecialAccess
{
protected IInvBox inventory;
protected boolean lockInv;

View file

@ -185,7 +185,7 @@ public abstract class TileEntityMachine extends TileEntityInv implements ISidedI
}
if (id.equalsIgnoreCase(SimplePacketTypes.NBT.name))
{
this.readFromNBT(PacketHandler.instance().readNBTTagCompound(dis));
this.readFromNBT(PacketHandler.readNBTTagCompound(dis));
return true;
}
}
@ -204,7 +204,7 @@ public abstract class TileEntityMachine extends TileEntityInv implements ISidedI
{
NBTTagCompound tag = new NBTTagCompound();
this.writeToNBT(tag);
PacketHandler.instance().sendPacketToClients(PacketHandler.instance().getTilePacket(this.getChannel(), SimplePacketTypes.NBT.name, this, tag), worldObj, new Vector3(this), 64);
PacketHandler.sendPacketToClients(PacketHandler.getTilePacket(this.getChannel(), SimplePacketTypes.NBT.name, this, tag), worldObj, new Vector3(this), 64);
}
}

View file

@ -1,135 +0,0 @@
package com.builtbroken.minecraft.prefab;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import resonantinduction.core.network.ISimplePacketReceiver;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.network.PacketHandler;
import com.builtbroken.minecraft.DarkCore;
import com.builtbroken.minecraft.interfaces.IBlockActivated;
import com.builtbroken.minecraft.interfaces.IMultiBlock;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.Player;
public class TileEntityMulti extends TileEntity implements ISimplePacketReceiver
{
private Vector3 hostPosition;
public Vector3 getMainBlock()
{
if (this.hostPosition != null)
{
return new Vector3(this).translate(this.hostPosition);
}
return null;
}
public void setMainBlock(Vector3 mainBlock)
{
this.hostPosition = mainBlock.clone().translate(new Vector3(this).invert());
if (!this.worldObj.isRemote)
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}
@Override
public Packet getDescriptionPacket()
{
if (this.hostPosition != null)
{
return PacketHandler.instance().getTilePacket(DarkCore.CHANNEL, "desc", this, this.hostPosition.intX(), this.hostPosition.intY(), this.hostPosition.intZ());
}
return null;
}
@Override
public boolean simplePacket(String id, ByteArrayDataInput data, Player player)
{
try
{
if (id.equalsIgnoreCase("desc"))
{
this.hostPosition = new Vector3(data.readInt(), data.readInt(), data.readInt());
return true;
}
}
catch (Exception e)
{
e.printStackTrace();
return true;
}
return false;
}
public void onBlockRemoval(BlockMulti block)
{
if (this.getMainBlock() != null)
{
TileEntity tileEntity = this.getMainBlock().getTileEntity(this.worldObj);
if (tileEntity instanceof IMultiBlock)
{
block.destroyMultiBlockStructure((IMultiBlock) tileEntity);
}
}
}
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer entityPlayer)
{
if (this.getMainBlock() != null)
{
TileEntity tileEntity = this.getMainBlock().getTileEntity(this.worldObj);
if (tileEntity instanceof IBlockActivated)
{
return ((IBlockActivated) tileEntity).onActivated(entityPlayer);
}
}
return false;
}
/** Reads a tile entity from NBT. */
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
if (nbt.hasKey("mainBlockPosition"))
{
this.hostPosition = new Vector3(nbt.getCompoundTag("mainBlockPosition"));
}
}
/** Writes a tile entity to NBT. */
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
if (this.hostPosition != null)
{
nbt.setCompoundTag("mainBlockPosition", this.hostPosition.writeToNBT(new NBTTagCompound()));
}
}
/**
* Determines if this TileEntity requires update calls.
*
* @return True if you want updateEntity() to be called, false if not
*/
@Override
public boolean canUpdate()
{
return false;
}
}

View file

@ -1,565 +0,0 @@
package com.builtbroken.minecraft.recipes;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBucket;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import com.builtbroken.common.Pair;
import cpw.mods.fml.relauncher.ReflectionHelper;
/**
* Rewrite of the imprinter crafting system into its own manageable class
*
* @author DarkGuardsman
*/
public class AutoCraftingManager
{
static boolean doDebug = false;
TileEntity craftingEntity;
IInventory craftingInv;
/** The entity must be an instance of IInventory to pass only the tileEntity */
public AutoCraftingManager(final IAutoCrafter entity)
{
this.craftingEntity = (TileEntity) entity;
if (entity instanceof IInventory)
{
this.craftingInv = (IInventory) entity;
}
}
/** Use only the entity if it is also an instance of IInventory */
public AutoCraftingManager(final IAutoCrafter entity, final IInventory inv)
{
this(entity);
if (inv != null)
{
this.craftingInv = inv;
}
}
public void printDebug(String pre, String msg)
{
if (doDebug)
{
System.out.println("[AutoCrafter]: " + pre + " > " + msg);
}
}
public static void printRecipe(Object[] objects)
{
// TODO format and make it look nice
for (Object obj : objects)
{
System.out.println(obj);
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void printRecipes(ItemStack stack)
{
List<IRecipe> recipes = getRecipes(stack);
for (IRecipe recipe : recipes)
{
if (recipe.getRecipeOutput() != null)
{
if (AutoCraftingManager.areStacksEqual(recipe.getRecipeOutput(), stack))
{
if (recipe instanceof ShapedRecipes)
{
printRecipe(((ShapedRecipes) recipe).recipeItems);
}
else if (recipe instanceof ShapelessRecipes)
{
printRecipe(((ShapelessRecipes) recipe).recipeItems.toArray(new Object[1]));
}
else if (recipe instanceof ShapedOreRecipe)
{
ShapedOreRecipe oreRecipe = (ShapedOreRecipe) recipe;
printRecipe((Object[]) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, "input"));
}
else if (recipe instanceof ShapelessOreRecipe)
{
ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) recipe;
ArrayList oreRecipeInput = (ArrayList) ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input");
for (Object obj : oreRecipeInput)
{
System.out.println(obj);
}
}
}
}
}
}
/** Grabs a list of recipes that can be used to create the given item */
public static List<IRecipe> getRecipes(ItemStack stack)
{
List<IRecipe> recipes = new ArrayList<IRecipe>();
for (Object object : CraftingManager.getInstance().getRecipeList())
{
if (object instanceof IRecipe)
{
if (((IRecipe) object).getRecipeOutput() != null)
{
if (AutoCraftingManager.areStacksEqual(stack, ((IRecipe) object).getRecipeOutput()))
{
recipes.add((IRecipe) object);
}
}
}
}
return recipes;
}
/**
* Does this player's inventory contain the required resources to craft this item?
*
* @return Required items to make the desired item.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public Pair<ItemStack, ItemStack[]> getIdealRecipe(ItemStack outputItem)
{
this.printDebug("IdealRecipe", outputItem.toString());
for (Object object : CraftingManager.getInstance().getRecipeList())
{
if (object instanceof IRecipe)
{
if (((IRecipe) object).getRecipeOutput() != null)
{
if (AutoCraftingManager.areStacksEqual(outputItem, ((IRecipe) object).getRecipeOutput()))
{
this.printDebug("IdealRecipe", "Output Match Found");
if (object instanceof ShapedRecipes)
{
if (this.hasResource(((ShapedRecipes) object).recipeItems) != null)
{
this.printDebug("IdealRecipe", "Shaped Recipe Found");
return new Pair<ItemStack, ItemStack[]>(((IRecipe) object).getRecipeOutput().copy(), ((ShapedRecipes) object).recipeItems);
}
}
else if (object instanceof ShapelessRecipes)
{
if (this.hasResource(((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[1])) != null)
{
this.printDebug("IdealRecipe", "Shapeless Recipe Found");
return new Pair<ItemStack, ItemStack[]>(((IRecipe) object).getRecipeOutput().copy(), (ItemStack[]) ((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[1]));
}
}
else if (object instanceof ShapedOreRecipe)
{
ShapedOreRecipe oreRecipe = (ShapedOreRecipe) object;
Object[] oreRecipeInput = (Object[]) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, "input");
ArrayList<ItemStack> hasResources = this.hasResource(oreRecipeInput);
if (hasResources != null)
{
this.printDebug("IdealRecipe", "ShapedOre Recipe Found");
return new Pair<ItemStack, ItemStack[]>(((IRecipe) object).getRecipeOutput().copy(), hasResources.toArray(new ItemStack[1]));
}
}
else if (object instanceof ShapelessOreRecipe)
{
ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) object;
ArrayList oreRecipeInput = (ArrayList) ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input");
List<ItemStack> hasResources = this.hasResource(oreRecipeInput.toArray());
if (hasResources != null)
{
this.printDebug("IdealRecipe", "ShapelessOre Recipe Found");
return new Pair<ItemStack, ItemStack[]>(((IRecipe) object).getRecipeOutput().copy(), hasResources.toArray(new ItemStack[1]));
}
}
}
}
}
}
return null;
}
/**
* Gets a basic array containing all items that were used to craft the given item. Doesn't sort
* threw the recipes and will return the first possible recipe
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static ItemStack[] getReverseRecipe(ItemStack outputItem, int outputSize)
{
for (Object object : CraftingManager.getInstance().getRecipeList())
{
if (object instanceof IRecipe)
{
if (((IRecipe) object).getRecipeOutput() != null)
{
if (((IRecipe) object).getRecipeOutput().isItemEqual(outputItem) && (outputSize == -1 || ((IRecipe) object).getRecipeOutput().stackSize == outputItem.stackSize))
{
if (object instanceof ShapedRecipes)
{
return ((ShapedRecipes) object).recipeItems.clone();
}
else if (object instanceof ShapelessRecipes)
{
return (ItemStack[]) ((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[9]).clone();
}
else if (object instanceof ShapedOreRecipe)
{
ShapedOreRecipe oreRecipe = (ShapedOreRecipe) object;
Object[] recipeItems = (Object[]) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, "input");
ItemStack[] actualResources;
if (recipeItems != null)
{
actualResources = new ItemStack[recipeItems.length];
for (int i = 0; i < recipeItems.length; i++)
{
if (recipeItems[i] instanceof ItemStack)
{
actualResources[i] = ((ItemStack) recipeItems[i]).copy();
}
else if (recipeItems[i] instanceof ArrayList)
{
Object[] ingredientsArray = ((ArrayList) recipeItems[i]).toArray();
for (int x = 0; x < ingredientsArray.length; x++)
{
if (ingredientsArray[x] != null && ingredientsArray[x] instanceof ItemStack)
{
actualResources[i] = ((ItemStack) ingredientsArray[x]).copy();
break;
}
}
}
}
return actualResources;
}
}
else if (object instanceof ShapelessOreRecipe)
{
ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) object;
return (ItemStack[]) ((ArrayList) ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input")).toArray(new ItemStack[9]).clone();
}
}
}
}
}
return null;
}
/**
* Gets the itemStacks in the inv based on slots
*
* @param inv - @IInventory instance
* @param slots - slot # to be used
* @return array of itemStack the same size as the slots input array
*/
public ItemStack[] getInvItems(IInventory inv, int... slots)
{
ItemStack[] containingItems = new ItemStack[slots.length];
for (int slot = 0; slot < slots.length; slot++)
{
if (inv.getStackInSlot(slots[slot]) != null)
{
containingItems[slot] = inv.getStackInSlot(slots[slot]).copy();
}
}
return containingItems;
}
/**
* Returns if the following inventory has the following resource required.
*
* @param recipeItems - The items to be checked for the recipes.
*/
@SuppressWarnings("rawtypes")
public ArrayList<ItemStack> hasResource(Object[] recipeItems)
{
try
{
ItemStack[] containingItems = this.getInvItems(this.craftingInv, ((IAutoCrafter) this.craftingEntity).getCraftingInv());
this.printDebug("ResourceChecker", "Looking for items");
for (int i = 0; i < recipeItems.length && AutoCraftingManager.doDebug; i++)
{
this.printDebug("ResourceChecker", "Looking for " + recipeItems.toString());
}
/**
* The actual amount of resource required. Each ItemStack will only have stacksize of 1.
*/
ArrayList<ItemStack> actualResources = new ArrayList<ItemStack>();
int itemMatch = 0;
int itemInList = 0;
for (Object obj : recipeItems)
{
itemInList++;
if (obj instanceof ItemStack)
{
ItemStack recipeItem = (ItemStack) obj;
actualResources.add(recipeItem.copy());
if (recipeItem != null)
{
this.printDebug("ResourceChecker", "Item0" + itemInList + " = " + recipeItem.toString());
int match = this.doesItemExist(recipeItem, containingItems);
if (match >= 0)
{
containingItems[match] = AutoCraftingManager.decrStackSize(containingItems[match], recipeItem.stackSize);
this.printDebug("ResourceChecker", "Match found @" + match);
itemMatch++;
}
}
}
else if (obj instanceof ArrayList)
{
/** Look for various possible ingredients of the same item and try to match it. */
ArrayList ingredientsList = (ArrayList) obj;
Object[] ingredientsArray = ingredientsList.toArray();
this.printDebug("ResourceChecker", "Obj0" + itemInList + " = " + obj.toString());
for (int x = 0; x < ingredientsArray.length; x++)
{
if (ingredientsArray[x] != null && ingredientsArray[x] instanceof ItemStack)
{
ItemStack recipeItem = (ItemStack) ingredientsArray[x];
actualResources.add(recipeItem.copy());
if (recipeItem != null)
{
int match = this.doesItemExist(recipeItem, containingItems);
if (match >= 0)
{
containingItems[match] = AutoCraftingManager.decrStackSize(containingItems[match], recipeItem.stackSize);
this.printDebug("ResourceChecker", "Match found @" + match);
itemMatch++;
break;
}
}
}
}
}
else
{
this.printDebug("ResourceChecker", "Item0" + itemInList + " = null");
}
}
boolean resourcesFound = itemMatch >= actualResources.size();
this.printDebug("ResourceChecker", actualResources.size() + " items needed and " + itemMatch + " valid matches found");
this.printDebug("ResourceChecker", "has all resources been found? /n A: " + resourcesFound);
return resourcesFound ? actualResources : null;
}
catch (Exception e)
{
System.out.println("Failed to find recipes in the imprinter.");
e.printStackTrace();
}
return null;
}
/**
* Decreases the stack by a set amount
*
* @param stack - starting stack
* @param amount - amount of items
* @return the edited stack
*/
public static ItemStack decrStackSize(ItemStack stack, int amount)
{
if (stack != null)
{
ItemStack itemStack = stack.copy();
if (itemStack.stackSize <= amount)
{
return null;
}
else
{
itemStack.stackSize -= amount;
if (itemStack.stackSize <= 0)
{
return null;
}
return itemStack;
}
}
else
{
return null;
}
}
/**
* Checks if an item exist within the inv array
*
* @param recipeItem - itemstack being searched for
* @param containingItems - inv array containing the search bounds
* @return the point in the array the item was found -1 = the item was null or not valid -2 =
* the item was not found
*/
private int doesItemExist(ItemStack recipeItem, ItemStack[] containingItems)
{
if (recipeItem == null || recipeItem.itemID == 0 || recipeItem.stackSize <= 0)
{
return -1;
}
this.printDebug("ResourceChecker", "Checking inv for item " + recipeItem.toString());
for (int i = 0; i < containingItems.length; i++)
{
ItemStack checkStack = containingItems[i];
if (checkStack != null)
{
this.printDebug("ResourceChecker", " -----Item in slot0" + i + " = " + checkStack.toString());
if (AutoCraftingManager.areStacksEqual(recipeItem, checkStack))
{
this.printDebug("ResourceChecker", "Found matching item " + checkStack.toString());
return i;
}
}
}
return -2;
}
/**
* Checks if itemstack are equal based on crafting result rather than normal itemstack this is
* done so that if the itemstack returns with
*
* @param recipeItem - itemstack being compared
* @param checkStack - itemstack being comparted
* @return true if the items are a match for each other
*
* If the item can't be stack and is able to take damage the item will be check on damaged
* status
*
* If the item's meta data is not normal or in other words equals 32767 the meta data will be
* ignored
*/
public static boolean areStacksEqual(ItemStack recipeItem, ItemStack checkStack)
{
if (recipeItem == null || checkStack == null)
{
return false;
}
if (recipeItem.itemID < Block.blocksList.length && recipeItem.getItemDamage() == 32767)
{
return recipeItem.itemID == checkStack.itemID;
}
if (recipeItem.isItemStackDamageable())
{
return !recipeItem.isItemDamaged() && recipeItem.itemID == checkStack.itemID;
}
return recipeItem.isItemEqual(checkStack);
}
/**
* Consumes an item checking for extra conditions like container items
*
* @param stack - starting itemStack
* @param ammount - amount to consume
* @return what is left of the itemStack if any
*/
public static ItemStack consumeItem(ItemStack itemStack, int amount)
{
if (itemStack == null)
{
return null;
}
ItemStack stack = itemStack.copy();
if (stack.getItem() instanceof ItemBucket && stack.itemID != Item.bucketEmpty.itemID)
{
return new ItemStack(Item.bucketEmpty, 1);
}
if (stack.getItem().hasContainerItem())
{
ItemStack containerStack = stack.getItem().getContainerItemStack(stack);
if (containerStack.isItemStackDamageable() && containerStack.getItemDamage() > containerStack.getMaxDamage())
{
try
{
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(null, containerStack));
}
catch (Exception e)
{
}
return null;
}
if (containerStack != null && !stack.getItem().doesContainerItemLeaveCraftingGrid(stack))
{
return containerStack;
}
}
// System.out.println("ItemGrinder: "+stack.toString());
return decrStackSize(stack, amount);
}
/**
* Used to automatically remove selected items from crafting inv
*
* @param requiredItems - items that are to be removed
*/
public void consumeItems(ItemStack... requiredItems)
{
if (requiredItems != null)
{
for (ItemStack searchStack : requiredItems)
{
if (searchStack != null)
{
int[] invSlots = ((IAutoCrafter) this.craftingEntity).getCraftingInv();
for (int i = 0; i < invSlots.length; i++)
{
ItemStack checkStack = this.craftingInv.getStackInSlot(invSlots[i]);
if (checkStack != null)
{
if (AutoCraftingManager.areStacksEqual(searchStack, checkStack))
{
this.craftingInv.setInventorySlotContents(invSlots[i], AutoCraftingManager.consumeItem(checkStack, 1));
break;
}
}
}
}
}
}
}
public static interface IAutoCrafter
{
/** The slots used by the crafter for resources */
public int[] getCraftingInv();
}
}

View file

@ -7,6 +7,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import calclavia.lib.utility.AutoCraftingManager;
import com.builtbroken.common.Pair;

View file

@ -1,12 +0,0 @@
package com.builtbroken.minecraft.save;
import net.minecraft.nbt.NBTTagCompound;
public interface ISaveObj
{
/** Saves the object to NBT */
public void save(NBTTagCompound nbt);
/** Load the object from NBT */
public void load(NBTTagCompound nbt);
}

View file

@ -1,22 +0,0 @@
package com.builtbroken.minecraft.save;
import java.io.File;
/**
* Used in combination with the save manager and other managers to say this object needs to be save
* since its not connected with the world
*
* @author DarkGuardsman
*/
public interface IVirtualObject extends ISaveObj
{
/** File this is saved as, don't create anything here as the manager will do that for you */
public File getSaveFile();
/**
* Will only be called after an object has been loaded. Allows the object to know were its been
* loaded from and decide if it wants to use the location as its getSaveFile return
*/
public void setSaveFile(File file);
}

View file

@ -1,356 +0,0 @@
package com.builtbroken.minecraft.save;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagByteArray;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.nbt.NBTTagLong;
import net.minecraft.nbt.NBTTagShort;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.server.MinecraftServer;
import universalelectricity.api.vector.Vector2;
import universalelectricity.api.vector.Vector3;
import com.builtbroken.common.science.units.UnitHelper;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
/**
* Helper class used to work with minecraft's NBT file system.
*
* @author DarkGuardsman
*/
public class NBTFileHelper
{
/**
* @param saveDirectory - file
* @param filename
* @param data
* @return
*/
public static boolean saveNBTFile(File saveDirectory, String filename, NBTTagCompound data)
{
return saveNBTFile(new File(saveDirectory, filename), data);
}
/**
* Saves an NBT file
*
* @param file - exact File
* @param data - nbt data
* @return
*/
public static boolean saveNBTFile(File file, NBTTagCompound data)
{
if (file != null && data != null)
{
try
{
File tempFile = new File(file.getParent(), file.getName() + ".tmp");
CompressedStreamTools.writeCompressed(data, new FileOutputStream(tempFile));
if (file.exists())
{
file.delete();
}
tempFile.renameTo(file);
FMLLog.fine("Saved " + file.getName() + " NBT data file successfully.");
return true;
}
catch (Exception e)
{
System.out.println("Failed to save " + file.getName());
e.printStackTrace();
}
}
return false;
}
/**
* Uses the default world directory to save the data to file by the given name
*
* @param filename - file name
* @param data - nbt data
* @return true if everything goes well
*/
public static boolean saveNBTFile(String filename, NBTTagCompound data)
{
return saveNBTFile(getWorldSaveDirectory(MinecraftServer.getServer().getFolderName()), filename + ".dat", data);
}
/**
* Reads NBT data from the world folder.
*
* @return The NBT data
*/
public static NBTTagCompound loadNBTFile(File saveDirectory, String filename, boolean create)
{
if (saveDirectory != null && filename != null)
{
if (create && !saveDirectory.exists())
{
saveDirectory.mkdirs();
}
return loadNBTFile(new File(saveDirectory, filename + ".dat"), create);
}
return null;
}
public static NBTTagCompound loadNBTFile(File file, boolean create)
{
if (file != null)
{
try
{
if (file.exists())
{
FMLLog.fine("Loaded " + file.getName() + " data.");
return CompressedStreamTools.readCompressed(new FileInputStream(file));
}
else if (create)
{
FMLLog.fine("Created new " + file.getName() + " data.");
return new NBTTagCompound();
}
}
catch (Exception e)
{
System.out.println("Failed to load " + file.getName() + ".dat!");
e.printStackTrace();
return null;
}
}
return null;
}
/**
* Loads an NBT file from the current world file
*
* @param filename - name of the file
* @return NBTTagCompound that was stored in the file
*/
public static NBTTagCompound loadNBTFile(String filename)
{
return loadNBTFile(getWorldSaveDirectory(MinecraftServer.getServer().getFolderName()), filename, true);
}
public static File getWorldSaveDirectory(String worldName)
{
File parent = getBaseDirectory();
if (FMLCommonHandler.instance().getSide().isClient())
{
parent = new File(getBaseDirectory(), "saves" + File.separator);
}
return new File(parent, worldName + File.separator);
}
public static File getBaseDirectory()
{
if (FMLCommonHandler.instance().getSide().isClient())
{
FMLClientHandler.instance().getClient();
return Minecraft.getMinecraft().mcDataDir;
}
else
{
return new File(".");
}
}
/**
* Used to save an object without knowing what the object is exactly. Supports most
* NBTTagCompound save methods including some special cases. Which includes boolean being saves
* as a string so it can be loaded as a boolean from an object save.
*
* @param tag - NBTTagCompound to save the tag too
* @param key - name to save the object as
* @param value - the actual object
* @return the tag when done saving too i
*/
public static NBTTagCompound saveObject(NBTTagCompound tag, String key, Object value)
{
if (value instanceof Float)
{
tag.setFloat(key, (Float) value);
}
else if (value instanceof Double)
{
tag.setDouble(key, (Double) value);
}
else if (value instanceof Integer)
{
tag.setInteger(key, (Integer) value);
}
else if (value instanceof String)
{
tag.setString(key, (String) value);
}
else if (value instanceof Short)
{
tag.setShort(key, (Short) value);
}
else if (value instanceof Byte)
{
tag.setByte(key, (Byte) value);
}
else if (value instanceof Long)
{
tag.setLong(key, (Long) value);
}
else if (value instanceof Boolean)
{
tag.setString(key, "NBT:SAVE:BOOLEAN:" + value);
}
else if (value instanceof NBTBase)
{
tag.setTag(key, (NBTBase) value);
}
else if (value instanceof String)
{
tag.setString(key, (String) value);
}
else if (value instanceof byte[])
{
tag.setByteArray(key, (byte[]) value);
}
else if (value instanceof int[])
{
tag.setIntArray(key, (int[]) value);
}
else if (value instanceof NBTTagCompound)
{
tag.setCompoundTag(key, (NBTTagCompound) value);
}
else if (value instanceof Vector2)
{
tag.setString(key, "NBT:SAVE:VECTOR:2:" + ((Vector2) value).x + ":" + ((Vector2) value).y);
}
else if (value instanceof Vector3)
{
tag.setString(key, "NBT:SAVE:VECTOR:3:" + ((Vector3) value).x + ":" + ((Vector3) value).y + ":" + ((Vector3) value).z);
}
return tag;
}
/**
* @param key
* @param value
* @return NBTTagCompound that then can be added to save file
*/
public static NBTTagCompound saveObject(String key, Object value)
{
return NBTFileHelper.saveObject(new NBTTagCompound(), key, value);
}
/**
* Reads an unknown object with a known name from NBT
*
* @param tag - tag to read the value from
* @param key - name of the value
* @param suggestionValue - value to return in case nothing is found
* @return object or suggestionValue if nothing is found
*/
public static Object loadObject(NBTTagCompound tag, String key)
{
if (tag != null && key != null)
{
NBTBase saveTag = tag.getTag(key);
if (saveTag instanceof NBTTagFloat)
{
return tag.getFloat(key);
}
else if (saveTag instanceof NBTTagDouble)
{
return tag.getDouble(key);
}
else if (saveTag instanceof NBTTagInt)
{
return tag.getInteger(key);
}
else if (saveTag instanceof NBTTagString)
{
String str = tag.getString(key);
if (str.startsWith("NBT:SAVE:"))
{
str.replaceAll("NBT:SAVE:", "");
if (str.startsWith("BOOLEAN:"))
{
str.replaceAll("BOOLEAN:", "");
if (str.equalsIgnoreCase("true"))
{
return true;
}
if (str.equalsIgnoreCase("false"))
{
return false;
}
}
if (str.startsWith("VECTOR:"))
{
str.replaceAll("VECTOR:", "");
String[] nums = str.split(":");
if (UnitHelper.tryToParseDouble(nums[0]) == 2)
{
return new Vector2(UnitHelper.tryToParseDouble(nums[1]), UnitHelper.tryToParseDouble(nums[2]));
}
if (UnitHelper.tryToParseDouble(nums[0]) == 3)
{
return new Vector3(UnitHelper.tryToParseDouble(nums[1]), UnitHelper.tryToParseDouble(nums[2]), UnitHelper.tryToParseDouble(nums[3]));
}
}
return null;
}
return str;
}
else if (saveTag instanceof NBTTagShort)
{
return tag.getShort(key);
}
else if (saveTag instanceof NBTTagByte)
{
return tag.getByte(key);
}
else if (saveTag instanceof NBTTagLong)
{
return tag.getLong(key);
}
else if (saveTag instanceof NBTBase)
{
return tag.getTag(key);
}
else if (saveTag instanceof NBTTagByteArray)
{
return tag.getByteArray(key);
}
else if (saveTag instanceof NBTTagIntArray)
{
return tag.getIntArray(key);
}
else if (saveTag instanceof NBTTagCompound)
{
return tag.getCompoundTag(key);
}
}
return null;
}
}

View file

@ -1,166 +0,0 @@
package com.builtbroken.minecraft.save;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.world.WorldEvent;
import cpw.mods.fml.common.FMLLog;
public class SaveManager
{
private static HashMap<String, Class<?>> idToClassMap = new HashMap<String, Class<?>>();
private static HashMap<Class<?>, String> classToIDMap = new HashMap<Class<?>, String>();
private static List<Object> saveList = new ArrayList<Object>();
private static List<Object> objects = new ArrayList<Object>();
private static SaveManager instance;
public static SaveManager instance()
{
if (instance == null)
{
instance = new SaveManager();
}
return instance;
}
/**
* Called when the object wants to be save only on the next save call. Will be removed from the
* save manager after
*/
public static void markNeedsSaved(Object object)
{
if (object instanceof IVirtualObject && !saveList.contains(object))
{
saveList.add(object);
}
}
/** Registers the object to be saved on each world save event */
public static void register(Object object)
{
if (object instanceof IVirtualObject && !objects.contains(object))
{
objects.add(object);
}
}
public static void registerClass(String id, Class clazz)
{
if (id != null && clazz != null)
{
if (idToClassMap.containsKey(id) && idToClassMap.get(id) != null)
{
System.out.println("[CoreMachine]SaveManager: Something attempted to register a class with the id of another class");
System.out.println("[CoreMachine]SaveManager: Id:" + id + " Class:" + clazz.getName());
System.out.println("[CoreMachine]SaveManager: OtherClass:" + idToClassMap.get(id).getName());
}
else
{
idToClassMap.put(id, clazz);
classToIDMap.put(clazz, id);
}
}
}
public static Object createAndLoad(File file)
{
if (file.exists())
{
Object obj = createAndLoad(NBTFileHelper.loadNBTFile(file, false));
if (obj instanceof IVirtualObject)
{
((IVirtualObject) obj).setSaveFile(file);
}
return obj;
}
return null;
}
/** Creates an object from the save using its id */
public static Object createAndLoad(NBTTagCompound par0NBTTagCompound)
{
Object obj = null;
if (par0NBTTagCompound != null && par0NBTTagCompound.hasKey("id"))
{
try
{
Class clazz = getClass(par0NBTTagCompound.getString("id"));
if (clazz != null)
{
obj = clazz.newInstance();
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
if (obj instanceof IVirtualObject)
{
try
{
((IVirtualObject) obj).load(par0NBTTagCompound);
}
catch (Exception e)
{
FMLLog.log(Level.SEVERE, e, "An object %s(%s) has thrown an exception during loading, its state cannot be restored. Report this to the mod author", par0NBTTagCompound.getString("id"), obj.getClass().getName());
obj = null;
}
}
else
{
MinecraftServer.getServer().getLogAgent().logWarning("Skipping object with id " + par0NBTTagCompound.getString("id"));
}
return obj;
}
return null;
}
@ForgeSubscribe
public void worldSave(WorldEvent evt)
{
SaveManager.saveList.addAll(SaveManager.objects);
for (Object object : SaveManager.saveList)
{
if (object instanceof IVirtualObject)
{
saveObject(object);
}
}
saveList.clear();
}
/** Saves an object along with its ID */
public static void saveObject(Object object)
{
if (object instanceof IVirtualObject && getID(object.getClass()) != null && ((IVirtualObject) object).getSaveFile() != null)
{
File file = ((IVirtualObject) object).getSaveFile();
file.mkdirs();
NBTTagCompound tag = new NBTTagCompound();
((IVirtualObject) object).save(tag);
tag.setString("id", getID(object.getClass()));
NBTFileHelper.saveNBTFile(file, tag);
}
}
/** Gets the ID that the class will be saved using */
public static String getID(Class clazz)
{
return classToIDMap.get(clazz);
}
/** Gets the class that was registered with the ID */
public static Class getClass(String id)
{
return idToClassMap.get(id);
}
}

View file

@ -5,8 +5,7 @@ import net.minecraft.world.World;
import net.minecraftforge.event.Cancelable;
import net.minecraftforge.event.Event;
import universalelectricity.api.vector.Vector3;
import com.builtbroken.minecraft.recipes.AutoCraftingManager.IAutoCrafter;
import calclavia.lib.utility.AutoCraftingManager.IAutoCrafter;
/**
* Events called when an automated crafter is working on crafting an item

View file

@ -6,8 +6,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import resonantinduction.api.coding.args.ArgumentData;
import universalelectricity.api.vector.Vector2;
import com.builtbroken.minecraft.save.ISaveObj;
import calclavia.lib.utility.ISaveObj;
/** @author DarkGuardsman */
public interface ITask extends Cloneable, ISaveObj

View file

@ -1,9 +1,7 @@
package resonantinduction.api.coding.args;
import net.minecraft.nbt.NBTTagCompound;
import com.builtbroken.minecraft.save.ISaveObj;
import com.builtbroken.minecraft.save.NBTFileHelper;
import calclavia.lib.utility.ISaveObj;
/**
* Used to store arguments in a way that can be easier to read, limit, and understand

View file

@ -28,8 +28,8 @@ import cofh.api.energy.IEnergyStorage;
import com.builtbroken.minecraft.DarkCore;
import com.builtbroken.minecraft.FluidHelper;
import com.builtbroken.minecraft.interfaces.IToolReadOut;
import com.builtbroken.minecraft.interfaces.IToolReadOut.EnumTools;
import com.builtbroken.minecraft.interfaces.IReadOut;
import com.builtbroken.minecraft.interfaces.IReadOut.EnumTools;
import com.builtbroken.minecraft.prefab.ItemBasic;
import com.builtbroken.minecraft.prefab.TileEntityEnergyMachine;
@ -105,9 +105,9 @@ public class ItemReadoutTools extends ItemBasic
if (tool != null)
{
ForgeDirection hitSide = ForgeDirection.getOrientation(side);
if (tileEntity instanceof IToolReadOut)
if (tileEntity instanceof IReadOut)
{
String output = ((IToolReadOut) tileEntity).getMeterReading(player, hitSide, tool);
String output = ((IReadOut) tileEntity).getMeterReading(player, hitSide, tool);
if (output != null && !output.isEmpty())
{
if (output.length() > 100)

View file

@ -21,7 +21,7 @@ import resonantinduction.transport.fluid.pipes.FluidPartsMaterial;
import com.builtbroken.minecraft.EnumMaterial;
import com.builtbroken.minecraft.EnumOrePart;
import com.builtbroken.minecraft.helpers.ColorCode;
import com.builtbroken.minecraft.interfaces.IToolReadOut.EnumTools;
import com.builtbroken.minecraft.interfaces.IReadOut.EnumTools;
import com.builtbroken.minecraft.recipes.MachineRecipeHandler;
import com.builtbroken.minecraft.recipes.ProcessorType;

View file

@ -14,7 +14,6 @@ import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.ResonantInductionTabs;
import resonantinduction.core.Settings;
import resonantinduction.energy.CommonProxy;
import resonantinduction.energy.ResonantInductionEnergy;
import universalelectricity.api.UniversalElectricity;
import universalelectricity.api.energy.IConductor;

View file

@ -14,8 +14,6 @@ import resonantinduction.api.coding.ITask;
import resonantinduction.api.coding.TaskRegistry;
import universalelectricity.api.vector.Vector2;
import com.builtbroken.minecraft.save.NBTFileHelper;
public class Program implements IProgram
{
protected Vector2 currentPos = new Vector2(0, 0);

View file

@ -11,8 +11,6 @@ import resonantinduction.api.coding.ITask;
import resonantinduction.api.coding.args.ArgumentData;
import universalelectricity.api.vector.Vector2;
import com.builtbroken.minecraft.save.NBTFileHelper;
/** @author DarkGuardsman */
public abstract class TaskBase implements ITask
{

View file

@ -2,8 +2,8 @@ package resonantinduction.mechanics.generator.solar;
import java.util.EnumSet;
import resonantinduction.mechanics.generator.TileGenerator;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.mechanics.generator.TileGenerator;
public class TileEntitySolarPanel extends TileGenerator
{

View file

@ -11,7 +11,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import resonantinduction.energy.battery.ContainerBatteryBox;
import resonantinduction.energy.battery.TileBatteryBox;
import resonantinduction.mechanics.generator.ContainerCoalGenerator;
import resonantinduction.mechanics.generator.steam.TileEntitySteamGen;
import resonantinduction.mechanics.processor.ContainerProcessor;
import resonantinduction.mechanics.processor.TileEntityProcessor;

View file

@ -42,7 +42,6 @@ import resonantinduction.core.resource.ItemOreDirv;
import resonantinduction.core.resource.ItemParts;
import resonantinduction.core.resource.ItemParts.Parts;
import resonantinduction.energy.battery.BlockBatteryBox;
import resonantinduction.energy.battery.ItemBattery;
import resonantinduction.energy.battery.ItemBlockEnergyStorage;
import resonantinduction.mechanics.armbot.BlockArmbot;
import resonantinduction.mechanics.armbot.command.TaskBreak;
@ -96,6 +95,7 @@ import resonantinduction.transport.vechicle.ItemVehicleSpawn;
import calclavia.lib.network.PacketHandler;
import calclavia.lib.ore.OreGenReplaceStone;
import calclavia.lib.ore.OreGenerator;
import calclavia.lib.utility.SaveManager;
import com.builtbroken.minecraft.CoreRegistry;
import com.builtbroken.minecraft.DarkCore;
@ -106,7 +106,6 @@ import com.builtbroken.minecraft.LaserEntityDamageSource;
import com.builtbroken.minecraft.TranslationHelper;
import com.builtbroken.minecraft.helpers.PlayerKeyHandler;
import com.builtbroken.minecraft.prefab.ItemBlockHolder;
import com.builtbroken.minecraft.save.SaveManager;
import com.builtbroken.minecraft.tilenetwork.prefab.NetworkUpdateHandler;
import cpw.mods.fml.common.Loader;

View file

@ -15,7 +15,6 @@ import resonantinduction.client.render.BlockRenderHelper;
import com.builtbroken.common.Pair;
import com.builtbroken.minecraft.FluidHelper;
import com.builtbroken.minecraft.prefab.TileEntityAdvanced;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

View file

@ -10,8 +10,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import resonantinduction.transport.fluid.network.IFluidRecipeCrafter;
import resonantinduction.transport.fluid.network.FluidRecipeInfo.SimpleFluidRecipe;
import resonantinduction.transport.fluid.network.IFluidRecipeCrafter;
import com.builtbroken.common.Pair;
import com.builtbroken.common.Triple;

View file

@ -11,10 +11,10 @@ import resonantinduction.transport.fluid.network.NetworkPipes;
import resonantinduction.transport.fluid.prefab.TileEntityFluidDevice;
import com.builtbroken.minecraft.helpers.HelperMethods;
import com.builtbroken.minecraft.interfaces.IToolReadOut;
import com.builtbroken.minecraft.interfaces.IReadOut;
import com.builtbroken.minecraft.tilenetwork.ITileConnector;
public class TileEntityReleaseValve extends TileEntityFluidDevice implements ITileConnector, IToolReadOut
public class TileEntityReleaseValve extends TileEntityFluidDevice implements ITileConnector, IReadOut
{
public TileEntity[] connected = new TileEntity[6];

View file

@ -4,13 +4,13 @@ import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.ForgeDirection;
import calclavia.lib.prefab.tile.TileAdvanced;
import com.builtbroken.minecraft.interfaces.IToolReadOut;
import com.builtbroken.minecraft.prefab.TileEntityAdvanced;
import com.builtbroken.minecraft.interfaces.IReadOut;
import com.builtbroken.minecraft.tilenetwork.ITileConnector;
import com.builtbroken.minecraft.tilenetwork.prefab.NetworkTileEntities;
public abstract class TileEntityFluidDevice extends TileEntityAdvanced implements IToolReadOut, ITileConnector
public abstract class TileEntityFluidDevice extends TileAdvanced implements IReadOut, ITileConnector
{
public Random random = new Random();

View file

@ -15,11 +15,11 @@ import universalelectricity.api.vector.Vector3;
import com.builtbroken.common.Pair;
import com.builtbroken.minecraft.FluidHelper;
import com.builtbroken.minecraft.interfaces.IToolReadOut;
import com.builtbroken.minecraft.interfaces.IReadOut;
import com.builtbroken.minecraft.prefab.TileEntityEnergyMachine;
import com.builtbroken.minecraft.tilenetwork.ITileConnector;
public class TileEntityStarterPump extends TileEntityEnergyMachine implements IToolReadOut, ITileConnector
public class TileEntityStarterPump extends TileEntityEnergyMachine implements IReadOut, ITileConnector
{
private int currentWorldEdits, MAX_WORLD_EDITS_PER_PROCESS;

View file

@ -15,13 +15,12 @@ import resonantinduction.api.IArmbot;
import resonantinduction.api.IArmbotUseable;
import resonantinduction.api.coding.args.ArgumentData;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.utility.AutoCraftingManager;
import calclavia.lib.utility.AutoCraftingManager.IAutoCrafter;
import com.builtbroken.common.Pair;
import com.builtbroken.minecraft.TranslationHelper;
import com.builtbroken.minecraft.prefab.TileEntityAdvanced;
import com.builtbroken.minecraft.prefab.invgui.ISlotPickResult;
import com.builtbroken.minecraft.recipes.AutoCraftingManager;
import com.builtbroken.minecraft.recipes.AutoCraftingManager.IAutoCrafter;
public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInventory, IArmbotUseable, ISlotPickResult, IAutoCrafter
{