It's all in the title, the issue : Where should i start? created the project with forge builder, then started coding in eclipse, here is the result so far :
public void invChecker() {
checkFreeSlot: {
for(int i=0; i > 36; i++) {
if(player.inventory.getStackInSlot(i).equals(ItemStack.EMPTY)) {
p.sendMessage(new TextComponentString(Your inventory is full);
break checkFreeSlot;
}
}
//Failed check
return;
}
//Check passed, do something.
}
but i need to know what classes / packages i would need to create / edit to add that bit of code.
Most of the modding tutorials only talk about adding blocks / mobs / items... but i havn't seen so far that explain this.
EDIT: Forge version used in eclipse, recommended (1.12.1 - 14.22.1.2478)
i've create a class in another package with the code above, no errors, but to check every ticks, i used this in my main class, so i can call for my other class every ticks :
@EventHandler
public void chkInv(TickEvent.ClientTickEvent event) {
if(Minecraft.getInstance().player.notEqual(null)) {
}
}
but it say that "the method getInstance() is undefined for the type Minecraft"
Fixed that part as well as others, now got this issue :
[f]: The mod f appears to have an invalid event annotation EventHandler. This annotation can only apply to methods with recognized event arguments - it will not be called
Fixed all this, here is main.java so far :
package Gess.mod;
import Gess.mod.proxy.iProxy;
import net.minecraft.client.Minecraft;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventHandler;
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 net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import util.Reference;
@EventBusSubscriber
@Mod(modid=Reference.MODID, name=Reference.MODNAME, version=Reference.VERSION)
public class Main
{
public static Main instance;
public static final String CLIENT = "gess.mod.proxy.ClientProxy";
public static final String SERVER = "gess.mod.proxy.CommonProxy";
@SidedProxy(clientSide = Reference.CLIENT, serverSide = Reference.COMMON)
public static iProxy proxy;
@EventHandler
public void preInit(FMLPreInitializationEvent event){}
@EventHandler
public void init(FMLInitializationEvent event){}
@EventHandler
public void postInit(FMLPostInitializationEvent event){}
public Main() {
}
@SubscribeEvent
public static void chkInv(TickEvent.ClientTickEvent event) throws InterruptedException {
if(Minecraft.getMinecraft().player != null) {
int s = 0;
for(int i=0; i < 37; i++) {
if(!Minecraft.getMinecraft().player.inventory.getStackInSlot(i).isEmpty()) {
s++;
if(s > 35) {
Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Your inventory is full"));
return;
}
}
}
return;
}
}
}
Unfortunately, i can't make a delay between each messages by myself without breaking all the code! (i've tried for 3hours after the official forge forum locked my thread)
EDIT N°Unknown: finally, i was able to put a delay between messages, using worldgetTotalWorldTime(), but now
there is delay between the moment where i pickup the items and the message appearing
bump as i still update my thread with was i've done so far, still need help with the delay between the moment where i pickup the object and the message sending.
the github has been updated with the most recent and working code
Try creating a field that saves the time that you last sent a message.
private float lastMessageTime;
In the OnTick event, check for a full inventory in just the same way, but instead of printing out a message, you'll want something like this,
float currentTime = Minecraft.getMinecraft().world.getTotalWorldTime();
if(currentTime > this.lastMessageTime + 300) {
// Show message, it's been 300 ticks since the last one was sent
this.lastMessageTime = currentTime;
}
But you also want a message to be shown right away when the player picks up an item. Try subscribing to the
EntityItemPickupEvent
Whenever the event is triggered, display the message, AND, "reset" the field
lastMessageTime
to the worldTime.
I didn't try this out, but it should get you going in the right direction.
The only reason you would want to subscribe to the EntityItemPickupEvent is if you wanted to know exactly when a player picked up an item. If you don't need to know, don't worry about it.
And you are correct, you will have to make the field static, I didn't realize the method was marked as static.
well i've made an independent method instead, it will be fine like this, yesterday, i was making the config file so we can actually control the delay between messages and the game crashed (at least, the file was created but nothing is written in it) here's the crash report
net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Full Inventory Checker (fullinvchecker)
Caused by: java.lang.NullPointerException
at Gess.mod.config.Config.readConfig(Config.java:21)
at Gess.mod.Main.preInit(Main.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:611)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
at com.google.common.eventbus.EventBus.post(EventBus.java:217)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:253)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:231)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
at com.google.common.eventbus.EventBus.post(EventBus.java:217)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:148)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:604)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:266)
at net.minecraft.client.Minecraft.init(Minecraft.java:508)
at net.minecraft.client.Minecraft.run(Minecraft.java:416)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:25)
Check, because on soem servers, there are custom max stack size for some items, like heads on hypixel skyblock (backpack, minions) or weapons on wynncraft
I'm not sure which line is line 21, where the error is, but you're getting a null pointer exception. Make sure the reference you're using isn't null. On a side note, why not just pass a reference to your Configuration object into the readConfig method, instead of saving it to a static field in your CommonProxy class.
I don't know a ton about the writing of server plugins, what hypixel and wynncraft would use, but I'm pretty sure there isn't an easy way to find out the custom limit.
well then, add an exception manually for each items that isn't stackable
i started working on an "else" way thinking about doing it by just comparing the item in getStackInSlot() with some kind of "filter" with all the block IDs that you could edit in the config file.
but i'm having issue with how i should implement that you know, starting with my previous methods to check all the 36 slots then if(Minecraft.getMinecraft() .player.inventory.getStackInSlot(i).getItem() == [One of the items in the filter]
should had copied my Main class instead :
package Gess.mod;
import java.io.File;
import Gess.mod.config.Config;
import Gess.mod.proxy.iProxy;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventHandler;
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 net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import util.Reference;
@EventBusSubscriber
@Mod(modid=Reference.MODID, name=Reference.MODNAME, version=Reference.VERSION)
public class Main
{
public static Configuration config;
public static int time = 10;
public static Main instance;
float lastMessageTime = 0;
public static final String CLIENT = "gess.mod.proxy.ClientProxy";
public static final String SERVER = "gess.mod.proxy.CommonProxy";
@SidedProxy(clientSide = Reference.CLIENT, serverSide = Reference.COMMON)
public static iProxy proxy;
@EventHandler
public void preInit(FMLPreInitializationEvent event){
File directory = event.getModConfigurationDirectory();
config = new Configuration(new File(directory.getPath(), "FullInventoryChecker.cfg"));
Config.readConfig();
}
@EventHandler
public void init(FMLInitializationEvent event){}
@EventHandler
public void postInit(FMLPostInitializationEvent event){
if (config.hasChanged()) {
config.save();
}
}
public Main() {
}
@SubscribeEvent
public static void PckUpItm(EntityItemPickupEvent event) throws InterruptedException {
int s = 0;
for(int i=0; i < 37; i++) {
if(!Minecraft.getMinecraft().player.inventory.getStackInSlot(i).isEmpty() && Minecraft.getMinecraft()
.player.inventory.getStackInSlot(i).getCount() == Minecraft.getMinecraft().player.inventory.getStackInSlot(i).getMaxStackSize()) {;
float currentTime = Minecraft.getMinecraft().world.getTotalWorldTime();
s++;
if(s > 35) {
Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Your inventory is full"));
}
}
}
}
@SubscribeEvent
public static void chkInv(TickEvent.ClientTickEvent event) throws InterruptedException {
if(Minecraft.getMinecraft().player != null) {
int s = 0;
for(int i=0; i < 37; i++) {
if(!Minecraft.getMinecraft().player.inventory.getStackInSlot(i).isEmpty() && Minecraft.getMinecraft()
.player.inventory.getStackInSlot(i).getCount() == Minecraft.getMinecraft().player.inventory.getStackInSlot(i).getMaxStackSize()) {
s++;
if(s > 35) {
if(Minecraft.getMinecraft().world.getTotalWorldTime() % 200 == 3L && event.phase == TickEvent.Phase.END) {
Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Your inventory is full"));
return;
}
}
//else {
//for(int t=0; i < 37; t++) {
//if(Minecraft.getMinecraft().player.inventory.getStackInSlot(t).getItem() == ) {
//}
//}
//}
}
}
return;
}
}
}
//@SideOnly(Side.CLIENT)
//public void TickhHandler(TickEvent.ClientTickEvent event) throws InterruptedException {
//wait(200);
//}
Config.java :
package Gess.mod.config;
import Gess.mod.proxy.CommonProxy;
import net.minecraftforge.common.config.Config.Name;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber
public class Config {
public static final String CATEGORY_GENERAL = "general";
public static int time = 10;
public static void readConfig() {
Configuration cfg = CommonProxy.config;
try {
cfg.load();
initGeneralConfig(cfg);
}
catch (Exception e) {
// Failed reading/writing, just continue
}
finally
{
if (cfg.hasChanged()) {
cfg.save();
}
}
}
private static void initGeneralConfig(Configuration cfg) {
cfg.addCustomCategoryComment(CATEGORY_GENERAL, "General configuration");
time = cfg.getInt("time", CATEGORY_GENERAL, 10, 1, 60, "Set time in seconds here between 1 and 60");
}
}
CommonProxy:
package Gess.mod.proxy;
import java.io.File;
import Gess.mod.config.Config;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
public class CommonProxy implements iProxy {
public static Configuration config;
public void preInit(FMLPreInitializationEvent event) {
File directory = event.getModConfigurationDirectory();
config = new Configuration(new File(directory.getPath(), "FullInventoryChecker.cfg"));
Config.readConfig();
}
public void init(FMLInitializationEvent event) {
}
public void postInit(FMLPostInitializationEvent event) {
if (config.hasChanged()) {
config.save();
}
}
}
why not just pass a reference to your Configuration object into the readConfig method, instead of saving it to a static field in your CommonProxy class.
Because i don't know how to create a working config file yet and the amount of tutorials about it is limited? yeah probably that.
Check out this file in one of my projects. I call the
readConfig
method from the
FMLPreInitializationEvent
in my main mod file. I then use the static getters from just about anywhere to get the values of the fields. The mod is 1.12.2, but 1.14 (that looks like the version you're in), should be very similar.
On a side note, instead of calling
Minecraft.getMinecraft().player.inventory
frequently, save the result as a field of type
InventoryPlayer
or whatever the type is, maybe it got changed in your version. That should make your code a little bit nicer looking.
my mod is 1.12.1 (so compatible with 1.12.2) i've checked your mod as well as others, and it look around the same other, the fact that the variable in my config file isn't like
public static void readConfig(FMLPreInitializationEvent event) {
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
config.load();
[Variables and booleans here]
if (config.hasChanged()) {
config.save();
}
}
my variables and booleans are setup outside of the readConfig method, and it should work, cause some other mods does that too, so i'm just confused at this point, and my time these 2 previous week was limited, so i hope to find a solution soon cause idk if i'll be able to completely finish it.
i'm going to work on a fix when i'll have enough time, the issue is in this ReadConfig, i just need to figure what cause it, question of time again.
i could try as a last chance to import my mod in MCreator and create a config there if this is possible
i start seeing more and more people coming to check the repo and clone it, maybe it's also the time to release it?
Just updated my github with the most recent and working code (work for me at least, i had no feedback for the others).
EDIT: the other day, all my methods to check the inventory and send the message when full were working, now it's not working anymore! like wtf at this point? i havn't edited the methods since they were working, now myEntityItemPickupEvent doesn't work anymore
EDIT2: repasted my method from the tickevent, deleted the delay and the other thing, still not working, forge is broken, more forge shenanigans, i'm even more confused.
EDIT:3 added some outputs to check, it stop checking at the 35th slot (included) when it should also check the 36th as it always did.
so after re-writing couple thing, i gave up on making a config file, instead, i'm going to work on my method to detect itemstack change on client side.
package Gess.mod;
import Gess.mod.proxy.iProxy;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventHandler;
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 net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import util.Reference;
@EventBusSubscriber
@Mod(modid=Reference.MODID, name=Reference.MODNAME, version=Reference.VERSION)
public class Main
{
public static Configuration config;
//public static int time = 10;
public static Main instance;
//float lastMessageTime = 0;
public boolean inventoryIsFull;
public static final String CLIENT = "gess.mod.proxy.ClientProxy";
public static final String SERVER = "gess.mod.proxy.CommonProxy";
@SidedProxy(clientSide = Reference.CLIENT, serverSide = Reference.COMMON)
public static iProxy proxy;
@EventHandler
public void preInit(FMLPreInitializationEvent e){
//File directory = event.getModConfigurationDirectory();
//config = new Configuration(new File(directory.getPath(), "FullInventoryChecker.cfg"));
//Config.readConfig();
}
@EventHandler
public void init(FMLInitializationEvent e){}
@EventHandler
public void postInit(FMLPostInitializationEvent e){
// if (config.hasChanged())
// config.save();
//}
}
public Main() {
}
private ItemStack[] previous;
private ItemStack[] now;
@SubscribeEvent
public void PckUpItm(TickEvent.ClientTickEvent event) {
if(Minecraft.getMinecraft().player != null) {
EntityPlayer player = Minecraft.getMinecraft().player;
int g = 0;
System.out.println("starting to count e");
for(int e=0; e < 36; e++) {
System.out.println("checking slot " + e);
ItemStack stack = player.inventory.getStackInSlot(e);
if(ItemStack.areItemStacksEqual(previous[e], stack)) {
if(!stack.isEmpty() && stack.getCount() == stack.getMaxStackSize()) {
g++;
System.out.println("g = " + g);
previous[e] = stack;
System.out.println("Itemstack " + e + "copied");
if(g > 34) {
Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Your inventory is full"));
return;
}
}
}
}
}
}
@SubscribeEvent
public static void chkInv(TickEvent.ClientTickEvent event) throws InterruptedException {
if(Minecraft.getMinecraft().player != null) {
int s = 0;
for(int i=0; i < 37; i++) {
if(!Minecraft.getMinecraft().player.inventory.getStackInSlot(i).isEmpty() && Minecraft.getMinecraft()
.player.inventory.getStackInSlot(i).getCount() == Minecraft.getMinecraft().player.inventory.getStackInSlot(i).getMaxStackSize()) {
s++;
if(s > 35) {
if(Minecraft.getMinecraft().world.getTotalWorldTime() % 200 == 3L && event.phase == TickEvent.Phase.END) {
Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Your inventory is full"));
System.out.println("chkInv: Triggerred with s = " + s);
return;
}
}
//else {
//for(int t=0; i < 37; t++) {
//if(!Minecraft.getMinecraft().player.inventory.getStackInSlot(i).isEmpty() && Minecraft.getMinecraft().player.inventory.getStackInSlot(t).getItem() == ) {
//}
//}
//}
}
}
return;
}
}
}
//@SideOnly(Side.CLIENT)
//public void TickhHandler(TickEvent.ClientTickEvent event) throws InterruptedException {
//wait(200);
//}
the thing is, when i connect to a server, i get timed out with this error:
[20:43:41] [main/INFO] [minecraft/GuiConnecting]: Connecting to localhost, 25565
[20:43:41] [Netty Client IO #4/INFO] [FML]: Aborting client handshake "VANILLA"
[20:43:41] [Netty Client IO #4/INFO] [FML]: [Netty Client IO #4] Client side vanilla connection established
[20:44:06] [Netty Client IO #4/ERROR] [FML]: NetworkDispatcher exception
java.io.IOException: Une connexion existante a dû être fermée par l’hôte distant // timeout
at sun.nio.ch.SocketDispatcher.read0(Native Method) ~[?:1.8.0_212]
at sun.nio.ch.SocketDispatcher.read(Unknown Source) ~[?:1.8.0_212]
at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source) ~[?:1.8.0_212]
at sun.nio.ch.IOUtil.read(Unknown Source) ~[?:1.8.0_212]
at sun.nio.ch.SocketChannelImpl.read(Unknown Source) ~[?:1.8.0_212]
at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288) ~[PooledUnsafeDirectByteBuf.class:4.1.9.Final]
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1100) ~[AbstractByteBuf.class:4.1.9.Final]
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:372) ~[NioSocketChannel.class:4.1.9.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:123) [AbstractNioByteChannel$NioByteUnsafe.class:4.1.9.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:624) [NioEventLoop.class:4.1.9.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:559) [NioEventLoop.class:4.1.9.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:476) [NioEventLoop.class:4.1.9.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438) [NioEventLoop.class:4.1.9.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) [SingleThreadEventExecutor$5.class:4.1.9.Final]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_212]
[20:44:07] [main/INFO] [FML]: Applying holder lookups
[20:44:07] [main/INFO] [FML]: Holder lookups applied
a forum gave up already, experimented modders there don't know how to fix it, it also doesn't run at all in solo,
the issue is the public void PckUpItm(TickEvent.ClientTickEvent event) method
It's all in the title, the issue : Where should i start? created the project with forge builder, then started coding in eclipse, here is the result so far :
https://github.com/Mrcubix/Full-Inventory-Checker
i already know i need to use :
but i need to know what classes / packages i would need to create / edit to add that bit of code.
Most of the modding tutorials only talk about adding blocks / mobs / items... but i havn't seen so far that explain this.
EDIT: Forge version used in eclipse, recommended (1.12.1 - 14.22.1.2478)
i've create a class in another package with the code above, no errors, but to check every ticks, i used this in my main class, so i can call for my other class every ticks :
but it say that "the method getInstance() is undefined for the type Minecraft"
Fixed that part as well as others, now got this issue :
Fixed all this, here is main.java so far :
Unfortunately, i can't make a delay between each messages by myself without breaking all the code! (i've tried for 3hours after the official forge forum locked my thread)
EDIT N°Unknown: finally, i was able to put a delay between messages, using worldgetTotalWorldTime(), but now
there is delay between the moment where i pickup the items and the message appearing
bump as i still update my thread with was i've done so far, still need help with the delay between the moment where i pickup the object and the message sending.
the github has been updated with the most recent and working code
tried to add a boolean and it broke my code
I think I know what you're looking for.
Try creating a field that saves the time that you last sent a message.
In the OnTick event, check for a full inventory in just the same way, but instead of printing out a message, you'll want something like this,
But you also want a message to be shown right away when the player picks up an item. Try subscribing to the
Whenever the event is triggered, display the message, AND, "reset" the field
to the worldTime.
I didn't try this out, but it should get you going in the right direction.
So i was 2 words away to get getTotalWorldTime working out of an if statement? well f
can't use "this" in a static statement, so i had to remove them, shouldn't be an issue anyway,
i don't exactly understand what do you mean by subscribe to EntityItemPickupEvent.
do i have to add an or statement with or something? cause i can't fin it in the list.
The only reason you would want to subscribe to the EntityItemPickupEvent is if you wanted to know exactly when a player picked up an item. If you don't need to know, don't worry about it.
And you are correct, you will have to make the field static, I didn't realize the method was marked as static.
well i've made an independent method instead, it will be fine like this, yesterday, i was making the config file so we can actually control the delay between messages and the game crashed (at least, the file was created but nothing is written in it) here's the crash report
and here is the lines of code erroring:
ReadConfig (error at line 21):
PreInit (error at line 41):
also, i've tried for 1h30 to make this sh*t work : Minecraft.getMinecraft().getSoundHandler().playSound();
but it return an error, basically i want to play a sound, on client side when the player inventory is full.
finally, i'm wandering if it's possible to add Some items to exclude from the
Check, because on soem servers, there are custom max stack size for some items, like heads on hypixel skyblock (backpack, minions) or weapons on wynncraft
I'm not sure which line is line 21, where the error is, but you're getting a null pointer exception. Make sure the reference you're using isn't null. On a side note, why not just pass a reference to your Configuration object into the readConfig method, instead of saving it to a static field in your CommonProxy class.
I don't know a ton about the writing of server plugins, what hypixel and wynncraft would use, but I'm pretty sure there isn't an easy way to find out the custom limit.
well then, add an exception manually for each items that isn't stackable
i started working on an "else" way thinking about doing it by just comparing the item in getStackInSlot() with some kind of "filter" with all the block IDs that you could edit in the config file.
but i'm having issue with how i should implement that you know, starting with my previous methods to check all the 36 slots then if(Minecraft.getMinecraft() .player.inventory.getStackInSlot(i).getItem() == [One of the items in the filter]
should had copied my Main class instead :
Config.java :
CommonProxy:
Because i don't know how to create a working config file yet and the amount of tutorials about it is limited? yeah probably that.
Check out this file in one of my projects. I call the
method from the
in my main mod file. I then use the static getters from just about anywhere to get the values of the fields. The mod is 1.12.2, but 1.14 (that looks like the version you're in), should be very similar.
On a side note, instead of calling
frequently, save the result as a field of type
or whatever the type is, maybe it got changed in your version. That should make your code a little bit nicer looking.
my mod is 1.12.1 (so compatible with 1.12.2) i've checked your mod as well as others, and it look around the same other, the fact that the variable in my config file isn't like
my variables and booleans are setup outside of the readConfig method, and it should work, cause some other mods does that too, so i'm just confused at this point, and my time these 2 previous week was limited, so i hope to find a solution soon cause idk if i'll be able to completely finish it.
i'm going to work on a fix when i'll have enough time, the issue is in this ReadConfig, i just need to figure what cause it, question of time again.
i could try as a last chance to import my mod in MCreator and create a config there if this is possible
i start seeing more and more people coming to check the repo and clone it, maybe it's also the time to release it?
Just updated my github with the most recent and working code (work for me at least, i had no feedback for the others).
EDIT: the other day, all my methods to check the inventory and send the message when full were working, now it's not working anymore! like wtf at this point? i havn't edited the methods since they were working, now myEntityItemPickupEvent doesn't work anymore
EDIT2: repasted my method from the tickevent, deleted the delay and the other thing, still not working, forge is broken, more forge shenanigans, i'm even more confused.
EDIT:3 added some outputs to check, it stop checking at the 35th slot (included) when it should also check the 36th as it always did.
so after re-writing couple thing, i gave up on making a config file, instead, i'm going to work on my method to detect itemstack change on client side.
the thing is, when i connect to a server, i get timed out with this error:
a forum gave up already, experimented modders there don't know how to fix it, it also doesn't run at all in solo,
the issue is the public void PckUpItm(TickEvent.ClientTickEvent event) method
So i tried to hardcode every slots as i obtain this mess:
First line explain perfectly what this mod became
and the game crash when i force the method to work and when joining a world / server:
any idea?