Started working on tiered crafting tables

Also founds some files CMD missed
This commit is contained in:
Robert 2013-12-28 20:02:46 -05:00
parent 2e6357787c
commit 99143865cc
7 changed files with 458 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

View file

@ -0,0 +1,89 @@
package com.builtbroken.assemblyline.crafting;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import com.builtbroken.assemblyline.AssemblyLine;
import com.builtbroken.minecraft.prefab.BlockMachine;
/** Advanced tiering of a crafting table adding advanced features such as visual crafting, and auto
* crafting. Original idea by Infinite
*
* @author DarkGuardsman */
public class BlockCraftingTable extends BlockMachine
{
public BlockCraftingTable()
{
super(AssemblyLine.CONFIGURATION, "CraftingTable", Material.rock);
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileEntityCraftingTable();
}
@Override
public TileEntity createTileEntity(World world, int metadata)
{
if (metadata >= 0 && metadata < CraftingTables.values().length)
{
CraftingTables table = CraftingTables.values()[metadata];
if (table.enabled && table.tileClass != null)
{
try
{
return table.tileClass.newInstance();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
return super.createTileEntity(world, metadata);
}
public static enum CraftingTables
{
/** Upgraded wooden crafting table, stores items, and contains a small inventory */
ADVANCED(),
/** Stone version of the advanced, renders end result of crafting on surface */
STONE(),
/** Iron version of stone adding ability to repair armor */
IRON(),
/** Upgraded version of the iron allowing repair of tools, as well upgrades of tools */
STEEL(),
/** First work bench that can be combined with robotics to auto craft items */
AUTOMATED(),
/** Crafting table that allows large long term projects to be made one item at a time */
PROJECT(),
/** Crafting table that allows industrial machines to be crafted */
INDUSTRIAL(),
/** Crafting table that allows advanced electronics to be crafted, also allows electronic
* devices to be designed */
ELECTRONICS(),
/** Upgraded auto table that can use blueprints, works faster, and do some cool tricks */
INDUSTRIAL_AUTOMATED(),
/** Auto crafting version of the electronics table, allows autocrafting of custom devices */
ELECTRONICS_AUTOMATED(),
/** Auto crafting table that allows long term projects to be made one item at a time */
AUTOMATED_PROJECT();
public final boolean enabled;
public Class<? extends TileEntity> tileClass = null;
private CraftingTables()
{
this(false);
}
private CraftingTables(boolean enabled)
{
this.enabled = enabled;
}
}
}

View file

@ -0,0 +1,8 @@
package com.builtbroken.assemblyline.crafting;
import com.builtbroken.minecraft.prefab.TileEntityInv;
public class TileEntityCraftingTable extends TileEntityInv
{
}

View file

@ -0,0 +1,160 @@
package com.builtbroken.assemblyline.redstone;
import java.util.List;
import java.util.Set;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Facing;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import com.builtbroken.assemblyline.AssemblyLine;
import com.builtbroken.assemblyline.client.render.RenderAdvancedHopper;
import com.builtbroken.common.Pair;
import com.builtbroken.minecraft.IndustryTabs;
import com.builtbroken.minecraft.prefab.BlockMachine;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/** Block for an advanced version of the vanilla minecraft hopper
*
* @author DarkGuardsman */
public class BlockAdvancedHopper extends BlockMachine
{
@SideOnly(Side.CLIENT)
public static Icon hopperIcon;
@SideOnly(Side.CLIENT)
public static Icon hopperTopIcon;
@SideOnly(Side.CLIENT)
public static Icon hopperInsideIcon;
public BlockAdvancedHopper()
{
super(AssemblyLine.CONFIGURATION, "DMHopper", Material.iron);
this.setCreativeTab(IndustryTabs.tabAutomation());
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
/** Adds all intersecting collision boxes to a list. (Be sure to only add boxes to the list if
* they intersect the mask.) Parameters: World, X, Y, Z, mask, list, colliding entity */
@Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB box, List boxList, Entity entity)
{
float f = 0.125F;
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.625F, 1.0F);
super.addCollisionBoxesToList(world, x, y, z, box, boxList, entity);
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
super.addCollisionBoxesToList(world, x, y, z, box, boxList, entity);
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
super.addCollisionBoxesToList(world, x, y, z, box, boxList, entity);
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.addCollisionBoxesToList(world, x, y, z, box, boxList, entity);
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
super.addCollisionBoxesToList(world, x, y, z, box, boxList, entity);
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
@Override
public int onBlockPlaced(World world, int x, int y, int z, int side, float xSide, float ySide, float zSide, int meta)
{
meta = Facing.oppositeSide[side];
if (meta == 1)
{
meta = 0;
}
return meta;
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileEntityAdvancedHopper();
}
@Override
public void getTileEntities(int blockID, Set<Pair<String, Class<? extends TileEntity>>> list)
{
list.add(new Pair<String, Class<? extends TileEntity>>("DMTileHopper", TileEntityAdvancedHopper.class));
}
@Override
@SideOnly(Side.CLIENT)
public void getClientTileEntityRenderers(List<Pair<Class<? extends TileEntity>, TileEntitySpecialRenderer>> list)
{
list.add(new Pair<Class<? extends TileEntity>, TileEntitySpecialRenderer>(TileEntityAdvancedHopper.class, new RenderAdvancedHopper()));
}
/** The type of render function that is called for this block */
@Override
public int getRenderType()
{
return -1;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side)
{
return true;
}
@Override
@SideOnly(Side.CLIENT)
public Icon getIcon(int side, int meta)
{
return side == 1 ? BlockAdvancedHopper.hopperTopIcon : BlockAdvancedHopper.hopperIcon;
}
@Override
public boolean hasComparatorInputOverride()
{
return true;
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
BlockAdvancedHopper.hopperIcon = par1IconRegister.registerIcon("hopper_outside");
BlockAdvancedHopper.hopperTopIcon = par1IconRegister.registerIcon("hopper_top");
BlockAdvancedHopper.hopperInsideIcon = par1IconRegister.registerIcon("hopper_inside");
}
@Override
@SideOnly(Side.CLIENT)
public String getItemIconName()
{
return "hopper";
}
}

View file

@ -0,0 +1,19 @@
package com.builtbroken.assemblyline.redstone;
import net.minecraft.block.material.Material;
import com.builtbroken.assemblyline.AssemblyLine;
import com.builtbroken.minecraft.prefab.BlockMachine;
/** This will be a piston that can extend from 1 - 20 depending on teir and user settings
*
* @author Guardsman */
public class BlockPistonPlus extends BlockMachine
{
public BlockPistonPlus()
{
super(AssemblyLine.CONFIGURATION, "DMPiston", Material.piston);
}
}

View file

@ -0,0 +1,146 @@
package com.builtbroken.assemblyline.redstone;
import java.util.List;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.api.vector.Vector3;
import com.builtbroken.assemblyline.imprinter.ItemImprinter;
import com.builtbroken.assemblyline.imprinter.prefab.TileEntityFilterable;
import com.builtbroken.minecraft.helpers.DarksHelper;
import com.builtbroken.minecraft.helpers.InvInteractionHelper;
/** Advanced version of the hopper with features such as redstone control, sorting, filtering, and
* crate version.
*
* @author DarkGuardsman */
public class TileEntityAdvancedHopper extends TileEntityFilterable
{
public ForgeDirection connection = ForgeDirection.DOWN;
public boolean[] connections = new boolean[6];
public boolean singleConnection = true;
/** The class that interacts with inventories for this machine */
private InvInteractionHelper invExtractionHelper;
public TileEntityAdvancedHopper()
{
this.invSlots = 5;
}
/** Gets the class that managed extracting and placing items into inventories */
public InvInteractionHelper invHelper()
{
if (invExtractionHelper == null || invExtractionHelper.world != this.worldObj)
{
this.invExtractionHelper = new InvInteractionHelper(this.worldObj, new Vector3(this), this.getFilter() != null ? ItemImprinter.getFilters(getFilter()) : null, this.isInverted());
}
return invExtractionHelper;
}
/** Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner
* uses this to count ticks and creates a new spawn inside its implementation. */
@Override
public void updateEntity()
{
super.updateEntity();
if (!this.worldObj.isRemote && this.ticks % 8 == 0)
{
this.grabItems();
this.dumpItems();
}
}
public void grabItems()
{
Vector3 inputPos = this.getThisPos().clone().modifyPositionFromSide(ForgeDirection.UP);
List<EntityItem> itemsInBound = DarksHelper.getEntitiesInDirection(worldObj, this.getThisPos(), ForgeDirection.UP);
ItemStack itemStack = invHelper().tryGrabFromPosition(inputPos, ForgeDirection.UP, 1);
if (itemStack != null)
{
itemStack = invHelper().tryPlaceInPosition(itemStack, this.getThisPos(), ForgeDirection.UNKNOWN);
if (itemStack != null)
{
itemStack = invHelper().tryPlaceInPosition(itemStack, inputPos, ForgeDirection.DOWN);
if (itemStack != null)
{
invHelper().throwItem(inputPos, itemStack);
}
}
}
else if (inputPos.getTileEntity(worldObj) == null && itemsInBound != null)
{
for (EntityItem entity : itemsInBound)
{
if (entity.isDead)
{
continue;
}
ItemStack remainingStack = entity.getEntityItem().copy();
if (this.getFilter() == null || this.isFiltering(remainingStack))
{
if (remainingStack != null)
{
remainingStack = invHelper().tryPlaceInPosition(itemStack, this.getThisPos(), ForgeDirection.UNKNOWN);
}
if (remainingStack == null || remainingStack.stackSize <= 0)
{
entity.setDead();
}
else
{
entity.setEntityItemStack(remainingStack);
}
}
}
}
}
public void dumpItems()
{
Vector3 outputPos = this.getThisPos().clone().modifyPositionFromSide(this.connection);
for (int slot = 0; slot < this.getInventory().getSizeInventory(); slot++)
{
if (this.getInventory().getStackInSlot(slot) != null)
{
ItemStack stack = this.getInventory().getStackInSlot(slot).copy();
if (this.getFilter() == null || this.isFiltering(stack))
{
stack = this.invHelper().tryGrabFromPosition(outputPos, this.connection.getOpposite(), 1);
if (stack == null || !areItemStacksEqualItem(stack, this.getInventory().getStackInSlot(slot)) || this.getInventory().getStackInSlot(slot).stackSize != stack.stackSize)
{
this.getInventory().setInventorySlotContents(slot, stack);
this.onInventoryChanged();
}
}
}
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
}
@Override
public String getInvName()
{
return "container.advancedhopper";
}
private static boolean areItemStacksEqualItem(ItemStack stack, ItemStack stack2)
{
return stack.itemID != stack2.itemID ? false : (stack.getItemDamage() != stack2.getItemDamage() ? false : (stack.stackSize > stack.getMaxStackSize() ? false : ItemStack.areItemStackTagsEqual(stack, stack2)));
}
}

View file

@ -0,0 +1,36 @@
package com.builtbroken.assemblyline.redstone;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import universalelectricity.api.vector.Vector3;
import com.builtbroken.minecraft.interfaces.IMultiBlock;
import com.builtbroken.minecraft.prefab.TileEntityMachine;
public class TileEntityPistonPlus extends TileEntityMachine implements IMultiBlock
{
int extensionLimit = 1;
boolean isExtended = false;
@Override
public boolean onActivated(EntityPlayer entityPlayer)
{
// TODO Auto-generated method stub
return false;
}
@Override
public void onCreate(Vector3 placedPosition)
{
//Don't do anything here as we will handle this in the update area
}
@Override
public void onDestroy(TileEntity callingBlock)
{
// TODO Auto-generated method stub
}
}