This commit is contained in:
70000hp 2024-06-02 12:18:15 -04:00
parent eb8155b11b
commit 518a949306
12 changed files with 209 additions and 73 deletions

View File

@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack;
* @author 70k **/
public class ContainerBase extends Container {
protected IInventory te;
public IInventory te;
public ContainerBase (InventoryPlayer invPlayer, IInventory tedf){
te = tedf;

View File

@ -1,5 +1,6 @@
package com.hbm.inventory.container;
import com.hbm.inventory.SlotPattern;
import com.hbm.tileentity.network.TileEntityRadioTorchCounter;
import net.minecraft.entity.player.EntityPlayer;
@ -8,35 +9,22 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerCounterTorch extends Container {
public class ContainerCounterTorch extends ContainerBase {
protected TileEntityRadioTorchCounter radio;
public ContainerCounterTorch(InventoryPlayer invPlayer, TileEntityRadioTorchCounter radio) {
super(invPlayer, radio);
this.radio = radio;
for(int i = 0; i < 3; i++) {
this.addSlotToContainer(new Slot(radio, i, 138, 18 + 44 * i));
}
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 9; j++) {
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 12 + j * 18, 156 + i * 18));
}
}
for(int i = 0; i < 9; i++) {
this.addSlotToContainer(new Slot(invPlayer, i, 12 + i * 18, 214));
this.addSlotToContainer(new SlotPattern(radio, i, 138, 18 + 44 * i));
}
playerInv(invPlayer, 12, 156, 214);
}
@Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { return null; }
@Override
public boolean canInteractWith(EntityPlayer player) {
return radio.isUseableByPlayer(player);
}
@Override
public ItemStack slotClick(int index, int button, int mode, EntityPlayer player) {

View File

@ -11,11 +11,12 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerCraneExtractor extends Container {
public class ContainerCraneExtractor extends ContainerBase {
protected TileEntityCraneExtractor extractor;
public ContainerCraneExtractor(InventoryPlayer invPlayer, TileEntityCraneExtractor extractor) {
super(invPlayer, extractor);
this.extractor = extractor;
//filter
@ -36,15 +37,8 @@ public class ContainerCraneExtractor extends Container {
this.addSlotToContainer(new SlotUpgrade(extractor, 18, 152, 23));
this.addSlotToContainer(new SlotUpgrade(extractor, 19, 152, 47));
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 9; j++) {
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 103 + i * 18));
}
}
playerInv(invPlayer, 8, 103, 161);
for(int i = 0; i < 9; i++) {
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 161));
}
}
@Override
@ -91,11 +85,6 @@ public class ContainerCraneExtractor extends Container {
return var3;
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return extractor.isUseableByPlayer(player);
}
@Override
public ItemStack slotClick(int index, int button, int mode, EntityPlayer player) {

View File

@ -10,11 +10,13 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerCraneGrabber extends Container {
public class ContainerCraneGrabber extends ContainerBase {
protected TileEntityCraneGrabber grabber;
public ContainerCraneGrabber(InventoryPlayer invPlayer, TileEntityCraneGrabber grabber) {
super(invPlayer, grabber);
this.grabber = grabber;
//filter
@ -37,6 +39,7 @@ public class ContainerCraneGrabber extends Container {
for(int i = 0; i < 9; i++) {
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 161));
}
playerInv(invPlayer, 8, 103, 161);
}
@Override
@ -81,11 +84,6 @@ public class ContainerCraneGrabber extends Container {
return var3;
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return grabber.isUseableByPlayer(player);
}
@Override
public ItemStack slotClick(int index, int button, int mode, EntityPlayer player) {

View File

@ -9,11 +9,12 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerCraneRouter extends Container {
public class ContainerCraneRouter extends ContainerBase {
private TileEntityCraneRouter router;
public ContainerCraneRouter(InventoryPlayer invPlayer, TileEntityCraneRouter router) {
super(invPlayer, router);
this.router = router;
for(int j = 0; j < 2; j++) {
@ -23,16 +24,7 @@ public class ContainerCraneRouter extends Container {
}
}
}
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 9; j++) {
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 47 + j * 18, 119 + i * 18));
}
}
for(int i = 0; i < 9; i++) {
this.addSlotToContainer(new Slot(invPlayer, i, 47 + i * 18, 177));
}
playerInv(invPlayer, 47, 119, 177);
}
@Override
@ -78,9 +70,4 @@ public class ContainerCraneRouter extends Container {
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
return null;
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return router.isUseableByPlayer(player);
}
}

