Jump to content
Search In
  • More options...
Find results that contain...
Find results in...


  • Posts

  • Joined

  • Last visited

Everything posted by NindyBun

  1. FINALLY, the whole problem was that I was accessing the wrong nbt tag in readShareTag this whole time.
  2. https://github.com/NindyBun/BurnerGun_1.16.5/blob/master/src/main/java/com/nindybun/burnergun/common/network/packets/PacketFuelValue.java Okay...I got the fuel renderer to work properly after fixing the get/readsharetag but now when I try to play on a dedicated server, the fuel renderer doesn't work, I don't know if my packet handler is right.
  3. I continued messing with it and noticed that when the fuel value is above 500_000 which is half of the max buffer, the fuel renderer shows that it goes down, but when it gets below 500_000, I have to open my itemstack's gui to update it and I don't understand why it doesn't update by it self under 500_000.
  4. Scratch that. I have found one problem that is my fuel renderer is working as intended when the fuel level increases, but when it decreases the value doesn't change until I enter my world again. Why does that happen? https://github.com/NindyBun/BurnerGun_1.16.5/blob/master/src/main/java/com/nindybun/burnergun/client/renderer/FuelValueRenderer.java#L63
  5. https://github.com/NindyBun/BurnerGun_1.16.5/blob/master/src/main/java/com/nindybun/burnergun/common/items/GlitteringDiamond.java I was able to get the capability working but now I'm stuck on how to save the data...
  6. Okay, so I think I made the beginning of a capability but how do I set and get values? https://github.com/NindyBun/BurnerGun_1.16.5/tree/master/src/main/java/com/nindybun/burnergun/common/capabilities
  7. I've only ever used capability for messing with the itemstack's inventory so I don't exactly know how the process of using it for data goes, and I have read the documentation multiple times but I just can't wrap my head around it. To synchronize my data I would do that in the form of packets right? But what should I be sending and to where?
  8. So I figured out that when I try to get the nbt tag in the RenderGameOverlayEvent it doesn't show the updated values, only the values made when the item was created. Therefore how would I get the current updated tag when playing on the dedicated server?
  9. It might actually be this line that's causing the problem, but how else do I check if my itemstack is in a players hand so that I knows to draw the text?
  10. So I have a FontRenderer that displays the Fuel value of my tool, on a singleplayer world the text updates fine but once I go on the server the same text does not update. So I'm assuming that I would have to send the server packet to the client, problem is how would I do that if I need a ServerPlayerEntity. My Font renderer: https://github.com/NindyBun/BurnerGun_1.16.5/blob/master/src/main/java/com/nindybun/burnergun/client/renderer/FuelValueRenderer.java package com.nindybun.burnergun.client.renderer; import com.nindybun.burnergun.common.BurnerGun; import com.nindybun.burnergun.common.items.upgrades.Upgrade; import com.nindybun.burnergun.common.network.PacketHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import javax.annotation.Nonnull; import java.awt.*; @Mod.EventBusSubscriber(modid = BurnerGun.MOD_ID, value = Dist.CLIENT) public class FuelValueRenderer { private static final Logger LOGGER = LogManager.getLogger(); private static final int base_buffer = com.nindybun.burnergun.common.items.Burner_Gun.BurnerGun.base_use_buffer; private static final int base_heat_buffer = com.nindybun.burnergun.common.items.Burner_Gun.BurnerGun.base_heat_buffer; @SubscribeEvent public static void renderOverlay(@Nonnull RenderGameOverlayEvent.Post event){ if (event.getType() == RenderGameOverlayEvent.ElementType.ALL){ ItemStack stack = ItemStack.EMPTY; PlayerEntity player = Minecraft.getInstance().player; if (player.getMainHandItem().getItem() instanceof com.nindybun.burnergun.common.items.Burner_Gun.BurnerGun) stack = player.getMainHandItem(); else if (player.getOffhandItem().getItem() instanceof com.nindybun.burnergun.common.items.Burner_Gun.BurnerGun) stack = player.getOffhandItem(); if (stack.getItem() instanceof com.nindybun.burnergun.common.items.Burner_Gun.BurnerGun) renderFuel(event, stack); } } public static void renderFuel(RenderGameOverlayEvent event, ItemStack stack){ FontRenderer fontRenderer = Minecraft.getInstance().font; IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null); int level = stack.getTag().getInt("FuelValue"); int hLevel = stack.getTag().getInt("HeatValue"); Color color; if (level > base_buffer*3/4) color = Color.GREEN; else if (level > base_buffer*1/4 && level <= base_buffer*3/4) color = Color.ORANGE; else color = Color.RED; if (hLevel > base_heat_buffer*3/4) color = Color.RED; else if (hLevel > base_heat_buffer*1/4 && hLevel <= base_heat_buffer*3/4) color = Color.ORANGE; else color = Color.GREEN; //fontRenderer.drawString(event.getMatrixStack(), "Fuel level: "+level, 6, event.getWindow().getScaledHeight()-12, Color.WHITE.getRGB()); if (!handler.getStackInSlot(0).getItem().equals(Upgrade.UNIFUEL.getCard().getItem()) && !handler.getStackInSlot(0).getItem().equals(Upgrade.REACTOR.getCard().getItem())){ fontRenderer.draw(event.getMatrixStack(), "Fuel level: ", 6, event.getWindow().getGuiScaledHeight()-12, Color.WHITE.getRGB()); fontRenderer.draw(event.getMatrixStack(), level+"", 61, event.getWindow().getGuiScaledHeight()-12, color.getRGB()); }else if (handler.getStackInSlot(0).getItem().equals(Upgrade.REACTOR.getCard().getItem())){ double heat = (double)hLevel/base_heat_buffer*100; String heatString = heat+""; int deci = heatString.lastIndexOf("."); heatString = heatString.substring(0, deci+2); fontRenderer.draw(event.getMatrixStack(), "Heat level: ", 6, event.getWindow().getGuiScaledHeight()-12, Color.WHITE.getRGB()); fontRenderer.draw(event.getMatrixStack(), heatString+"%", 61, event.getWindow().getGuiScaledHeight()-12, color.getRGB()); } } } My packet handler package com.nindybun.burnergun.common.network; import com.nindybun.burnergun.common.BurnerGun; import com.nindybun.burnergun.common.network.packets.PacketOpenAutoFuelGui; import com.nindybun.burnergun.common.network.packets.PacketOpenBurnerGunGui; import com.nindybun.burnergun.common.network.packets.PacketOpenTrashGui; import com.nindybun.burnergun.common.network.packets.PacketOpenUpgradeBagGui; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.fml.network.NetworkDirection; import net.minecraftforge.fml.network.NetworkRegistry; import net.minecraftforge.fml.network.simple.SimpleChannel; public class PacketHandler { private static final String PROTOCOL_VERSION = "2"; private static int index = 0; public static final SimpleChannel INSTANCE = NetworkRegistry.ChannelBuilder .named(new ResourceLocation(BurnerGun.MOD_ID, "main")) .clientAcceptedVersions(PROTOCOL_VERSION::equals) .serverAcceptedVersions(PROTOCOL_VERSION::equals) .networkProtocolVersion(() -> PROTOCOL_VERSION) .simpleChannel(); public static void register(){ int id = 0; INSTANCE.registerMessage(id++, PacketOpenBurnerGunGui.class, PacketOpenBurnerGunGui::encode, PacketOpenBurnerGunGui::decode, PacketOpenBurnerGunGui.Handler::handle); INSTANCE.registerMessage(id++, PacketOpenAutoFuelGui.class, PacketOpenAutoFuelGui::encode, PacketOpenAutoFuelGui::decode, PacketOpenAutoFuelGui.Handler::handle); INSTANCE.registerMessage(id++, PacketOpenTrashGui.class, PacketOpenTrashGui::encode, PacketOpenTrashGui::decode, PacketOpenTrashGui.Handler::handle); INSTANCE.registerMessage(id++, PacketOpenUpgradeBagGui.class, PacketOpenUpgradeBagGui::encode, PacketOpenUpgradeBagGui::decode, PacketOpenUpgradeBagGui.Handler::handle); } public static void sendTo(Object msg, ServerPlayerEntity player) { if (!(player instanceof FakePlayer)) INSTANCE.sendTo(msg, player.connection.connection, NetworkDirection.PLAY_TO_CLIENT); } public static void sendToServer(Object msg){ INSTANCE.sendToServer(msg); } } Yes I know, my coding is not the best looking.
  11. I have two gui's/containers one with 8 slots and the other with 15. My tool opens the former container whenever you press a keybind, but I want to open the latter using the same tool. Essentially, if I pressed a certain keybind, the 15 slot container supersedes the original 8 slot container, therefor my tool it's container gains 7 more slots while retaining whatever's in it's previous inventory. Is there a way to go about this? https://github.com/NindyBun/TestMod
  12. public class KeyInputHandler { private static final Logger LOGGER = LogManager.getLogger(); @SubscribeEvent public void onKeyInput(InputEvent.KeyInputEvent event) { PlayerEntity player = Minecraft.getInstance().player; if (Keybinds.test_item_gui_key.isPressed() && player.getHeldItemMainhand().getItem() instanceof ItemTestItem){ LOGGER.info("KEY PRESSED"); } } } How can I open my ItemTestItem's GUI when I press the C key? Right Now I am opening it from NetworkHooks in my ItemTestItem class. @Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand handIn) { ItemStack stack = player.getHeldItem(handIn).getStack(); if (!world.isRemote){ if (player.isSneaking()){ INamedContainerProvider containerProviderTestItem = new ContainerProviderTestItem(this, stack); final int NUMBER_OF_SLOTS = 8; NetworkHooks.openGui((ServerPlayerEntity) player, containerProviderTestItem, (packetBuffer)-> packetBuffer.writeInt(NUMBER_OF_SLOTS);}); return ActionResult.resultSuccess(stack); } } } Here's the git repo if needed: https://github.com/NindyBun/TestMod/blob/master/src/main/java/com/nindybun/miningtool/KeyInputHandler.java Apologies in advance if my code is crude.
  13. https://github.com/NindyBun/TestMod/blob/master/src/main/java/com/nindybun/miningtool/test_item/ItemStackHandlerTestItem.java
  14. Basically I want to make an Item Filter that allows the player to set a copy of the held item stack into a slot.
  15. So I returned stack.copy() and I am still holding the stack, but when I try to set stack in slot, it doesn't set the ItemStack.
  16. My item container works fine, it acts as a normal bag; but I want to turn it into a filter, so how can I make my item container set/remove "ghost" items instead of setting/removing the physical item in a slot? Thanks in advance. Note: I am asleep so I won't be able to answer till I wake up.
  17. I see it works now but why does checking that do things on the server?
  18. Ah, the null is coming from world.getServer().getWorld(world.getDimension().getType()) where world.getServer() is null
  19. oh...give me a while then, I've never done anything with Intellij Debugger before so I'm wandering about.
  20. So it's saying to insert @NotNull for BlockState and World.
  21. I know it's that line, but why is it wrong? What is making it null.
  22. I would if I knew why the LootContext#Builder is throwing an error.
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.