3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-03 01:50:07 +01:00

All but commands and config directory are ported.

Dieser Commit ist enthalten in:
Matthew Miller 2019-02-19 21:49:06 +10:00
Ursprung 29b6c84230
Commit aa295d91e8
8 geänderte Dateien mit 140 neuen und 110 gelöschten Zeilen

Datei anzeigen

@ -19,13 +19,22 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.forge.gui.GuiHandler;
import net.minecraftforge.fml.network.NetworkRegistry;
import com.sk89q.worldedit.forge.gui.GuiReferenceCard;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.ExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
public class CommonProxy {
public static ResourceLocation REFERENCE_GUI = new ResourceLocation("worldedit", "resource_gui");
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;
});
}
}

Datei anzeigen

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

Datei anzeigen

@ -21,7 +21,6 @@ package com.sk89q.worldedit.forge;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.io.Files;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
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.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location;
@ -57,7 +55,6 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.ResourceLocation;
@ -65,9 +62,6 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
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.BigRedMushroomFeature;
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.TreeFeature;
import net.minecraft.world.storage.WorldInfo;
import net.minecraftforge.common.DimensionManager;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
@ -289,44 +281,46 @@ public class ForgeWorld extends AbstractWorld {
@Override
public boolean regenerate(Region region, EditSession editSession) {
// Don't even try to regen if it's going to fail.
IChunkProvider provider = getWorld().getChunkProvider();
if (!(provider instanceof ChunkProviderServer)) {
return false;
}
File saveFolder = Files.createTempDir();
// register this just in case something goes wrong
// normally it should be deleted at the end of this method
saveFolder.deleteOnExit();
WorldServer originalWorld = (WorldServer) getWorld();
MinecraftServer server = originalWorld.getServer();
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__();
// 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));
for (BlockVector2 chunk : expandedPreGen.getChunks()) {
freshWorld.getChunk(chunk.getBlockX(), chunk.getBlockZ());
}
ForgeWorld from = new ForgeWorld(freshWorld);
try {
for (BlockVector3 vec : region) {
editSession.setBlock(vec, from.getFullBlock(vec));
}
} catch (MaxChangedBlocksException e) {
throw new RuntimeException(e);
} finally {
saveFolder.delete();
DimensionManager.setWorld(originalWorld.dimension.getType(), null, server);
DimensionManager.setWorld(originalWorld.dimension.getType(), originalWorld, server);
}
return true;
// TODO Fix for 1.13
return false;
// // Don't even try to regen if it's going to fail.
// IChunkProvider provider = getWorld().getChunkProvider();
// if (!(provider instanceof ChunkProviderServer)) {
// return false;
// }
//
// File saveFolder = Files.createTempDir();
// // register this just in case something goes wrong
// // normally it should be deleted at the end of this method
// saveFolder.deleteOnExit();
//
// WorldServer originalWorld = (WorldServer) getWorld();
//
// MinecraftServer server = originalWorld.getServer();
// 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__();
//
// // 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));
// for (BlockVector2 chunk : expandedPreGen.getChunks()) {
// freshWorld.getChunk(chunk.getBlockX(), chunk.getBlockZ());
// }
//
// ForgeWorld from = new ForgeWorld(freshWorld);
// try {
// for (BlockVector3 vec : region) {
// editSession.setBlock(vec, from.getFullBlock(vec));
// }
// } catch (MaxChangedBlocksException e) {
// throw new RuntimeException(e);
// } finally {
// saveFolder.delete();
// DimensionManager.setWorld(originalWorld.dimension.getType(), null, server);
// DimensionManager.setWorld(originalWorld.dimension.getType(), originalWorld, server);
// }
//
// return true;
}
@Nullable

Datei anzeigen

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

Datei anzeigen

@ -19,7 +19,7 @@
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.settings.KeyBinding;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -39,7 +39,9 @@ public class KeyHandler {
@SubscribeEvent
public void onKey(KeyInputEvent evt) {
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));
}
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -33,7 +33,14 @@ public class GuiReferenceCard extends GuiScreen {
@Override
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
@ -42,18 +49,11 @@ public class GuiReferenceCard extends GuiScreen {
int y = (this.height - this.backgroundHeight) / 2 - this.closeButton.height;
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);
super.render(mouseX, mouseY, par3);
}
@Override
protected void actionPerformed(GuiButton button) {
if (button.id == 0) {
this.mc.player.closeScreen();
}
}
@Override
public boolean doesGuiPauseGame() {
return true;

Datei anzeigen

@ -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;
}
}