Jump to content

44tim44

Members
  • Posts

    25
  • Joined

  • Last visited

Everything posted by 44tim44

  1. Yeah, I'll try to learn capabilities. But, I'd rather start from a point where my code is already working, so I don't run into trouble. I do think I found the problem myself though: the variable totalChargeTime in TESolarPanel is not initialized unless an item is place in the charging slot in ContainerSolarPanel. Which is a bit stupid, since as you said, I don't even use the passed itemstack in getItemChargeTime() to calculate totalChargeTime.
  2. 1) Code is still WIP, and a lot of the code is copypasted from when I was only using batteries, and not cables. (Will be fixed) 2) See 1) The nullable is just an addon, so I don't have to pass an Itemstack to get the chargeRate. 3) See 1) 4) Because an Battery can give and take Charge, IChargeable can only take. (In the logic of my machines) 5) Because whenever I've tried to learn capabilities, I've run into troubles. I had troubles with capabilities attached to itemstacks not syncing properly between server and client. (I know I know, I should learn how to use capabilities properly, but I haven't yet. And this works in the meantime.) 6) Will fix. 7) Old code not cleaned up properly.
  3. Update: If I use if(!world.isRemote){ chargingStation.increaseCharge(); } then everything works, except it won't start unless the SOLARPANEL is initialized, by placing a battery in the solarpanels charging-slot
  4. I've implemented an energy-cable-system in my mod, and I'm having trouble with the communication between the two machines on either side of a cable. I've made a generator, "SolarPanel", and a consumer, "Pulverizer". They both work perfectly, transferring generated energy from the solar panel to the pulverizer through the cable. (The cables forward what the machine on the opposite end of the cables is, to the the machine on the first end) However, I'm now implementing a second consumer, "ChargingStation", which is a battery-bank of sorts. It has an internal storage of energy. When my SolarPanel tries to use the ChargingStations increaseCharge()-method, the method executes, but the result; a higher energy-value in the storage, does not get recorded. In other words: if I'm looking at the GUI of the ChargingStation, I can see the energy in the storage increase, but as soon as I close (and reopen) the GUI, the value resets to 0. I assumed this was because of client/server mismatch, so I made the call of increaseCharge() from the SolarPanel check for !isRemote(), which solved the problem, but only if the ChargingStation is "initialized" by having it use increaseCharge() itself (which is done when the ChargingStation tries to charge using a battery in its inventory.) Otherwise, it never starts charging to begin with. Any help on how to fix this would be awesome. Thank you. Code: ChargingStation: https://github.com/44tim44/BetterThanElectricity_1.12.2/blob/master/src/main/java/se/sst_55t/betterthanelectricity/block/chargingstation/TileEntityChargingStation.java SolarPanel: https://github.com/44tim44/BetterThanElectricity_1.12.2/blob/master/src/main/java/se/sst_55t/betterthanelectricity/block/solarpanel/TileEntitySolarPanel.java Cable: https://github.com/44tim44/BetterThanElectricity_1.12.2/blob/master/src/main/java/se/sst_55t/betterthanelectricity/block/cable/TileEntityCable.java
  5. Nevermind, managed to solve it on my own. My cables were referring back to the hub, so the hub got itself in its list of things to find the charge of, which resulted in a loop.
  6. Hi, I'm trying to implement a energy-cable system in my mod. My choice of algorithm was; Having the cables simply forward which generator it's connected to, to the machine on the other end of the cable. [G][C][C][C][M] (G = Generator, C = Cable, M = Machine) Now, I'm trying to implement a hub, which allows multiple generators to connect to one hub, which sums up the charge from the generators and sends it along its one output-side. [G][C] [H][C][M] [G][C] (G = Generator, C = Cable, M = Machine, H = Hub) However, I'm getting a StackOverflowError, when calculating the charge-sum in the hub. I'm not quite sure if I've accidentally programmed a recursive method, but I don't think so, and I'm unable to find why it's happening. All code is available at https://github.com/44tim44/BetterThanElectricity_1.12.2/tree/master/src/main/java/se/sst_55t/betterthanelectricity The hub's TE is block/multiSocket/TileEntityMultiSocketIn Any help is appreciated!
  7. I do think my main problem, for the bug itself, was the fact that I didn't have a unique id when registering the Packet&Handler. *facepalm* But I still get "ByteBuf.release() was not called before it's garbage-collected." in my stacktrace from time to time. Is that because of something I did wrong? Because I can't find anyone else with the same problem on google (relating to minecraft).
  8. I thought I was handling the packet on the main thread by using serverPlayer.getServerWorld().addScheduledTask(() -> { //Insert code here } ? So basically, in ItemJetpack, the only thing that should happen inside if(Minecraft.getMinecraft().gameSettings.keyBindJump.isKeyDown()) { //Insert code here } is sending a packet saying "Space is pressed" and let onMessage() handle everything? EDIT: Okay, nevermind. I just do it like I did before, but let the packet handle the decreasing of the charge, instead of settingCharge to what is clientSide. Thanks!
  9. I've implemented a simple Jetpack in my mod, which utilizes the damagevalue of the item to hold it's batterycharge. The majority of the code is executed client-side, since it requires KeyInput from the player, hence I update the charge drained on the server with a custom Packet. However, at seemingly random times, the charge of the item is reset to a higher value, for seemingly no reason. (Only tested during Multiplayer-play.) Something that might be related is the fact that I sometime get a "ByteBuf.release() was not called before it's garbage-collected.", which I've been unable to find the reason for. Code: https://github.com/44tim44/BetterThanElectricity_1.12.2 The jetpack itself is in item>ItemJetpack.java The jetpack-packet is in network/PacketToServerJetpack.java Thanks!
  10. That fixed it! I changed is BlockPane to this and now it works! public static boolean isBlockPane(IBlockState state) { return state.getBlock() instanceof BlockSlabVerticalBase && !((BlockSlabVerticalBase) state.getBlock()).isDouble(); } But since I've already started this thread I'm gonna hijack it and ask for help with the collision boxes too. The Vertical Slabs don't have the correct collision boxes. Even though I am overriding addCollisionBoxToList the Vertical Slabs still have "full block" collision boxes. And I have no idea why. Github is up to date.
  11. Yeah, sorry wasn't aware of the package naming conventions. I fixed that, and all the other things you mentioned, except for EntityEntryBuilder. Gonna take a look at that later. I've cleaned up my repo now, and it should compile properly now. Sorry, and thanks! https://github.com/44tim44/BetterThanElectricity
  12. So, I've implemented sideways-slabs, and I'm trying to add a outer/inner corner effect on them, just like stairs have. I'm having a few problems with collisionBoxes, but that's beside the point for now. Now, my problem: For some reason, I get this error, when placing a sideways-double-slab: java.lang.IllegalArgumentException: Cannot get property PropertyEnum{name=position, clazz=class com.bte.mod.block.BlockSlabVerticalBase$EnumPosition, values=[north, south, east, west]} as it does not exist in BlockStateContainer{block=bte:smoothstone_vertical_doubleslab, properties=[]} at net.minecraft.block.state.BlockStateContainer$StateImplementation.getValue(BlockStateContainer.java:204) at com.bte.mod.block.BlockSlabVerticalBase.getPaneShape(BlockSlabVerticalBase.java:134) at com.bte.mod.block.BlockSlabVerticalBase.getActualState(BlockSlabVerticalBase.java:122) Which makes NO sense, since this is what the code looks like in BlockSlabVerticalBase.getActualState(): public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { if(isDouble()) { return state; } else { return state.withProperty(SHAPE, getPaneShape(state, worldIn, pos)); } } For some reason, the instance of bte:smoothstone_vertical_doubleslab seems to return isDouble() as false, even though it's class has: @Override public boolean isDouble() { return true; } I'm going insane trying to figure out why this is happening... All my code is available on https://github.com/44tim44/BetterThanElectricity in case you want to check on anything. Any help at all would be tremendously appreciated!
  13. Hi. I'm planning to make a sliding door, but I'm uncertain on how to go about implementing it. I'd like to avoid too complex multi-block structures because I don't really know enough about how to make them. Instead I've been thinking of simply having a normal door (albeit with a different model) that is somehow animated, to simulate the door sliding open, when interacted with. However, I'm not sure how to best achieve the effect. The ideas I have so far: - Spawning an entity, replacing the "closed door"-block, have the entity move to desired position and then replace the entity with an "open door"-block. - Simulate the pushing effect of a block being pushed by a piston - Making the door based on the piston itself. Essentialy making a pseudo piston which is unable to push things, and simply acts as an extendable block. I'm quite new to minecraft modding, and I'm definitely no expert at java, but I do know it. Any help at all would be appreciated!
  14. Soo, I can just add all the contents of pre-/post-/Init to the respective methods in the main Mod-file instead? Awesome. I was just following a tutorial for setting up the basic stuff, so I wasn't sure what I could or couldn't do. Are there any things that NEED to be handled in the proxies, rather than the main Mod-file?
  15. Okay, I seem to have fixed everything. ...I think. But if someone has the time to go through my implemation of the Charge-Capability properly, I'd really appreciate it, because I think I haven't properly initialized my ItemBattery to have it's correct starting charge and maxCharge. I just have a default maxCharge in the capability itself, and it magically works as of now, but I'd really like for it to be done properly. The GitHub is updated to latest version. https://github.com/44tim44/Capability_Battery/tree/master/src/main/java/com/bte/mod
  16. Yeah, I was suspecting that! But it does unfortunately not solve the actual problem... But any help at all is appreciated. Thanks! EDIT: I found the problem for the NPE; I had this: CapabilityManager.INSTANCE.register(ICharge.class, new ChargeStorage(), Charge.class); MinecraftForge.EVENT_BUS.register(new CapabilityHandler()); in init() instead of in preInit() in the proxy. However, it seems as if the NBTwriting isn't working properly, because as soon as I close an inventory, the Battery resets it's charge to 0, despite actual charge before closing an inventory.
  17. https://github.com/44tim44/Capability_Battery/tree/master/src/main/java/com/bte/mod The classes of interest are all the capability-classes in ../capability/ and ItemBattery in ../item/.
  18. Anybody have any idea what I've done wrong? I'm completely stumped. I basically followed this tutorial: https://www.planetminecraft.com/blog/forge-tutorial-capability-system/ But I don't have an eventHandler, since I'm attaching to an ItemStack and not an Entity, so I have this: @Override @Nullable public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { return new ChargeProvider(); } in my ItemBattery.java-class instead. And as I said in the previous post, I now get an NPE for this line in my Provider: private ICharge instance = CHARGE_CAPABILITY.getDefaultInstance(); EDIT: And sorry for tripleposting. Couldn't find a delete-post button...
  19. Um, okay, new problem! I get a NullPointerException when trying to start the Client. I know I haven't properly initialized the capability for my item somehow, but I don't know what I've done wrong... java.lang.NullPointerException: Initializing game at com.bte.mod.capability.ChargeProvider.<init>(ChargeProvider.java:17) at com.bte.mod.item.ItemBattery.initCapabilities(ItemBattery.java:37) at net.minecraft.item.ItemStack.forgeInit(ItemStack.java:1350) EDIT: Uh, okay nevermind. The problem seems to occur whenever I try to stack.getCapability(ChargeProvider.CHARGE_CAPABILITY,null).getCharge() from within the ItemBattery.java. I tried removing the tooltip, and that allowed the game to start, but as soon as it tried to render the Durability-bar, it crashed for the same reason. I assume that is because the field charge is null in the capability, but I have default values set in the implementation... public class Charge implements ICharge { private int charge = 0; private int maxCharge = 640; //... }
  20. Okay, awesome, but how would I handle: @Override public double getDurabilityForDisplay(ItemStack stack) { return (double)this.getMaxCharge() / (double)this.getCharge(); } which is also inside the ItemBattery? Because then the getCharge wouldn't be correct, right?
  21. Okay, I think I've started making progress, but I'm still completely new to Capabilities... I have changed all usages in the charging station and the furnace to use: ICharge charge = itemstack.getCapability(ChargeProvider.CHARGE_CAPABILITY,null); return charge.getCharge(); instead of: ItemBattery battery = (ItemBattery)itemstack.getItem(); return battery.getCharge(); However, I want to set the "maxCharge" of all battery items to, let's say, 6400. And I want them all to start off with a "charge" of 0. Where do I set these values? I don't do it from inside the ItemBattery.java-class itself, right?
  22. So, I've made a modified furnace which only takes the custom item "Battery" as fuel. The battery can only have a stack of 1, and it's using a custom "durability" which tracks the amount of charge it holds. Now for some reason, the charge of a Battery is shared across all instances of the item Battery in my inventory. So if I put 1 Battery in a charging station, and 1 Battery in the furnace, the battery in the furnace lasts forever, since the other battery is constantly being charged. Is this because the charge-increasing/-decreasing/setting/getting is being done inside the Battery-Item's class? If so, how am I supposed to implement it otherwise? Am I supposed to make my own implemantion of ItemStack instead?? ItemBattery.java:
×
×
  • Create New...

Important Information

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