mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-20 03:59:37 +00:00
Work on Oredictionificator operations
This commit is contained in:
1 parent
d61723c5f7
commit
02cb425cbd
2 files changed
+87
-3
No files matched your search
@@ -29,8 +29,6 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiOredictionificatorFilter extends GuiMekanism
|
||||
{
|
||||
public static List<String> possibleFilters = Arrays.asList("ingot", "ore", "dust");
|
||||
|
||||
public TileEntityOredictionificator tileEntity;
|
||||
|
||||
public OredictionificatorFilter origFilter;
|
||||
@@ -67,7 +65,7 @@ public class GuiOredictionificatorFilter extends GuiMekanism
|
||||
String newFilter = filterText.getText();
|
||||
boolean has = false;
|
||||
|
||||
for(String s : possibleFilters)
|
||||
for(String s : TileEntityOredictionificator.possibleFilters)
|
||||
{
|
||||
if(newFilter.startsWith(s))
|
||||
{
|
||||
|
||||
@@ -3,23 +3,28 @@ package mekanism.common.tile;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.IFilterAccess;
|
||||
import mekanism.api.Range4D;
|
||||
import mekanism.common.HashList;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.OreDictCache;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.base.IRedstoneControl;
|
||||
import mekanism.common.base.ISustainedData;
|
||||
import mekanism.common.block.BlockMachine.MachineType;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class TileEntityOredictionificator extends TileEntityContainerBlock implements IRedstoneControl, IFilterAccess, ISustainedData
|
||||
{
|
||||
@@ -27,6 +32,8 @@ public class TileEntityOredictionificator extends TileEntityContainerBlock imple
|
||||
|
||||
public HashList<OredictionificatorFilter> filters = new HashList<OredictionificatorFilter>();
|
||||
|
||||
public static List<String> possibleFilters = Arrays.asList("ingot", "ore", "dust");
|
||||
|
||||
public RedstoneControl controlType = RedstoneControl.DISABLED;
|
||||
|
||||
public TileEntityOredictionificator()
|
||||
@@ -49,9 +56,88 @@ public class TileEntityOredictionificator extends TileEntityContainerBlock imple
|
||||
Mekanism.packetHandler.sendTo(new TileEntityMessage(Coord4D.get(this), getGenericPacket(new ArrayList())), (EntityPlayerMP)player);
|
||||
}
|
||||
}
|
||||
|
||||
if(inventory[0] != null && getValidName(inventory[0]) != null)
|
||||
{
|
||||
ItemStack result = getResult(inventory[0]);
|
||||
|
||||
if(result != null)
|
||||
{
|
||||
if(inventory[1] == null)
|
||||
{
|
||||
inventory[0].stackSize--;
|
||||
|
||||
if(inventory[0].stackSize <= 0)
|
||||
{
|
||||
inventory[0] = null;
|
||||
}
|
||||
|
||||
inventory[1] = result;
|
||||
}
|
||||
else if(inventory[0].isItemEqual(result) && inventory[0].stackSize < inventory[0].getMaxStackSize())
|
||||
{
|
||||
inventory[0].stackSize--;
|
||||
|
||||
if(inventory[0].stackSize <= 0)
|
||||
{
|
||||
inventory[0] = null;
|
||||
}
|
||||
|
||||
inventory[1].stackSize++;
|
||||
}
|
||||
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getValidName(ItemStack stack)
|
||||
{
|
||||
List<String> def = OreDictCache.getOreDictName(stack);
|
||||
|
||||
for(String s : def)
|
||||
{
|
||||
for(String pre : possibleFilters)
|
||||
{
|
||||
if(s.startsWith(pre))
|
||||
{
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack getResult(ItemStack stack)
|
||||
{
|
||||
String s = getValidName(stack);
|
||||
|
||||
if(s == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ItemStack> ores = OreDictionary.getOres(s);
|
||||
|
||||
for(OredictionificatorFilter filter : filters)
|
||||
{
|
||||
if(filter.filter.equals(s))
|
||||
{
|
||||
if(ores.size()-1 >= filter.index)
|
||||
{
|
||||
return MekanismUtils.size(ores.get(filter.index), 1);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtTags)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user