View File

@ -1,10 +1,17 @@
package com.hbm.inventory.gui;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import codechicken.nei.VisiblityData;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.TaggedInventoryArea;
import com.hbm.inventory.SlotPattern;
import com.hbm.inventory.container.ContainerBase;
import com.hbm.packet.NBTControlPacket;
import com.hbm.packet.PacketDispatcher;
import cpw.mods.fml.common.Optional;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
@ -25,8 +32,9 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
public abstract class GuiInfoContainer extends GuiContainer {
@Optional.Interface(iface = "codechicken.nei.api.INEIGuiHandler", modid = "NotEnoughItems")
public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHandler {
static final ResourceLocation guiUtil = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_utility.png");
public GuiInfoContainer(Container p_i1072_1_) {
@ -106,6 +114,22 @@ public abstract class GuiInfoContainer extends GuiContainer {
protected boolean isMouseOverSlot(Slot slot, int x, int y) {
return this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, x, y);
}
//whoever made this private on the super deserves to eat a bowl of wasps
public Slot getSlotAtPosition(int p_146975_1_, int p_146975_2_)
{
for (int k = 0; k < this.inventorySlots.inventorySlots.size(); ++k)
{
Slot slot = (Slot)this.inventorySlots.inventorySlots.get(k);
if (this.isMouseOverSlot(slot, p_146975_1_, p_146975_2_))
{
return slot;
}
}
return null;
}
protected boolean checkClick(int x, int y, int left, int top, int sizeX, int sizeY) {
return guiLeft + left <= x && guiLeft + left + sizeX > x && guiTop + top < y && guiTop + top + sizeY >= y;
@ -136,6 +160,7 @@ public abstract class GuiInfoContainer extends GuiContainer {
return this.fontRendererObj;
}
protected void drawItemStack(ItemStack stack, int x, int y, String label) {
GL11.glTranslatef(0.0F, 0.0F, 32.0F);
this.zLevel = 200.0F;
@ -266,4 +291,51 @@ public abstract class GuiInfoContainer extends GuiContainer {
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
}
}
///NEI drag and drop support
@Override
@Optional.Method(modid = "NotEnoughItems")
public boolean handleDragNDrop(GuiContainer gui, int x, int y, ItemStack stack, int button) {
if(gui instanceof GuiInfoContainer && stack != null){
Slot slot = getSlotAtPosition(x,y);
if(slot instanceof SlotPattern){
if(inventorySlots instanceof ContainerBase) {
NBTTagCompound tag = new NBTTagCompound();
tag.setInteger("slot", slot.slotNumber);
//Item IDs are usually dangerous, but this is only getting called from clientside, while ingame anyway
//if someone somehow gets an ID shift with this i will eat my shoe - 70k
tag.setInteger("id", Item.getIdFromItem(stack.getItem()));
tag.setInteger("meta", stack.getItemDamage());
TileEntity te = (TileEntity) ((ContainerBase) inventorySlots).te;
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(tag, te.xCoord, te.yCoord, te.zCoord));
return true;
}
}
}
return false;
}
//all credits for impl to GTNH's EnderCore fork
@Override
@Optional.Method(modid = "NotEnoughItems")
public boolean hideItemPanelSlot(GuiContainer gc, int x, int y, int w, int h) {
return false;
}
@Override
@Optional.Method(modid = "NotEnoughItems")
public VisiblityData modifyVisiblity(GuiContainer gc, VisiblityData vd) {
return vd;
}
@Override
@Optional.Method(modid = "NotEnoughItems")
public Iterable<Integer> getItemSpawnSlots(GuiContainer gc, ItemStack is) {
return null;
}
@Override
@Optional.Method(modid = "NotEnoughItems")
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gc) {
return Collections.emptyList();
}
}

View File

@ -0,0 +1,17 @@
package com.hbm.tileentity;
import com.hbm.interfaces.IControlReceiver;
import net.minecraft.nbt.NBTTagCompound;
public interface IFilterable extends IControlReceiver {
void nextMode(int i);
@Override
default void receiveControl(NBTTagCompound data) {
if(data.hasKey("slot")){
setFilterContents(data);
}
}
void setFilterContents(NBTTagCompound nbt);
}

View File

@ -7,6 +7,7 @@ import com.hbm.inventory.container.ContainerCraneExtractor;
import com.hbm.inventory.gui.GUICraneExtractor;
import com.hbm.items.ModItems;
import com.hbm.module.ModulePatternMatcher;
import com.hbm.tileentity.IFilterable;
import com.hbm.tileentity.IGUIProvider;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -16,6 +17,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -24,7 +26,7 @@ import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityCraneExtractor extends TileEntityCraneBase implements IGUIProvider, IControlReceiver {
public class TileEntityCraneExtractor extends TileEntityCraneBase implements IGUIProvider, IControlReceiver, IFilterable {
public boolean isWhitelist = false;
public ModulePatternMatcher matcher;
@ -191,7 +193,8 @@ public class TileEntityCraneExtractor extends TileEntityCraneBase implements IGU
return false;
}
@Override
public void nextMode(int i) {
this.matcher.nextMode(worldObj, slots[i], i);
}
@ -246,5 +249,17 @@ public class TileEntityCraneExtractor extends TileEntityCraneBase implements IGU
if(data.hasKey("whitelist")) {
this.isWhitelist = !this.isWhitelist;
}
if(data.hasKey("slot")){
setFilterContents(data);
}
}
@Override
public void setFilterContents(NBTTagCompound nbt) {
int slot = nbt.getInteger("slot");
setInventorySlotContents(
slot,
new ItemStack(Item.getItemById(nbt.getInteger("id")), nbt.getInteger("meta")));
nextMode(slot);
markChanged();
}
}

View File

@ -8,6 +8,7 @@ import com.hbm.inventory.container.ContainerCraneGrabber;
import com.hbm.inventory.gui.GUICraneGrabber;
import com.hbm.items.ModItems;
import com.hbm.module.ModulePatternMatcher;
import com.hbm.tileentity.IFilterable;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.util.InventoryUtil;
@ -19,6 +20,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -29,7 +31,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import java.util.List;
public class TileEntityCraneGrabber extends TileEntityCraneBase implements IGUIProvider, IControlReceiver {
public class TileEntityCraneGrabber extends TileEntityCraneBase implements IGUIProvider, IFilterable {
public boolean isWhitelist = false;
public ModulePatternMatcher matcher;
@ -38,7 +40,8 @@ public class TileEntityCraneGrabber extends TileEntityCraneBase implements IGUIP
super(11);
this.matcher = new ModulePatternMatcher(9);
}
@Override
public void nextMode(int i) {
this.matcher.nextMode(worldObj, slots[i], i);
}
@ -194,5 +197,17 @@ public class TileEntityCraneGrabber extends TileEntityCraneBase implements IGUIP
if(data.hasKey("whitelist")) {
this.isWhitelist = !this.isWhitelist;
}
if(data.hasKey("slot")){
setFilterContents(data);
}
}
@Override
public void setFilterContents(NBTTagCompound nbt) {
int slot = nbt.getInteger("slot");
setInventorySlotContents(
slot,
new ItemStack(Item.getItemById(nbt.getInteger("id")), nbt.getInteger("meta")));
nextMode(slot);
markChanged();
}
}

View File

@ -4,6 +4,7 @@ import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.container.ContainerCraneRouter;
import com.hbm.inventory.gui.GUICraneRouter;
import com.hbm.module.ModulePatternMatcher;
import com.hbm.tileentity.IFilterable;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachineBase;
@ -12,12 +13,13 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
public class TileEntityCraneRouter extends TileEntityMachineBase implements IGUIProvider, IControlReceiver {
public class TileEntityCraneRouter extends TileEntityMachineBase implements IGUIProvider, IFilterable {
public ModulePatternMatcher[] patterns = new ModulePatternMatcher[6]; //why did i make six matchers???
public int[] modes = new int[6];
@ -76,7 +78,7 @@ public class TileEntityCraneRouter extends TileEntityMachineBase implements IGUI
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUICraneRouter(player.inventory, this);
}
@Override
public void nextMode(int index) {
int matcher = index / 5;
@ -123,9 +125,23 @@ public class TileEntityCraneRouter extends TileEntityMachineBase implements IGUI
@Override
public void receiveControl(NBTTagCompound data) {
int i = data.getInteger("toggle");
modes[i]++;
if(modes[i] > 3)
modes [i] = 0;
if(data.hasKey("toggle")) {
int i = data.getInteger("toggle");
modes[i]++;
if (modes[i] > 3)
modes[i] = 0;
}
if(data.hasKey("slot")){
setFilterContents(data);
}
}
@Override
public void setFilterContents(NBTTagCompound nbt) {
int slot = nbt.getInteger("slot");
setInventorySlotContents(
slot,
new ItemStack(Item.getItemById(nbt.getInteger("id")), nbt.getInteger("meta")));
nextMode(slot);
markChanged();
}
}

View File

@ -3,12 +3,14 @@ package com.hbm.tileentity.network;
import java.util.ArrayList;
import java.util.List;
import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.RecipesCommon.AStack;
import com.hbm.inventory.RecipesCommon.ComparableStack;
import com.hbm.inventory.RecipesCommon.OreDictStack;
import com.hbm.inventory.container.ContainerDroneRequester;
import com.hbm.inventory.gui.GUIDroneRequester;
import com.hbm.module.ModulePatternMatcher;
import com.hbm.tileentity.IFilterable;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.INBTPacketReceiver;
import com.hbm.tileentity.network.RequestNetwork.PathNode;
@ -20,12 +22,14 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
public class TileEntityDroneRequester extends TileEntityRequestNetworkContainer implements INBTPacketReceiver, IGUIProvider {
public class TileEntityDroneRequester extends TileEntityRequestNetworkContainer implements INBTPacketReceiver, IGUIProvider, IFilterable {
public ModulePatternMatcher matcher;
@ -55,7 +59,8 @@ public class TileEntityDroneRequester extends TileEntityRequestNetworkContainer
public void networkUnpack(NBTTagCompound nbt) {
this.matcher.readFromNBT(nbt);
}
@Override
public void nextMode(int i) {
this.matcher.nextMode(worldObj, slots[i], i);
}
@ -122,4 +127,19 @@ public class TileEntityDroneRequester extends TileEntityRequestNetworkContainer
}
return new RequestNode(pos, this.reachableNodes, request);
}
@Override
public boolean hasPermission(EntityPlayer player) {
return Vec3.createVectorHelper(xCoord - player.posX, yCoord - player.posY, zCoord - player.posZ).lengthVector() < 20;
}
@Override
public void setFilterContents(NBTTagCompound nbt) {
int slot = nbt.getInteger("slot");
setInventorySlotContents(
slot,
new ItemStack(Item.getItemById(nbt.getInteger("id")), nbt.getInteger("meta")));
nextMode(slot);
markChanged();
}
}

View File

@ -2,17 +2,19 @@ package com.hbm.tileentity.network;
import com.hbm.interfaces.IControlReceiver;
import com.hbm.module.ModulePatternMatcher;
import com.hbm.tileentity.IFilterable;
import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.util.Compat;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityRadioTorchCounter extends TileEntityMachineBase implements IControlReceiver {
public class TileEntityRadioTorchCounter extends TileEntityMachineBase implements IFilterable {
public String[] channel;
public int[] lastCount;
@ -31,6 +33,10 @@ public class TileEntityRadioTorchCounter extends TileEntityMachineBase implement
public String getName() {
return "container.rttyCounter";
}
@Override
public void nextMode(int i) {
this.matcher.nextMode(worldObj, slots[i], i);
}
@Override
public void updateEntity() {
@ -123,5 +129,18 @@ public class TileEntityRadioTorchCounter extends TileEntityMachineBase implement
}
this.markChanged();
}
if(data.hasKey("slot")){
setFilterContents(data);
}
}
@Override
public void setFilterContents(NBTTagCompound nbt) {
int slot = nbt.getInteger("slot");
setInventorySlotContents(
slot,
new ItemStack(Item.getItemById(nbt.getInteger("id")), nbt.getInteger("meta")));
nextMode(slot);
markChanged();
}
}