Add client-side left-click-air handler

This commit is contained in:
Kenzie Togami 2017-08-16 15:12:45 -07:00
parent d1c2b8c3e5
commit f2c5b272ad
No known key found for this signature in database
GPG Key ID: 5D200B325E157A81
5 changed files with 114 additions and 3 deletions

View File

@ -21,7 +21,7 @@ buildscript {
configurations.all {
resolutionStrategy {
force 'com.google.guava:guava:21.0'
force 'com.google.guava:guava:20.0'
}
}

View File

@ -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'

View File

@ -28,6 +28,7 @@ import com.sk89q.worldedit.WorldVector;
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;
@ -40,6 +41,7 @@ import net.minecraft.world.World;
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;
@ -99,6 +101,7 @@ public class ForgeWorldEdit {
public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this);
WECUIPacketHandler.init();
InternalPacketHandler.init();
proxy.registerHandlers();
}
@ -157,6 +160,12 @@ public class ForgeWorldEdit {
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;
@ -172,7 +181,12 @@ public class ForgeWorldEdit {
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());

View File

@ -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() {
}
}

View File

@ -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) {
}
}