Format
This commit is contained in:
parent
6e0ec1d861
commit
4ac26ac086
137 changed files with 10339 additions and 7322 deletions
|
@ -7,12 +7,18 @@ import net.minecraftforge.oredict.ShapelessOreRecipe;
|
|||
|
||||
public class CraftingHelper {
|
||||
|
||||
public static void addShapedOreRecipe(ItemStack outputItemStack, Object... objectInputs) {
|
||||
CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(outputItemStack, objectInputs));
|
||||
}
|
||||
public static void addShapedOreRecipe(ItemStack outputItemStack,
|
||||
Object... objectInputs)
|
||||
{
|
||||
CraftingManager.getInstance().getRecipeList()
|
||||
.add(new ShapedOreRecipe(outputItemStack, objectInputs));
|
||||
}
|
||||
|
||||
public static void addShapelessOreRecipe(ItemStack outputItemStack, Object... objectInputs) {
|
||||
CraftingManager.getInstance().getRecipeList().add(new ShapelessOreRecipe(outputItemStack, objectInputs));
|
||||
}
|
||||
public static void addShapelessOreRecipe(ItemStack outputItemStack,
|
||||
Object... objectInputs)
|
||||
{
|
||||
CraftingManager.getInstance().getRecipeList()
|
||||
.add(new ShapelessOreRecipe(outputItemStack, objectInputs));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,57 +10,80 @@ import net.minecraftforge.fluids.IFluidHandler;
|
|||
|
||||
public class FluidUtils {
|
||||
|
||||
public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot) {
|
||||
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||
ItemStack output = inv.getStackInSlot(outputSlot);
|
||||
public static boolean drainContainers(IFluidHandler fluidHandler,
|
||||
IInventory inv, int inputSlot, int outputSlot)
|
||||
{
|
||||
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||
ItemStack output = inv.getStackInSlot(outputSlot);
|
||||
|
||||
if (input != null) {
|
||||
FluidStack fluidInContainer = getFluidStackInContainer(input);
|
||||
ItemStack emptyItem = input.getItem().getContainerItem(input);
|
||||
if (fluidInContainer != null && (emptyItem == null || output == null || (output.stackSize < output.getMaxStackSize() && ItemUtils.isItemEqual(output, emptyItem, true, true)))) {
|
||||
int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false);
|
||||
if (used >= fluidInContainer.amount) {
|
||||
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true);
|
||||
if (emptyItem != null)
|
||||
if (output == null)
|
||||
inv.setInventorySlotContents(outputSlot, emptyItem);
|
||||
else
|
||||
output.stackSize++;
|
||||
inv.decrStackSize(inputSlot, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (input != null)
|
||||
{
|
||||
FluidStack fluidInContainer = getFluidStackInContainer(input);
|
||||
ItemStack emptyItem = input.getItem().getContainerItem(input);
|
||||
if (fluidInContainer != null
|
||||
&& (emptyItem == null || output == null || (output.stackSize < output
|
||||
.getMaxStackSize() && ItemUtils.isItemEqual(output,
|
||||
emptyItem, true, true))))
|
||||
{
|
||||
int used = fluidHandler.fill(ForgeDirection.UNKNOWN,
|
||||
fluidInContainer, false);
|
||||
if (used >= fluidInContainer.amount)
|
||||
{
|
||||
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer,
|
||||
true);
|
||||
if (emptyItem != null)
|
||||
if (output == null)
|
||||
inv.setInventorySlotContents(outputSlot, emptyItem);
|
||||
else
|
||||
output.stackSize++;
|
||||
inv.decrStackSize(inputSlot, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean fillContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill) {
|
||||
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||
ItemStack output = inv.getStackInSlot(outputSlot);
|
||||
ItemStack filled = getFilledContainer(fluidToFill, input);
|
||||
if (filled != null && (output == null || (output.stackSize < output.getMaxStackSize() && ItemUtils.isItemEqual(filled, output, true, true)))) {
|
||||
FluidStack fluidInContainer = getFluidStackInContainer(filled);
|
||||
FluidStack drain = fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, false);
|
||||
if (drain != null && drain.amount == fluidInContainer.amount) {
|
||||
fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, true);
|
||||
if (output == null)
|
||||
inv.setInventorySlotContents(outputSlot, filled);
|
||||
else
|
||||
output.stackSize++;
|
||||
inv.decrStackSize(inputSlot, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static boolean fillContainers(IFluidHandler fluidHandler,
|
||||
IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill)
|
||||
{
|
||||
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||
ItemStack output = inv.getStackInSlot(outputSlot);
|
||||
ItemStack filled = getFilledContainer(fluidToFill, input);
|
||||
if (filled != null
|
||||
&& (output == null || (output.stackSize < output
|
||||
.getMaxStackSize() && ItemUtils.isItemEqual(filled,
|
||||
output, true, true))))
|
||||
{
|
||||
FluidStack fluidInContainer = getFluidStackInContainer(filled);
|
||||
FluidStack drain = fluidHandler.drain(ForgeDirection.UNKNOWN,
|
||||
fluidInContainer, false);
|
||||
if (drain != null && drain.amount == fluidInContainer.amount)
|
||||
{
|
||||
fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer,
|
||||
true);
|
||||
if (output == null)
|
||||
inv.setInventorySlotContents(outputSlot, filled);
|
||||
else
|
||||
output.stackSize++;
|
||||
inv.decrStackSize(inputSlot, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static FluidStack getFluidStackInContainer(ItemStack stack) {
|
||||
return FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||
}
|
||||
public static FluidStack getFluidStackInContainer(ItemStack stack)
|
||||
{
|
||||
return FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||
}
|
||||
|
||||
public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty) {
|
||||
if (fluid == null || empty == null) return null;
|
||||
return FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid, Integer.MAX_VALUE), empty);
|
||||
}
|
||||
public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty)
|
||||
{
|
||||
if (fluid == null || empty == null)
|
||||
return null;
|
||||
return FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid,
|
||||
Integer.MAX_VALUE), empty);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package techreborn.util;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -11,148 +10,181 @@ import net.minecraftforge.common.util.Constants;
|
|||
|
||||
public class Inventory implements IInventory {
|
||||
|
||||
private final ItemStack[] contents;
|
||||
private final String name;
|
||||
private final int stackLimit;
|
||||
private TileEntity tile = new TileEntity();
|
||||
private final ItemStack[] contents;
|
||||
private final String name;
|
||||
private final int stackLimit;
|
||||
private TileEntity tile = new TileEntity();
|
||||
|
||||
public Inventory(int size, String invName, int invStackLimit) {
|
||||
contents = new ItemStack[size];
|
||||
name = invName;
|
||||
stackLimit = invStackLimit;
|
||||
}
|
||||
public Inventory(int size, String invName, int invStackLimit)
|
||||
{
|
||||
contents = new ItemStack[size];
|
||||
name = invName;
|
||||
stackLimit = invStackLimit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return contents.length;
|
||||
}
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return contents.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slotId) {
|
||||
return contents[slotId];
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slotId)
|
||||
{
|
||||
return contents[slotId];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slotId, int count) {
|
||||
if (slotId < contents.length && contents[slotId] != null) {
|
||||
if (contents[slotId].stackSize > count) {
|
||||
ItemStack result = contents[slotId].splitStack(count);
|
||||
markDirty();
|
||||
return result;
|
||||
}
|
||||
ItemStack stack = contents[slotId];
|
||||
setInventorySlotContents(slotId, null);
|
||||
return stack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slotId, int count)
|
||||
{
|
||||
if (slotId < contents.length && contents[slotId] != null)
|
||||
{
|
||||
if (contents[slotId].stackSize > count)
|
||||
{
|
||||
ItemStack result = contents[slotId].splitStack(count);
|
||||
markDirty();
|
||||
return result;
|
||||
}
|
||||
ItemStack stack = contents[slotId];
|
||||
setInventorySlotContents(slotId, null);
|
||||
return stack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slotId, ItemStack itemstack) {
|
||||
if (slotId >= contents.length) {
|
||||
return;
|
||||
}
|
||||
contents[slotId] = itemstack;
|
||||
@Override
|
||||
public void setInventorySlotContents(int slotId, ItemStack itemstack)
|
||||
{
|
||||
if (slotId >= contents.length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
contents[slotId] = itemstack;
|
||||
|
||||
if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) {
|
||||
itemstack.stackSize = this.getInventoryStackLimit();
|
||||
}
|
||||
markDirty();
|
||||
}
|
||||
if (itemstack != null
|
||||
&& itemstack.stackSize > this.getInventoryStackLimit())
|
||||
{
|
||||
itemstack.stackSize = this.getInventoryStackLimit();
|
||||
}
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return name;
|
||||
}
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return stackLimit;
|
||||
}
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return stackLimit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
readFromNBT(data, "Items");
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
readFromNBT(data, "Items");
|
||||
}
|
||||
public void readFromNBT(NBTTagCompound data, String tag)
|
||||
{
|
||||
NBTTagList nbttaglist = data
|
||||
.getTagList(tag, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
public void readFromNBT(NBTTagCompound data, String tag) {
|
||||
NBTTagList nbttaglist = data.getTagList(tag, Constants.NBT.TAG_COMPOUND);
|
||||
for (int j = 0; j < nbttaglist.tagCount(); ++j)
|
||||
{
|
||||
NBTTagCompound slot = nbttaglist.getCompoundTagAt(j);
|
||||
int index;
|
||||
if (slot.hasKey("index"))
|
||||
{
|
||||
index = slot.getInteger("index");
|
||||
} else
|
||||
{
|
||||
index = slot.getByte("Slot");
|
||||
}
|
||||
if (index >= 0 && index < contents.length)
|
||||
{
|
||||
setInventorySlotContents(index,
|
||||
ItemStack.loadItemStackFromNBT(slot));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
|
||||
NBTTagCompound slot = nbttaglist.getCompoundTagAt(j);
|
||||
int index;
|
||||
if (slot.hasKey("index")) {
|
||||
index = slot.getInteger("index");
|
||||
} else {
|
||||
index = slot.getByte("Slot");
|
||||
}
|
||||
if (index >= 0 && index < contents.length) {
|
||||
setInventorySlotContents(index, ItemStack.loadItemStackFromNBT(slot));
|
||||
}
|
||||
}
|
||||
}
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
writeToNBT(data, "Items");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
writeToNBT(data, "Items");
|
||||
}
|
||||
public void writeToNBT(NBTTagCompound data, String tag)
|
||||
{
|
||||
NBTTagList slots = new NBTTagList();
|
||||
for (byte index = 0; index < contents.length; ++index)
|
||||
{
|
||||
if (contents[index] != null && contents[index].stackSize > 0)
|
||||
{
|
||||
NBTTagCompound slot = new NBTTagCompound();
|
||||
slots.appendTag(slot);
|
||||
slot.setByte("Slot", index);
|
||||
contents[index].writeToNBT(slot);
|
||||
}
|
||||
}
|
||||
data.setTag(tag, slots);
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data, String tag) {
|
||||
NBTTagList slots = new NBTTagList();
|
||||
for (byte index = 0; index < contents.length; ++index) {
|
||||
if (contents[index] != null && contents[index].stackSize > 0) {
|
||||
NBTTagCompound slot = new NBTTagCompound();
|
||||
slots.appendTag(slot);
|
||||
slot.setByte("Slot", index);
|
||||
contents[index].writeToNBT(slot);
|
||||
}
|
||||
}
|
||||
data.setTag(tag, slots);
|
||||
}
|
||||
public void setTile(TileEntity tileEntity)
|
||||
{
|
||||
tile = tileEntity;
|
||||
}
|
||||
|
||||
public void setTile(TileEntity tileEntity) {
|
||||
tile = tileEntity;
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slotId)
|
||||
{
|
||||
if (this.contents[slotId] == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slotId) {
|
||||
if (this.contents[slotId] == null) {
|
||||
return null;
|
||||
}
|
||||
ItemStack stackToTake = this.contents[slotId];
|
||||
setInventorySlotContents(slotId, null);
|
||||
return stackToTake;
|
||||
}
|
||||
|
||||
ItemStack stackToTake = this.contents[slotId];
|
||||
setInventorySlotContents(slotId, null);
|
||||
return stackToTake;
|
||||
}
|
||||
public ItemStack[] getStacks()
|
||||
{
|
||||
return contents;
|
||||
}
|
||||
|
||||
public ItemStack[] getStacks() {
|
||||
return contents;
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
tile.markDirty();
|
||||
}
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
tile.markDirty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,65 +10,80 @@ import net.minecraftforge.oredict.OreDictionary;
|
|||
* Created by mark on 12/04/15.
|
||||
*/
|
||||
public class ItemUtils {
|
||||
public static boolean isItemEqual(final ItemStack a, final ItemStack b, final boolean matchDamage, final boolean matchNBT) {
|
||||
if (a == null || b == null)
|
||||
return false;
|
||||
if (a.getItem() != b.getItem())
|
||||
return false;
|
||||
if (matchNBT && !ItemStack.areItemStackTagsEqual(a, b))
|
||||
return false;
|
||||
if (matchDamage && a.getHasSubtypes()) {
|
||||
if (isWildcard(a) || isWildcard(b))
|
||||
return true;
|
||||
if (a.getItemDamage() != b.getItemDamage())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static boolean isItemEqual(final ItemStack a, final ItemStack b,
|
||||
final boolean matchDamage, final boolean matchNBT)
|
||||
{
|
||||
if (a == null || b == null)
|
||||
return false;
|
||||
if (a.getItem() != b.getItem())
|
||||
return false;
|
||||
if (matchNBT && !ItemStack.areItemStackTagsEqual(a, b))
|
||||
return false;
|
||||
if (matchDamage && a.getHasSubtypes())
|
||||
{
|
||||
if (isWildcard(a) || isWildcard(b))
|
||||
return true;
|
||||
if (a.getItemDamage() != b.getItemDamage())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isWildcard(ItemStack stack) {
|
||||
return isWildcard(stack.getItemDamage());
|
||||
}
|
||||
public static boolean isWildcard(ItemStack stack)
|
||||
{
|
||||
return isWildcard(stack.getItemDamage());
|
||||
}
|
||||
|
||||
public static boolean isWildcard(int damage) {
|
||||
return damage == -1 || damage == OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
public static boolean isWildcard(int damage)
|
||||
{
|
||||
return damage == -1 || damage == OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
|
||||
public static void writeInvToNBT(IInventory inv, String tag, NBTTagCompound data) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (byte slot = 0; slot < inv.getSizeInventory(); slot++) {
|
||||
ItemStack stack = inv.getStackInSlot(slot);
|
||||
if (stack != null) {
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
itemTag.setByte("Slot", slot);
|
||||
writeItemToNBT(stack, itemTag);
|
||||
list.appendTag(itemTag);
|
||||
}
|
||||
}
|
||||
data.setTag(tag, list);
|
||||
}
|
||||
public static void writeInvToNBT(IInventory inv, String tag,
|
||||
NBTTagCompound data)
|
||||
{
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (byte slot = 0; slot < inv.getSizeInventory(); slot++)
|
||||
{
|
||||
ItemStack stack = inv.getStackInSlot(slot);
|
||||
if (stack != null)
|
||||
{
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
itemTag.setByte("Slot", slot);
|
||||
writeItemToNBT(stack, itemTag);
|
||||
list.appendTag(itemTag);
|
||||
}
|
||||
}
|
||||
data.setTag(tag, list);
|
||||
}
|
||||
|
||||
public static void readInvFromNBT(IInventory inv, String tag, NBTTagCompound data) {
|
||||
NBTTagList list = data.getTagList(tag, 10);
|
||||
for (byte entry = 0; entry < list.tagCount(); entry++) {
|
||||
NBTTagCompound itemTag = list.getCompoundTagAt(entry);
|
||||
int slot = itemTag.getByte("Slot");
|
||||
if (slot >= 0 && slot < inv.getSizeInventory()) {
|
||||
ItemStack stack = readItemFromNBT(itemTag);
|
||||
inv.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void readInvFromNBT(IInventory inv, String tag,
|
||||
NBTTagCompound data)
|
||||
{
|
||||
NBTTagList list = data.getTagList(tag, 10);
|
||||
for (byte entry = 0; entry < list.tagCount(); entry++)
|
||||
{
|
||||
NBTTagCompound itemTag = list.getCompoundTagAt(entry);
|
||||
int slot = itemTag.getByte("Slot");
|
||||
if (slot >= 0 && slot < inv.getSizeInventory())
|
||||
{
|
||||
ItemStack stack = readItemFromNBT(itemTag);
|
||||
inv.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeItemToNBT(ItemStack stack, NBTTagCompound data) {
|
||||
if (stack == null || stack.stackSize <= 0)
|
||||
return;
|
||||
if (stack.stackSize > 127)
|
||||
stack.stackSize = 127;
|
||||
stack.writeToNBT(data);
|
||||
}
|
||||
public static void writeItemToNBT(ItemStack stack, NBTTagCompound data)
|
||||
{
|
||||
if (stack == null || stack.stackSize <= 0)
|
||||
return;
|
||||
if (stack.stackSize > 127)
|
||||
stack.stackSize = 127;
|
||||
stack.writeToNBT(data);
|
||||
}
|
||||
|
||||
public static ItemStack readItemFromNBT(NBTTagCompound data) {
|
||||
return ItemStack.loadItemStackFromNBT(data);
|
||||
}
|
||||
public static ItemStack readItemFromNBT(NBTTagCompound data)
|
||||
{
|
||||
return ItemStack.loadItemStackFromNBT(data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,45 +1,55 @@
|
|||
package techreborn.util;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import techreborn.lib.ModInfo;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
public class LogHelper {
|
||||
|
||||
public static void log(Level logLevel, Object object) {
|
||||
FMLLog.log(ModInfo.MOD_NAME, logLevel, String.valueOf(object));
|
||||
}
|
||||
public static void log(Level logLevel, Object object)
|
||||
{
|
||||
FMLLog.log(ModInfo.MOD_NAME, logLevel, String.valueOf(object));
|
||||
}
|
||||
|
||||
public static void all(Object object) {
|
||||
log(Level.ALL, object);
|
||||
}
|
||||
public static void all(Object object)
|
||||
{
|
||||
log(Level.ALL, object);
|
||||
}
|
||||
|
||||
public static void debug(Object object) {
|
||||
log(Level.DEBUG, object);
|
||||
}
|
||||
public static void debug(Object object)
|
||||
{
|
||||
log(Level.DEBUG, object);
|
||||
}
|
||||
|
||||
public static void error(Object object) {
|
||||
log(Level.ERROR, object);
|
||||
}
|
||||
public static void error(Object object)
|
||||
{
|
||||
log(Level.ERROR, object);
|
||||
}
|
||||
|
||||
public static void fatal(Object object) {
|
||||
log(Level.FATAL, object);
|
||||
}
|
||||
public static void fatal(Object object)
|
||||
{
|
||||
log(Level.FATAL, object);
|
||||
}
|
||||
|
||||
public static void info(Object object) {
|
||||
log(Level.INFO, object);
|
||||
}
|
||||
public static void info(Object object)
|
||||
{
|
||||
log(Level.INFO, object);
|
||||
}
|
||||
|
||||
public static void off(Object object) {
|
||||
log(Level.OFF, object);
|
||||
}
|
||||
public static void off(Object object)
|
||||
{
|
||||
log(Level.OFF, object);
|
||||
}
|
||||
|
||||
public static void trace(Object object) {
|
||||
log(Level.TRACE, object);
|
||||
}
|
||||
public static void trace(Object object)
|
||||
{
|
||||
log(Level.TRACE, object);
|
||||
}
|
||||
|
||||
public static void warn(Object object) {
|
||||
log(Level.WARN, object);
|
||||
}
|
||||
public static void warn(Object object)
|
||||
{
|
||||
log(Level.WARN, object);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,41 +1,49 @@
|
|||
package techreborn.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RecipeRemover {
|
||||
public static void removeShapedRecipes(List<ItemStack> removelist) {
|
||||
for (ItemStack stack : removelist)
|
||||
removeShapedRecipe(stack);
|
||||
}
|
||||
public static void removeShapedRecipes(List<ItemStack> removelist)
|
||||
{
|
||||
for (ItemStack stack : removelist)
|
||||
removeShapedRecipe(stack);
|
||||
}
|
||||
|
||||
public static void removeAnyRecipe(ItemStack resultItem) {
|
||||
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
IRecipe tmpRecipe = recipes.get(i);
|
||||
ItemStack recipeResult = tmpRecipe.getRecipeOutput();
|
||||
if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) {
|
||||
recipes.remove(i--);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void removeAnyRecipe(ItemStack resultItem)
|
||||
{
|
||||
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
|
||||
for (int i = 0; i < recipes.size(); i++)
|
||||
{
|
||||
IRecipe tmpRecipe = recipes.get(i);
|
||||
ItemStack recipeResult = tmpRecipe.getRecipeOutput();
|
||||
if (ItemStack.areItemStacksEqual(resultItem, recipeResult))
|
||||
{
|
||||
recipes.remove(i--);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeShapedRecipe(ItemStack resultItem) {
|
||||
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
IRecipe tmpRecipe = recipes.get(i);
|
||||
if (tmpRecipe instanceof ShapedRecipes) {
|
||||
ShapedRecipes recipe = (ShapedRecipes) tmpRecipe;
|
||||
ItemStack recipeResult = recipe.getRecipeOutput();
|
||||
public static void removeShapedRecipe(ItemStack resultItem)
|
||||
{
|
||||
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
|
||||
for (int i = 0; i < recipes.size(); i++)
|
||||
{
|
||||
IRecipe tmpRecipe = recipes.get(i);
|
||||
if (tmpRecipe instanceof ShapedRecipes)
|
||||
{
|
||||
ShapedRecipes recipe = (ShapedRecipes) tmpRecipe;
|
||||
ItemStack recipeResult = recipe.getRecipeOutput();
|
||||
|
||||
if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) {
|
||||
recipes.remove(i++);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ItemStack.areItemStacksEqual(resultItem, recipeResult))
|
||||
{
|
||||
recipes.remove(i++);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package techreborn.util;
|
||||
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
@ -8,46 +7,51 @@ import net.minecraftforge.fluids.FluidTank;
|
|||
|
||||
public class Tank extends FluidTank {
|
||||
|
||||
private final String name;
|
||||
|
||||
private final String name;
|
||||
public Tank(String name, int capacity, TileEntity tile)
|
||||
{
|
||||
super(capacity);
|
||||
this.name = name;
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
public Tank(String name, int capacity, TileEntity tile) {
|
||||
super(capacity);
|
||||
this.name = name;
|
||||
this.tile = tile;
|
||||
}
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return getFluid() == null || getFluid().amount <= 0;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getFluid() == null || getFluid().amount <= 0;
|
||||
}
|
||||
public boolean isFull()
|
||||
{
|
||||
return getFluid() != null && getFluid().amount >= getCapacity();
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return getFluid() != null && getFluid().amount >= getCapacity();
|
||||
}
|
||||
public Fluid getFluidType()
|
||||
{
|
||||
return getFluid() != null ? getFluid().getFluid() : null;
|
||||
}
|
||||
|
||||
public Fluid getFluidType() {
|
||||
return getFluid() != null ? getFluid().getFluid() : null;
|
||||
}
|
||||
@Override
|
||||
public final NBTTagCompound writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
NBTTagCompound tankData = new NBTTagCompound();
|
||||
super.writeToNBT(tankData);
|
||||
nbt.setTag(name, tankData);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
NBTTagCompound tankData = new NBTTagCompound();
|
||||
super.writeToNBT(tankData);
|
||||
nbt.setTag(name, tankData);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final FluidTank readFromNBT(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(name)) {
|
||||
// allow to read empty tanks
|
||||
setFluid(null);
|
||||
|
||||
NBTTagCompound tankData = nbt.getCompoundTag(name);
|
||||
super.readFromNBT(tankData);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public final FluidTank readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
if (nbt.hasKey(name))
|
||||
{
|
||||
// allow to read empty tanks
|
||||
setFluid(null);
|
||||
|
||||
NBTTagCompound tankData = nbt.getCompoundTag(name);
|
||||
super.readFromNBT(tankData);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,24 +9,36 @@ import net.minecraftforge.event.ForgeEventFactory;
|
|||
|
||||
public class TorchHelper {
|
||||
|
||||
public static boolean placeTorch(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
|
||||
for (int i = 0; i < player.inventory.mainInventory.length; i++) {
|
||||
ItemStack torchStack = player.inventory.mainInventory[i];
|
||||
if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) continue;
|
||||
Item item = torchStack.getItem();
|
||||
if (!(item instanceof ItemBlock)) continue;
|
||||
int oldMeta = torchStack.getItemDamage();
|
||||
int oldSize = torchStack.stackSize;
|
||||
boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset);
|
||||
if (player.capabilities.isCreativeMode) {
|
||||
torchStack.setItemDamage(oldMeta);
|
||||
torchStack.stackSize = oldSize;
|
||||
} else if (torchStack.stackSize <= 0) {
|
||||
ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
|
||||
player.inventory.mainInventory[i] = null;
|
||||
}
|
||||
if (result) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static boolean placeTorch(ItemStack stack, EntityPlayer player,
|
||||
World world, int x, int y, int z, int side, float xOffset,
|
||||
float yOffset, float zOffset)
|
||||
{
|
||||
for (int i = 0; i < player.inventory.mainInventory.length; i++)
|
||||
{
|
||||
ItemStack torchStack = player.inventory.mainInventory[i];
|
||||
if (torchStack == null
|
||||
|| !torchStack.getUnlocalizedName().toLowerCase()
|
||||
.contains("torch"))
|
||||
continue;
|
||||
Item item = torchStack.getItem();
|
||||
if (!(item instanceof ItemBlock))
|
||||
continue;
|
||||
int oldMeta = torchStack.getItemDamage();
|
||||
int oldSize = torchStack.stackSize;
|
||||
boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x,
|
||||
y, z, side, xOffset, yOffset, zOffset);
|
||||
if (player.capabilities.isCreativeMode)
|
||||
{
|
||||
torchStack.setItemDamage(oldMeta);
|
||||
torchStack.stackSize = oldSize;
|
||||
} else if (torchStack.stackSize <= 0)
|
||||
{
|
||||
ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
|
||||
player.inventory.mainInventory[i] = null;
|
||||
}
|
||||
if (result)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue