mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-27 23:45:55 +00:00
Merge branch 'master' of https://github.com/CrazyPants/EnderIO.git
This commit is contained in:
commit
4c800028fe
8 files changed
+214
-10
No files matched your search
@@ -0,0 +1,24 @@
|
||||
package cofh.api.inventory;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface on TileEntities which should connect to item transportation blocks.
|
||||
*/
|
||||
public interface IInventoryConnection {
|
||||
|
||||
/**
|
||||
* @param from
|
||||
* Side to which a connector would connect
|
||||
* @return DEFAULT if the connector should decide how to connect; FORCE if the connector should always connect; DENY if the connector should never connect.
|
||||
*/
|
||||
public ConnectionType canConnectInventory(ForgeDirection from);
|
||||
|
||||
public static enum ConnectionType {
|
||||
DEFAULT, FORCE, DENY;
|
||||
|
||||
public final boolean canConnect = ordinal() != 2;
|
||||
public final boolean forceConnect = ordinal() == 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package cofh.api.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface on TileEntities which should handle items.
|
||||
*
|
||||
* A reference implementation is provided {@link TileInventoryHandler}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IInventoryHandler extends IInventoryConnection {
|
||||
|
||||
/**
|
||||
* Insert an ItemStack into the IInventoryHandler, internal distribution is left entirely to the IInventoryHandler. This returns what is remaining of the
|
||||
* original stack - a null return means that the entire stack was accepted!
|
||||
*
|
||||
* @param from
|
||||
* Orientation the item is inserted from.
|
||||
* @param item
|
||||
* ItemStack to be inserted. The size of this stack corresponds to the maximum amount to insert.
|
||||
* @param simulate
|
||||
* If TRUE, the insertion will only be simulated.
|
||||
* @return An ItemStack representing how much is remaining after the item was inserted (or would have been, if simulated) into the container inventory.
|
||||
*/
|
||||
ItemStack insertItem(ForgeDirection from, ItemStack item, boolean simulate);
|
||||
|
||||
/**
|
||||
* Extract an ItemStack from an IInventoryHandler, internal distribution is left entirely to the IInventoryHandler. This returns the resulting stack - a
|
||||
* null return means that nothing was extracted!
|
||||
*
|
||||
* @param from
|
||||
* Orientation the item is extracted from.
|
||||
* @param item
|
||||
* ItemStack to be extracted. The size of this stack corresponds to the maximum amount to extract. If this is null, then a null ItemStack should
|
||||
* immediately be returned.
|
||||
* @param simulate
|
||||
* If TRUE, the extraction will only be simulated.
|
||||
* @return An ItemStack representing how much was extracted (or would have been, if simulated) from the container inventory.
|
||||
*/
|
||||
ItemStack extractItem(ForgeDirection from, ItemStack item, boolean simulate);
|
||||
|
||||
/**
|
||||
* Extract an ItemStack from an IInventoryHandler, internal distribution is left entirely to the IInventoryHandler. This returns the resulting stack - a
|
||||
* null return means that nothing was extracted!
|
||||
*
|
||||
* @param from
|
||||
* Orientation the item is extracted from.
|
||||
* @param maxExtract
|
||||
* Maximum number of items to extract. (The returned ItemStack should have a stackSize no higher than this.)
|
||||
* @param simulate
|
||||
* If TRUE, the extraction will only be simulated.
|
||||
* @return An ItemStack representing how much was extracted (or would have been, if simulated) from the container inventory.
|
||||
*/
|
||||
ItemStack extractItem(ForgeDirection from, int maxExtract, boolean simulate);
|
||||
|
||||
/**
|
||||
* Get the contents of the IInventoryHandler's inventory. This returns a COPY. This should only return non-null ItemStacks, and an empty List if the
|
||||
* inventory has nothing.
|
||||
*/
|
||||
List<ItemStack> getInventoryContents(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Get the size (number of internal slots) of the IInventoryHandler's inventory.
|
||||
*/
|
||||
int getSizeInventory(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns whether or not the IInventoryHandler's inventory is empty (for a given side).
|
||||
*/
|
||||
boolean isEmpty(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns whether or not the IInventoryHandler's inventory is full (for a given side).
|
||||
*/
|
||||
boolean isFull(ForgeDirection from);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package cofh.api.inventory;
|
||||
|
||||
/**
|
||||
* Marks a block which will retain its inventory when broken.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IInventoryRetainer {
|
||||
|
||||
// There's nothing else to go here at the moment. Potentially a conditional at a later date.
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* (C) 2014 Team CoFH / CoFH / Cult of the Full Hub
|
||||
* http://www.teamcofh.com
|
||||
*/
|
||||
@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHAPI", provides = "CoFHAPI|inventory")
|
||||
package cofh.api.inventory;
|
||||
|
||||
import cofh.api.CoFHAPIProps;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import cofh.api.inventory.IInventoryConnection;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -542,16 +543,15 @@ public class ItemConduit extends AbstractConduit implements IItemConduit {
|
||||
@Override
|
||||
public boolean canConnectToExternal(ForgeDirection direction, boolean ignoreDisabled) {
|
||||
IInventory inv = getExternalInventory(direction);
|
||||
if(inv instanceof ISidedInventory) {
|
||||
if (inv==null) return false;
|
||||
else if (inv instanceof IInventoryConnection){
|
||||
return ((IInventoryConnection)inv).canConnectInventory(direction.getOpposite()).canConnect;
|
||||
}
|
||||
else if(inv instanceof ISidedInventory) {
|
||||
int[] slots = ((ISidedInventory) inv).getAccessibleSlotsFromSide(direction.getOpposite().ordinal());
|
||||
//TODO: The MFR thing is a horrible hack. Blocks like the harvester make no slots accessible but will push into a connected
|
||||
//conduit. I could just return true for sided inventories but this will lead to confusing connections in some cases.
|
||||
//Therefore, bad hack for now.
|
||||
|
||||
return (slots != null && slots.length != 0) || inv.getClass().getName().startsWith("powercrystals.minefactoryreloaded") ||
|
||||
inv.getClass().getName().endsWith("TileTesseract");
|
||||
return slots!=null && slots.length>0;
|
||||
} else {
|
||||
return inv != null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ import net.minecraft.util.Facing;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
@@ -31,6 +33,7 @@ import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.gui.IResourceTooltipProvider;
|
||||
import crazypants.util.EntityUtil;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class ItemSoulVessel extends Item implements IResourceTooltipProvider {
|
||||
|
||||
@@ -135,6 +138,10 @@ public class ItemSoulVessel extends Item implements IResourceTooltipProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(itemstack.hasDisplayName() && mob instanceof EntityLiving) {
|
||||
((EntityLiving)mob).setCustomNameTag(itemstack.getDisplayName());
|
||||
}
|
||||
|
||||
world.spawnEntityInWorld(mob);
|
||||
if(mob instanceof EntityLiving) {
|
||||
((EntityLiving)mob).playLivingSound();
|
||||
@@ -186,11 +193,13 @@ public class ItemSoulVessel extends Item implements IResourceTooltipProvider {
|
||||
entity.writeToNBT(root);
|
||||
|
||||
ItemStack capturedMobVessel = new ItemStack(EnderIO.itemSoulVessel);
|
||||
capturedMobVessel.setTagCompound(root);
|
||||
setDisplayNameFromEntityNameTag(capturedMobVessel, entity);
|
||||
|
||||
player.swingItem();
|
||||
if(!isCreative) {
|
||||
entity.setDead();
|
||||
if(entity.isDead) {
|
||||
capturedMobVessel.setTagCompound(root);
|
||||
item.stackSize--;
|
||||
if (!player.inventory.addItemStackToInventory(capturedMobVessel))
|
||||
{
|
||||
@@ -201,7 +210,6 @@ public class ItemSoulVessel extends Item implements IResourceTooltipProvider {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
capturedMobVessel.setTagCompound(root);
|
||||
if (!player.inventory.addItemStackToInventory(capturedMobVessel)) //Inventory full, drop it in the world!
|
||||
{
|
||||
entity.worldObj.spawnEntityInWorld(new EntityItem(entity.worldObj,entity.posX, entity.posY, entity.posZ, capturedMobVessel));
|
||||
@@ -231,9 +239,23 @@ public class ItemSoulVessel extends Item implements IResourceTooltipProvider {
|
||||
|
||||
ItemStack res = new ItemStack(this);
|
||||
res.stackTagCompound = root;
|
||||
|
||||
setDisplayNameFromEntityNameTag(res, ent);
|
||||
return res;
|
||||
}
|
||||
|
||||
private void setDisplayNameFromEntityNameTag(ItemStack item, Entity ent) {
|
||||
if(ent instanceof EntityLiving) {
|
||||
EntityLiving entLiv = (EntityLiving)ent;
|
||||
if(entLiv.hasCustomNameTag()) {
|
||||
String name = entLiv.getCustomNameTag();
|
||||
if(name.length() > 0) {
|
||||
item.setStackDisplayName(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsSoul(ItemStack item) {
|
||||
if(item == null) {
|
||||
return false;
|
||||
@@ -254,6 +276,17 @@ public class ItemSoulVessel extends Item implements IResourceTooltipProvider {
|
||||
return item.stackTagCompound.getString("id");
|
||||
}
|
||||
|
||||
/** Support for displaying fluid name of captured Moo Fluids cow */
|
||||
public String getFluidNameFromStack(ItemStack item) {
|
||||
if(!containsSoul(item)) {
|
||||
return null;
|
||||
}
|
||||
if(item == null || item.stackTagCompound == null || !item.stackTagCompound.hasKey("FluidName")) {
|
||||
return null;
|
||||
}
|
||||
return item.stackTagCompound.getString("FluidName");
|
||||
}
|
||||
|
||||
private boolean isBlackListed(String entityId) {
|
||||
for (String str : blackList) {
|
||||
if(str != null && str.equals(entityId)) {
|
||||
@@ -278,6 +311,14 @@ public class ItemSoulVessel extends Item implements IResourceTooltipProvider {
|
||||
} else {
|
||||
par3List.add("Empty");
|
||||
}
|
||||
|
||||
String fluidName = getFluidNameFromStack(par1ItemStack);
|
||||
if(fluidName != null) {
|
||||
Fluid fluid = FluidRegistry.getFluid(fluidName);
|
||||
if(fluid != null) {
|
||||
par3List.add(Lang.localize("item.itemSoulVessel.tooltip.fluidname") + " " + fluid.getLocalizedName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user