Jump to content

Bektor

Forge Modder
  • Posts

    852
  • Joined

  • Last visited

Posts posted by Bektor

  1. 4 minutes ago, JTK222 said:

    Math.ceil(chapters.size()/10f) should return the required amount of pages for the chapters.
    But without an Idea how the rest of your code looks and how you handle the pages we cannot tell you anything more.

    Ah, ok. That works. (I guess my idea of fixing this would have been more resource intensive ^^)

     

    I'm handling the pages by actually having an integer variable which counts on which page we are currenty.

    Thats basically how I handle the pages.

        private int page = 0;
        private int maxPages = 0;
        private ArrayList<Chapter> chapters = new ArrayList<>(APIMod.chapters);
    
        protected void initGui() {
            if(!this.chapters.isEmpty()) {
                int buttons = this.buttonList.size() - 1;
                int y = (this.top + 20) / this.chapters.size() + 10;
                for(int i = 0; i < this.chapters.size(); i++) {
                    y += 10;
                    GuiButtonChapter button = new GuiButtonChapter(i + buttons, this.left + 20, y, 100, 10, this.chapters.get(i));
                    button.displayString = I18n.format(this.chapters.get(i).getTitle());
                    this.buttonList.add(button);
                }
            }
        }
    
    public void drawScreen(int mouseX, int mouseY, float partialTicks) {
      super.drawScreen(mouseX, mouseY, partialTicks);
    }

     

  2. Anyone got an idea as I'm stuck on this problem.

     

    Just to mention, also tried this piece of code... well, it resulted in an index out of bounds exception

    for(int z = 0; z < this.maxPages; z++) {
                for(int i = 0; i < this.chapters.size(); i++) {
                    y += 10;
                    if(!(this.chapters.size() > i + z)) {
                        System.out.println("max: " + maxPages);
                        System.out.println("chapters: " + chapters.size());
                        System.out.println("i: " + i);
                        System.out.println("z: " + z);
                        break;
                    }
                    GuiButtonChapter button = new GuiButtonChapter(i + buttons, this.left + 20, y, 100, 10, this.chapters.get(i + z));
                    button.displayString = I18n.format(this.chapters.get(i).getTitle());
                    this.buttonList.add(button);
                }
    }

     

    Quote

    max: 2 // yeah, it should be 3 as chapters is 21 and only 10 per page...

    chapters: 21

    i: 20

    z: 1

     

    Also it does not work. Somehow it even seems to do some weird stuff when going a page back...

  3. Hi,

     

    I'm currently working on a custom book and want to create new pages on fly for it.

    I've got myself and index which includes all chapters the book has and instead of using a scrollbar when more than 10 chapters

    exists for this book, I want to add a new page to show the rest of the chapters.

    So each site on the index page shows only 10 chapters and when you've got 100 chapters the index part of the book will be 10 pages long.

     

    Here is what I've currently got:

     

            if(!this.chapters.isEmpty()) {
                int buttons = this.buttonList.size() - 1;
                int y = (this.top + 20) / this.chapters.size() + 10;
                for(int i = 0; i < this.chapters.size(); i++) {
                    y += 10;
                    GuiButtonChapter button = new GuiButtonChapter(i + buttons, this.left + 20, y, 100, 10, this.chapters.get(i));
                    button.displayString = I18n.format(this.chapters.get(i).getTitle());
                    this.buttonList.add(button);
                }
            }

     

    GuiButtonChapter is the button used to display the chapter and to actually choose to read it.

    Chapters is a ArrayList which get's loaded in from my API as other mods might want to add chapters to the book. This happens when the Gui object is created.

    The top and left variables are used to determine the start point of the GUI.

     

    Thx in advance.

    Bektor

  4. 16 hours ago, LexManos said:

    We are still working on the backend and getting it all together. Sadly its a slow process as there arnt many people working on it. We're trying to bring on another person but ya, it's slow.

    The other side of this, is we don't really collect much data. So there isn't much to actually show.

    The only real important thing this has shown us so far is that J8 is by far the java version of choice.

    Which is what allowed us to decide to force J8 for 1.12+. Minecraft following suit is just bonus reason to do it :P

    If you can think of a metric that you'd like to see on the public front let us know and we can consider it, If we have the data.

    I guess the usage of the Java Version would be interesting. So Modders can see how many people are using which Java Version for modded Minecraft.

  5. Just now, Jay Avery said:

    There should be no need for packets. Where do you change the item name (where do you send the packet)?

    There is a need for sending packets as the code which has the name is Client Side only.

    I also don't have any Container stuff, it's just a normal GuiScreen. So the GuiScreen has to send a packet

    to the Server as the GuiScreen is client side and the server doesn't know about that stuff.

  6. As it seems like stuff changed in the network handler (as it's been a long time I send packets the last time), how

    do I execute this code:

     

    I mean, the network stuff is now running in an extra thread and so I don't have access to the code I want to execute in my onMessage method.

    public class MessageItemNameChanged implements IMessage {
        
        private String name;
        
        /** Default constructor, as it is required. */
        public MessageItemNameChanged() { }
        
        public MessageItemNameChanged(String name) {
            this.name = name;
        }
        
        @Override
        public void fromBytes(ByteBuf buf) {
            ByteBufUtils.readUTF8String(buf);
        }
        
        @Override
        public void toBytes(ByteBuf buf) {
            ByteBufUtils.writeUTF8String(buf, this.name);
        }
        
        public static class MessageItemNameChangedHandler implements IMessageHandler<MessageItemNameChanged, IMessage> {
            
            @Override
            public IMessage onMessage(MessageItemNameChanged message, MessageContext ctx) {
                // This is the player the packet was sent to the server from
                EntityPlayerMP serverPlayer = ctx.getServerHandler().player;
                
                ItemStack stack = serverPlayer.getActiveItemStack();
                stack.setStackDisplayName(message.name);
                
                // No respond packet
                return null;
            }
        }
    }

     

    Just to mention, the packet gets send from the Client to the Server to inform the server about the change in the name of the item.

  7. Hi,

     

    I want to how I can rename an item. For example I've got an item with which you can open up a GUI and inside of this GUI

    you can change the name of the item. I just don't know how to achieve this (besides of sending packets to the Server).

     

    Thx in advance.

    Bektor

  8. 6 minutes ago, JTK222 said:

    Do you mean scale like increase the width by 5 pixels or like stretch that GUI for 10 pixels?

    And this thread might be useful for you too: 

     

    I mean something like what the GUI Scale Option from Minecraft does.

    So when I create a GUI for my Mod which is a bit small I can just scale it to be bigger and when some

    other GUI is too big I can scale it down, without having to change anything globally.

     

    Oh and I already looked at that thread.

  9. I just found out, there is a class called ScaledResolution which could be usefull for this, but

    as this class does not has any documentation I don't know how (or if I should) use this

    class in combination with GlStateManager.scale.

    I also don't know how to recalculate the mouse position after applying the scale stuff.

  10. Hi,

     

    I've got a question: How do I change the scale of my Gui?

    I know there is a scale function in GlStateManager, but using this alone breaks

    my Gui, as it is no longer centered.

     

    Here is my code:

    @SideOnly(Side.CLIENT)
    public class GuiBooks extends GuiScreen {
    
        private int left;
        private int top;
        private final int guiWidth = 146;
        private final int guiHeight = 182;
    
        
        @Override
        public void initGui() {
            super.initGui();
            
            this.left = this.width / 2 - this.guiHeight / 2;
            this.top = this.height / 2 - this.guiHeight / 2;
        }
        
        @Override
        public void drawScreen(int mouseX, int mouseY, float partialTicks) {
            super.drawScreen(mouseX, mouseY, partialTicks);
            
            GlStateManager.color(1.f, 1.f, 1.f, 1.f);
            this.mc.getTextureManager().bindTexture(GuiLexicon.GUI_BACKGROUND);
            this.drawTexturedModalRect(this.left, this.top, 0, 0, this.guiWidth, this.guiHeight);
        }

     

    Just to mention, later I will add buttons and stuff like that to the Gui, so it shouldn't break those things when scaling the Gui (like that the bounding box for the button is after scaling on a different position than the button).

     

    Thx in advance.

    Bektor

  11. 6 minutes ago, larsgerrits said:

    There are multiple ways of handling energy. A few I can think of:

    • Have a main "controller" block which handles everything in the network. (e.g. Applied Energistics, Refined Storage)
    • Have the cables extract energy from outputs and move it around per block (to stop energy from bouncing around, save the block latest received from) until it finds an energy user.
    • Have energy users go down a line of cables to find the nearest energy output and extract it from them instantly. This way the cables don't have to do anything and just serve as a guide.

    Well, the basic network is already working.

    I'm now just wondering how my cables (or to be more clear the controller for the cable line at each end of the cable) can determine if the block they are connected to is a machine or a generator. This should be done mod independent. 

    So my cables could be for example connected to an EnderIO generator and EnderIO machine and still work or EnderIO generator and a machine from me and still work.

    That's why I am wondering how a cable controller can determine if the block it's connceted to is a generator or a machine.

  12. Hi,

     

    I've got some cables which should either extract the energy or send it (haven't decided yet.)

     

    So, to make it here easier: When the machines send energy into the cables and the cables send energy around:

    How does a cable know that the block it should send the energy is the machine in direction A and not the generator in direction B?

     

    It would be simple if I would just implement this for my own mod as I could then use a different TileEntityBase for Generators and

    Machines and check with instanceof, but I don't want my cables to be incompatible with other mods.

    So how does a cable know the energy should go to this machine.

    Spoiler

    (Optional) If anyone knows: Would also be interesting to know how other mods solved this question/problem.

     

    Thx in advance.

    Bektor

  13. Hm... I had a similiar problem with FTB in 1.7.10. On my side the problem was caused by the Windows 10 Anniversary Update.

    I don't know what exaclty went wrong, but after the update I had such problems like you describe above. After a clean install of Windows 10 [again]

    (still the same Update etc., as I made the clean install shortly after the update) it worked again.

     

    So it could be that Windows did something wrong there.

     

    A friend of me had also similiar problems: We fixed it with updating his out of date drivers (CPU and GPU drivers).

  14. Hm, when placing a breakpoint in the findTransferPipes methods in this line:

                if(this.getWorld().getTileEntity(current) instanceof TileEntityPipeEnergy) 
                    this.getBlocksToScan(toSearch, scanned, current); // Breakpoint at this line

     

    It seems like the block is always scanning the same position, as the current BlockPos had the same values even after going through about 40 times this breakpoint.

    It also seems like the else if statement is never reached.

     

    What was my construct for testing it (shows y axis, as x and z are the same for all of these blocks):

    Quote

     

    X -> transfer pipe

    Y -> cable

    X -> transfer pipe

     

     

    EDIT: Hm, seems like the if-statement which checks if new blocks should be added was wrong. I also changed EnumSet.allOf(EnumFacing.class) back to EnumFacing.VALUES. But now it scans all block positions which should be scanned again and adds the correct blocks to the list. ;)

  15. 32 minutes ago, diesieben07 said:

    You need two getCapability calls, one with side, one with null (if side fails).

     

    Make sure that you have a breakpoint inside the lambda. You can't step-into a lambda (unless you are using IntelliJ's new smart step-into). If it really is not called then the map is empty.

    Well, I've had one breakpoint before the lambda and one breakpoint inside the forEach loop with the lambda.

     

    EDIT: Hm, the list seems to be emtpy, so somewhere in the search method findTransferPipes has to be a problem.

  16. 6 minutes ago, diesieben07 said:

    That was a derp on my part. You only need the null when querying getCapability.

     

    With getCapability is the problem that the HashMap does not contains null as I removed it from getBlocksToScan and changed it back to EnumSet.allOf(EnumFacing.class).

    This can be seen there:

    IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, side);

     

    And the debug mode tells me that there seems to be a problem with the forEach loop. Everything above the forEach loop get's called, but not even the first line of the forEach loop get's executed.

  17. Hm, got some problems after adding the energy handling logic (WIP) to all the blocks:

     

    1. @diesieben07 NullPointerException when having null as a side like you suggested.
    2. Energy seems not to get transfered to other the transfer pipe at the end of the cable

     

    Transfer Pipe:

    Spoiler
    
        private void getBlocksToScan(Queue<Pair<BlockPos, EnumFacing>> toSearch, HashSet<BlockPos> scanned, BlockPos pos) {
            // EnumSet.allOf(EnumFacing.class) does not include the null, so machines which don't require a specific
            // site will be ignored
            for(EnumFacing face : TileEntityPipeTransferEnergy.SIDES) {
                // same as pos.north(), just for all directions
                BlockPos offset = pos.offset(face); //NPE... with if(face == null) return; no error, but it won't check null (internal) energy stuff
                if(!scanned.contains(offset))
                    // create a new pair and add it to the list
                    // a pair is just some class which holds two fields
                    toSearch.add(Pair.of(offset, face.getOpposite()));
            }
        }

     

     

    Spoiler
    
    // in update
    
            this.connected.forEach((pos, side) -> {
                final TileEntity tile = this.getWorld().getTileEntity(pos);
                if(tile == null) return;
                
                IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, side);
                if(storage != null) {
                    storage.receiveEnergy(this.container.extractEnergy((int)(10 / this.connected.size()), false), false);
                    System.out.println("Transfer at " + pos.getX() + "," + pos.getY() + "," + pos.getZ() + " contains " + this.container.getEnergyStored() + "FE");
                    this.flag = true; // flag has to be a class member because of inner classes
                }
            });

     

     

    Solar Panel update:

    Spoiler
    
            if(this.world.getTileEntity(this.pos.down()) instanceof TileEntityPipeTransferEnergy) {
                TileEntityPipeTransferEnergy tile = (TileEntityPipeTransferEnergy) world.getTileEntity(getPos().down());
                tile.container.receiveEnergy(this.container.extractEnergy(10, false), false);
            }

     

     

    There is also no log output from transfer pipe with syso and when having it outside of the forEach loop, the log tells me the transfer pipe at the beginning has energy, but at the end of the pipe doesn't have energy.

  18. 7 minutes ago, Choonster said:

     

    The second argument of NBTTagCompound#getTagList is the type ID of the tags contained in the list. Use the IDs from the Constants.NBT class.

     

    For a list of compound tags, pass Constants.NBT.TAG_COMPOUND as the second argument.

    Thx. :)

  19. Just now, Choonster said:

    Use NBTTagList#tagCount to get the number of tags in the list and NBTTagList#getCompoundTagAt to get the compound tag at the specified index of the list.

     

    There are several other specialised NBTTagList#get[Type]At methods that return the number/array/string at the specified index and a general-purpose NBTTagList#get method that returns the NBTBase at the specified index.

    Ah, ok.

    Also what type should I put into there: 

    compound.getTagList("machines", type);
    

    And from where do I get these types? I guess NBTBase, thought.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.