java.lang.NoSuchMethodError when it is clearly there - java

General Info: I am using the Bukkit/Spigot API in version git-Spigot-1d14d5f-ba32592 (MC: 1.8.3) (Implementing API version 1.8.3-R0.1-SNAPSHOT), IntelliJ IDEA 14.1.3 and compile with its default compiler. The java jdk version is 1.8.0_25.
So when I try to call this class's constructor, it throws the runtime exception from the title.
Inventory menu class
package me.lakan.util.inventory;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Map;
#SuppressWarnings("unused") // Util functionality is not always used
public class InventoryMenu implements Listener {
private InventoryType type;
private String title;
private Map<Integer, MenuOption> options;
// Constructors
public InventoryMenu(InventoryType type, String title, JavaPlugin plugin) {
this.options = new HashMap<Integer, MenuOption>();
this.type = type;
this.title = title;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
public boolean addOption(int position, MenuOption option) {
boolean res = isPosEmpty(position);
this.options.put(position, option);
return res;
}
public void addOption(String name, int position, ItemStack icon) {
addOption(position, new MenuOption(icon, name));
}
public boolean isPosEmpty(int position) {
return !this.options.containsKey(position);
}
public void openFor(Player p) {
// Create a new inventory
Inventory inv = Bukkit.createInventory(p, this.type, this.title);
// Fill all icons at their positions
for (Map.Entry<Integer, MenuOption> key : this.options.entrySet()) {
inv.setItem(key.getKey(), key.getValue().getIcon());
}
// If the inventory is a player inventory, update the player's
if (inv.getType() == InventoryType.PLAYER) {
p.getInventory().setContents(inv.getContents());
}
// For any openable inventory, just open it up
else {
p.openInventory(inv);
}
}
/**
* Listens for inventory clicks
* If the inventory is a menu:
* - Cancel movement
* - Push event
* - Close inventory if it should
* #param e The actual event
*/
#EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryClick(InventoryClickEvent e) {
// Prevent clicking if this inventory was clicked
if (e.getClickedInventory().getName().equals(this.title)) {
e.setCancelled(true);
// Check for option
if (this.options.containsKey(e.getRawSlot())) {
// Get the option for this slot
MenuOption option = this.options.get(e.getRawSlot());
// Fill out an event and push it
MenuClickEvent event = new MenuClickEvent((Player) e.getWhoClicked(), true, option.getName(), e.getRawSlot());
Bukkit.getServer().getPluginManager().callEvent(event);
// Now close inventory if not cancelled
if (event.willCLose()) {
e.getWhoClicked().closeInventory();
}
}
}
}
#SuppressWarnings("unused")
public interface OptionClickEventHandler {
public void onOptionClick(MenuClickEvent event);
}
}
The item menu class
package me.lakan.test;
import me.lakan.util.inventory.InventoryMenu;
import me.lakan.util.inventory.MenuClickEvent;
import me.lakan.util.inventory.MenuOption;
import me.lakan.util.item.ItemBuilder;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryType;
public class ItemMenu implements Listener {
private PluginEntry plugin;
private InventoryMenu menu;
// Commands
private TestCommand testCmd;
public ItemMenu(PluginEntry plugin) {
Validate.notNull(this.plugin, "The plugin reference may not be null");
this.plugin = plugin;
this.menu = new InventoryMenu(InventoryType.CHEST, "" + ChatColor.DARK_GRAY + "Abilities", this.plugin);
// Test
this.menu.addOption(1,
new MenuOption(
new ItemBuilder()
.amount(1)
.material(Material.RAW_FISH)
.name(ChatColor.LIGHT_PURPLE + "Test")
.lore(ChatColor.WHITE + "Click me")
.build(),
"TestIdentifier"));
this.testCmd= new TestCmd(this.plugin);
}
public void openFor(Player p) {
this.menu.openFor(p);
}
#EventHandler(priority = EventPriority.NORMAL)
public void onOptionClick(MenuClickEvent e) {
// Test
if (e.getName().equals("TestIdentifier")) {
this.testCmd.executeFor(e.getWhoClicked());
}
}
}
Exception stack trace
[12:48:25] [Server thread/ERROR]: Error occurred while enabling Test v1.0 (Is it up to date?)
java.lang.NoSuchMethodError: me.lakan.util.inventory.InventoryMenu.(Lorg/bukkit/event/inventory/InventoryType;Ljava/lang/String;Lorg/bukkit/plugin/java/JavaPlugin;)V
at me.lakan.test.ItemMenu.(ItemMenu.java:33) ~[?:?]
at me.lakan.test.CommandParser.(CommandParser.java:20) ~[?:?]
at me.lakan.test.PluginEntry.onEnable(PluginEntry.java:21) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot_server.jar:git-Spigot-1d14d5f-ba32592]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335) [spigot_server.jar:git-Spigot-1d14d5f-ba32592]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot_server.jar:git-Spigot-1d14d5f-ba32592]
at org.bukkit.craftbukkit.v1_8_R2.CraftServer.loadPlugin(CraftServer.java:356) [spigot_server.jar:git-Spigot-1d14d5f-ba32592]
at org.bukkit.craftbukkit.v1_8_R2.CraftServer.enablePlugins(CraftServer.java:316) [spigot_server.jar:git-Spigot-1d14d5f-ba32592]
at net.minecraft.server.v1_8_R2.MinecraftServer.r(MinecraftServer.java:416) [spigot_server.jar:git-Spigot-1d14d5f-ba32592]
at net.minecraft.server.v1_8_R2.MinecraftServer.k(MinecraftServer.java:382) [spigot_server.jar:git-Spigot-1d14d5f-ba32592]
at net.minecraft.server.v1_8_R2.MinecraftServer.a(MinecraftServer.java:337) [spigot_server.jar:git-Spigot-1d14d5f-ba32592]
at net.minecraft.server.v1_8_R2.DedicatedServer.init(DedicatedServer.java:257) [spigot_server.jar:git-Spigot-1d14d5f-ba32592]
at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:522) [spigot_server.jar:git-Spigot-1d14d5f-ba32592]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
As you can see the constructor is there and is to my knowledge properly called. So is this error a mistake in my project setup, an API thing, or something entirely different?
The utility classes are in a seperate module and everything works if I paste them into my test plugin module, but not inside the other module. However any other constructor in any other class inside me.lakan.util.inventory can be called normally.

