Skip to content

Commit

Permalink
Add client-side left-click-air handler
Browse files Browse the repository at this point in the history
  • Loading branch information
octylFractal committed Aug 16, 2017
1 parent 143de19 commit e9734c2
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -21,7 +21,7 @@ buildscript {

configurations.all {
resolutionStrategy {
force 'com.google.guava:guava:21.0'
force 'com.google.guava:guava:20.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion worldedit-core/build.gradle
Expand Up @@ -5,7 +5,7 @@ dependencies {
compile 'de.schlichtherle:truezip:6.8.3'
compile 'rhino:js:1.7R2'
compile 'org.yaml:snakeyaml:1.9'
compile 'com.google.guava:guava:21.0'
compile 'com.google.guava:guava:17.0'
compile 'com.sk89q:jchronic:0.2.4a'
compile 'com.google.code.findbugs:jsr305:1.3.9'
compile 'com.thoughtworks.paranamer:paranamer:2.6'
Expand Down
Expand Up @@ -28,6 +28,7 @@
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.forge.net.LeftClickAirEventMessage;
import com.sk89q.worldedit.internal.LocalWorldAdapter;
import com.sk89q.worldedit.util.Java8Detector;

Expand All @@ -40,6 +41,7 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.CommandEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickEmpty;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
Expand Down Expand Up @@ -99,6 +101,7 @@ public void preInit(FMLPreInitializationEvent event) {
public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this);
WECUIPacketHandler.init();
InternalPacketHandler.init();
proxy.registerHandlers();
}

Expand Down Expand Up @@ -157,6 +160,12 @@ public void onPlayerInteract(PlayerInteractEvent event) {
if (!platform.isHookingEvents())
return; // We have to be told to catch these events

if (event.getWorld().isRemote && event instanceof LeftClickEmpty) {
// catch LCE, pass it to server
InternalPacketHandler.CHANNEL.sendToServer(new LeftClickAirEventMessage());
return;
}

boolean isLeftDeny = event instanceof PlayerInteractEvent.LeftClickBlock
&& ((PlayerInteractEvent.LeftClickBlock) event)
.getUseItem() == Result.DENY;
Expand All @@ -172,7 +181,12 @@ public void onPlayerInteract(PlayerInteractEvent event) {
ForgePlayer player = wrap((EntityPlayerMP) event.getEntityPlayer());
ForgeWorld world = getWorld(event.getEntityPlayer().world);

if (event instanceof PlayerInteractEvent.LeftClickBlock) {
if (event instanceof PlayerInteractEvent.LeftClickEmpty) {
if (we.handleArmSwing(player)) {
// this event cannot be canceled
// event.setCanceled(true);
}
} else if (event instanceof PlayerInteractEvent.LeftClickBlock) {
@SuppressWarnings("deprecation")
WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world),
event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
Expand Down
@@ -0,0 +1,41 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.forge;

import java.nio.charset.Charset;

import com.sk89q.worldedit.forge.net.LeftClickAirEventMessage;

import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;

public class InternalPacketHandler {
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
public static SimpleNetworkWrapper CHANNEL;

public static void init() {
CHANNEL = NetworkRegistry.INSTANCE.newSimpleChannel(ForgeWorldEdit.MOD_ID);
CHANNEL.registerMessage(LeftClickAirEventMessage.Handler.class, LeftClickAirEventMessage.class, 0, Side.SERVER);
}

private InternalPacketHandler() {
}
}
@@ -0,0 +1,56 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.forge.net;

import com.sk89q.worldedit.forge.ForgeWorldEdit;

import io.netty.buffer.ByteBuf;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class LeftClickAirEventMessage implements IMessage {

public static final class Handler implements IMessageHandler<LeftClickAirEventMessage, IMessage> {

@Override
public IMessage onMessage(LeftClickAirEventMessage message, final MessageContext ctx) {
ctx.getServerHandler().player.mcServer.addScheduledTask(new Runnable() {

@Override
public void run() {
ForgeWorldEdit.inst.onPlayerInteract(new PlayerInteractEvent.LeftClickEmpty(ctx.getServerHandler().player));
}
});
return null;
}

}

@Override
public void fromBytes(ByteBuf buf) {
}

@Override
public void toBytes(ByteBuf buf) {
}

}

0 comments on commit e9734c2

Please sign in to comment.