coding imports not working

Started by Freddy101 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
coding imports not working

hi whenever i use this code it tells me to fix my imports but they are fine from what I can tell 

the code in question

package net.mcreator.cbsrpg.entity;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;

public class AnimatedBeamEntity extends Entity {

private PlayerEntity player;

public AnimatedBeamEntity(World world) {
super(world);
}

// Getter and setter methods for player entity
public void setPlayer(PlayerEntity player) {
this.player = player;
}

// Override onUpdate method
@Override
public void onUpdate() {
super.onUpdate(); // Call superclass onUpdate method
if (player != null) {
// Calculate deltas and set rotation
double deltaX = player.getPosX() - this.getPosX();
double deltaY = player.getPosY() - this.getPosY();
double deltaZ = player.getPosZ() - this.getPosZ();
float yaw = (float) Math.atan2(deltaZ, deltaX) * (180F / (float) Math.PI) - 90.0F;
float pitch = (float) (-Math.atan2(deltaY, Math.sqrt(deltaX * deltaX + deltaZ * deltaZ)) * (180F / Math.PI));
this.rotationYaw = yaw;
this.rotationPitch = pitch;
this.setRotation(yaw, pitch);
}
}
}
 
Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
> Task :compileJavaC:\Users…
Wed, 03/20/2024 - 22:36

> Task :compileJava
C:\Users\fredn\OneDrive\Desktop\noww V2\src\main\java\net\mcreator\cbsrpg\LaserLooking.java:23: error: class AnimatedBeamEntity is public, should be declared in a file named AnimatedBeamEntity.java public class AnimatedBeamEntity extends Entity {
^
C:\Users\fredn\OneDrive\Desktop\noww V2\src\main\java\net\mcreator\cbsrpg\LaserLooking.java:19: error: package net.minecraft.entity does not exist import net.minecraft.entity.Entity;
^
C:\Users\fredn\OneDrive\Desktop\noww V2\src\main\java\net\mcreator\cbsrpg\LaserLooking.java:20: error: package net.minecraft.entity.player does not exist import net.minecraft.entity.player.PlayerEntity;
^
C:\Users\fredn\OneDrive\Desktop\noww V2\src\main\java\net\mcreator\cbsrpg\LaserLooking.java:21: error: cannot find symbol import net.minecraft.world.World;
^

Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
the error log^
Wed, 03/20/2024 - 22:36

the error log^

Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i have cleared my cache…
Wed, 03/20/2024 - 22:56

i have cleared my cache already

Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
still need help :(
Wed, 03/27/2024 - 18:11

still need help :(

This seems like code using…
Wed, 03/27/2024 - 20:02

This seems like code using old 1.16 MCP mappings, it will not work in new versions anyway.

 

Here's a tip when it comes to imports in MCreator's code editor: if your code uses valid classes that exist, pressing control + w automatically generates the imports.

 

In some cases it may import the wrong classes when multiple classes have the same name, but you can just replace those if it does.