From 4629c1f7e476b5d90350b7f5e5446fcdf7d2def8 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Tue, 26 Mar 2019 21:09:41 +1000 Subject: [PATCH] Few fixes for the Forge version. --- .../com/sk89q/worldedit/forge/ForgeWorld.java | 5 ++-- .../sk89q/worldedit/forge/ForgeWorldEdit.java | 5 +++- .../com/sk89q/worldedit/forge/KeyHandler.java | 2 +- .../worldedit/forge/gui/GuiReferenceCard.java | 3 +++ .../forge/{ => proxy}/ClientProxy.java | 9 ++++--- .../worldedit/forge/proxy/CommonProxy.java | 25 ++++++++++++++++++ .../ServerProxy.java} | 26 +++++++++---------- 7 files changed, 55 insertions(+), 20 deletions(-) rename worldedit-forge/src/main/java/com/sk89q/worldedit/forge/{ => proxy}/ClientProxy.java (79%) create mode 100644 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/proxy/CommonProxy.java rename worldedit-forge/src/main/java/com/sk89q/worldedit/forge/{CommonProxy.java => proxy/ServerProxy.java} (58%) diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java index a8b4ba13b..43a9399b9 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java @@ -187,8 +187,9 @@ public class ForgeWorld extends AbstractWorld { @Override public boolean notifyAndLightBlock(BlockVector3 position, BlockState previousType) throws WorldEditException { - // TODO Implement - return false; + BlockPos pos = new BlockPos(position.getX(), position.getY(), position.getZ()); + getWorld().notifyBlockUpdate(pos, ForgeAdapter.adapt(previousType), getWorld().getBlockState(pos), 1 | 2); + return true; } @Override diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java index 07bf6c4d9..aef34005a 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java @@ -31,6 +31,9 @@ import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.forge.net.handler.InternalPacketHandler; import com.sk89q.worldedit.forge.net.handler.WECUIPacketHandler; import com.sk89q.worldedit.forge.net.packet.LeftClickAirEventMessage; +import com.sk89q.worldedit.forge.proxy.ClientProxy; +import com.sk89q.worldedit.forge.proxy.CommonProxy; +import com.sk89q.worldedit.forge.proxy.ServerProxy; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockCategory; @@ -89,7 +92,7 @@ public class ForgeWorldEdit { public static ForgeWorldEdit inst; - public static CommonProxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> CommonProxy::new); + public static CommonProxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> ServerProxy::new); private ForgePlatform platform; private ForgeConfiguration config; diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/KeyHandler.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/KeyHandler.java index d0a23fcf1..06c59eb7f 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/KeyHandler.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/KeyHandler.java @@ -41,7 +41,7 @@ public class KeyHandler { if (mc.player != null && mc.world != null && mainKey.isPressed()) { mc.displayGuiScreen(new GuiReferenceCard()); // TODO Seems GuiHandlers don't work on client right now -// NetworkHooks.openGui(mc.player, new ResourceLocationInteractionObject(CommonProxy.REFERENCE_GUI)); +// NetworkHooks.openGui(mc.player, new ResourceLocationInteractionObject(ServerProxy.REFERENCE_GUI)); } } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/gui/GuiReferenceCard.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/gui/GuiReferenceCard.java index d15642934..a3b9756af 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/gui/GuiReferenceCard.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/gui/GuiReferenceCard.java @@ -23,8 +23,11 @@ import com.sk89q.worldedit.forge.ForgeWorldEdit; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import org.lwjgl.opengl.GL11; +@OnlyIn(Dist.CLIENT) public class GuiReferenceCard extends GuiScreen { private GuiButton closeButton; diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ClientProxy.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/proxy/ClientProxy.java similarity index 79% rename from worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ClientProxy.java rename to worldedit-forge/src/main/java/com/sk89q/worldedit/forge/proxy/ClientProxy.java index 688728a63..fab4e7d67 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ClientProxy.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/proxy/ClientProxy.java @@ -17,15 +17,18 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.forge; +package com.sk89q.worldedit.forge.proxy; +import com.sk89q.worldedit.forge.KeyHandler; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.MinecraftForge; -public class ClientProxy extends CommonProxy { +@OnlyIn(Dist.CLIENT) +public class ClientProxy implements CommonProxy { @Override public void registerHandlers() { - super.registerHandlers(); MinecraftForge.EVENT_BUS.register(new KeyHandler()); } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/proxy/CommonProxy.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/proxy/CommonProxy.java new file mode 100644 index 000000000..9f4c166b3 --- /dev/null +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/proxy/CommonProxy.java @@ -0,0 +1,25 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +package com.sk89q.worldedit.forge.proxy; + +public interface CommonProxy { + + void registerHandlers(); +} diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/CommonProxy.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/proxy/ServerProxy.java similarity index 58% rename from worldedit-forge/src/main/java/com/sk89q/worldedit/forge/CommonProxy.java rename to worldedit-forge/src/main/java/com/sk89q/worldedit/forge/proxy/ServerProxy.java index 7c5708358..9ec84e328 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/CommonProxy.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/proxy/ServerProxy.java @@ -17,24 +17,24 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.forge; +package com.sk89q.worldedit.forge.proxy; -import com.sk89q.worldedit.forge.gui.GuiReferenceCard; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.ExtensionPoint; -import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; -public class CommonProxy { +@OnlyIn(Dist.DEDICATED_SERVER) +public class ServerProxy implements CommonProxy { - public static ResourceLocation REFERENCE_GUI = new ResourceLocation("worldedit", "resource_gui"); +// public static ResourceLocation REFERENCE_GUI = new ResourceLocation("worldedit", "resource_gui"); + @Override public void registerHandlers() { - ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.GUIFACTORY, () -> openContainer -> { - if (openContainer.getId().equals(REFERENCE_GUI)) { - return new GuiReferenceCard(); - } - return null; - }); +// ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.GUIFACTORY, () -> openContainer -> { +// if (openContainer.getId().equals(REFERENCE_GUI)) { +// return new GuiReferenceCard(); +// } +// return null; +// }); } }