CraftTweaker

CraftTweaker

151M Downloads

Error when preventing interacting with entities

TRLWeiss opened this issue ยท 4 comments

commented

Issue Description:

When i tried to cancel the event which interacts with an entity, a error occured and i had no idea how to fix it

What happens:

I used those codes to try preventing interacting:
import crafttweaker.events.IEventManager;
import crafttweaker.event.IEventCancelable;
import crafttweaker.player.IPlayer;
import crafttweaker.event.PlayerInteractEvent;
import crafttweaker.event.PlayerInteractBlockEvent;
import crafttweaker.event.PlayerInteractEntityEvent;
import crafttweaker.entity.IEntityDefinition;

events.onPlayerInteractEntity(function(event as PlayerInteractEntityEvent)
{
if (event.entity.definition.id == entity:ancientwarfarenpc:aw_npc_worker.id || event.entity.definition.id == "entity:ancientwarfarenpc:aw_npc_worker" || event.entity.definition.id == "ancientwarfarenpc:aw_npc_worker")
{
event.player.sendMessage("You cannot interact with a npc!");
event.cancel() ;
}

}
);

but error occurs:
[SERVER_STARTED][SERVER][ERROR] null
java.lang.NullPointerException
at ZenClassCrafttweakerEvents0.handle(Unknown Source)
at ZenClassCrafttweakerEvents0.handle(Unknown Source)
at crafttweaker.util.EventList.publish(EventList.java:51)
at crafttweaker.api.event.MTEventManager.publishPlayerInteractEntity(MTEventManager.java:263)
at crafttweaker.mc1120.events.CommonEventHandler.onPlayerInteractEntity(CommonEventHandler.java:150)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_570_CommonEventHandler_onPlayerInteractEntity_EntityInteract.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
at net.minecraftforge.common.ForgeHooks.onInteractEntity(ForgeHooks.java:1116)
at net.minecraft.entity.player.EntityPlayer.func_190775_a(EntityPlayer.java:1194)
at net.minecraft.network.NetHandlerPlayServer.func_147340_a(NetHandlerPlayServer.java:1075)
at net.minecraft.network.play.client.CPacketUseEntity.func_148833_a(SourceFile:69)
at net.minecraft.network.play.client.CPacketUseEntity.func_148833_a(SourceFile:13)
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:22)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at net.minecraft.util.Util.func_181617_a(Util.java:529)
at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:723)
at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668)
at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:279)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)
at java.lang.Thread.run(Unknown Source)

Script used :

events.txt
using txt file just because zs file can not be uploaded. I used a events.zs into Minecraft.

crafttweaker.log file :

crafttweaker.log


Affected Versions):

  • Minecraft:1.12.2
  • Forge:2847
  • Crafttweaker: 4.1.20
  • Using a server: no
  • If yes, does the client have the exact same scripts?

Your most recent log file where the issue was present

latest.log

commented

I just want to know whether my codes have something wrong , or the crafttweaker has something wrong.
If my codes are wrong, glad to know how to prevent interacting with a entity.

commented

Follow the template, it specifically asks for the scripts and logs to be on pastebin or gist.github.com, not just pasted into this issue.

commented
commented

try this
https://pastebin.com/NPN0zUYM

miss a ")" in the end of the codes.
I added it and thanks i made it!
Thanks for your help.