The problem was in the project structure.
For the test artifact, I chose the module output of the util module.
Changing it to the artifact output of the util module fixed it.

Related

getItemMeta is always returning null in my spigot plugin

Hi fellow coders I have been trying to make a custom sword and put it into a shop gui but when I try to change the swords meta using ItemStack.getitemmeta() and then i try to set the display name or something it says the sword meta is null. Also I am changing My actual name in irl to my name and the server name to server name
Error:
Caused by: java.lang.NullPointerException: Cannot invoke "org.bukkit.inventory.meta.ItemMeta.setDisplayName(String)" because "weaponMeta" is null
Blunt Knife.java
package me.myname.servername.items.weapons;
import me.myname.servername.Utils.Weapon;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
public class BluntKnife extends Weapon
{
public void BluntKnife()
{
tradable = true;
damage = 12;
rarity = "COMMON";
name = "Blunt Knife";
ArrayList<String> lore = new ArrayList<String>();
lore.add("Damage: +12");
lore.add("");
lore.add("Can be upgraded with /upgrade for 500 coins!");
lore.add("");
lore.add("⚔ COMMON SWORD ⚔");
item = new ItemStack(Material.AIR, 1);
}
}
MakeItem.java
package me.myname.servername.Utils;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public interface MakeItem
{
public default ItemStack makeItemFromWeapon(Weapon wpn)
{
ItemStack weapon = wpn.item;
ItemMeta weaponMeta = weapon.getItemMeta();
weaponMeta.setDisplayName(wpn.name);
weaponMeta.setLore(wpn.lore);
weapon.setItemMeta(weaponMeta);
return weapon;
}
}
Weapon.java
package me.myname.servername.Utils;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
public class Weapon
{
protected boolean tradable = true;
protected int damage = 5;
protected String rarity = null;
protected String name = null;
protected ArrayList<String> lore = new ArrayList<>();
protected ItemStack item = new ItemStack(Material.AIR, 1);
}
ShopCommand.java
package me.myname.servername.commands;
import me.myname.servername.Utils.MakeItem;
import me.myname.servername.Utils.Weapon;
import me.myname.servername.items.weapons.BluntKnife;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class ShopCommand implements CommandExecutor, MakeItem {
#Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if(sender instanceof Player){
Player player = (Player) sender;
Inventory shopinv = Bukkit.createInventory(player, 9, ChatColor.AQUA + "Shop");
BluntKnife item1 = new BluntKnife();
ItemStack[] menu_items = {makeItemFromWeapon(item1)};
shopinv.setContents(menu_items);
player.openInventory(shopinv);
}
return true;
}
}
Of public interface MakeItem.
An interface in Java is always public and static
and
All fields (variables) must be static constants
and
All methods are an abstract signature only , no body code
You must "implement" the coded methods inside a class that uses the implement keyword and the interface name.
In BluntKnife.java I did the constructor wrong.
So I changed it from public void BluntKnife() too public BluntKnife()

Player turns invisible and immobile when loading custom mod

