Jump to content

Roboguy99

Members
  • Posts

    230
  • Joined

  • Last visited

Posts posted by Roboguy99

  1. Kill me.

     

    public int getField(int id)
    {
    	switch (id)
    	{
    		case 0:
    			return this.processTimeRemaining;
    		case 1:
    			return TileOreProcessor.PROCESS_TIME;
    		case 2:
    			return this.energyStorage.getEnergyStored();
    		case 3:
    			return this.energyStorage.getMaxEnergyStored();
    	}
    
    	return 0;
    }
    
    public void setField(int id, int value)
    {
    	switch (id)
    	{
    		case 0:
    			this.processTimeRemaining = value;
    			break;
    		case 3:
    			this.energyStorage.setEnergyStored(value);
    	}
    }

     

    setField

    case 3

    should be

    case 2

    .

     

    Further evidence that magic numbers are hell. I'm changing them now.

  2. Err...I'm going to say no, they did not...Perhaps you should explain what you mean by BlockState property enums more?

     

    That code is far from being finished and tidied, and yes, I know, the magic numbers do need to go ASAP. Hell, the whole class is a disgusting mess that needs splitting.

     

    The get/set field methods do sorta sync, but I guess that's not properly syncing between server/client?

     

    What *should* I be doing to sync then? And why does

    processTimeRemaining

    sync when the energy doesn't?

  3. I'm trying to implement the RF energy API on a TileEntity. I'm having quite a bit of trouble with synchronizing the energy between server and client though. What confuses me most is that I am already synchronizing another variable,

    processTimeRemaining

    , without an issue. Replicating the same steps for energy has not worked.

     

    I thought perhaps I need a packet, but

    processTimeRemaining

    works without one, which confuses me.

     

    The exact issue is with a progress bar in the GUI not being synced correctly; investigation shows this is because the client/server show different values for the energy. As I said, this issue does not exist with

    processTimeRemaining

    .

     

    Code:

     

    TileEntity update

    TileEntity sync code (various methods as well as energy getters/setters until pretty much the end of the class)

    Container

    Gui

     

    I'm sure it's something stupid and obvious; it normally is. I've spent hours trying various things, and nothing has worked so far, and I am very confused. Any help is appreciated.

  4. Right - I've taken everything into account (and overall the code is a lot better), but I'm still getting the same issue (stack size 0). I think maybe this is because I'm using

    Minecraft.getMinecraft().thePlayer

    so the update is inevitably still client-side only, in which case how do I get the player from the server? Or is it something else (it normally is...)?

     

    Code here.

    Hmmm I wonder

    public void onUpdate(ItemStack stack, World world, "Entity entity", int par4, boolean par5)
    

     

    Ah! I forgot casting existed. I assumed that was related to the actual item rather than the player. Thanks.

     

    --

     

    I know it may seem stupid to you, and I fully understand why you get annoyed, but perhaps a little less of the sarcasm please? People have to start somewhere...

  5. So, first of all, calling Math.floor like that does not actually do anything. Math.floor has a return value, which you completely ignore. You do half the stack size, but not because you call Math.floor.

    stack

    is a local variable. Assigning a value to it does not change anything about the players inventory. You have to actually set the slot to null in the inventory.

     

    As for the ticksUntilUpdate: You cannot store data in the Item object like that. There is one instance of your Item class for everything, it is shared between client and server in singleplayer and shared across the whole server on a Dedicated Server. If you want a countdown, you need to store it in the ItemStack.

     

    Everything you just said made total sense and seems so obvious I feel really stupid. I saw Math.Floor earlier and thought "Oh I put /=, it doesn't matter I'm ignoring the return".

     

    One thing though: How would I store it on the ItemStack (principally as opposed to literally)? Is there an ItemStack tick method, or do I need a TickEvent or something else? At this point I've gone from stupid to blank.

     

    This is why you don't leave unfinished code for months...I started this method like half a year ago...

     

    Thanks for all the help so far.

  6. What in the heck are you doing? You don't need packets or anything like that for this...

    onUpdate

    is called on both client and server. Check that you are on the server and then do the deletion directly.

     

    I didn't actually think I needed a packet, I just quickly made one to be 100% sure...The reason I left such a mess of code in was mainly to give people an idea of what I had actually tried.

     

    Anyway, to my understanding I was already doing that? I've tidied the code up:

     

    if(!world.isRemote)
    {
    Math.floor(stack.stackSize /= 2F); //Reduce stack size
    f(stack.stackSize == 0) stack = null;
    }
    

     

    But this doesn't run.

     

    After some investigation, though, I have discovered that this is due to the half-life tick system and lag/desync. I'm afraid I'm about to hijack my own thread a little bit here.

     

    Currently I am attempting to reduce

    ticksUntilUpdate

    every time the item updates, but the number does not decrease by 1 every time and the server and client threads are on different numbers (either that or IntelliJ has a problem keeping up with printing numbers so often?). As a result, the update code is never actually fired server-side.

     

    Is there a "proper" way of counting ticks/firing code every second?

     

    Code here

  7. I am trying to create an itemstack "half-life" system, in that every x number of ticks the itemstack halves in size. Then, when the stack is at a size of 1 and halves, I want the stack to be deleted.

     

    I am sure this is really simple, but I have tried everything I can think of and the stack does not delete properly. Instead, it displays with a stack size of 0 in red, and then as soon as you right click/drop/attempt to move in inventory it is instantly deleted (making me think it's an odd sync issue).

     

    This runs in the item's OnUpdate() method

     

                     Math.floor(stack.stackSize /= 2F); //Reduce stack size
    
    				if (stack.stackSize <= 0)
    				{
    					Chemistry.INSTANCE.getNetworkWrapper().sendToServer(new ItemDelete(stack));
    
    					EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    					player.inventory.markDirty();
    					player.inventory.deleteStack(stack);
    
    					stack.stackSize = 0;
    					stack = null;
    				}

     

     

    As you can see, there is a lot of things there, and I'm fairly certain everything there results in the same odd 0-sized stack.

     

    Here is the ItemDelete packet referenced in the above code (again, I've tried pretty much everything):

     

                            ItemStack stack = message.stack;
                    	stack.useItemRightClick(ctx.getServerHandler().playerEntity.worldObj, ctx.getServerHandler().playerEntity, ctx.getServerHandler().playerEntity.getActiveHand());
                    	stack.stackSize = 0;
                    stack = null;
                    ctx.getServerHandler().playerEntity.inventory.deleteStack(stack);

     

     

    Sorry the indentation is a bit off...

  8. Well I registered the ItemBlock and it worked perfectly.

     

    I then thought about why it crashed when I didn't register the block.

     

    I then realised the block is used as a creative tab icon, so it crashed.

     

    Whoops.  :-\

     

    --

     

    Thanks for the help, I'll look at those two other things you just mentioned and change them accordingly.

     

    EDIT: Ah, you picked it up before I did. I just didn't read your reply in time. Thanks again.

  9. Well I registered the ItemBlock and it worked perfectly.

     

    I then thought about why it crashed when I didn't register the block.

     

    I then realised the block is used as a creative tab icon, so it crashed.

     

    Whoops.  :-\

     

    --

     

    Thanks for the help, I'll look at those two other things you just mentioned and change them accordingly.

     

  10. Eh, no you are definitely also registering Blocks. Or at least one Block: https://git.io/v63IP. This Block does not have an ItemBlock, meaning it cannot exist in any inventory or as an item entity, etc. It can only exit placed down in the world.

     

    I've commented the registry line out: https://github.com/JakeStanger/Chemistry/blob/master/src/main/java/roboguy99/chemistry/block/BlockCompoundCreator.java#L30

     

    I'll try actually registering an ItemBlock still and see if that makes a difference still though.

     

    P.S. how do you get shortened GitHub links?

  11. Something is causing there to be an ItemStack with a null item.

    I suspect this is because you are creating ItemStacks for your Blocks but they don't have an ItemBlock registered.

     

    Hmm, I'm registering items rather than blocks, and just to make sure I've disabled all blocks from my mod. I am a little unsure with the new registry system though. Is this correct?

     

    this.setRegistryName(name);
    GameRegistry.register(this);
    

     

    (where

    this 

    is a class extending

    Item

    )

     

    The game launches correctly, but maybe it's the problem...?

  12. Sorry to bring this up again after so long, but I haven't had the time to play around since you replied.

     

    I have (as far as I can tell) done what you said, and I'm still getting a NullPointerException. It is is a different place this time though:

     

     

    ---- Minecraft Crash Report ----
    // Daisy, daisy...
    
    Time: 06/08/16 15:20
    Description: Rendering screen
    
    java.lang.NullPointerException: Rendering screen
    at net.minecraft.client.renderer.RenderItem.renderItemOverlayIntoGUI(RenderItem.java:429)
    at net.minecraft.client.renderer.RenderItem.renderItemOverlays(RenderItem.java:399)
    at net.minecraft.client.gui.inventory.GuiContainerCreative.drawTab(GuiContainerCreative.java:923)
    at net.minecraft.client.gui.inventory.GuiContainerCreative.drawGuiContainerBackgroundLayer(GuiContainerCreative.java:747)
    at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:94)
    at net.minecraft.client.renderer.InventoryEffectRenderer.drawScreen(InventoryEffectRenderer.java:59)
    at net.minecraft.client.gui.inventory.GuiContainerCreative.drawScreen(GuiContainerCreative.java:634)
    at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:374)
    at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1147)
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1139)
    at net.minecraft.client.Minecraft.run(Minecraft.java:406)
    at net.minecraft.client.main.Main.main(Main.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
    at GradleStart.main(GradleStart.java:26)
    
    

     

     

    As far as I can tell, nothing from my BakedModel class is null, and it's quite difficult to put breakpoints in item render code due to how often it executes.

     

    I hope this is an easy fix and me being stupid, thanks for any help.

  13. Ok that helps loads, thanks a lot.

     

    One thing:

     

    `if(!(model instanceof IBakedModel)) model = new IBakedModel.Wrapper(model, DefaultVertexFormats.ITEM)`

     

    The wrapper class no longer exists. What does this need to be, if this line needs to exist at all?

     

    Also, upon attempting to render the item the game crashes with a NullPointerException:

     

     

    net.minecraft.util.ReportedException: Rendering item
    at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1174) ~[EntityRenderer.class:?]
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1139) ~[Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:406) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_101]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_101]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_101]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_101]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_101]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_101]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:26) [start/:?]
    Caused by: java.lang.NullPointerException
    at net.minecraft.client.renderer.RenderItem.getItemModelWithOverrides(RenderItem.java:254) ~[RenderItem.class:?]
    at net.minecraft.client.renderer.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:356) ~[RenderItem.class:?]
    at net.minecraft.client.renderer.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:345) ~[RenderItem.class:?]
    at net.minecraft.client.gui.inventory.GuiContainerCreative.drawTab(GuiContainerCreative.java:922) ~[GuiContainerCreative.class:?]
    at net.minecraft.client.gui.inventory.GuiContainerCreative.drawGuiContainerBackgroundLayer(GuiContainerCreative.java:747) ~[GuiContainerCreative.class:?]
    at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:94) ~[GuiContainer.class:?]
    at net.minecraft.client.renderer.InventoryEffectRenderer.drawScreen(InventoryEffectRenderer.java:59) ~[inventoryEffectRenderer.class:?]
    at net.minecraft.client.gui.inventory.GuiContainerCreative.drawScreen(GuiContainerCreative.java:634) ~[GuiContainerCreative.class:?]
    at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:374) ~[ForgeHooksClient.class:?]
    at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1147) ~[EntityRenderer.class:?]
    ... 15 more

     

     

    I haven't got time to properly debug this at the moment, so is there anything obvious? My two existing theories are a) it's to do with the line above (I commented it out to test) or b) it's the bottom 2 methods in the class returning null (what should they be returning?)

  14. So I've been porting my mod from 1.8.9 to 1.10.2, and for the most part I've been able to do so without an issue. There are a few things I've been unable to fix, however:

     

    1) `Block#setBlockBounds()` apparently no longer exists. What is the replacement for this?

    2) What is the purpose of the new return value on `TileEntity#writeToNBT()`? Is it safe to just ignore it?

    3) (This is probably the larger question) `IFlexibleBakedModel` has gone. I previously wrote (with a LOT of help from Diesieben) rendering code so my item displayed using a different model in the player's hand compared to everywhere else. Is this an easy fix, and how would I go about updating this? See here for code.

     

    Any help is greatly appreciated. And just so you know my knowledge of the model system is pretty lacking.

  15. I'm still confused about the model-loop thing. Does that mean I could specify any item I liked in there? It requires an item to register, surely? So I need to give both models to every item, no?
    The item there can be any item, as long as it's registered. I don't know why that method takes an Item argument, all it does is make sure the given model will be loaded & baked so it's useable in-game.

     

    Where do go from here: Put a breakpoint in your IPAM and check what it does. It should never return null nor itself. Make sure it does not! If it does, check why.

     

    Found it! Y'know those methods you said would never be called in the IBakedModel? Well

    RenderEntityItem

    calls

    getItemCameraTransforms

    , which returns null. To fix it, all I had to do was return

    ItemCameraTransforms.DEFAULT

    .

     

    It's all deprecated, so as to what the deal is with it, I don't know. It might be worth pointing that out to a Forge model dev or something though...

     

    And with that, everything works exactly as it should. Thanks a lot for the help and actually sticking with me.

     

    EDIT: I'm on Forge 1.8.9 - 11.15.1.1722 if that helps/matters in any way.

  16. You're looking at an old version of the ClientProxy there. Try this. That might save a little bit of confusion.

     

    I'm still confused about the model-loop thing. Does that mean I could specify any item I liked in there? It requires an item to register, surely? So I need to give both models to every item, no?

     

    I didn't realise the "element_" models are actually rendered. In my head, out of sight out of mind.

  17. Eh?

     

    Maybe if I explained a little better:

     

    -Textures switch correctly in the inventory or when the item is held. This works absolutely fine. There are no errors about missing models or anything.

    -The game crashes when I drop the item, and it becomes an EntityItem.

     

    In terms of the models:

    -In the first instance, every element's name starts with the "element_" prefix. That is the registered model, but it does not actually exist as a resource because its never rendered.

    -The second instance is checking that it's an element, because every element name starts with "element_" and so do all of the registered model locations.

    -The third instance, where I used "element-" is the model when it is displayed in the GUI, and it does exist.

     

    I understand it's pretty poor and confusing at the moment, and I am slowly going through and tidying everything up. Perhaps it's because one of the models doesn't exist, but surely that wouldn't crash the game, because it should either return one of the two IBakedModel models or display as if the model wasn't found?

     

    And the loop - I'm registering 118 different items; surely I can't register 118 different items without looping, and surely it's therefore not the same thing being registered twice?

×
×
  • Create New...

Important Information

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