I will say right away, in the logs error does not appear, I use forge version 2859 for minecraft 1.12.2, I wrote a couple of classes one of which is responsible for RageMode, the essence is that the player when turning on RageMode should fly to the nearest entity and inflict it 200 damage, and so once again within 10 seconds, if the player meets obstacles, he must destroy them hitbox. The next class KeyInputHandler, it is responsible for checking the pressing of the key U and then activates RageMode. what is the problem – when entering the game everything is normal, but when you press U the game completely freezes and the only way to turn it off – it is forced to close, looking at the logs there is no record of any errors, just an inscription exit the game with code 0.
Here are the codes:
main file
package daun.aut.utils;
import daun.aut.utils.Handlers.KeyInputHandler;
import daun.aut.recipes.SmeltingRecipes;
import daun.aut.tabs.autTab;
import daun.aut.utils.Handlers.RegistryHandler;
import daun.aut.utils.proxy.CommonProxy;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION)
public class Main
{
public static final CreativeTabs autTab = new autTab("autismotab");
@Instance
public static Main instance;
@SidedProxy(modId = Reference.MODID, clientSide= Reference.CLIENT, serverSide = Reference.COMMON)
public static CommonProxy proxy;
@EventHandler
public static void preInit(FMLPreInitializationEvent event)
{
RegistryHandler.otherRegistries();
KeyInputHandler.registerKeyBindings();
}
@EventHandler
public static void Init(FMLInitializationEvent event) {
SmeltingRecipes.init();
MinecraftForge.EVENT_BUS.register(new CustomFog());
MinecraftForge.EVENT_BUS.register(new KeyInputHandler());
}
@EventHandler
public static void postInit(FMLPostInitializationEvent event) {
}
}
RageMode
package daun.aut.utils;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public class RageMode {
private EntityPlayer player;
private World world;
private long startTime;
private final long duration = 10 * 20; // 10 seconds (20 ticks per second)
private final double speed = 1.5; // Speed of movement
public RageMode(EntityPlayer player) {
this.player = player;
this.world = player.world;
this.startTime = world.getTotalWorldTime();
activateRage();
}
private void activateRage() {
while (world.getTotalWorldTime() < startTime + duration) {
EntityLivingBase target = findNearestTarget();
if (target != null) {
moveTowards(target);
attack(target);
breakObstacles();
}
}
}
private EntityLivingBase findNearestTarget() {
// Logic to find the nearest living entity
return player.world.getNearestAttackablePlayer(player, 50.0, 50.0);
}
private void moveTowards(EntityLivingBase target) {
// Logic to move towards the target entity linearly
Vec3d playerPos = player.getPositionVector();
Vec3d targetPos = target.getPositionVector();
Vec3d direction = targetPos.subtract(playerPos).normalize();
Vec3d newPos = playerPos.add(direction.scale(speed / 20.0)); // Move by speed per tick
player.setPositionAndUpdate(newPos.x, newPos.y, newPos.z);
}
private void attack(EntityLivingBase target) {
// Logic to attack the target entity
target.attackEntityFrom(DamageSource.causePlayerDamage(player), 200.0f);
}
private void breakObstacles() {
// Logic to break obstacles (blocks)
BlockPos playerPos = player.getPosition();
Vec3d lookVec = player.getLookVec();
BlockPos blockPos = playerPos.add(lookVec.x, lookVec.y, lookVec.z); // Convert Vec3d to BlockPos
if (!world.isAirBlock(blockPos)) {
world.destroyBlock(blockPos, true);
}
}
}
Handler
package daun.aut.utils.Handlers;
import daun.aut.utils.RageMode;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import org.lwjgl.input.Keyboard;
public class KeyInputHandler {
private static final KeyBinding rageKey = new KeyBinding("key.ragemode", Keyboard.KEY_U, "key.categories.gameplay");
public static void registerKeyBindings() {
ClientRegistry.registerKeyBinding(rageKey);
}
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
if (rageKey.isPressed()) {
EntityPlayer player = Minecraft.getMinecraft().player;
if (player != null) {
new RageMode(player);
}
}
}
}
I need everything to work properly and not crash.