I'm starting to code my own minecraft 1.14.4 mod. I want to create a very simple mod which will just display a clok showing the in-game time (I couldn't find a similar updated mod, since all other mods show the real-time time, not the in-game time). I took the example mod which comes with Forge, and added some custom code.
When I load the mod, the player turns invisible and immobile. He is there, I can look around and dig and so on, but I can not see him nor move.
If I suppress my custom code, it works... very weird to me.
this is my code so far (it does not show anything since I am stuck in this problem).
package com.alef.simpleclock;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.stream.Collectors;
// The value here should match an entry in the META-INF/mods.toml file
#Mod("simpleclock")
public class SimpleClock
{
// Directly reference a log4j logger.
private static final Logger LOGGER = LogManager.getLogger();
public static boolean startTimer;
public static int tick;
public SimpleClock() {
// Register the setup method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
// Register the enqueueIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
// Register the processIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
// Register the doClientStuff method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
}
private void setup(final FMLCommonSetupEvent event)
{
// some preinit code
LOGGER.info("HELLO FROM PREINIT");
LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
}
private void doClientStuff(final FMLClientSetupEvent event) {
// do something that can only be done on the client
LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
}
private void enqueueIMC(final InterModEnqueueEvent event)
{
// some example code to dispatch IMC to another mod
InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
}
private void processIMC(final InterModProcessEvent event)
{
// some example code to receive and process InterModComms from other mods
LOGGER.info("Got IMC {}", event.getIMCStream().
map(m->m.getMessageSupplier().get()).
collect(Collectors.toList()));
}
// You can use SubscribeEvent and let the Event Bus discover methods to call
#SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
// do something when the server starts
LOGGER.info("HELLO from server starting");
}
// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
#Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
public static class RegistryEvents {
#SubscribeEvent
public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
// register a new block here
LOGGER.info("HELLO from Register Block");
}
}
#EventBusSubscriber
public static class showClock
{
#SubscribeEvent
public static void onJoin(final EntityJoinWorldEvent event)
{
if (event.getEntity() != null && event.getEntity() instanceof ClientPlayerEntity)
{
LOGGER.info("WELCOME " + event.getEntity().getName() + "!!!");
event.setCanceled(true);
if (!SimpleClock.startTimer)
{
SimpleClock.startTimer = true;
}
}
}
#SubscribeEvent
public static void timer(final TickEvent.WorldTickEvent event)
{
if (SimpleClock.startTimer)
{
if (SimpleClock.tick >= 1000)
{
SimpleClock.tick = 0;
drawClock(event.world);
}
else
{
SimpleClock.tick++;
}
}
}
private static void drawClock(World world)
{
int time = (int) world.getWorldInfo().getDayTime() % 1000;
LOGGER.info(time);
}
}
}
Any help is welcome!!!

My Minecraft Spigot Plugin Not Reporting Back

I am pretty new to coding java and I have done a few tutorials, which have been great but i don't know why it isn't working in-game. I have tried everything such as changing it and looking at so many different forums. There are two classes for the events(Join and Leave Event) and the main class. I have made sure to check for importing them and errors none for me to see from where I have looked. If anyone can help it would be a blessing.
Code: - Main class:
package me.JimmyClown.FirstPlugin;
import org.bukkit.plugin.java.JavaPlugin;
public class MainClass extends JavaPlugin {
#Override
public void onEnable() {
System.out.println("It works!");
getServer().getPluginManager().registerEvents(new PlayerJoin(), this);
getServer().getPluginManager().registerEvents(new PlayerLeave(), this);
}
#Override
public void onDisable() {
}
}
**Code for the Join-Class:**
package me.JimmyClown.FirstPlugin;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class PlayerJoin implements Listener{
#EventHandler
void onPlayerJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
e.setJoinMessage(ChatColor.BLUE + "Welcome back to the server!" + player.getDisplayName());
}
}
**Code for Leave Class:**
package me.JimmyClown.FirstPlugin;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
public class PlayerLeave implements Listener {
#EventHandler
void onPlayerLeave(PlayerQuitEvent e) {
Player player = e.getPlayer();
e.setQuitMessage(ChatColor.DARK_BLUE + "Awwww, We hope we see you soon" + player.getDisplayName());
}
}
The plugin.yml:
name: FirstProject
version: 1.0
main: me.JimmyClown.FirstPlugin.MainClass
authors: JimmyTheClown
description: This is my first plugin.
Try to set the access modifier of the event methods to public.
public void onPlayerLeave(PlayerQuitEvent e) { }
public void onPlayerJoin(PlayerJoinEvent e) { }

Command not working

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.

Item not working in minecraft mod - Minecraft Forge Mod Development [EDIT: FIXED]

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]
}
}
}

Categories