Jump to content

Preventing replacement entity attack from being cancelled in event call


Turtledove

Recommended Posts

Based on the default player inputs (left click with WASD), I'm trying to change the behavior of sword attacks, however I've run into a problem.

 

1. Server-side, I've gone and cancelled the event whenever the player is attacking an entity with a sword, this is the event thats called whenever attackEntityFrom is called.

 

2. Client-side, when the player presses the left key and strike, I cancel the vanilla sword animations + rendering, and do my own. Then I send a packet to server to let it know to do my logic there.

 

3.????

 

Step 3 is the problem, I then need to be able to call attackEntityFrom, but it would get cancelled because of #1, correct? What do I need to do to circumvent this?

Edited by Turtledove
Link to comment
Share on other sites

I wonder if it'll work if I do something stupid like:

 

if damage source is player
{
	if damage source's main hand is sword
    {
		cancel event
      		//call replacement logic
      		call attackEntityFrom(CUSTOM DAMAGE SOURCE, 100.0F)
	}
}
else
	//let the event happen

 

Is there a better way to do this?

Edited by Turtledove
Link to comment
Share on other sites

6 hours ago, diesieben07 said:

I am not sure why you need step one at all. If you cancel the client-side left-click handling the server will never know you left clicked and will never execute the attack logic.

I don't cancel anything related to attack logic clientside, I only cancel the render event there. I cancel the event that attackentity calls, on the server.

 

So the results should be something like: 

 

Player left clicks -> Cancel render event, render my own weapon animation -> send packet to server -> Cancel the attack event if the source is from a player holding a sword, otherwise leave it alone -> call attackentity manually, but change damage source to custom, that way it can pass through the previous step when it's called a second time.

 

And I'm not sure if there's a better way to do this

Link to comment
Share on other sites

44 minutes ago, diesieben07 said:

Prevent the client from ever sending the "I attacked" action? You can cancel InputEvent.ClickInputEvent (which I assume you are using to detect attacking on the client side), which will prevent the server from ever knowing about the attack.

I see, it's better to be more direct. But cancelling the input event prevents the sword swing from activating, the render hand event relies on the sword swing progress values to animate properly. In that case how would I manually initialize the swing progress counter?

Link to comment
Share on other sites

18 minutes ago, diesieben07 said:

Looking at the code what you said does not seem correct. Cancelling ClickInputEvent will still swing the hand. Preventing that would be a separate call (ClickInputEvent#setSwingHand). Is that not what you are talking about?

Hm right now I've something like:

 

    public static void onMouseEvent(InputEvent.ClickInputEvent event)
    {
        if (player is holding sword)
        {
            if (player attacks)
				return;
        }
    }

 

And the sword doesn't swing. 

Link to comment
Share on other sites

39 minutes ago, diesieben07 said:

Please do not post pseudocode...

Apologies, I was out and about when I posted that

 

Anyhow, the more i think about it I think it's best if I do more of the logic server-side instead, with what I'm trying to do. I need to prevent the player from swinging the sword until a certain number of ticks pass, so I'll probably just attach a value to the player whether they can swing by incrementing a tick counter on the server. Then send a packet to the client when they can swing again, and either let it happen or cancel swinghand like you said.

Edited by Turtledove
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This question would probably best be asked wherever fabric support is given; these are the Minecraft Forge forums. They aren't the same thing
    • client version: forge-1.7.10-10.13.4.1614-1.7.10 forgegradle version:forge-1.7.10-10.13.4.1614-1.7.10   i can run my mod in forgegradle but i put my mod into a client ,it will crash  cpw.mods.fml.common.LoaderException: java.lang.NoSuchMethodError: com.example.examplemod.items.CommonItem.setUnlocalizedName(Ljava/lang/String;)Lnet/minecraft/item/Item;     at cpw.mods.fml.common.LoadController.transition(LoadController.java:163)     at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:559)     at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:243)     at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:480)     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:878)     at net.minecraft.client.main.Main.main(SourceFile:148)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     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(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at oolloo.jlw.Wrapper.invokeMain(Wrapper.java:71)     at oolloo.jlw.Wrapper.main(Wrapper.java:51) Caused by: java.lang.NoSuchMethodError: com.example.examplemod.items.CommonItem.setUnlocalizedName(Ljava/lang/String;)Lnet/minecraft/item/Item;     at com.example.examplemod.items.CommonItem.<init>(CommonItem.java:10)     at com.example.examplemod.proxy.register.ItemRegister.createItem(ItemRegister.java:30)     at com.example.examplemod.proxy.register.ItemRegister.registerItems(ItemRegister.java:18)     at com.example.examplemod.proxy.CommonProxy.preInit(CommonProxy.java:12)     at com.example.examplemod.proxy.ClientProxy.preInit(ClientProxy.java:6)     at com.example.examplemod.ExampleMod.preInit(ExampleMod.java:26)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532)     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)     at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)     at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)     at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)     at com.google.common.eventbus.EventBus.post(EventBus.java:275)     at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)     at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)     at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)     at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)     at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)     at com.google.common.eventbus.EventBus.post(EventBus.java:275)     at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119)     at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:556)     ... 16 more  
    • In mine forge 1.16.5 was written net.minecraftforge.fml.config.ConfigFileTypeHandler$ConfigLoadingException: Failed loading config file forge-common.toml of type COMMON for modid forge. How can I fix it?
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.