Jump to content

Bektor

Forge Modder
  • Posts

    852
  • Joined

  • Last visited

Everything posted by Bektor

  1. Hi. When changing the default EnergyStorage class, so basically implementing my own using IEnergyStorage, do I need to register a new capability for and do I need a new interface for it? Or can I work with the default capability while using my own implementation of EnergyStorage? Thx in advance. Bektor
  2. Yup! Two arrows and a small number on the end is rather reasonable. It's when you get 4+ that things go stupid. (Windows calculator gives up at 5.65↑↑7) What do these arrows even mean and how to write them on a PC?
  3. Hi, I'm currently working on my own energy system in Forge and I am now struggling with implementing the Forge Energy system in the correct way. Could someone provide some code of a simple block which can store energy so that I can see how to implement this system properly? I'm also wondering if I need stuff like TileEntities etc. for it.... Yeah, got totally no clue about energy on code base, except for that I need capabilities. I'm also wondering how to teleport energy efficient from A to B, so basically you connect two machines with cables and the energy will then be teleported from machine A to machine B instead of teleporting it from machine A to cable A to cable B to machine B. Well, this little text example might look quite simple, but think about a base in the world with kilometers of cable and multiply machines and cable types connected to the network. Thx in advance. Bektor
  4. Hm... after a little testing the cause of the problem, that the item text changes as soon as you put it in your inventory could be caused by the onCreated method, that this method is somehow causing that the nbt data will be re-created or re-set. And without having it (so without having the onCreated method) I just can craft the item and then put it in my inventory. Item has text 1. When I click on it, so that I've got it "over" the inventory and then place it back into the inventory (in the same slot) it has the text 2. As soon as I close the crafting GUI and open it again the problem is gone with that item, but when I craft a new one it occurs with the new one. When pulling items from creative tab into inventory it does not happen somehow the last 2 times I tested a few minutes ago. Also the game seems to remember the NBT Tag of the item in the creative slot. As soon as I get my mouse over it to see the tooltip it shows me for example text 1. When I now close the creative inv and re-open it, the item stills shows the text 1. Only when I then re-start the Game (didn't tested with re-opening the world) it chooses a new random text because the NBT Data of the item in the creative inventory is gone (all items in the inventory still got their data and show the text they showed before). So not sure what's going on there.... Just wrote down here what I've found out with some testing in the last 15-20 minutes. Well, how can I check if a random text was already generated? (I'm currently saving the id of the text in NBT Data for the item, so it get's not lost) Your getLoreIndex method checks if the ItemStack 's compound tag has the "lore" key, use the same check in addInformation . Well, what would be the benefit of having the same check I've got in getLoreIndex in addInformation as of my addInformation method is currently calling the getLoreIndex method.
  5. But having a custom IRecipe (no idea how to do it) wouldn't change the problem with the creative tab. There it's also showing a different text then when you put it in your inventory. And the problem seems to come from that when you put your item into inventory the nbt data isn't saved and is re-created. Which I assume also happens when you haven't closed the crafting table and have the item in inventory. And when having a custom IRecipe, despite the fact that it would propably not fix the problem, I'm wondering how this works with mod compatibility and stuff like custom crafting tables from other mods or the AE system.
  6. Well, I tried to not use it, but when crafting something the text would change as soon as you click on the item. It would only stop when complelty leaving the crafting table and open it again.
  7. public class ItemCeuiScript extends Item { private Random random = new Random(); public ItemCeuiScript(String unlocalizedName, String registryName) { this.setMaxStackSize(1); this.setUnlocalizedName(unlocalizedName); this.setCreativeTab(ModCreativeTab.cTab); this.setRegistryName(new ResourceLocation(Reference.MODID, registryName)); } @Override public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn) { super.onCreated(stack, worldIn, playerIn); this.getLoreIndex(stack); } private int getLoreIndex(ItemStack stack) { if(!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound()); if(!stack.getTagCompound().hasKey("lore")) { int chapter = this.random.nextInt( + 1; stack.getTagCompound().setInteger("lore", UtilsScCeui.getIndexFromID(chapter)); } return stack.getTagCompound().getInteger("lore"); } @Override public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) { tooltip.add(UtilsScCeui.getTypeFromID(getLoreIndex(stack)).getText()); } }
  8. Well, because when I save it to NBT and then let it craft, it shows in the crafting grid for example the text 1 and as soon as it is crafted it shows text 2. Same goes for Creative Tab.
  9. Well, how can I check if a random text was already generated? (I'm currently saving the id of the text in NBT Data for the item, so it get's not lost)
  10. Well, the random thing isn't from me, a friend implemented this and I just didn't changed it because it is working. (never change a running system ) And what I am doing? I'm having an integer chapter which calculates a random number and then the getIndexFromID method get's the correct index at the given position, which basically means, it returns the index from the id. And thinking about it, the name might not be the best. So, chapter calculates a number, some kind of id... Then I've got a list (made out of an enum) and the method getIndexFromID returns the ID or index of the object at that position or 0 when the calculated chapter thing returns a number like for example 20 when the array is 10 long.
  11. You're still pulling the lore from the NBT. Stop that. This function should look like this: private string getLoreIndex(ItemStack stack) { int loreID = stack.getTagCompound().getInteger("lore"); return UtilsScCeui.getIndexFromID(loreID); } Along with the various "hasNBT" and "hasKey" checks. Well, but then the item does not have the nbt tag lore, because it's never created. And what do you mean by "pulling the lore from the NBT"?
  12. Hi, I've got an item which shows a random text and saves which text it displayes, so that it never changes. I'm doing this with an NBTTagCompound from the item stack in the tooltip method. Now I am wondering how I can show the player something like "Unknown Type" when the item is not yet crafted or the player sees it in the creative tab, because it looks weird when the crafting table and the creative tab shows a different text then the actual item has when you get it in your inventory. Example Item Tooltip: What I want: Thx in advance. Bektor
  13. Ok, nevermind, fixed. (hasKey fixed it)
  14. Ok, I changed it now and it does still not work like I want it to be: public class ItemCeuiScript extends Item { private Random random = new Random(); public ItemCeuiScript(String unlocalizedName, String registryName) { this.setMaxStackSize(1); this.setUnlocalizedName(unlocalizedName); this.setCreativeTab(ModCreativeTab.cTab); this.setRegistryName(new ResourceLocation(Reference.MODID, registryName)); } private int getLoreIndex(ItemStack stack) { if(!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound()); if(stack.getTagCompound().getString("lore") == null) { int chapter = this.random.nextInt((8 - 1) + 1) + 1; stack.getTagCompound().setInteger("lore", UtilsScCeui.getIndexFromID(chapter)); } return stack.getTagCompound().getInteger("lore"); } @Override public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) { tooltip.add(UtilsScCeui.getTypeFromID(getLoreIndex(stack)).getText()); } } Now it shows only one text, even when I create a thousand items.
  15. Hi, I've got an item which should display an text in the tooltip. My problem is now, how can I get it to work that each Item shows a different text (and that when the world get reloaded the same text applies to the same item as before). Currently I've got this code here and it works fine, but at the moment where I'm crafting multiply items at the same time (like having a stack of all materials in the crafting table and then clicking shift) it does no longer work. Since it been a very long time where I last dealed with such functionality item items, I don't even know if this is the best way to do it. public class ItemCeuiScript extends Item { private Random random = new Random(); public ItemCeuiScript(String unlocalizedName, String registryName) { this.setMaxStackSize(1); this.setUnlocalizedName(unlocalizedName); this.setRegistryName(new ResourceLocation(Reference.MODID, registryName)); } @Override public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn) { int chapter = random.nextInt((8 - 1) + 1) + 1; // Create a new NBT Tag Compound if one doesn't already exist, or you will crash if(!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound()); stack.getTagCompound().setString("lore", UtilsScCeui.getLine(chapter)); } @Override public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) { if(stack.hasTagCompound() && stack.getTagCompound().getString("lore") != null) tooltip.add(stack.getTagCompound().getString("lore")); } } Thx in advance. Bektor
  16. That's the last line the debugger could give me. When you get back to the precipice of the crash, examine the values of all of the objects involved in the offending statement. Figure out how it became possible for a stairs method to be called from inside a stone block. Then fix your logic so that doesn't happen. BTW, You might be able to make the approach less tedious by learning about conditional break points (test for block == stone brick stairs). Draco's suggestion to "step into" (if possible) is another precious debugging tool. PS: Why does the word "core" appear in your console output? Around here, "core" implies "core mod". Forge doesn't play nice with core mods, and threads asking for help with core mods don't fare well in this forum. Just to avoid the 7's itchy trigger finger, you might want to revise the naming of your package structure to avoid the word "core". (And if this really is a core mod, then we're done here) The word core there is part of a package name. I just created a few packages called core, so that it's clear that all base classes are in there, for example in the blocks package is a core package and in it are all base classes for block which do some stuff so that in the actual block I don't have duplicated code. The only thing I could think of is this line: state = state.getBlock().getActualState(state, worldIn, pos); But this is only called in the doCollapse method which is inside the block. And this method get's only called in the updateTick method. And because this is called in my block there is no way a stairs block can be in there. And I can't see anything where something from the stairs block is called. There isn't even the world stairs in my code. EDIT: With this conditional breakpoint otherState == Blocks.STONE_BRICK_STAIRS.getBlockState(); in the temp method it directly crashes. Last two lines of syso before crash: state is the state which was given from updateTick to doCollapse where it was set with getActualState and otherState is the state which is the scanState in the hasSupport method. While this is the crash log when using the conditional breakpoint; And that's what it looks like in the hasSupport method:
  17. Ok, I debugged now a bit, after I was the last few days ill, and it's kind of tricky to get something out of it: That's the last line the debugger could give me. It showed just something about BlockStone in the this field, I clicked next, and crash... and I think in the moment where I clicked next it gave me this line. EDIT: Exactly what I thought: It shows this message: When you click then on "Resume" in eclipse it crashes... Just a ms before the crash log is posted it posts this message on the console, then the crash and then nothing. Even all variables in the variable field are gone then. So I don't think that will bring me anyway further in fixing the problem.
  18. Ah, ok. So would this be correct? And how to find out from where the mismatch comes and what's causing it then? (never did such stuff before, so more or less lost, only did debugging before when npe's or arrayoutofboundsexceptions occur, so quite easy stuff (atleast it got never complicated in my tools)) private void temp(BlockPos pos, IBlockState state) { System.out.println("pos: " + pos.getX() + "," + pos.getY() + ","+ pos.getZ() + " || state: " + state); } @Override public boolean isHorizontalSupport(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing facing) { BlockPos otherPos = pos.offset(facing); // go 1 in the negative direction from the facing IBlockState otherState = worldIn.getBlockState(otherPos); temp(otherPos, otherState); if(otherState.getBlock().isAir(otherState, worldIn, otherPos) || !otherState.getBlock().isSideSolid(otherState, worldIn, otherPos, facing.getOpposite())) // check opposite direction return false; // Both blocks, the one in the facing direction and this one needs to have solid sides if(!state.getBlock().isSideSolid(otherState, worldIn, pos, facing)) return false; return true; }
  19. Ah, ok. Now I understand what you mean. With the debugger, I'm working on it. I even think I'm using test cases more frequently outside of Minecraft, cause I'm not always sure how to use them with Minecraft (JUnit Test (have to look more deeply into it, assertions and all of that stuff). Oh and after looking more deeply into the code, it's not real recursion, seems I wrote it that way because I first wrote it that way. But I still think it follows a bit the ways of what recursion does. Well, I think the problem is there not really that the code wasn't written for more than block changing, it's more that the complete stuff got so complex at the end, that I missed somewhere something.. Just where. Can't imagine what could go so wrong with just checking all neighbour blocks (which get stored in the list) for side solid and getting there block state and block pos to do so. How can I verify my assumption? And I don't think it's that easy to get an idea of what block it is, cause it's a huge structure. What do you mean by debugging method? Never heard of such a thing in school or while I thaught myself Java, a few years ago with some books. Maybe I've heard of it in German, cause I learned all of it in German cause my english wasn't the best back then and know we learn it in German in school... even less English than in my books.... I think I'm just printing all block-states and load the world which results direclty in a crash. I think that should give me the block pos and block state of the block causing the crash.. The result: EDIT: all block states on the position seem to be correct. But I'm not quite sure if the stair is correct, because of the half=top, shape=straigt and facing=east stuff: EDIT 2: Interesting, to check for the coords I broke the structure a bit apart while disabled the hasSupport check. Enabled it, no crash in the world... Placed a few of my blocks... no crash... broke one of my blocks, a few of my blocks fall down and crash because of BlockStairs. EDIT 3: I really start wondering what line of code can break that stuff so much appart...
  20. The method hasSupport get's called in the updateTick method like explained above. But the interesting stuff about the problem is, it happens only when copying blocks with the MC or world edit command. When placing them normal in creative or survival everything works fine. Besides, what's a stale state and how can I step through the recursive method in a way I can see when a block is getted which doesn't exist anymore or isn't there yet?
  21. Ok. I think I have to explain some stuff about this code. ^^ It's also not the full code cause I don't want to get too much code in here which has really nothing to do with the problem. And just to mention, some methods which might be called in the code above are classes from an interface and are not implemented in this abstract class, because this class is just the ground work from which all other block's extends. The onBlockAdded method and the neighborChanged just tell Minecraft to schedule an Update, so that I don't get stuff like flying sand which happens sometimes in Minecraft. The updateTick checks for block support with the hasSupport method from above. Before doing so it calls this line: state = state.getBlock().getActualState(state, worldIn, pos); The data from the updateTick method and the state data from the code above go to the hasSupport method. Then the hasSupport method starts a recursive scan. How many blocks are scanned depends on the location and the block which has asked for a scan, so that different materials can have different abilities (like harder rock does not fall as fast as softer rock). The hole thing is basically a physics calculation for block support physics. What to do with the boolean which is returned by hasSupport depens all on the block. It's the block's decision what to do with it. Some blocks get replaced by air, other might spawn a normal falling entity. That's all what it does. Besides the problem, if you know a way to get it more performant, let me know. (Also trying to get it done that 10k blocks can't fall at the same time which causes the netty thread to crash and for some reason my router seems to stop working when the Netty thread crashes on the local hosted server )
  22. Hm... after running in debug... Showed the value 123 as block id, clicked next breakpoint, crash. Breakpoint was on line 140, so if(state.getBlock().isSideSolid(worldIn.getBlockState(pos.down()), worldIn, pos.down(), EnumFacing.UP)) { Console output: Crash Report: The structure which was copied was made out of my stone, my stonebricks, vanilla lava, vanilla stonebricks, vanilla stairs, vanilla fences, much more vanilla stuff I don't recognize and a complete redstone circuit. I hope this helps.
  23. That's a weird crash, since my code has nothing to do with stairs or air. EDIT: harder then I thought to get it into debug mode.... just ticks every second so the breakpoint on the error will get called 5 times a second.... for each block. EDIT 2: How to debug this??? Got it now running fine in dev environment... Only problem while debugging is that all values are closed in the moment where it crashes....
×
×
  • Create New...

Important Information

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