
Tryhard
Members-
Posts
36 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
Tryhard's Achievements

Tree Puncher (2/8)
0
Reputation
-
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...