龙空技术网

我制作了一个简单的mc模组

慧眼识时机 81

前言:

目前姐妹们对“minecraftforgenet”大致比较关注,你们都需要了解一些“minecraftforgenet”的相关资讯。那么小编同时在网络上汇集了一些对于“minecraftforgenet””的相关内容,希望大家能喜欢,朋友们快快来学习一下吧!

在这个模组中,按下x键可以获得钻石

package com.example.mymod;

import net.minecraft.client.Minecraft;

import net.minecraft.init.Items;

import net.minecraft.util.text.TextComponentString;

import net.minecraftforge.fml.common.Mod;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;

import net.minecraftforge.fml.common.gameevent.TickEvent;

import org.lwjgl.input.Keyboard;

@Mod(modid = "mymod", name = "My Mod", version = "1.0")

public class MyMod {

private boolean keyPressed = false;

@Mod.EventHandler

public void init(FMLInitializationEvent event) {

MinecraftForge.EVENT_BUS.register(this);

}

@SubscribeEvent

public void onTick(TickEvent.ClientTickEvent event) {

if (keyPressed) {

Minecraft.getMinecraft().player.addItemStackToInventory(new ItemStack(Items.DIAMOND, 64));

Minecraft.getMinecraft().player.sendMessage(new TextComponentString("You have been granted 64 diamonds!"));

keyPressed = false;

}

}

@SubscribeEvent

public void onKeyPress(KeyInputEvent event) {

if (Keyboard.isKeyDown(Keyboard.KEY_X)) {

keyPressed = true;

}

}

}

标签: #minecraftforgenet