Jump to content

chxr

Members
  • Posts

    18
  • Joined

  • Last visited

Everything posted by chxr

  1. You would do good posting some code. I'm not expert, but I guess I would start by overriding the use() method of the item (or something equivalent, i really dont remember if use() was a thing on 1.16 anymore). Then youll there have to check if whatever it clicked is the entity you want (Wolf) and im pretty sure the wolf, as a tameable entity, has a getOwner() method or something similar EDIT: Use() cant be used to get an entity it interacted with but something like interactLivingEntity() does and im pretty sure it did exist back in 1.16.5
  2. Ok so in the end it was that I did not understand how the tags on the item and entity worked. I was trying to bulk add all the tags (including item id and stack count) directly to the rocket. but turns out that the fireworks go on the rocket item and the extra lifetime tag goes on the entity, if I understood correctly. So it ends up looking something like this: ListTag explosionsList = new ListTag(); CompoundTag explosionsTag = new CompoundTag(); explosionsTag.putByte("Type", (byte) 3); explosionsTag.putByte("Flicker", (byte) 0); explosionsTag.putByte("Trail", (byte) 1); explosionsTag.putIntArray("Colors", new int[] {5635925}); explosionsTag.putIntArray("FadeColors", new int[] {11141120}); //List of explosion parameters (I just copied from a /summon example to test it) explosionsList.add(explosionsTag); //There might be multiple customized explosions, so they go in a list CompoundTag fireworksTag = new CompoundTag(); fireworksTag.putInt("Flight", 2); fireworksTag.put("Explosions", explosionsList); // Flight:2,Explosions:[{Type:3,Flicker:0,Trail:1,Colors:[I;5635925],FadeColors:[I;11141120]}] //The whole firework data, including how high up will it go, go in a higher nested tag //NOW we create a rocket item stack and add ONLY the fireworks tag to it. The rest of the needed tags will be read for the entity later ItemStack fireworkItem = new ItemStack(Items.FIREWORK_ROCKET); CompoundTag fireWorkitemTag = fireworkItem.getOrCreateTag(); fireWorkitemTag.put("Fireworks", fireworksTag); // (The full item tag will have the item id and the stack Count) Fireworks:{Flight:2,Explosions:[{Type:3,Flicker:0,Trail:1,Colors:[I;5635925],FadeColors:[I;11141120]}]} // Create and spawn the firework rocket entity double x = pos.getX() + (new Random().nextDouble() * 20 - 10); double z = pos.getZ() + (new Random().nextDouble() * 20 - 10); BlockPos ypos = new BlockPos(x, 350, z); while (ypos.getY() > -64 && world.isEmptyBlock(ypos)) { ypos = ypos.below(); } double y = ypos.above().getY(); //Here we use the already crated rocket itemstsack to feed the entity: It will read all the tags (Including the needed ID and stackcount from the stack itself) Lastly, we also specify the lifetime of the rocket. This goes directly before the item data. FireworkRocketEntity rocket = new FireworkRocketEntity(world, x, y, z, fireworkItem); CompoundTag fireworkEntityTag = new CompoundTag(); fireworkEntityTag.putInt("LifeTime", 40); rocket.addAdditionalSaveData(fireworkEntityTag); // LifeTime:40,FireworksItem:{id:firework_rocket,Count:1,tag:{Fireworks:{Flight:2,Explosions:[{Type:3,Flicker:0,Trail:1,Colors:[I;5635925],FadeColors:[I;11141120]}]}}} This is what the full /summon command looks like and how the order of the tags ends up looking like (I think) world.addFreshEntity(rocket); //Spawn the rocket entity
  3. I think you may still need to register the method itself in the bus or specify it in the decorator.
  4. So is it the load what I'm missing? Now the rockets wont spawn hmm. I'll keep trying and report back if I get something
  5. For anyone wondering - it was the networking fault. As i was rendering all the GUI on the same block of code, the render failed when getting the information from the packets and stopped, and since it didn't reach the popStack at the end of the code block, the rest of the GUI just stayed with the same modified scale.
  6. I'm having a tiny bit of trouble getting rockets around the player to just... well go off and explode I don't exactly know if the rendering of the explosion is exclusively client-side or if I'm not understanding the tags correctly As far as I understand, there is a tag containing all the data for the explosion, then the rest of the tags are added. There is also the FIREWORK_STAR but I don't know if I should take it into account. I've been looking in the Rocket Recipe and and Entity as well as the item but I'm not getting anything clear out of it. I have this code now (which is obviously bad-) Any tips on how to move forward? ItemStack itemstack = new ItemStack(Items.FIREWORK_ROCKET); CompoundTag compoundtag = itemstack.getOrCreateTagElement("Fireworks"); ListTag listtag = new ListTag(); ItemStack itemstack2 = new ItemStack(Items.FIREWORK_STAR); CompoundTag compoundtag1 = itemstack2.getTagElement("Explosion"); listtag.add(compoundtag1); itemstack2.setTag(compoundtag1); compoundtag.putByte("Flight", (byte)1); compoundtag.put("Explosions", listtag); itemstack.setTag(compoundtag); itemstack.setTag(compoundtag1); // Create and spawn the firework rocket entity double x = pos.getX() + (new Random().nextDouble() * 20 - 10); double z = pos.getZ() + (new Random().nextDouble() * 20 - 10); BlockPos ypos = new BlockPos(x, 350, z); while (ypos.getY() > -64 && world.isEmptyBlock(ypos)) { ypos = ypos.below(); } double y = ypos.above().getY(); FireworkRocketEntity rocket = new FireworkRocketEntity(world, x, y, z, ItemStack.EMPTY); world.addFreshEntity(rocket);
  7. @HipposgrummFunnily enough, this is the tutorial I was using on my other post, which just reinforces the fact I'm missing something stupidly obvious. I'll check it all again.
  8. Okay so since my other post I've seen some other posts and videos. My custom GUI now extends Screen, so I have a couple of questions I'm not quite getting: 1) Does the code that renders image, text and other elements be on a render() mehtod? on an init() method? 2) How do I register the GUI? Some other answers I've seen are for GUIS inside buttons, or items, but mine needs to be visible while the player moves (like the hotbar, for example) and I haven't found any good examples. Where in the vanilla code can I see where the vanilla GUIs are registred?
  9. Yeah, I had already scouted through it before (though I didn't see that clearly what I could use, so I'll check on your tip later). My main problem (the reason why I'm scaling the GUI in the first place) is that I can't find a way to scale the text itself, that's why I resorted to scale the whole thin Also, why is the client behaving differently on the SDK vs the regular client? (This is more out of curiosity really, i don't know if the reason is in my code or somewhere else)
  10. I'm going blind with GUI stuff so I've just followed a tutorial that has yielded results. so no actual reason. If you can point me to a more correct direction then I'm all ears, too!
  11. So, I'm preparing a little HUD for an event I'm going to do with some friends. It all works fine in the client executed when running ./gradlew runClient. It's the expected result: But the problem comes when I either open the Forge SDK world to LAN OR load the mod to a separate Forge server instance, both needing the packed .jar made via ./gradlew build: As you can see, it drags the whole pause GUI with it. Of the four text lines, only one is seen. I use both scale and translate methods, and this exact thing happened on the SDK client too, but I fixed it using pushpose and poppose methods initially. The timer updates via network packets and works fine, as I said, on the Forge SDK instance of the client. The packets also work fine on their own, I only changed it so it would update the text in the GUI instead of outputting directly to the game chat. Here is the code of the GUI I made: public class PVPStateOverlay{ //if you need custom textures they should be placed unde resources/assets/yourmodid/textures/gui (gui interchangable with other folders) //https://www.youtube.com/watch?v=J3a7JT0rxTM //Refer to ClientEvents.java for the gui registration private static final ResourceLocation TEXTURE = new ResourceLocation(MOD_ID, "textures/mainvisor/fhcmclogo.png"); public static final IGuiOverlay HUD_MAINOVERLAY = ((gui, poseStack, partialTick, width, height) -> { int x = width / 2; int y = height; int logoxoffset = 145; int logoyoffset = -225; int rextanglexstart= -35; int rextangleystart = 13; int rextanglexend= 60; int rextangleyend = 70; int textxoffset = 12; int textyoffset = 20; //Push the matrix to the stack, so that the scale and translation don't affect other elements //At the end, pop the matrix from the stack so that subsequent renders aren't affected! poseStack.pushPose(); poseStack.pushPose(); final double scaled = (1.f / gui.getMinecraft().getWindow().getGuiScale()) * 3; final float scale = (float) scaled; poseStack.scale(scale, scale, scale); poseStack.translate(175F, 75F, 0F); // Draw semi-transparent grey rectangle RenderSystem.setShader(GameRenderer::getPositionColorShader); RenderSystem.setShaderColor(0.5F, 0.5F, 0.5F, 0.5F); GuiComponent.fill(poseStack,x + logoxoffset + rextanglexstart, y + logoyoffset + rextangleystart, x + logoxoffset + rextanglexend, y + logoyoffset + rextangleyend,0xFFFFFFFF);//Pos and then scale // Draw "Time remaining" text Minecraft minecraft = Minecraft.getInstance(); Font font = minecraft.font; String timeRemaining = "Tiempo restante:"; int textWidth = font.width(timeRemaining); int textX = (x + logoxoffset + textxoffset - textWidth / 2); int textY =(y + logoyoffset + textyoffset); GuiComponent.drawString(poseStack, font, timeRemaining, textX, textY, 0xFFFFFFFF); // Draw "HH:MM:SS" text PlayerTimeTracker trckr = PlayerTimeManager.getTracker(gui.getMinecraft().player.getUUID()); LocalTime remainingTimeLT = LocalTime.ofSecondOfDay(PlayerTimeManager.getDailyTimeLimit() - trckr.getSecsPlayed()); String remainingTime = remainingTimeLT.format(DateTimeFormatter.ofPattern("HH:mm:ss")).toString(); textWidth = font.width(remainingTime); textX = x + logoxoffset + textxoffset - textWidth / 2; textY += font.lineHeight + 2; // add some space between the two lines of text font.draw(poseStack, remainingTime, textX, textY, 0xFFFFFFFF); // Draw PVP State text String pvpstate = "PVP:"; // replace with your logic to get the remaining time textWidth = font.width(pvpstate); textX = x + logoxoffset + textxoffset - textWidth / 2; textY += font.lineHeight + 8; // add some space between the two lines of text GuiComponent.drawString(poseStack, font, pvpstate, textX, textY, 0xFFFFFFFF); // Draw "OFF/ON/HARDCORE" text String statePVP = "ULTRA"; // replace with your logic to get the remaining time textWidth = font.width(statePVP); textX = x + logoxoffset + textxoffset - textWidth / 2; textY += font.lineHeight + 2; // add some space between the two lines of text font.draw(poseStack, statePVP, textX, textY, 0xFFFFFFFF); //Render the logo RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, TEXTURE); GuiComponent.blit(poseStack, x + logoxoffset, y + logoyoffset, 0, 0, 25, 25, 25, 25); poseStack.popPose(); poseStack.popPose(); }); } And it is registered on a separate class: @SubscribeEvent public static void registerGuiOverlays(RegisterGuiOverlaysEvent event) { event.registerAboveAll("mainoverlayid", PVPStateOverlay.HUD_MAINOVERLAY); } Any insights? I'm really scratching my head right now
  12. You mean CompoundTag, right? I was under the impression that they need to be synchronized manually too. I will try and get back here if i need any more help
  13. So, I'm making a custom compass item that points to a player on the same team as the player. The problem comes in the following part of the code: int teamSize = stringTeamPlayers.size(); if (!currentWorld.isClientSide()) { //Null pointer excepction. GetPlayerList only works server side? if (teamSize == 1) { nearestPlayer = currentWorld.getServer().getPlayerList().getPlayerByName(listTeamPlayers.get(0)); } else { Random rand = new Random(); nearestPlayer = currentWorld.getServer().getPlayerList().getPlayerByName(listTeamPlayers.get(rand.nextInt(teamSize))); } distanceToItemUser = userPlayer.distanceTo(nearestPlayer); } else { //Distance and nearestPlayer are still wrongly defined on client side distanceToItemUser = 1; } So the initial problem (before I had the outermost if that makes the code only execute server-side) the session would crash with a Nullpointerexception. I guessed that getPlayerList would only work server-side and the error disappeared. The problem now is that, while the calculation is done server-side, client-side still has undefined (or rather incorrect) result for the distance and NearestPlayer. It looks like it works because I choose a value for the client-side that enters a block of code that deletes the object once the player approaches the targeted player: if (distanceToItemUser < 5) { if (!currentWorld.isClientSide()) { //Delete the item from the inventory once you approach to 5 blocks or less from the tracked player if (currentWorld.isClientSide()) { userPlayer.sendSystemMessage(Component.literal(String.format("poof"))); } Inventory inv = userPlayer.getInventory(); inv.removeItem(itemStack); } }else{ //Code that calculates the angle and changes the texture goes here } That's why it "flickers" (The animation for when the item is deleted is played, as it f it was about to be deleted but the server keeps it from doing so since it has the actual updated info) Obviously, if i change the value to something higher than 5 and let it go to the else it will throw a NullPointerException since it needs data it's only available in the server-only code. Any idea of how can I proceed with this? The main idea I have is to use packets but I'm really lost with that and I don't know if there's a simpler solution to this problem
  14. That's where they are now, inside resources/assets/mod_id/ (unless I did not understand soomething in which case sorry) I tried changing the name from plural to singular (textures->texture, blocks->block) but still does not recognize the textures EDIT: Okay that was the error. I have come back to my mod after a month and I forgot I had to change the texture json file from plural to singular too, so you're right
  15. So, after reading all the "debacle" happening with the support for both minor versions, I decided to upgrade my project to 1.19.3 I managed to fix everything after upgrading forge and the mappings, everything works now except not a single texture gets recognized. This is the error it gives for all items and blocks: [00:12:28] [Worker-Main-11/WARN] [minecraft/ModelManager]: Missing textures in model chrmscmds:testitem1#inventory: minecraft:textures/atlas/blocks.png:chrmscmds:items/testitem1 I used both addcreative and buildcontents to make and use a custom creative tab (which is working) Everything else is as its supposed to work on 1.19.2 with the jsons under resources/assets/mod_id, the models themselves being recognized and blockstates working as they're supposed to. I also have stumbled upon ResourceLocation but I'm not sure if that's the way to go. Has anything changed on .3 in regard to resource locating or I'm just dumb? Thanks
  16. So, I'm having an idea which involves having a vehicle going "automatically" (no user control needed) over a rail, pretty much like the regular minecart (But mostly similar/inspired by Black Mesa Transit System from the game Half-Life) I have been searching around but I don't seem to find any useful information. Like the last question, if anyone could point me into the right direction, what should I look for or tinker with, maybe some tutorials if anybody knows some, it would be highly appreciated!
  17. Thanks for mentioning capabilites, I will definitely need it somewhere down the line. I managed to get a tickevent working after having squeezed my head for these last days. It turns out I was having problems understanding how to register the event handler using and so I was trailing off searching for other unrelated things. All I needed was to MinecraftForge.EVENT_BUS.register(this); in the item constructor instead of going around all the mumbo jumbo I was trying to make. Since the handler itself was correctly constructed and with the correct decorator, it worked immediately. I still need to figure out some other things but I think the info you provided should suffice, so thanks!
  18. Okay so, this is not an specific coding question, but rather a probably rather basic question: I'm fairly new to the minecraft modding scene. I've started to tinker around with Forge for Minecraft 1.19.2 and so right now I'm playing with items and such, and while making some random ideas I've come to a point where I want to just wait for some moments (around a sec or two) after a player has used an item. (Right now I'm doing everything on public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand){...} ) After trying thin gs like "K let's put the thread to sleep", and "What IF i create A NEW THREAD and put that to sleep" which were the easy thing to do and, obviously wrong, I find myself searching about events, and ticks and tick handlers, and while I'm familiar with the concept due to having played with datapacks and command blocks before, I'm going in blindly with Forge. If someone could point into the right direction, what should I research about, what things I could try, (maybe even point me to sources to better learn about Forge in general) that'd be greatly appreciated.
×
×
  • Create New...

Important Information

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