All but commands and config directory are ported.

This commit is contained in:
Matthew Miller 2019-02-19 21:49:06 +10:00
parent 29b6c84230
commit aa295d91e8
8 changed files with 140 additions and 110 deletions

View File

@ -19,13 +19,22 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.forge.gui.GuiHandler; import com.sk89q.worldedit.forge.gui.GuiReferenceCard;
import net.minecraftforge.fml.network.NetworkRegistry; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.ExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
public class CommonProxy { public class CommonProxy {
public static ResourceLocation REFERENCE_GUI = new ResourceLocation("worldedit", "resource_gui");
public void registerHandlers() { public void registerHandlers() {
NetworkRegistry.INSTANCE.registerGuiHandler(ForgeWorldEdit.inst, new GuiHandler()); ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.GUIFACTORY, () -> openContainer -> {
if (openContainer.getId().equals(REFERENCE_GUI)) {
return new GuiReferenceCard();
}
return null;
});
} }
} }

View File

@ -35,7 +35,6 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerList; import net.minecraft.server.management.PlayerList;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.server.ServerLifecycleHooks; import net.minecraftforge.fml.server.ServerLifecycleHooks;
import java.util.ArrayList; import java.util.ArrayList;
@ -83,8 +82,8 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
@Override @Override
public List<? extends com.sk89q.worldedit.world.World> getWorlds() { public List<? extends com.sk89q.worldedit.world.World> getWorlds() {
WorldServer[] worlds = DimensionManager.getWorlds(); Iterable<WorldServer> worlds = server.getWorlds();
List<com.sk89q.worldedit.world.World> ret = new ArrayList<>(worlds.length); List<com.sk89q.worldedit.world.World> ret = new ArrayList<>();
for (WorldServer world : worlds) { for (WorldServer world : worlds) {
ret.add(new ForgeWorld(world)); ret.add(new ForgeWorld(world));
} }
@ -108,7 +107,7 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
if (world instanceof ForgeWorld) { if (world instanceof ForgeWorld) {
return world; return world;
} else { } else {
for (WorldServer ws : DimensionManager.getWorlds()) { for (WorldServer ws : server.getWorlds()) {
if (ws.getWorldInfo().getWorldName().equals(world.getName())) { if (ws.getWorldInfo().getWorldName().equals(world.getName())) {
return new ForgeWorld(ws); return new ForgeWorld(ws);
} }

View File

@ -21,7 +21,6 @@ package com.sk89q.worldedit.forge;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.io.Files;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
@ -34,7 +33,6 @@ import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
@ -57,7 +55,6 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext; import net.minecraft.item.ItemUseContext;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumActionResult;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -65,9 +62,6 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.chunk.storage.AnvilSaveHandler;
import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraft.world.gen.feature.BigBrownMushroomFeature; import net.minecraft.world.gen.feature.BigBrownMushroomFeature;
import net.minecraft.world.gen.feature.BigRedMushroomFeature; import net.minecraft.world.gen.feature.BigRedMushroomFeature;
import net.minecraft.world.gen.feature.BigTreeFeature; import net.minecraft.world.gen.feature.BigTreeFeature;
@ -85,9 +79,7 @@ import net.minecraft.world.gen.feature.SwampTreeFeature;
import net.minecraft.world.gen.feature.TallTaigaTreeFeature; import net.minecraft.world.gen.feature.TallTaigaTreeFeature;
import net.minecraft.world.gen.feature.TreeFeature; import net.minecraft.world.gen.feature.TreeFeature;
import net.minecraft.world.storage.WorldInfo; import net.minecraft.world.storage.WorldInfo;
import net.minecraftforge.common.DimensionManager;
import java.io.File;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -289,44 +281,46 @@ public class ForgeWorld extends AbstractWorld {
@Override @Override
public boolean regenerate(Region region, EditSession editSession) { public boolean regenerate(Region region, EditSession editSession) {
// Don't even try to regen if it's going to fail. // TODO Fix for 1.13
IChunkProvider provider = getWorld().getChunkProvider();
if (!(provider instanceof ChunkProviderServer)) {
return false; return false;
} // // Don't even try to regen if it's going to fail.
// IChunkProvider provider = getWorld().getChunkProvider();
File saveFolder = Files.createTempDir(); // if (!(provider instanceof ChunkProviderServer)) {
// register this just in case something goes wrong // return false;
// normally it should be deleted at the end of this method // }
saveFolder.deleteOnExit(); //
// File saveFolder = Files.createTempDir();
WorldServer originalWorld = (WorldServer) getWorld(); // // register this just in case something goes wrong
// // normally it should be deleted at the end of this method
MinecraftServer server = originalWorld.getServer(); // saveFolder.deleteOnExit();
AnvilSaveHandler saveHandler = new AnvilSaveHandler(saveFolder, originalWorld.getSaveHandler().getWorldDirectory().getName(), server, server.getDataFixer()); //
World freshWorld = new WorldServer(server, saveHandler, originalWorld.getSavedDataStorage(), originalWorld.getWorldInfo(), originalWorld.dimension.getType(), originalWorld.profiler).func_212251_i__(); // WorldServer originalWorld = (WorldServer) getWorld();
//
// Pre-gen all the chunks // MinecraftServer server = originalWorld.getServer();
// We need to also pull one more chunk in every direction // AnvilSaveHandler saveHandler = new AnvilSaveHandler(saveFolder, originalWorld.getSaveHandler().getWorldDirectory().getName(), server, server.getDataFixer());
CuboidRegion expandedPreGen = new CuboidRegion(region.getMinimumPoint().subtract(16, 0, 16), region.getMaximumPoint().add(16, 0, 16)); // World freshWorld = new WorldServer(server, saveHandler, originalWorld.getSavedDataStorage(), originalWorld.getWorldInfo(), originalWorld.dimension.getType(), originalWorld.profiler).func_212251_i__();
for (BlockVector2 chunk : expandedPreGen.getChunks()) { //
freshWorld.getChunk(chunk.getBlockX(), chunk.getBlockZ()); // // Pre-gen all the chunks
} // // We need to also pull one more chunk in every direction
// CuboidRegion expandedPreGen = new CuboidRegion(region.getMinimumPoint().subtract(16, 0, 16), region.getMaximumPoint().add(16, 0, 16));
ForgeWorld from = new ForgeWorld(freshWorld); // for (BlockVector2 chunk : expandedPreGen.getChunks()) {
try { // freshWorld.getChunk(chunk.getBlockX(), chunk.getBlockZ());
for (BlockVector3 vec : region) { // }
editSession.setBlock(vec, from.getFullBlock(vec)); //
} // ForgeWorld from = new ForgeWorld(freshWorld);
} catch (MaxChangedBlocksException e) { // try {
throw new RuntimeException(e); // for (BlockVector3 vec : region) {
} finally { // editSession.setBlock(vec, from.getFullBlock(vec));
saveFolder.delete(); // }
DimensionManager.setWorld(originalWorld.dimension.getType(), null, server); // } catch (MaxChangedBlocksException e) {
DimensionManager.setWorld(originalWorld.dimension.getType(), originalWorld, server); // throw new RuntimeException(e);
} // } finally {
// saveFolder.delete();
return true; // DimensionManager.setWorld(originalWorld.dimension.getType(), null, server);
// DimensionManager.setWorld(originalWorld.dimension.getType(), originalWorld, server);
// }
//
// return true;
} }
@Nullable @Nullable

View File

@ -47,6 +47,8 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickEmpty
import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent; import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
@ -79,6 +81,8 @@ public class ForgeWorldEdit {
private ForgeConfiguration config; private ForgeConfiguration config;
private File workingDir; private File workingDir;
private ModContainer container;
public ForgeWorldEdit() { public ForgeWorldEdit() {
inst = this; inst = this;
@ -92,6 +96,8 @@ public class ForgeWorldEdit {
} }
public void init(FMLCommonSetupEvent event) { public void init(FMLCommonSetupEvent event) {
this.container = ModLoadingContext.get().getActiveContainer();
// Setup working directory // Setup working directory
workingDir = new File(event.getModConfigurationDirectory() + File.separator + "worldedit"); workingDir = new File(event.getModConfigurationDirectory() + File.separator + "worldedit");
workingDir.mkdir(); workingDir.mkdir();
@ -299,7 +305,7 @@ public class ForgeWorldEdit {
* @return a version string * @return a version string
*/ */
String getInternalVersion() { String getInternalVersion() {
return ForgeWorldEdit.class.getAnnotation(Mod.class).version(); return container.getModInfo().getVersion().toString();
} }
public void setPermissionsProvider(ForgePermissionsProvider provider) { public void setPermissionsProvider(ForgePermissionsProvider provider) {

View File

@ -19,7 +19,7 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.forge.gui.GuiHandler; import com.sk89q.worldedit.forge.gui.GuiReferenceCard;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -39,7 +39,9 @@ public class KeyHandler {
@SubscribeEvent @SubscribeEvent
public void onKey(KeyInputEvent evt) { public void onKey(KeyInputEvent evt) {
if (mc.player != null && mc.world != null && mainKey.isPressed()) { if (mc.player != null && mc.world != null && mainKey.isPressed()) {
mc.player.openGui(ForgeWorldEdit.inst, GuiHandler.REFERENCE_ID, mc.world, 0, 0, 0); mc.displayGuiScreen(new GuiReferenceCard());
// TODO Seems GuiHandlers don't work on client right now
// NetworkHooks.openGui(mc.player, new ResourceLocationInteractionObject(CommonProxy.REFERENCE_GUI));
} }
} }

View File

@ -1,45 +0,0 @@
/*
* 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.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;
public class GuiHandler implements IGuiHandler {
public static final int REFERENCE_ID = 0;
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
return null;
}
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
switch (id) {
case REFERENCE_ID:
return new GuiReferenceCard();
}
return null;
}
}

View File

@ -33,7 +33,14 @@ public class GuiReferenceCard extends GuiScreen {
@Override @Override
public void initGui() { public void initGui() {
this.buttonList.add(this.closeButton = new GuiButton(0, (this.width - this.backgroundWidth + 100) / 2, (this.height + this.backgroundHeight - 60) / 2, this.backgroundWidth - 100, 20, "Close")); this.closeButton = new GuiButton(0, (this.width - this.backgroundWidth + 100) / 2, (this.height + this.backgroundHeight - 60) / 2, this.backgroundWidth - 100, 20, "Close") {
@Override
public void onClick(double p_194829_1_, double p_194829_3_) {
super.onClick(p_194829_1_, p_194829_3_);
mc.player.closeScreen();
}
};
} }
@Override @Override
@ -42,18 +49,11 @@ public class GuiReferenceCard extends GuiScreen {
int y = (this.height - this.backgroundHeight) / 2 - this.closeButton.height; int y = (this.height - this.backgroundHeight) / 2 - this.closeButton.height;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.bindTexture(new ResourceLocation(ForgeWorldEdit.MOD_ID, "textures/gui/reference.png")); this.mc.textureManager.bindTexture(new ResourceLocation(ForgeWorldEdit.MOD_ID, "textures/gui/reference.png"));
this.drawTexturedModalRect(x, y, 0, 0, this.backgroundWidth, this.backgroundHeight); this.drawTexturedModalRect(x, y, 0, 0, this.backgroundWidth, this.backgroundHeight);
super.render(mouseX, mouseY, par3); super.render(mouseX, mouseY, par3);
} }
@Override
protected void actionPerformed(GuiButton button) {
if (button.id == 0) {
this.mc.player.closeScreen();
}
}
@Override @Override
public boolean doesGuiPauseGame() { public boolean doesGuiPauseGame() {
return true; return true;

View File

@ -0,0 +1,65 @@
/*
* 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.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.IInteractionObject;
import javax.annotation.Nullable;
public class ResourceLocationInteractionObject implements IInteractionObject {
private ResourceLocation resourceLocation;
public ResourceLocationInteractionObject(ResourceLocation resourceLocation) {
this.resourceLocation = resourceLocation;
}
@Override
public Container createContainer(InventoryPlayer inventoryPlayer, EntityPlayer entityPlayer) {
throw new UnsupportedOperationException();
}
@Override
public String getGuiID() {
return resourceLocation.toString();
}
@Override
public ITextComponent getName() {
return new TextComponentString(resourceLocation.toString());
}
@Override
public boolean hasCustomName() {
return false;
}
@Nullable
@Override
public ITextComponent getCustomName() {
return null;
}
}