
Tryhard
Members-
Posts
36 -
Joined
-
Last visited
Everything posted by Tryhard
-
As the title says, i just need to know that. Why? i'm updating some bone rotations from an ai goal, and so i need it to run as frequently as possible.
-
Got entity data to work, thanks!
-
I made some progress with entity data. I've managed to get the rotation from the bone into EntityDataAccessor fields in the entity class. But now they are not synched to the server. So i need to mark them as dirty? or are they supposed to synch automatically?
-
Hello, I'm trying to make a new turret entity. The entity itself is already done and into the game (with geckolib). Now i need to pass data from the model to the AI (client to server, for aiming purposes) I'm trying to understand packets, but i don't see how i can send data from the entity's model all the way to the goal it's going to use. Any ideas? Is there a better tool for this other than packets? should i look into entity data instead?
-
Opinions on this entity spawning item and some questions. (1.19)
Tryhard replied to Tryhard's topic in Modder Support
I do understand raytracing. And i think it's pretty clear what i want to achieve (which i've done) the comments are clear. -
For now it's working as intended. What are your opinions on the code? - How could things be done better? Let me know what you think. - Am i right in assuming ClipContext is for ray tracing? - I couldn't find the RayTracingContext, it took me some time of digging around blind to finally stumble upon this ClipContext class. How could i have investigated the topic faster? By digging through minecraft and other mods? By asking you here? package net.ja.testmod.item; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LightningBolt; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; public class ThunderWand extends Item { public ThunderWand(Item.Properties properties){ super(properties); } @Override public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand interactionHand) { //if main hand, lightningbolt at crosshair if(interactionHand == InteractionHand.MAIN_HAND) { BlockHitResult result = getCrosshairLocation(level, player, 50f); Vec3 location = correctLightningBoltSpawnHeight(level, result); spawnLightningBoltAt(level, location); } //if offhand, lightningbolt at player if(interactionHand == InteractionHand.OFF_HAND) spawnLightningBoltAtPlayer(level, player); //super return super.use(level, player, interactionHand); } public Vec3 correctLightningBoltSpawnHeight(Level level, BlockHitResult prevResult){ //avoid spawning lightningbolts in the air, spawn them straight down instead BlockState state = level.getBlockState(prevResult.getBlockPos()); if(state.isAir()){ Vec3 down = new Vec3(0, -1, 0); ClipContext cc = new ClipContext(prevResult.getLocation(), prevResult.getLocation().add(down.scale(500)), ClipContext.Block.COLLIDER, ClipContext.Fluid.ANY, null); BlockHitResult result = level.clip(cc); return result.getLocation(); } return prevResult.getLocation(); } public BlockHitResult getCrosshairLocation(Level level, Player player, float distance){ Vec3 view = player.getViewVector(0f); Vec3 from = player.getEyePosition(); Vec3 to = from.add(view.scale(distance)); ClipContext cc = new ClipContext(from, to, ClipContext.Block.COLLIDER, ClipContext.Fluid.ANY, null); BlockHitResult result = level.clip(cc); return result; } public void spawnLightningBoltAt(Level level, Vec3 location){ if(!level.isClientSide()){ LightningBolt lb = new LightningBolt(EntityType.LIGHTNING_BOLT, level); lb.setPos(location); level.addFreshEntity(lb); } } //Minecraft.getInstance().player.chat('msg'); public void spawnLightningBoltAtPlayer(Level level, Player player){ if(!level.isClientSide()){ LightningBolt lb = new LightningBolt(EntityType.LIGHTNING_BOLT, level); lb.setPos(player.getPosition(0f)); level.addFreshEntity(lb); } } }
-
There's literally nothing else other than the default project, this item is the only thing i'm doing. Also it turns out the error was indeed in the snippets i attached and it was trivially obvious. i needed to change: eventBus.register(ITEMS_REGISTRY) to: ITEMS_REGISTRY.register(eventBus);
-
so i'm using loader version 41, for minecraft 1.19 This one item i want to add won't show up in creative menu. Any problem with the code? the game runs fine, and the mod shows up in the 'mods' menu. Also i notice the /give command doesn't detect the modid which is 'testmod'. public class ModItems { public static final DeferredRegister<Item> ITEMS_REGISTRY = DeferredRegister.create(ForgeRegistries.ITEMS, TestMod.MOD_ID); //registry objects public static final RegistryObject<Item> ZIRCON = ITEMS_REGISTRY.register("zircon", () -> new Item(new Item.Properties().tab(CreativeModeTab.TAB_COMBAT)) ); public static void INIT_ITEMS(IEventBus eventBus){ eventBus.register(ITEMS_REGISTRY); } } init_items is called from main class constructor public TestMod() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); //init item registration ModItems.INIT_ITEMS(modEventBus); modEventBus.addListener(this::commonSetup); MinecraftForge.EVENT_BUS.register(this); }
-
getEyePosition is not annotated with @OnlyIn(Dist.CLIENT), is it sitll going to make the server crash?
-
Nevermind, i figured it out. I simply wanted to get the position the player is aiming at, and summon lightning at that point, to do so i needed to raytrace. I solved my previous problem by using RayTracingContext. Code looks like this now. Then, from the method in which i spawn lightning: This works as i want it, right now. Any advice from the pros on what could be done better?
-
I'm trying to get the position of the block the player is aiming at: private BlockRayTraceResult rayTrace(PlayerEntity playerIn, float reach) { Vector3d pos = playerIn.getPositionVec(); Vector3d forward = playerIn.getLookVec(); Vector3d rayVector = forward.scale(reach); return playerIn.world.rayTraceBlocks(pos, rayVector, ?, ?, ?); } I understand what the vectors are doing. My only 2 questions are simple: 1.- For the vector i call 'pos', should i be using player.getEyePosition instead? if so, it's argument is a float called partialTicks, what does this argument represent? 2.- what are the three last arguments for world.rayTraceBlocks? i understand the first one is the start of the ray, and the second the end of it. But no clue about what the others are supposed to be I've tried looking for info on this method and i found nothing.
-
Perhaps it has something to do with the modid being the same as the block's name? Loot table looks ok to me.
-
Code should look something like this: public class ModItems { public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ExampleMod.MODID); public static void initItems() { ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus()); } public static final RegistryObject<Item> COPPER_INGOT = ITEMS.register("copper_ingot", ()-> new Item(new Item.Properties().tab(CreativeModeTab.TAB_MATERIALS)) ); } Not an expert myself, but the main things here are: 1.- A deferred register must be in the same class as it's RegistryObjects (it's entries) 2.- The method register(name, supplier) of a DeferredRegister (the one you call when you need to register something) returns a RegistryObject, not a DeferredRegister. In your code you incorrectly assign it to a DeferredRegister. 3.- About the ItemGroup problem, at some point ItemGroup must've changed to CreativeModeTab (like in my example which i've tested and it works). I don't know if that's the case for the version of forge you're using. In any case, just check what argument the method 'tab' wants, and give it that. Like in the image. idk if i messed up on something, hope this helps.
-
...Yes, thanks alot for instanceof, already knew about it. What i didn't know, however, is that #onItemRightClick runs twice per click (client & server) and only once is the argument "worldIn" a ServerWorld... That doesn't seem like "basic java concepts" to me... more like basic forge concepts (which i'm completely new to) To me, it' didn't make sense to use instanceof without knowing that "little" detail about #onItemRightClick. It makes complete sense now, i have to run the code only when worldIn is a serverworld, otherwise i get a class cast exception. Now it's working tho. Thanks to TrazorMC for actually pointing that out! The only thing left now, is to get the correct BlockPos to spawn the LightningBoltEntity on. It seems i need to use raytracing for that. I've been looking it up but i still don't quite get it. I've seen that on older versions they used PlayerEntity#rayTrace, but that class no longer has that method. Actually as i was writting this, i found this method with a weird name on the Entity class. (does that annotation mean that this method should only run on the client or something like that?) @OnlyIn(Dist.CLIENT) public RayTraceResult func_213324_a(double p_213324_1_, float p_213324_3_, boolean p_213324_4_) { Vec3d vec3d = this.getEyePosition(p_213324_3_); Vec3d vec3d1 = this.getLook(p_213324_3_); Vec3d vec3d2 = vec3d.add(vec3d1.x * p_213324_1_, vec3d1.y * p_213324_1_, vec3d1.z * p_213324_1_); return this.world.rayTraceBlocks(new RayTraceContext(vec3d, vec3d2, RayTraceContext.BlockMode.OUTLINE, p_213324_4_ ? RayTraceContext.FluidMode.ANY : RayTraceContext.FluidMode.NONE, this)); } It is working now. I still don't know what RayTraceContext is for, and what its enumerations mean, or what the arguments of this function do (why those names tho). But it seems it is all done now. The class of my item looks like this now. public class TestSword extends Item { public static final String REGISTRY_NAME = "testmod:test_sword"; public static final String DISPLAY_NAME = "Test Sword"; public TestSword(){ super(new Item.Properties().group(ModSetup.itemGroup).maxStackSize(3).rarity(Rarity.EPIC)); this.setRegistryName(this.REGISTRY_NAME); MinecraftForge.EVENT_BUS.register(this); } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn){ //test the side if(!(worldIn instanceof ServerWorld)) return new ActionResult<>(ActionResultType.PASS, playerIn.getHeldItem(handIn)); //cast World to ServerWorld ServerWorld world = (ServerWorld) worldIn; //get the correct position RayTraceResult rts = playerIn.func_213324_a(100, 1, false); BlockPos pos = new BlockPos(rts.getHitVec().getX(), rts.getHitVec().getY(), rts.getHitVec().getZ()); System.out.println(pos.getX()+" "+pos.getY()+" "+pos.getZ()); //create & spawn entity LightningBoltEntity l = new LightningBoltEntity(world, pos.getX(), pos.getY(), pos.getZ(), false); world.addLightningBolt(l); return new ActionResult<>(ActionResultType.SUCCESS, playerIn.getHeldItem(handIn)); } } I'm totally sure this can be improved. I'd love to hear what the seniors have to say.
-
wow, talk about: I know what exceptions are... and i know why i am getting this one. I'm downcasting to a type which "worldIn" isn't an instance of... what i was asking is: how am i supposed to get access to #addLightningBolt then? I've also been researching this on my own of course... but i found nothing too useful, i thought: "hey whats the best place to look for help on this minecraft forge related problem i'm facing? oh, how about the minecraft forge forum Well, i guess it's not, sunce i'm practically been told to *uck off...
-
Okey @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn){ ServerWorld world = (ServerWorld) worldIn; world.addLightningBolt(new LightningBoltEntity(world, playerIn.posX, playerIn.posY, playerIn.posZ, false)); return new ActionResult<>(ActionResultType.SUCCESS, playerIn.getHeldItem(handIn)); } It won't allow me to do cast it like this. It crashes. The crash report say the following: java.lang.ClassCastException: net.minecraft.client.world.ClientWorld cannot be cast to net.minecraft.world.server.ServerWorld
-
I saw someone use this code for RayTracing the position the player is looking at: public RayTraceResult rayTrace(EntityPlayer playerIn, double blockReachDistance, float partialTicks){ Vec3d vec3d = playerIn.getPositionEyes(partialTicks); Vec3d vec3d1 = playerIn.getLook(partialTicks); Vec3d vec3d2 = vec3d.addVector(vec3d1.x * blockReachDistance, vec3d1.y * blockReachDistance, vec3d1.z * blockReachDistance); return playerIn.world.rayTraceBlocks(vec3d, vec3d2, false, false, true); } I don't want to just copy it, i want to understand it. Can someone pls explain what is this method really doing? Also, i'm having trouble spawning the LightningBoltEntity, because "World", for some reason, doesn't have any #addLightningBolt method
-
Can you go a bit more in depth on the RayTracing thing? i'm completely new to this concept, what is it used for? I'm assuming it is to get the location the player is looking at, but, how should i handle it?
-
Thank you all for your suggestions/corrections people. How Would i get a ServerWorld object? (to do this: ServerWorld#addLightningBolt). What are the differences between World and ServerWorld?? I'll get rid of those events and override #onItemRightClick. And i apologize for that thing i wrote up there, but after almost two days of not getting any response, i thought this post would end up just being ignored. Anyway, thanks alot for your help. I will update on the changes i make. Btw my World instance doesn't have the addWeatherEffect, is that because i shouldn't be using "World" at all? I'm currently using forge 1.14.4.
-
woow so useful this forum
-
The idea is to summon a lightningbolt where the player is looking, so far i've got this: package mod.joanalbert.testmod.item.items; import mod.joanalbert.testmod.ModSetup; import net.minecraft.client.Minecraft; import net.minecraft.client.MinecraftGame; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.client.renderer.entity.LightningBoltRenderer; import net.minecraft.entity.effect.LightningBoltEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Rarity; import net.minecraft.network.play.client.CPlayerTryUseItemPacket; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import net.minecraftforge.client.event.DrawBlockHighlightEvent; import net.minecraftforge.client.event.InputEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import java.util.Iterator; public class TestSword extends Item { public static final String REGISTRY_NAME = "testmod:test_sword"; public static final String DISPLAY_NAME = "Test Sword"; private World world; private PlayerEntity player; public BlockPos lookingAt; public TestSword(){ super(new Item.Properties().group(ModSetup.itemGroup).maxStackSize(3).rarity(Rarity.EPIC)); this.setRegistryName(this.REGISTRY_NAME); MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent public void lightning(InputEvent.MouseInputEvent event){ if(event.getButton() != 1 || this.lookingAt == null) return; System.out.println(this.lookingAt.getX()+" "+this.lookingAt.getY()+" "+this.lookingAt.getZ()); LightningBoltEntity l = new LightningBoltEntity(this.world, this.lookingAt.getX(), this.lookingAt.getY(), this.lookingAt.getZ(), false); this.world.addEntity(l); } @SubscribeEvent public void updatePos(DrawBlockHighlightEvent event){ RayTraceResult result = event.getTarget(); this.lookingAt = new BlockPos(result.getHitVec().getX(), result.getHitVec().getY(), result.getHitVec().getZ()); } @SubscribeEvent public void test(EntityJoinWorldEvent event){ if(event.getEntity() instanceof PlayerEntity){ this.world = event.getWorld(); this.player = (PlayerEntity) event.getEntity(); } } } I don't really know what i'm doing, im new to this. This isn't quite working... what am i missing and what could i be doing better?
-
No, i don't think i did lol. I simply created a new project and started over with the newer forge.
-
Here it is: buildscript { repositories { maven { url = 'https://files.minecraftforge.net/maven' } jcenter() mavenCentral() } dependencies { classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true } } apply plugin: 'net.minecraftforge.gradle' // Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. apply plugin: 'eclipse' apply plugin: 'maven-publish' version = '1.14.4-0.1.0' group = 'mod.joanalbert.tutorial_mod' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'tutorial_mod' sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. minecraft { // The mappings can be changed at any time, and must be in the following format. // snapshot_YYYYMMDD Snapshot are built nightly. // stable_# Stables are built at the discretion of the MCP team. // Use non-default mappings at your own risk. they may not always work. // Simply re-run your setup task after changing the mappings to update your workspace. //mappings channel: 'snapshot', version: '20190719-1.14.3' mappings channel: 'snapshot', version: '20190917-1.14.3'; // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Default run configurations. // These can be tweaked, removed, or duplicated as needed. runs { client { workingDirectory project.file('run') // Recommended logging data for a userdev environment property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' // Recommended logging level for the console property 'forge.logging.console.level', 'debug' mods { examplemod { source sourceSets.main } } } server { workingDirectory project.file('run') // Recommended logging data for a userdev environment property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' // Recommended logging level for the console property 'forge.logging.console.level', 'debug' mods { examplemod { source sourceSets.main } } } data { workingDirectory project.file('run') // Recommended logging data for a userdev environment property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' // Recommended logging level for the console property 'forge.logging.console.level', 'debug' args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/') mods { examplemod { source sourceSets.main } } } } } dependencies { // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied. // The userdev artifact is a special name and will get all sorts of transformations applied to it. minecraft 'net.minecraftforge:forge:1.14.4-28.1.0' // You may put jars on which you depend on in ./libs or you may define them like so.. // compile "some.group:artifact:version:classifier" // compile "some.group:artifact:version" // Real examples // compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env // compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env // The 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime. // provided 'com.mod-buildcraft:buildcraft:6.0.8:dev' // These dependencies get remapped to your current MCP mappings // deobf 'com.mod-buildcraft:buildcraft:6.0.8:dev' // For more info... // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html // http://www.gradle.org/docs/current/userguide/dependency_management.html } // Example for how to get properties into the manifest for reading by the runtime.. jar { manifest { attributes([ "Specification-Title": "examplemod", "Specification-Vendor": "examplemodsareus", "Specification-Version": "1", // We are version 1 of ourselves "Implementation-Title": project.name, "Implementation-Version": "${version}", "Implementation-Vendor" :"examplemodsareus", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } } // Example configuration to allow publishing using the maven-publish task // we define a custom artifact that is sourced from the reobfJar output task // and then declare that to be published // Note you'll need to add a repository here def reobfFile = file("$buildDir/reobfJar/output.jar") def reobfArtifact = artifacts.add('default', reobfFile) { type 'jar' builtBy 'reobfJar' } publishing { publications { mavenJava(MavenPublication) { artifact reobfArtifact } } repositories { maven { url "file:///${project.projectDir}/mcmodsrepo" } } } /////////////////////// task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' from sourceSets.main.allSource } build.dependsOn sourcesJar artifacts { archives sourcesJar } // Process resources on build processResources { // This will ensure that this task is redone when the versions change. inputs.property 'version', project.version // Replace stuff in mods.toml, nothing else from(sourceSets.main.resources.srcDirs) { include 'META-INF/mods.toml' // Replace version expand 'version':project.version } // Copy everything else except the mods.toml from(sourceSets.main.resources.srcDirs) { exclude 'META-INF/mods.toml' } } ///////////////////////////////////////////
-
Okry, i've updated forge. I'm now using version 1.14.4-28.1.0. I still can't find the addLightningbolt method tho.
-
I think my current version is: 1.14.3-27.0.21. I'm adding two images showing what version shows up in the actual game. Is there a better way of knowing what version i'm using? And if i were using a wrong version, how should i go about updating it? I'm currently trying to update the mappings (which i also don't fully comprehend what they are)