This is my code, I have errors on line 16 and 17, i don't know where im going wrong, this is in the main ModItems class and i have been using this video as a guide If you need the rest of my class files i have uploaded the current copy of my classes here
The error on both lines is The constructor Item(Item, Item) is undefined
package TheStraying11.QuarkyPower.init;
import TheStraying11.QuarkyPower.Reference;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemSoup;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;
import TheStraying11.QuarkyPower.items.QuarkUp;
import TheStraying11.QuarkyPower.items.QuarkDown;
public class ModItems {
public static Item QuarkUp;
public static Item QuarkDown;
public static void init() {
QuarkUp = new Item(QuarkUp, QuarkUp);
QuarkDown = new Item(QuarkDown, QuarkDown);
}
public static void register() {
registerItem(QuarkUp);
registerItem(QuarkDown);
}
public static void registerRenders() {
}
public static void registerItem(Item item) {
GameRegistry.register(item);
}
public static void registerRender(Item item) {
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(Reference.MODID, item.getUnlocalizedName().substring(5)), "inventory"));
}
}
friend helped, changed
QuarkUp = new Item(QuarkUp, QuarkUp);
QuarkDown = new Item(QuarkDown, QuarkDown);
to
quark_Up = new itemQuarkUp();
quark_Down = new itemQuarkDown();
EDIT:
Completely started again as that video just made a mess imo, that i didn't understand, I guess ill get better soon haha, i just wish i could use Python instead
Related
I am trying to make a basic mod for minecraft and am following a tutorial for the same. When I run runClient, it gives me the following error
Reference to undefined variable MC_VERSION
Here is my main.java for reference:
package rattandeep.basicmod;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import rattandeep.basicmod.proxy.CommonProxy;
import rattandeep.basicmod.util.Reference;
#Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION)
public class Main {
#Instance
public static Main instance;
#SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.COMMON_PROXY_CLASS)
public static CommonProxy proxy;
#EventHandler
public static void PreInit(FMLPreInitializationEvent event) {
}
#EventHandler
public static void init(FMLInitializationEvent event) {
}
#EventHandler
public static void Postinit(FMLPostInitializationEvent event) {
}
}
I have searched for a solution but found none. How do I solve this?
I found out how to solve it. I just needed to change the variable value of MC_VERSION in my runClient launch file to my minecraft version.
Today I started on my first big project, which is a Minecraft Spigot plugin for my server called Pixel Network. When creating the /help command I encountered a problem. Whenever I called the command it just returned itself. I know that this is a question frequently asked, but I just couldn't get it to work. Here is my code:
Main Class
package gq.pixelnetwork.main;
import gq.pixelnetwork.listeners.CommandListener;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
public void onEnable() {
System.out.println("If you see this, the Pixel Network plugin is loaded!");
Bukkit.getServer().getPluginManager().registerEvents(new CommandListener(), this);
}
public void onDisable() { System.out.println("If you see this, the Pixel Network plugin is unloaded!"); }
}
And my Command Listener Class
package gq.pixelnetwork.listeners;
import gq.pixelnetwork.modules.Colors;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
public class CommandListener implements Listener{
Colors c = new Colors();
// Returning false will return the command to the sender!
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (cmd.getName().equalsIgnoreCase("help")) {
if (!(sender instanceof Player)) {
sender.sendMessage(c.red + "This is a Player-only command!");
return true;
} else{
openHelp();
return true;
}
}
return true;
}
private void openHelp() {
Inventory helpGUI = Bukkit.createInventory(null, 27, "§a§lHelp Menu");
createDisplay(Material.BOOK, helpGUI, 11, "§7/spawn", "§fUse it to get to Spawn.");
createDisplay(Material.BOOK, helpGUI, 13, "§7/hub", "§fUse it to get to HUB.");
createDisplay(Material.BOOK, helpGUI, 15, "§7/help", "§fUse it to see this menu.");
}
private static void createDisplay(Material material, Inventory inv, int Slot, String name, String lore) {
ItemStack item = new ItemStack(material);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
ArrayList<String> Lore = new ArrayList<String>();
Lore.add(lore);
meta.setLore(Lore);
item.setItemMeta(meta);
inv.setItem(Slot, item);
}
}
The reference to the Colors class is not the problem, as that is just a small 'module' I have made to make using colors easier.
I hope that someone can help me with this.
Thanks in advance,
- Xaaf
Unless the Spigot API has changed significantly since I've used it, your problem is that you're using onCommand in an event handler, not in your JavaPlugin class.
For example, you can have something like this
public class Whatever extends JavaPlugin {
#Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(command.getName().equalsIgnoreCase("hello")){
sender.sendMessage("Hello!");
return true;
}
return false;
}
}
Which will work fine, but you're registering your CommandListener as an Event Listener, meaning that when bukkit parses the class, it looks for any methods with an #EventHandler annotation and processes them as an event when they're fired.
You can also a Command Executor, which would look something like this:
public class Whatever extends JavaPlugin {
#Override
public void onEnable(){
this.getCommand("test").setExecutor(new MyCommandExecutor(this));
// register the class MyCommandExecutor as the executor for the "test" command
}
#Override
public void onDisable(){
}
}
then have another class like so:
public class MyCommandExecutor implements CommandExecutor {
private final Whatever plugin;
public MyPluginCommandExecutor(Whatever plugin) {
this.plugin = plugin; // Store the plugin in situations where you need it.
}
#Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(command.getName().equalsIgnoreCase("test")){
sender.sendMessage("Hello World!");
return true;
}
return false;
}
}
Essentially, you're trying to implement a CommandExecutor inside an EventListener, which shouldn't work, as far as I'm aware.
You're also returning true by default if the command isn't the one your plugin is handling, which is wrong, you should return false if it's not your command.
Why I am getting this error?
The constructor C17PacketCustomPayload(String, byte[]) is undefined
Java Code:
package pw.cinque.ping;
import java.awt.Color;
import net.minecraft.client.Minecraft;
import net.minecraft.network.Packet;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.C17PacketCustomPayload;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import java.awt.*;
import java.nio.ByteBuffer;
import org.lwjgl.input.Keyboard;
#Mod(modid = Packets.MODID, version = Packets.VERSION)
public class Packets
{
public static final String MODID = "Lower ur ping!";
public static final String VERSION = "1.0";
private static final Minecraft mc = Minecraft.getMinecraft();
private boolean textGui;
private final int textGuiKey = Keyboard.KEY_P;
private boolean reachToogle;
private final int reachKey = Keyboard.KEY_L;
#EventHandler
public void init(FMLInitializationEvent event)
{
FMLCommonHandler.instance().bus().register(this);
MinecraftForge.EVENT_BUS.register(this);
System.out.println("Intialized Reach Mod by Shiny");
}
#SubscribeEvent
public void onRender(TickEvent.RenderTickEvent e) {
if(textGui)
mc.fontRendererObj.drawStringWithShadow("Shiny", 2, 2, Color.BLACK.hashCode());
}
#SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent e) {
if(Keyboard.isKeyDown(textGuiKey)) {
textGui = !textGui;
return;
}
else if(Keyboard.isKeyDown(reachKey)) {
reachToogle = !reachToogle;
}
Packet spoofedReachPacket = manipulateReachPacket(spoofReachValue(4.2));
mc.thePlayer.sendQueue.addToSendQueue(spoofedReachPacket);
}
private Packet manipulateReachPacket(byte[] spoofedReachValue) {
return new C17PacketCustomPayload("reach", spoofedReachValue);
}
private byte[] spoofReachValue(double reachValue) {
byte[] buffer = new byte[8];
ByteBuffer.wrap(buffer).putDouble(reachValue`enter code here`);
return buffer;
}
}
I'm guessing you're getting your error here:
return new C17PacketCustomPayload("reach", spoofedReachValue);
It's saying that the constructor is undefined which means the class C17PacketCustomPayload does not have a constructor that takes a string and/or byte[] as arguments. If you created this class yourself then you need to add a method that looks like this
public C17PacketCustomPayload(String string, byte[] bytes){
//add behavior here
}
If you didn't create this class but are merely importing, then you need to look up just what parameters this constructor takes and fix it accordingly.
Why I am getting this error?
The answer is evident from these reverse engineered javadocs.
Constructors:
C17PacketCustomPayload()
C17PacketCustomPayload(java.lang.String p1, PacketBuffer p1)
In your code, the second parameter to the constructor call needs to be a PacketBuffer object, not a byte[].
I have started making a mod, it's not registering as an item. When i type /give Fidojj222 fcm:fuel_canister it should give me the item except it says it doesn't exist! I am using eclipse as my IDE I am suspecting it might be this warning when I compile it into a jar:
JAR export finished with warnings. See details for additional information.
Can not export external class folder at 'C:\Users\J.J\.gradle\caches\minecraft\net\minecraftforge\forge\1.8-11.14.3.1450\start'.
If that is the problem, then how can I fix it? If not here's my code:
CarsMod.java:
package com.fidojj222.carsmod;
import com.fidojj222.carsmod.init.CarsItems;
import com.fidojj222.carsmod.proxy.CommonProxy;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
#Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)
public class CarsMod {
#SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
public static CommonProxy proxy;
public void PreInit(FMLPreInitializationEvent event){
CarsItems.init();
CarsItems.register();
}
public void Init(FMLInitializationEvent event){
proxy.registerRenders();
}
public void PostInit(FMLPostInitializationEvent event){
}
}
Reference.java:
package com.fidojj222.carsmod;
public class Reference {
public static final String MOD_ID = "fcm";
public static final String MOD_NAME = "Fidojj222\'s Cars Mod";
public static final String VERSION = "1.0";
public static final String CLIENT_PROXY_CLASS = "com.fidojj222.carsmod.proxy.ClientProxy";
public static final String SERVER_PROXY_CLASS = "com.fidojj222.carsmod.proxy.CommonProxy";
}
CarsItems.java:
package com.fidojj222.carsmod.init;
import com.fidojj222.carsmod.Reference;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class CarsItems {
public static Item fuel_canister;
public static void init(){
fuel_canister = new Item().setUnlocalizedName("fuel_canister");
}
public static void register(){
GameRegistry.registerItem(fuel_canister, fuel_canister.getUnlocalizedName().substring(5));
}
public static void registerRenders(){
registerRender(fuel_canister);
}
public static void registerRender(Item item){
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
}
}
CommonProxy.java:
package com.fidojj222.carsmod.proxy;
public class CommonProxy {
public void registerRenders(){
}
}
ClientProxy.java:
package com.fidojj222.carsmod.proxy;
import com.fidojj222.carsmod.init.CarsItems;
public class ClientProxy extends CommonProxy {
#Override
public void registerRenders(){
CarsItems.registerRenders();
}
}
What do you mean by not showing? The item isn't found at all in the creative search menu, or it is an untextured (purple/black checkered) block?
If it is untextured, you need to make sure these 2 things are done:
Make sure you have this texture in place src/main/resources/assets/fcm/textures/items/fuel_canister.png it needs to be 16x16 pixels.
Create a fuel_canister.json file at src/main/resources/assets/fcm/models/item/fuel_canister.json This file defines how the image should be rendered ingame.
The contents of that file should be
{
"parent": "builtin/generated",
"textures":{
"layer0":"fcm:items/fuel_canister"
},
"display":{
"thirdperson":{
"rotation":[-90, 0, 0],
"translation":[0, 1, -3],
"scale":[0.55,0.55,0.55]
},
"firstperson":{
"rotation":[0,-135,25],
"translation":[0,4,2],
"scale":[1.7,1.7,1.7]
}
}
}
I followed these instructions using the Eclipse IDE:
http://blogs.locusta.gr/argy/2011/09/setup-an-apache-pivot-project-in-eclipse/
So now I've imported and attached the respective Apache Pivot libraries. I tried to run this code they have on their website, but a proper main method is missing. Eclipse has underlined the first line of the code as an error.
This is the error I get:
Error: Main method not found in class HelloJava, please define the main method
as: public static void main(String[] args)
I understand the error, but what should the main method contain? https://www.mail-archive.com/user#pivot.apache.org/msg06027.html
This guy suggests the following
public static void main(String[] args) {
DesktopApplicationContext.main(HelloJava.class, args);
}
But this returns the error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
DesktopApplicationContext cannot be resolved
Anyone got any ideas? Here is the code, I'm pretty sure only the first bits are important:
package org.apache.pivot.tutorials;
import java.awt.Color;
import java.awt.Font;
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.HorizontalAlignment;
import org.apache.pivot.wtk.Label;
import org.apache.pivot.wtk.VerticalAlignment;
import org.apache.pivot.wtk.Window;
public class HelloJava implements Application {
private Window window = null;
public static void main(String[] args) {
DesktopApplicationContext.main(HelloJava.class, args);
}
#Override
public void startup(Display display, Map<String, String> properties) {
window = new Window();
Label label = new Label();
label.setText("Hello World!");
label.getStyles().put("font", new Font("Arial", Font.BOLD, 24));
label.getStyles().put("color", Color.RED);
label.getStyles().put("horizontalAlignment",
HorizontalAlignment.CENTER);
label.getStyles().put("verticalAlignment",
VerticalAlignment.CENTER);
window.setContent(label);
window.setTitle("Hello World!");
window.setMaximized(true);
window.open(display);
}
#Override
public boolean shutdown(boolean optional) {
if (window != null) {
window.close();
}
return false;
}
#Override
public void suspend() {
}
#Override
public void resume() {
}
}
Never mind, I fixed it. I just had to erase the first line of the code, and add:
import org.apache.pivot.wtk.DesktopApplicationContext;