mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-21 20:52:42 +00:00
Merge pull request #1879 from MatthiasMann/vacuum_chest_filters
#991 add item filters, range and redstone control and to vacuum chest
This commit is contained in:
commit
8467cf96c5
12 files changed
+765
-49
No files matched your search
@@ -66,6 +66,10 @@ public class ItemFilter implements IInventory, IItemFilter {
|
||||
|
||||
@Override
|
||||
public boolean doesItemPassFilter(NetworkedInventory inv, ItemStack item) {
|
||||
return doesItemPassFilter(item);
|
||||
}
|
||||
|
||||
public boolean doesItemPassFilter(ItemStack item) {
|
||||
if(!isValid()) {
|
||||
return true;
|
||||
}
|
||||
@@ -88,7 +92,7 @@ public class ItemFilter implements IInventory, IItemFilter {
|
||||
matched = false;
|
||||
}
|
||||
}
|
||||
if(!matched && isOreDicMatch(i, item)) {
|
||||
if(!matched && useOreDict && isOreDicMatch(i, item)) {
|
||||
matched = true;
|
||||
}
|
||||
if(matched) {
|
||||
@@ -99,10 +103,7 @@ public class ItemFilter implements IInventory, IItemFilter {
|
||||
return matched;
|
||||
}
|
||||
|
||||
private boolean isOreDicMatch(int filterItemIndex, ItemStack item) {
|
||||
if(!useOreDict || item == null) {
|
||||
return false;
|
||||
}
|
||||
private boolean isOreDicMatch(int filterItemIndex, ItemStack item) {
|
||||
int[] ids1 = getCachedIds(filterItemIndex);
|
||||
if(ids1 == null || ids1.length == 0) {
|
||||
return false;
|
||||
|
||||
@@ -325,7 +325,7 @@ public final class Config {
|
||||
|
||||
public static int painterEnergyPerTaskRF = 2000;
|
||||
|
||||
public static double vacuumChestRange = 6;
|
||||
public static int vacuumChestRange = 6;
|
||||
|
||||
public static boolean useModMetals = true;
|
||||
|
||||
@@ -647,7 +647,7 @@ public final class Config {
|
||||
"'line of sight' distance rather than conduit path distance is used to calculate priorities.")
|
||||
.getBoolean(itemConduitUsePhyscialDistance);
|
||||
|
||||
vacuumChestRange = config.get(sectionEfficiency.name, "vacumChestRange", vacuumChestRange, "The range of the vacuum chest").getDouble(vacuumChestRange);
|
||||
vacuumChestRange = config.get(sectionEfficiency.name, "vacumChestRange", vacuumChestRange, "The range of the vacuum chest").getInt(vacuumChestRange);
|
||||
|
||||
if(!useSneakMouseWheelYetaWrench && !useSneakRightClickYetaWrench) {
|
||||
Log.warn("Both useSneakMouseWheelYetaWrench and useSneakRightClickYetaWrench are set to false. Enabling mouse wheel.");
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
package crazypants.enderio.machine.vacuum;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import crazypants.enderio.BlockEio;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.TileEntityEio;
|
||||
import crazypants.enderio.api.redstone.IRedstoneConnectable;
|
||||
import crazypants.enderio.gui.IResourceTooltipProvider;
|
||||
import crazypants.enderio.tool.ToolUtil;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
|
||||
public class BlockVacuumChest extends BlockEio implements IGuiHandler, IResourceTooltipProvider {
|
||||
public class BlockVacuumChest extends BlockEio implements IGuiHandler, IResourceTooltipProvider, IRedstoneConnectable {
|
||||
|
||||
public static BlockVacuumChest create() {
|
||||
PacketHandler.INSTANCE.registerMessage(PacketVaccumChest.class,PacketVaccumChest.class,PacketHandler.nextID(), Side.SERVER);
|
||||
BlockVacuumChest res = new BlockVacuumChest();
|
||||
res.init();
|
||||
return res;
|
||||
@@ -30,6 +35,19 @@ public class BlockVacuumChest extends BlockEio implements IGuiHandler, IResource
|
||||
setBlockTextureName("enderio:blockVacuumChest");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRedstoneConduitConnect(World world, int x, int y, int z, ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block blockId) {
|
||||
TileEntity ent = world.getTileEntity(x, y, z);
|
||||
if(ent instanceof TileVacuumChest) {
|
||||
((TileVacuumChest) ent).onNeighborBlockChange(blockId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
@@ -8,20 +8,20 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ContainerVacuumChest extends Container {
|
||||
|
||||
private int numRows = 3;
|
||||
|
||||
public ContainerVacuumChest(EntityPlayer player, InventoryPlayer inventory, TileVacuumChest te) {
|
||||
final Slot filterSlot;
|
||||
Runnable filterChangedCB;
|
||||
|
||||
public ContainerVacuumChest(EntityPlayer player, InventoryPlayer inventory, final TileVacuumChest te) {
|
||||
int x = 8;
|
||||
int y = 17;
|
||||
int y = 18;
|
||||
int index = -1;
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int i = 0; i < TileVacuumChest.ITEM_ROWS; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
addSlotToContainer(new Slot(te, ++index, x + j * 18, y + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
y = 84;
|
||||
y = 124;
|
||||
// add players inventory
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
@@ -31,6 +31,9 @@ public class ContainerVacuumChest extends Container {
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
addSlotToContainer(new Slot(inventory, i, x + i * 18, y + 58));
|
||||
}
|
||||
|
||||
filterSlot = new FilterSlot(new InventoryFilterUpgrade(te));
|
||||
addSlotToContainer(filterSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,6 +41,7 @@ public class ContainerVacuumChest extends Container {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(par2);
|
||||
@@ -46,11 +50,11 @@ public class ContainerVacuumChest extends Container {
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
if(par2 < this.numRows * 9) {
|
||||
if(!this.mergeItemStack(itemstack1, this.numRows * 9, this.inventorySlots.size(), true)) {
|
||||
if(par2 < TileVacuumChest.ITEM_SLOTS) {
|
||||
if(!this.mergeItemStack(itemstack1, TileVacuumChest.ITEM_SLOTS, this.inventorySlots.size()-1, true)) {
|
||||
return null;
|
||||
}
|
||||
} else if(!this.mergeItemStack(itemstack1, 0, this.numRows * 9, false)) {
|
||||
} else if(!this.mergeItemStack(itemstack1, 0, TileVacuumChest.ITEM_SLOTS, false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -63,4 +67,32 @@ public class ContainerVacuumChest extends Container {
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
void setFilterChangedCB(Runnable filterChangedCB) {
|
||||
this.filterChangedCB = filterChangedCB;
|
||||
}
|
||||
|
||||
void filterChanged() {
|
||||
if(filterChangedCB != null) {
|
||||
filterChangedCB.run();
|
||||
}
|
||||
}
|
||||
|
||||
class FilterSlot extends Slot {
|
||||
InventoryFilterUpgrade inv;
|
||||
|
||||
FilterSlot(InventoryFilterUpgrade inv) {
|
||||
super(inv, 0, 8, 86);
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotChanged() {
|
||||
filterChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return inv.isItemValidForSlot(0, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,24 +2,224 @@ package crazypants.enderio.machine.vacuum;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import crazypants.enderio.conduit.item.filter.ItemFilter;
|
||||
import crazypants.enderio.gui.IconButtonEIO;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.gui.RedstoneModeButton;
|
||||
import crazypants.enderio.gui.ToggleButtonEIO;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.gui.GhostSlot;
|
||||
import crazypants.gui.GuiContainerBase;
|
||||
import crazypants.gui.GuiToolTip;
|
||||
import crazypants.render.ColorUtil;
|
||||
import crazypants.render.RenderUtil;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.Lang;
|
||||
import java.awt.Color;
|
||||
import java.awt.Rectangle;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class GuiVacuumChest extends GuiContainer {
|
||||
public class GuiVacuumChest extends GuiContainerBase {
|
||||
|
||||
private static final int RANGE_LEFT = 145;
|
||||
private static final int RANGE_TOP = 86;
|
||||
private static final int RANGE_WIDTH = 16;
|
||||
|
||||
private static final int FILTER_LEFT = 29;
|
||||
private static final int FILTER_TOP = 85;
|
||||
|
||||
private static final int ID_RANGE_UP = 4711;
|
||||
private static final int ID_RANGE_DOWN = 4712;
|
||||
private static final int ID_WHITELIST = 4713;
|
||||
private static final int ID_MATCHMETA = 4714;
|
||||
private static final int ID_REDSTONE = 4715;
|
||||
|
||||
private final TileVacuumChest te;
|
||||
|
||||
private final GuiToolTip rangeTooltip;
|
||||
private final IconButtonEIO rangeUpB;
|
||||
private final IconButtonEIO rangeDownB;
|
||||
private final ToggleButtonEIO whiteListB;
|
||||
private final ToggleButtonEIO useMetaB;
|
||||
private final RedstoneModeButton rsB;
|
||||
private final String headerChest;
|
||||
private final String headerFilter;
|
||||
private final String headerRange;
|
||||
private final String headerInventory;
|
||||
|
||||
public GuiVacuumChest(EntityPlayer player, InventoryPlayer inventory, TileVacuumChest te) {
|
||||
super(new ContainerVacuumChest(player, inventory, te));
|
||||
this.te = te;
|
||||
|
||||
ySize = 206;
|
||||
|
||||
int x = RANGE_LEFT;
|
||||
int y = RANGE_TOP;
|
||||
|
||||
rangeTooltip = new GuiToolTip(new Rectangle(x, y, RANGE_WIDTH, 16), Lang.localize("gui.vacuum.range"));
|
||||
|
||||
x += RANGE_WIDTH;
|
||||
rangeUpB = new IconButtonEIO(this, ID_RANGE_UP, x, y, IconEIO.ADD_BUT);
|
||||
rangeUpB.setSize(8, 8);
|
||||
|
||||
y += 8;
|
||||
rangeDownB = new IconButtonEIO(this, ID_RANGE_DOWN, x, y, IconEIO.MINUS_BUT);
|
||||
rangeDownB.setSize(8, 8);
|
||||
|
||||
x = xSize - 16 - 7;
|
||||
y = 104;
|
||||
rsB = new RedstoneModeButton(this, ID_REDSTONE, x, y, te, new BlockCoord(te));
|
||||
|
||||
x = FILTER_LEFT + TileVacuumChest.FILTER_SLOTS*18 + 2;
|
||||
y = 86;
|
||||
whiteListB = new ToggleButtonEIO(this, ID_WHITELIST, x, y, IconEIO.FILTER_WHITELIST, IconEIO.FILTER_BLACKLIST);
|
||||
whiteListB.setUnselectedToolTip(Lang.localize("gui.conduit.item.whitelist"));
|
||||
whiteListB.setSelectedToolTip(Lang.localize("gui.conduit.item.blacklist"));
|
||||
whiteListB.setPaintSelectedBorder(false);
|
||||
|
||||
y += 18;
|
||||
useMetaB = new ToggleButtonEIO(this, ID_MATCHMETA, x, y, IconEIO.FILTER_META_OFF, IconEIO.FILTER_META);
|
||||
useMetaB.setSelectedToolTip(Lang.localize("gui.conduit.item.matchMetaData"));
|
||||
useMetaB.setUnselectedToolTip(Lang.localize("gui.conduit.item.ignoreMetaData"));
|
||||
useMetaB.setPaintSelectedBorder(false);
|
||||
|
||||
for(int i=0 ; i<TileVacuumChest.FILTER_SLOTS ; i++) {
|
||||
ghostSlots.add(new FilterGhostSlot(i, FILTER_LEFT + i*18 + 1, FILTER_TOP + 1));
|
||||
}
|
||||
|
||||
headerChest = Lang.localize("gui.vacuum.header.chest");
|
||||
headerFilter = Lang.localize("gui.vacuum.header.filter");
|
||||
headerRange = Lang.localize("gui.vacuum.header.range");
|
||||
headerInventory = Lang.localize("container.inventory", false);
|
||||
|
||||
((ContainerVacuumChest)inventorySlots).setFilterChangedCB(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
filterChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
rangeUpB.onGuiInit();
|
||||
rangeDownB.onGuiInit();
|
||||
rsB.onGuiInit();
|
||||
addToolTip(rangeTooltip);
|
||||
|
||||
filterChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton guiButton) {
|
||||
ItemFilter itemFilter;
|
||||
switch (guiButton.id) {
|
||||
case ID_RANGE_UP:
|
||||
setRange(te.getRange() + 1);
|
||||
break;
|
||||
case ID_RANGE_DOWN:
|
||||
setRange(te.getRange() - 1);
|
||||
break;
|
||||
case ID_WHITELIST:
|
||||
itemFilter = te.getItemFilter();
|
||||
if(itemFilter != null) {
|
||||
PacketHandler.INSTANCE.sendToServer(PacketVaccumChest.setFilterBlacklist(te, !itemFilter.isBlacklist()));
|
||||
updateButtons();
|
||||
}
|
||||
break;
|
||||
case ID_MATCHMETA:
|
||||
itemFilter = te.getItemFilter();
|
||||
if(itemFilter != null) {
|
||||
PacketHandler.INSTANCE.sendToServer(PacketVaccumChest.setFilterMatchMeta(te, !itemFilter.isMatchMeta()));
|
||||
updateButtons();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setRange(int range) {
|
||||
PacketHandler.INSTANCE.sendToServer(PacketVaccumChest.setRange(te, range));
|
||||
}
|
||||
|
||||
void setFilterSlot(int slot, ItemStack stack) {
|
||||
PacketHandler.INSTANCE.sendToServer(PacketVaccumChest.setFilterSlot(te, slot, stack));
|
||||
}
|
||||
|
||||
void filterChanged() {
|
||||
if(te.hasItemFilter()) {
|
||||
whiteListB.onGuiInit();
|
||||
useMetaB.onGuiInit();
|
||||
updateButtons();
|
||||
} else {
|
||||
whiteListB.detach();
|
||||
useMetaB.detach();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateButtons() {
|
||||
ItemFilter itemFilter = te.getItemFilter();
|
||||
whiteListB.setSelected(itemFilter.isBlacklist());
|
||||
useMetaB.setSelected(itemFilter.isMatchMeta());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float par1, int mouseX, int mouseY) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderUtil.bindTexture("enderio:textures/gui/vacumChest.png");
|
||||
int sx = (width - xSize) / 2;
|
||||
int sy = (height - ySize) / 2;
|
||||
drawTexturedModalRect(sx, sy, 0, 0, this.xSize, this.ySize);
|
||||
drawTexturedModalRect(sx, sy, 0, 0, this.xSize, this.ySize);
|
||||
|
||||
if(te.getItemFilter() != null) {
|
||||
drawTexturedModalRect(sx + FILTER_LEFT, sy + FILTER_TOP, 0, 238, TileVacuumChest.FILTER_SLOTS*18, 18);
|
||||
|
||||
drawGhostSlots(mouseX, mouseY);
|
||||
}
|
||||
|
||||
int headerColor = 0x404040;
|
||||
FontRenderer fr = getFontRenderer();
|
||||
fr.drawString(headerChest, sx+7, sy+6, headerColor);
|
||||
fr.drawString(headerFilter, sx+7, sy+74, headerColor);
|
||||
fr.drawString(headerRange, sx+xSize-7-fr.getStringWidth(headerRange), sy+74, headerColor);
|
||||
fr.drawString(headerInventory, sx+7, sy+111, headerColor);
|
||||
|
||||
IconEIO.BUTTON_DOWN.renderIcon(sx + RANGE_LEFT, sy + RANGE_TOP, RANGE_WIDTH, 16, 0, true);
|
||||
String str = Integer.toString(te.getRange());
|
||||
int sw = fr.getStringWidth(str);
|
||||
fr.drawString(str, sx + RANGE_LEFT + RANGE_WIDTH - sw - 5, sy + RANGE_TOP + 5, ColorUtil.getRGB(Color.black));
|
||||
}
|
||||
|
||||
class FilterGhostSlot extends GhostSlot {
|
||||
final int slot;
|
||||
FilterGhostSlot(int slot, int x, int y) {
|
||||
this.slot = slot;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return te.hasItemFilter();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void putStack(ItemStack stack) {
|
||||
PacketHandler.INSTANCE.sendToServer(PacketVaccumChest.setFilterSlot(te, slot, stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getStack() {
|
||||
ItemFilter itemFilter = te.getItemFilter();
|
||||
if(itemFilter != null) {
|
||||
return itemFilter.getStackInSlot(slot);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package crazypants.enderio.machine.vacuum;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class InventoryFilterUpgrade implements IInventory {
|
||||
|
||||
private final TileVacuumChest te;
|
||||
|
||||
public InventoryFilterUpgrade(TileVacuumChest te) {
|
||||
this.te = te;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
if(slot == 0) {
|
||||
return te.getFilterItem();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int num) {
|
||||
if(slot == 0) {
|
||||
ItemStack current = te.getFilterItem();
|
||||
if(current == null) {
|
||||
return current;
|
||||
}
|
||||
ItemStack result;
|
||||
ItemStack remaining;
|
||||
if(num >= current.stackSize) {
|
||||
result = current.copy();
|
||||
remaining = null;
|
||||
} else {
|
||||
result = current.copy();
|
||||
result.stackSize = num;
|
||||
remaining = current.copy();
|
||||
remaining.stackSize -= num;
|
||||
}
|
||||
te.setFilterItem(remaining);
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack is) {
|
||||
if(slot == 0) {
|
||||
te.setFilterItem(is);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return "FilterUpgrade";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer ep) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack is) {
|
||||
return slot == 0 && te.isItemValidForFilter(is);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package crazypants.enderio.machine.vacuum;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class PacketVaccumChest extends MessageTileEntity<TileVacuumChest> implements IMessageHandler<PacketVaccumChest, IMessage> {
|
||||
|
||||
public static final int CMD_SET_RANGE = 0;
|
||||
public static final int CMD_SET_SLOT = 1;
|
||||
public static final int CMD_SET_BLACKLIST = 2;
|
||||
public static final int CMD_SET_MATCHMETA = 3;
|
||||
|
||||
private int cmd;
|
||||
private int value;
|
||||
private ItemStack stack;
|
||||
|
||||
public PacketVaccumChest() {
|
||||
}
|
||||
|
||||
private PacketVaccumChest(TileVacuumChest tile, int cmd) {
|
||||
super(tile);
|
||||
this.cmd = cmd;
|
||||
}
|
||||
|
||||
public static PacketVaccumChest setRange(TileVacuumChest tile, int range) {
|
||||
PacketVaccumChest msg = new PacketVaccumChest(tile, CMD_SET_RANGE);
|
||||
msg.value = range;
|
||||
tile.setRange(range);
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static PacketVaccumChest setFilterSlot(TileVacuumChest tile, int slot, ItemStack stack) {
|
||||
PacketVaccumChest msg = new PacketVaccumChest(tile, CMD_SET_SLOT);
|
||||
msg.value = slot;
|
||||
msg.stack = stack;
|
||||
tile.setItemFilterSlot(slot, stack);
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static PacketVaccumChest setFilterBlacklist(TileVacuumChest tile, boolean isBlacklist) {
|
||||
PacketVaccumChest msg = new PacketVaccumChest(tile, CMD_SET_BLACKLIST);
|
||||
msg.value = isBlacklist ? 1 : 0;
|
||||
tile.setFilterBlacklist(isBlacklist);
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static PacketVaccumChest setFilterMatchMeta(TileVacuumChest tile, boolean matchMeta) {
|
||||
PacketVaccumChest msg = new PacketVaccumChest(tile, CMD_SET_MATCHMETA);
|
||||
msg.value = matchMeta ? 1 : 0;
|
||||
tile.setFilterMatchMeta(matchMeta);
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
cmd = buf.readByte() & 255;
|
||||
value = buf.readInt();
|
||||
stack = ByteBufUtils.readItemStack(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeByte(cmd);
|
||||
buf.writeInt(value);
|
||||
ByteBufUtils.writeItemStack(buf, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketVaccumChest msg, MessageContext ctx) {
|
||||
TileVacuumChest te = msg.getTileEntity(ctx.getServerHandler().playerEntity.worldObj);
|
||||
if (te != null) {
|
||||
switch (msg.cmd) {
|
||||
case CMD_SET_RANGE:
|
||||
te.setRange(msg.value);
|
||||
break;
|
||||
case CMD_SET_SLOT:
|
||||
te.setItemFilterSlot(msg.value, msg.stack);
|
||||
break;
|
||||
case CMD_SET_BLACKLIST:
|
||||
te.setFilterBlacklist(msg.value != 0);
|
||||
break;
|
||||
case CMD_SET_MATCHMETA:
|
||||
te.setFilterMatchMeta(msg.value != 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -12,25 +12,58 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.TileEntityEio;
|
||||
import crazypants.enderio.conduit.item.FilterRegister;
|
||||
import crazypants.enderio.conduit.item.filter.IItemFilter;
|
||||
import crazypants.enderio.conduit.item.filter.ItemFilter;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.IRedstoneModeControlable;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.render.BoundingBox;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.ItemUtil;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
public class TileVacuumChest extends TileEntityEio implements IEntitySelector, IInventory {
|
||||
public class TileVacuumChest extends TileEntityEio implements IEntitySelector, IInventory, IRedstoneModeControlable {
|
||||
|
||||
private static final double RANGE = Config.vacuumChestRange;
|
||||
private ItemStack[] inv = new ItemStack[27];
|
||||
public static final int ITEM_ROWS = 3;
|
||||
public static final int ITEM_SLOTS = 9*ITEM_ROWS;
|
||||
public static final int FILTER_SLOTS = 5;
|
||||
|
||||
private final ItemStack[] inv = new ItemStack[ITEM_SLOTS];
|
||||
private int range = Config.vacuumChestRange;
|
||||
private ItemFilter filter;
|
||||
private ItemStack filterItem;
|
||||
|
||||
protected RedstoneControlMode redstoneControlMode = RedstoneControlMode.IGNORE;
|
||||
protected boolean redstoneCheckPassed;
|
||||
private boolean redstoneStateDirty = true;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if(!isFull()) {
|
||||
if(redstoneStateDirty) {
|
||||
updateRedstoneStatus();
|
||||
}
|
||||
if(redstoneCheckPassed && !isFull()) {
|
||||
doHoover();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRedstoneStatus() {
|
||||
boolean prevRedstoneCheckPassed = redstoneCheckPassed;
|
||||
redstoneCheckPassed = RedstoneControlMode.isConditionMet(redstoneControlMode, this);
|
||||
redstoneStateDirty = false;
|
||||
if(redstoneCheckPassed != prevRedstoneCheckPassed) {
|
||||
updateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void onNeighborBlockChange(Block blockId) {
|
||||
redstoneStateDirty = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntityApplicable(Entity entity) {
|
||||
if(entity.isDead) {
|
||||
@@ -48,29 +81,31 @@ public class TileVacuumChest extends TileEntityEio implements IEntitySelector, I
|
||||
|
||||
private void doHoover() {
|
||||
|
||||
int rangeSqr = range*range;
|
||||
BoundingBox bb = new BoundingBox(getLocation());
|
||||
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
|
||||
aabb = aabb.expand(RANGE, RANGE, RANGE);
|
||||
aabb = aabb.expand(range, range, range);
|
||||
List<EntityItem> interestingItems = worldObj.selectEntitiesWithinAABB(EntityItem.class, aabb, this);
|
||||
|
||||
for (EntityItem entity : interestingItems) {
|
||||
double x = (xCoord + 0.5D - entity.posX);
|
||||
double y = (yCoord + 0.5D - entity.posY);
|
||||
double z = (zCoord + 0.5D - entity.posZ);
|
||||
if(filter == null || filter.doesItemPassFilter(entity.getEntityItem())) {
|
||||
double x = (xCoord + 0.5D - entity.posX);
|
||||
double y = (yCoord + 0.5D - entity.posY);
|
||||
double z = (zCoord + 0.5D - entity.posZ);
|
||||
|
||||
double distance = Math.sqrt(x * x + y * y + z * z);
|
||||
if(distance < 1.25) {
|
||||
hooverEntity(entity);
|
||||
} else {
|
||||
double speed = 0.06;
|
||||
double distScale = 1.0 - Math.min(0.9, distance / (RANGE * RANGE));
|
||||
distScale *= distScale;
|
||||
double distance = Math.sqrt(x * x + y * y + z * z);
|
||||
if(distance < 1.25) {
|
||||
hooverEntity(entity);
|
||||
} else {
|
||||
double speed = 0.06;
|
||||
double distScale = 1.0 - Math.min(0.9, distance / rangeSqr);
|
||||
distScale *= distScale;
|
||||
|
||||
entity.motionX += x / distance * distScale * speed;
|
||||
entity.motionY += y / distance * distScale * 0.2;
|
||||
entity.motionZ += z / distance * distScale * speed;
|
||||
entity.motionX += x / distance * distScale * speed;
|
||||
entity.motionY += y / distance * distScale * 0.2;
|
||||
entity.motionZ += z / distance * distScale * speed;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,9 +226,86 @@ public class TileVacuumChest extends TileEntityEio implements IEntitySelector, I
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isItemValidForFilter(ItemStack itemstack) {
|
||||
return itemstack != null && itemstack.getItem() == EnderIO.itemBasicFilterUpgrade && itemstack.getItemDamage() == 0;
|
||||
}
|
||||
|
||||
public int getRange() {
|
||||
return range;
|
||||
}
|
||||
|
||||
private int limitRange(int range) {
|
||||
return Math.max(1, Math.min(Config.vacuumChestRange, range));
|
||||
}
|
||||
|
||||
public void setRange(int range) {
|
||||
this.range = limitRange(range);
|
||||
updateBlock();
|
||||
}
|
||||
|
||||
public ItemStack getFilterItem() {
|
||||
return filterItem;
|
||||
}
|
||||
|
||||
public void setFilterItem(ItemStack filterItem) {
|
||||
IItemFilter newFilter = FilterRegister.getFilterForUpgrade(filterItem);
|
||||
if(newFilter == null || newFilter instanceof ItemFilter) {
|
||||
this.filterItem = filterItem;
|
||||
this.filter = (ItemFilter)newFilter;
|
||||
updateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFilterBlacklist(boolean isBlacklist) {
|
||||
if(filter != null) {
|
||||
filter.setBlacklist(isBlacklist);
|
||||
updateFilterItem();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFilterMatchMeta(boolean matchMeta) {
|
||||
if(filter != null) {
|
||||
filter.setMatchMeta(matchMeta);
|
||||
updateFilterItem();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasItemFilter() {
|
||||
return filter != null;
|
||||
}
|
||||
|
||||
public ItemFilter getItemFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public void setItemFilterSlot(int slot, ItemStack stack) {
|
||||
if(slot >= 0 && slot < FILTER_SLOTS && filter != null) {
|
||||
filter.setInventorySlotContents(slot, stack);
|
||||
updateFilterItem();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateFilterItem() {
|
||||
FilterRegister.writeFilterToStack(filter, filterItem);
|
||||
updateBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneControlMode getRedstoneControlMode() {
|
||||
return redstoneControlMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRedstoneControlMode(RedstoneControlMode redstoneControlMode) {
|
||||
this.redstoneControlMode = redstoneControlMode;
|
||||
redstoneStateDirty = true;
|
||||
updateBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCustomNBT(NBTTagCompound nbtRoot) {
|
||||
readContentsFromNBT(nbtRoot);
|
||||
redstoneCheckPassed = nbtRoot.getBoolean("redstoneCheckPassed");
|
||||
}
|
||||
|
||||
public void readContentsFromNBT(NBTTagCompound nbtRoot) {
|
||||
@@ -207,11 +319,36 @@ public class TileVacuumChest extends TileEntityEio implements IEntitySelector, I
|
||||
}
|
||||
}
|
||||
}
|
||||
if(nbtRoot.hasKey("range")) {
|
||||
range = limitRange(nbtRoot.getInteger("range"));
|
||||
} else {
|
||||
range = Config.vacuumChestRange;
|
||||
}
|
||||
if(nbtRoot.hasKey("filter")) {
|
||||
NBTTagCompound filterTag = (NBTTagCompound) nbtRoot.getTag("filter");
|
||||
filterItem = ItemStack.loadItemStackFromNBT(filterTag);
|
||||
IItemFilter flt = FilterRegister.getFilterForUpgrade(filterItem);
|
||||
if(flt instanceof ItemFilter) {
|
||||
filter = (ItemFilter)flt;
|
||||
} else {
|
||||
filterItem = null;
|
||||
}
|
||||
} else {
|
||||
filterItem = null;
|
||||
filter = null;
|
||||
}
|
||||
|
||||
int rsContr = nbtRoot.getInteger("redstoneControlMode");
|
||||
if(rsContr < 0 || rsContr >= RedstoneControlMode.values().length) {
|
||||
rsContr = 0;
|
||||
}
|
||||
redstoneControlMode = RedstoneControlMode.values()[rsContr];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCustomNBT(NBTTagCompound nbtRoot) {
|
||||
writeContentsToNBT(nbtRoot);
|
||||
nbtRoot.setBoolean("redstoneCheckPassed", redstoneCheckPassed);
|
||||
}
|
||||
|
||||
public void writeContentsToNBT(NBTTagCompound nbtRoot) {
|
||||
@@ -225,6 +362,13 @@ public class TileVacuumChest extends TileEntityEio implements IEntitySelector, I
|
||||
}
|
||||
}
|
||||
nbtRoot.setTag("Items", itemList);
|
||||
nbtRoot.setInteger("range", range);
|
||||
if(filterItem != null) {
|
||||
NBTTagCompound filterNBT = new NBTTagCompound();
|
||||
filterItem.writeToNBT(filterNBT);
|
||||
nbtRoot.setTag("filter", filterNBT);
|
||||
}
|
||||
nbtRoot.setInteger("redstoneControlMode", redstoneControlMode.ordinal());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package crazypants.gui;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class GhostSlot {
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
public boolean visible = true;
|
||||
public ItemStack stack;
|
||||
|
||||
public boolean isMouseOver(int mx, int my) {
|
||||
return mx >= x && mx < (x+16) && my >= y && my < (y+16);
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
protected ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
protected void putStack(ItemStack stack) {
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package crazypants.gui;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@@ -20,11 +19,9 @@ import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import codechicken.nei.VisiblityData;
|
||||
import codechicken.nei.api.INEIGuiHandler;
|
||||
import codechicken.nei.api.TaggedInventoryArea;
|
||||
import crazypants.enderio.Log;
|
||||
import crazypants.enderio.gui.IGuiOverlay;
|
||||
import crazypants.gui.ToolTipManager.ToolTipRenderer;
|
||||
import crazypants.render.RenderUtil;
|
||||
@@ -36,6 +33,9 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
|
||||
protected ToolTipManager ttMan = new ToolTipManager();
|
||||
protected List<IGuiOverlay> overlays = new ArrayList<IGuiOverlay>();
|
||||
protected List<GhostSlot> ghostSlots = new ArrayList<GhostSlot>();
|
||||
|
||||
protected GhostSlot hoverGhostSlot;
|
||||
|
||||
protected GuiContainerBase(Container par1Container) {
|
||||
super(par1Container);
|
||||
@@ -111,6 +111,11 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
|
||||
private int realMx, realMy;
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
|
||||
drawGhostSlots(mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
drawForegroundImpl(mouseX, mouseY);
|
||||
@@ -135,7 +140,7 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
|
||||
hoverGhostSlot = null;
|
||||
int mx = realMx = par1;
|
||||
int my = realMy = par2;
|
||||
for (IGuiOverlay overlay : overlays) {
|
||||
@@ -147,6 +152,13 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
}
|
||||
|
||||
super.drawScreen(mx, my, par3);
|
||||
|
||||
if(hoverGhostSlot != null && mc.thePlayer.inventory.getItemStack() == null) {
|
||||
ItemStack stack = hoverGhostSlot.getStack();
|
||||
if(stack != null) {
|
||||
renderToolTip(stack, par1, par2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// copied from super with hate
|
||||
@@ -168,13 +180,93 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
itemRender.zLevel = 0.0F;
|
||||
}
|
||||
|
||||
protected void drawFakeItemsStart() {
|
||||
zLevel = 100.0F;
|
||||
itemRender.zLevel = 100.0F;
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
}
|
||||
|
||||
protected void drawFakeItemStack(int x, int y, ItemStack stack) {
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, stack, x, y);
|
||||
}
|
||||
|
||||
protected void drawFakeItemHover(int x, int y) {
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glColorMask(true, true, true, false);
|
||||
drawGradientRect(x, y, x + 16, y + 16, 0x80FFFFFF, 0x80FFFFFF);
|
||||
GL11.glColorMask(true, true, true, true);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
}
|
||||
|
||||
protected void drawFakeItemsEnd() {
|
||||
GL11.glPopAttrib();
|
||||
itemRender.zLevel = 0.0F;
|
||||
zLevel = 0.0F;
|
||||
}
|
||||
|
||||
protected void drawGhostSlots(int mouseX, int mouseY) {
|
||||
if(ghostSlots.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int sx = getGuiLeft();
|
||||
int sy = getGuiTop();
|
||||
drawFakeItemsStart();
|
||||
try {
|
||||
hoverGhostSlot = null;
|
||||
for(GhostSlot slot : ghostSlots) {
|
||||
ItemStack stack = slot.getStack();
|
||||
if(slot.isVisible()) {
|
||||
if(stack != null) {
|
||||
drawFakeItemStack(slot.x + sx, slot.y + sy, stack);
|
||||
}
|
||||
if(slot.isMouseOver(mouseX - sx, mouseY - sy)) {
|
||||
hoverGhostSlot = slot;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(hoverGhostSlot != null) {
|
||||
// draw hover last to prevent it from affecting rendering of other slots ...
|
||||
drawFakeItemHover(hoverGhostSlot.x + sx, hoverGhostSlot.y + sy);
|
||||
}
|
||||
} finally {
|
||||
drawFakeItemsEnd();
|
||||
}
|
||||
}
|
||||
|
||||
protected GhostSlot getGhostSlot(int mouseX, int mouseY) {
|
||||
mouseX -= getGuiLeft();
|
||||
mouseY -= getGuiTop();
|
||||
for(GhostSlot slot : ghostSlots) {
|
||||
if(slot.isVisible() && slot.isMouseOver(mouseX, mouseY)) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if(!ghostSlots.isEmpty()) {
|
||||
GhostSlot slot = getGhostSlot(mouseX, mouseY);
|
||||
if(slot != null) {
|
||||
ItemStack st = Minecraft.getMinecraft().thePlayer.inventory.getItemStack();
|
||||
slot.putStack(st);
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
private boolean isMouseInOverlay(int mouseX, int mouseY, IGuiOverlay overlay) {
|
||||
int x = mouseX - getGuiLeft();
|
||||
int y = mouseY - getGuiTop();
|
||||
if(overlay.getBounds().contains(x, y)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return overlay.getBounds().contains(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user