Further work on 1.13

This commit is contained in:
Matthew Miller 2018-12-29 16:04:36 +10:00
parent a64d8dc6fa
commit 9fccfdfaeb
14 changed files with 144 additions and 98 deletions

View File

@ -14,7 +14,7 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle'
def minecraftVersion = "1.13"
def forgeVersion = "24.0.44-1.13-pre"
def forgeVersion = "24.0.45-1.13-pre"
dependencies {
compile project(':worldedit-core')

View File

@ -20,7 +20,7 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.forge.gui.GuiHandler;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.network.NetworkRegistry;
public class CommonProxy {

View File

@ -20,6 +20,8 @@
package com.sk89q.worldedit.forge;
import com.google.common.collect.ImmutableList;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.registry.state.BooleanProperty;
@ -35,13 +37,23 @@ import com.sk89q.worldedit.world.biome.BiomeTypes;
import net.minecraft.block.properties.IProperty;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.IProperty;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.stream.Collectors;
@ -124,4 +136,32 @@ final class ForgeAdapter {
return new IPropertyAdapter<>(property);
}
public static Block adapt(BlockType blockType) {
return ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockType.getId()));
}
public static BlockType adapt(Block block) {
return BlockTypes.get(ForgeRegistries.BLOCKS.getKey(block).toString());
}
public static Item adapt(ItemType itemType) {
return ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemType.getId()));
}
public static ItemType adapt(Item item) {
return ItemTypes.get(ForgeRegistries.ITEMS.getKey(item).toString());
}
public static ItemStack adapt(BaseItemStack baseItemStack) {
NBTTagCompound forgeCompound = null;
if (baseItemStack.getNbtData() != null) {
forgeCompound = NBTConverter.toNative(baseItemStack.getNbtData());
}
return new ItemStack(adapt(baseItemStack.getType()), baseItemStack.getAmount(), forgeCompound);
}
public static BaseItemStack adapt(ItemStack itemStack) {
CompoundTag tag = NBTConverter.fromNative(itemStack.serializeNBT());
return new BaseItemStack(adapt(itemStack.getItem()), tag, itemStack.getCount());
}
}

View File

@ -23,13 +23,13 @@ import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.registries.ForgeRegistries;
/**
* Provides access to biome data in Forge.
*/
class ForgeBiomeRegistry implements BiomeRegistry {
@Override
public BiomeData getData(BiomeType biome) {
return new ForgeBiomeData(ForgeAdapter.adapt(biome));

View File

@ -23,11 +23,9 @@ import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.state.IProperty;
import net.minecraft.util.ResourceLocation;
import java.util.Collection;
import java.util.HashMap;
@ -43,19 +41,29 @@ public class ForgeBlockRegistry extends BundledBlockRegistry {
@Nullable
@Override
public String getName(BlockType blockType) {
return Block.REGISTRY.get(new ResourceLocation(blockType.getId())).getNameTextComponent().getFormattedText();
Block block = ForgeAdapter.adapt(blockType);
if (block != null) {
return block.getNameTextComponent().getFormattedText();
} else {
return super.getName(blockType);
}
}
@Override
public BlockMaterial getMaterial(BlockType blockType) {
return materialMap.computeIfAbsent(Block.getBlockFromName(blockType.getId()).getDefaultState().getMaterial(),
Block block = ForgeAdapter.adapt(blockType);
if (block == null) {
return super.getMaterial(blockType);
}
return materialMap.computeIfAbsent(block.getDefaultState().getMaterial(),
m -> new ForgeBlockMaterial(m, super.getMaterial(blockType)));
}
@Override
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
Block block = ForgeAdapter.adapt(blockType);
Map<String, Property<?>> map = new TreeMap<>();
Collection<IProperty<?>> propertyKeys = Block.getBlockFromName(blockType.getId())
Collection<IProperty<?>> propertyKeys = block
.getDefaultState()
.getProperties();
for (IProperty<?> key : propertyKeys) {

View File

@ -29,7 +29,6 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.NullWorld;
import com.sk89q.worldedit.world.entity.EntityTypes;
import net.minecraft.entity.EntityList;
import net.minecraft.nbt.NBTTagCompound;
import java.lang.ref.WeakReference;
@ -49,7 +48,7 @@ class ForgeEntity implements Entity {
public BaseEntity getState() {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
String id = EntityList.getEntityString(entity);
String id = entity.getType().getRegistryName().toString();
if (id != null) {
NBTTagCompound tag = new NBTTagCompound();
entity.writeWithoutTypeId(tag);

View File

@ -23,6 +23,7 @@ import net.minecraft.command.ICommand;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.GameType;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
import org.spongepowered.api.entity.living.player.Player;
public interface ForgePermissionsProvider {
@ -43,7 +44,7 @@ public interface ForgePermissionsProvider {
public boolean hasPermission(EntityPlayerMP player, String permission) {
ForgeConfiguration configuration = platform.getConfiguration();
return configuration.cheatMode ||
FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().canSendCommands(player.getGameProfile()) ||
ServerLifecycleHooks.getCurrentServer().getPlayerList().canSendCommands(player.getGameProfile()) ||
(configuration.creativeEnable && player.interactionManager.getGameType() == GameType.CREATIVE);
}

View File

@ -37,7 +37,7 @@ 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.common.FMLCommonHandler;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
import java.util.ArrayList;
import java.util.Collection;
@ -55,7 +55,7 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
ForgePlatform(ForgeWorldEdit mod) {
this.mod = mod;
this.server = FMLCommonHandler.instance().getMinecraftServerInstance();
this.server = ServerLifecycleHooks.getCurrentServer();
}
boolean isHookingEvents() {

View File

@ -69,7 +69,7 @@ public class ForgePlayer extends AbstractPlayerActor {
@Override
public BaseItemStack getItemInHand(HandSide handSide) {
ItemStack is = this.player.getHeldItem(handSide == HandSide.MAIN_HAND ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND);
return new BaseItemStack(ItemTypes.get(Item.REGISTRY.getKey(is.getItem()).toString()));
return ForgeAdapter.adapt(is);
}
@Override
@ -105,7 +105,7 @@ public class ForgePlayer extends AbstractPlayerActor {
@Override
public void giveItem(BaseItemStack itemStack) {
this.player.inventory.addItemStackToInventory(new ItemStack(Item.REGISTRY.get(new ResourceLocation(itemStack.getType().getId())), itemStack.getAmount(), null));
this.player.inventory.addItemStackToInventory(ForgeAdapter.adapt(itemStack));
}
@Override

View File

@ -52,44 +52,48 @@ import com.sk89q.worldedit.world.weather.WeatherTypes;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
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.state.DirectionProperty;
import net.minecraft.state.EnumProperty;
import net.minecraft.state.IProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.BlockStateContainer;
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.WorldGenBigMushroom;
import net.minecraft.world.gen.feature.WorldGenBigTree;
import net.minecraft.world.gen.feature.WorldGenBirchTree;
import net.minecraft.world.gen.feature.WorldGenCanopyTree;
import net.minecraft.world.gen.feature.WorldGenMegaJungle;
import net.minecraft.world.gen.feature.WorldGenMegaPineTree;
import net.minecraft.world.gen.feature.WorldGenSavannaTree;
import net.minecraft.world.gen.feature.WorldGenShrub;
import net.minecraft.world.gen.feature.WorldGenSwamp;
import net.minecraft.world.gen.feature.WorldGenTaiga1;
import net.minecraft.world.gen.feature.WorldGenTaiga2;
import net.minecraft.world.gen.feature.WorldGenTrees;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraft.world.gen.feature.BigBrownMushroomFeature;
import net.minecraft.world.gen.feature.BigRedMushroomFeature;
import net.minecraft.world.gen.feature.BigTreeFeature;
import net.minecraft.world.gen.feature.BirchTreeFeature;
import net.minecraft.world.gen.feature.CanopyTreeFeature;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.JungleTreeFeature;
import net.minecraft.world.gen.feature.MegaJungleFeature;
import net.minecraft.world.gen.feature.MegaPineTree;
import net.minecraft.world.gen.feature.NoFeatureConfig;
import net.minecraft.world.gen.feature.PointyTaigaTreeFeature;
import net.minecraft.world.gen.feature.SavannaTreeFeature;
import net.minecraft.world.gen.feature.ShrubFeature;
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;
@ -101,6 +105,7 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Nullable;
@ -180,8 +185,8 @@ public class ForgeWorld extends AbstractWorld {
Block mcBlock = Block.getBlockFromName(block.getBlockType().getId());
IBlockState newState = mcBlock.getDefaultState();
Map<Property<?>, Object> states = block.getStates();
newState = applyProperties(mcBlock.getBlockState(), newState, states);
IBlockState successState = chunk.setBlockState(pos, newState);
newState = applyProperties(mcBlock.getStateContainer(), newState, states);
IBlockState successState = chunk.setBlockState(pos, newState, false);
boolean successful = successState != null;
// Create the TileEntity
@ -212,12 +217,9 @@ public class ForgeWorld extends AbstractWorld {
return false;
}
// Can't get the "Object" to be right for withProperty w/o this
@SuppressWarnings({ "rawtypes", "unchecked" })
private IBlockState applyProperties(BlockStateContainer stateContainer, IBlockState newState, Map<Property<?>, Object> states) {
private IBlockState applyProperties(StateContainer<Block, IBlockState> stateContainer, IBlockState newState, Map<Property<?>, Object> states) {
for (Map.Entry<Property<?>, Object> state : states.entrySet()) {
IProperty property = stateContainer.getProperty(state.getKey().getName());
IProperty<?> property = stateContainer.getProperty(state.getKey().getName());
Comparable value = (Comparable) state.getValue();
// we may need to adapt this value, depending on the source prop
if (property instanceof DirectionProperty) {
@ -259,7 +261,7 @@ public class ForgeWorld extends AbstractWorld {
@Override
public BiomeType getBiome(BlockVector2 position) {
checkNotNull(position);
return ForgeAdapter.adapt(getWorld().getBiomeForCoordsBody(new BlockPos(position.getBlockX(), 0, position.getBlockZ())));
return ForgeAdapter.adapt(getWorld().getBiomeBody(new BlockPos(position.getBlockX(), 0, position.getBlockZ())));
}
@Override
@ -269,7 +271,7 @@ public class ForgeWorld extends AbstractWorld {
Chunk chunk = getWorld().getChunk(new BlockPos(position.getBlockX(), 0, position.getBlockZ()));
if (chunk.isLoaded()) {
chunk.getBiomeArray()[((position.getBlockZ() & 0xF) << 4 | position.getBlockX() & 0xF)] = (byte) Biome.getIdForBiome(ForgeAdapter.adapt(biome));
chunk.getBiomes()[((position.getBlockZ() & 0xF) << 4 | position.getBlockX() & 0xF)] = ForgeAdapter.adapt(biome);
return true;
}
@ -278,16 +280,24 @@ public class ForgeWorld extends AbstractWorld {
@Override
public boolean useItem(BlockVector3 position, BaseItem item, Direction face) {
Item nativeItem = Item.REGISTRY.get(new ResourceLocation(item.getType().getId()));
ItemStack stack = null;
Item nativeItem = ForgeAdapter.adapt(item.getType());
ItemStack stack;
if (item.getNbtData() == null) {
stack = new ItemStack(nativeItem, 1);
} else {
stack = new ItemStack(nativeItem, 1, NBTConverter.toNative(item.getNbtData()));
}
World world = getWorld();
EnumActionResult used = stack.onItemUse(new WorldEditFakePlayer((WorldServer) world), world, ForgeAdapter.toBlockPos(position),
EnumHand.MAIN_HAND, ForgeAdapter.adapt(face), 0, 0, 0);
ItemUseContext itemUseContext = new ItemUseContext(
new WorldEditFakePlayer((WorldServer) world),
stack,
ForgeAdapter.toBlockPos(position),
ForgeAdapter.adapt(face),
0f,
0f,
0f
);
EnumActionResult used = stack.onItemUse(itemUseContext);
return used != EnumActionResult.FAIL;
}
@ -300,7 +310,7 @@ public class ForgeWorld extends AbstractWorld {
return;
}
EntityItem entity = new EntityItem(getWorld(), position.getX(), position.getY(), position.getZ(), ForgeWorldEdit.toForgeItemStack(item));
EntityItem entity = new EntityItem(getWorld(), position.getX(), position.getY(), position.getZ(), ForgeAdapter.adapt(item));
entity.setPickupDelay(10);
getWorld().spawnEntity(entity);
}
@ -309,8 +319,8 @@ public class ForgeWorld extends AbstractWorld {
public void simulateBlockMine(BlockVector3 position) {
BlockPos pos = ForgeAdapter.toBlockPos(position);
IBlockState state = getWorld().getBlockState(pos);
state.getBlock().dropBlockAsItem(getWorld(), pos, state, 0);
getWorld().setBlockToAir(pos);
state.dropBlockAsItem(getWorld(), pos, 0);
getWorld().removeBlock(pos);
}
@Override
@ -328,9 +338,9 @@ public class ForgeWorld extends AbstractWorld {
WorldServer originalWorld = (WorldServer) getWorld();
MinecraftServer server = originalWorld.getMinecraftServer();
AnvilSaveHandler saveHandler = new AnvilSaveHandler(saveFolder, originalWorld.getSaveHandler().getWorldDirectory().getName(), true, server.getDataFixer());
World freshWorld = new WorldServer(server, saveHandler, originalWorld.getWorldInfo(),
MinecraftServer server = originalWorld.getServer();
AnvilSaveHandler saveHandler = new AnvilSaveHandler(saveFolder, originalWorld.getSaveHandler().getWorldDirectory().getName(), server, server.getDataFixer());
World freshWorld = (World) new WorldServer(server, saveHandler, originalWorld.getWorldInfo(),
originalWorld.dimension.getId(), originalWorld.profiler).init();
// Pre-gen all the chunks
@ -357,26 +367,26 @@ public class ForgeWorld extends AbstractWorld {
}
@Nullable
private static WorldGenerator createWorldGenerator(TreeType type) {
private static Feature<NoFeatureConfig> createTreeFeatureGenerator(TreeType type) {
switch (type) {
case TREE: return new WorldGenTrees(true);
case BIG_TREE: return new WorldGenBigTree(true);
case REDWOOD: return new WorldGenTaiga2(true);
case TALL_REDWOOD: return new WorldGenTaiga1();
case BIRCH: return new WorldGenBirchTree(true, false);
case JUNGLE: return new WorldGenMegaJungle(true, 10, 20, JUNGLE_LOG, JUNGLE_LEAF);
case SMALL_JUNGLE: return new WorldGenTrees(true, 4 + random.nextInt(7), JUNGLE_LOG, JUNGLE_LEAF, false);
case SHORT_JUNGLE: return new WorldGenTrees(true, 4 + random.nextInt(7), JUNGLE_LOG, JUNGLE_LEAF, true);
case JUNGLE_BUSH: return new WorldGenShrub(JUNGLE_LOG, JUNGLE_SHRUB);
case RED_MUSHROOM: return new WorldGenBigMushroom(Blocks.BROWN_MUSHROOM_BLOCK);
case BROWN_MUSHROOM: return new WorldGenBigMushroom(Blocks.RED_MUSHROOM_BLOCK);
case SWAMP: return new WorldGenSwamp();
case ACACIA: return new WorldGenSavannaTree(true);
case DARK_OAK: return new WorldGenCanopyTree(true);
case MEGA_REDWOOD: return new WorldGenMegaPineTree(false, random.nextBoolean());
case TALL_BIRCH: return new WorldGenBirchTree(true, true);
case RANDOM:
case TREE: return new TreeFeature(true);
case BIG_TREE: return new BigTreeFeature(true);
case PINE:
case REDWOOD: return new PointyTaigaTreeFeature();
case TALL_REDWOOD: return new TallTaigaTreeFeature(true);
case BIRCH: return new BirchTreeFeature(true, false);
case JUNGLE: return new MegaJungleFeature(true, 10, 20, JUNGLE_LOG, JUNGLE_LEAF);
case SMALL_JUNGLE: return new JungleTreeFeature(true, 4 + random.nextInt(7), JUNGLE_LOG, JUNGLE_LEAF, false);
case SHORT_JUNGLE: return new JungleTreeFeature(true, 4 + random.nextInt(7), JUNGLE_LOG, JUNGLE_LEAF, true);
case JUNGLE_BUSH: return new ShrubFeature(JUNGLE_LOG, JUNGLE_SHRUB);
case RED_MUSHROOM: return new BigBrownMushroomFeature();
case BROWN_MUSHROOM: return new BigRedMushroomFeature();
case SWAMP: return new SwampTreeFeature();
case ACACIA: return new SavannaTreeFeature(true);
case DARK_OAK: return new CanopyTreeFeature(true);
case MEGA_REDWOOD: return new MegaPineTree(false, random.nextBoolean());
case TALL_BIRCH: return new BirchTreeFeature(true, true);
case RANDOM: return createTreeFeatureGenerator(TreeType.values()[ThreadLocalRandom.current().nextInt(TreeType.values().length)]);
case RANDOM_REDWOOD:
default:
return null;
@ -385,8 +395,8 @@ public class ForgeWorld extends AbstractWorld {
@Override
public boolean generateTree(TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException {
WorldGenerator generator = createWorldGenerator(type);
return generator != null && generator.generate(getWorld(), random, ForgeAdapter.toBlockPos(position));
Feature<NoFeatureConfig> generator = createTreeFeatureGenerator(type);
return generator != null && generator.func_212245_a(getWorld(), getWorld().getChunkProvider().getChunkGenerator(), random, ForgeAdapter.toBlockPos(position), new NoFeatureConfig());
}
@Override
@ -471,8 +481,8 @@ public class ForgeWorld extends AbstractWorld {
BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ());
IBlockState mcState = world.getBlockState(pos);
BlockType blockType = BlockType.REGISTRY.get(Block.REGISTRY.getKey(mcState.getBlock()).toString());
return blockType.getState(adaptProperties(blockType, mcState.getProperties()));
BlockType blockType = ForgeAdapter.adapt(mcState.getBlock());
return blockType.getState(adaptProperties(blockType, mcState.getValues()));
}
private Map<Property<?>, Object> adaptProperties(BlockType block, Map<IProperty<?>, Comparable<?>> mcProps) {
@ -546,7 +556,7 @@ public class ForgeWorld extends AbstractWorld {
@Override
public Entity createEntity(Location location, BaseEntity entity) {
World world = getWorld();
net.minecraft.entity.Entity createdEntity = EntityList.createEntityByIDFromName(new ResourceLocation(entity.getType().getId()), world);
net.minecraft.entity.Entity createdEntity = EntityType.create(world, new ResourceLocation(entity.getType().getId()));
if (createdEntity != null) {
CompoundTag nativeTag = entity.getNbtData();
if (nativeTag != null) {

View File

@ -24,7 +24,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Joiner;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
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;
@ -33,11 +32,7 @@ import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
@ -46,17 +41,17 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickEmpty;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent;
import net.minecraftforge.fml.common.event.FMLServerStartedEvent;
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
import net.minecraftforge.fml.common.eventhandler.Event.Result;
import net.minecraftforge.fml.javafmlmod.FMLModLoadingContext;
import net.minecraftforge.registries.ForgeRegistries;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -76,8 +71,7 @@ public class ForgeWorldEdit {
public static ForgeWorldEdit inst;
@SidedProxy(serverSide = "com.sk89q.worldedit.forge.CommonProxy", clientSide = "com.sk89q.worldedit.forge.ClientProxy")
public static CommonProxy proxy;
public static CommonProxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> CommonProxy::new);
private ForgePlatform platform;
private ForgeConfiguration config;
@ -126,20 +120,21 @@ public class ForgeWorldEdit {
WorldEdit.getInstance().getPlatformManager().register(platform);
if (Loader.isModLoaded("sponge")) {
if (ModList.get().isLoaded("sponge")) {
this.provider = new ForgePermissionsProvider.SpongePermissionsProvider();
} else {
this.provider = new ForgePermissionsProvider.VanillaPermissionsProvider(platform);
}
for (ResourceLocation name : Block.REGISTRY.getKeys()) {
// TODO Setup states
for (ResourceLocation name : ForgeRegistries.BLOCKS.getKeys()) {
String nameStr = name.toString();
if (!BlockType.REGISTRY.keySet().contains(nameStr)) {
BlockType.REGISTRY.register(nameStr, new BlockType(nameStr));
}
}
for (ResourceLocation name : Item.REGISTRY.getKeys()) {
for (ResourceLocation name : ForgeRegistries.ITEMS.getKeys()) {
String nameStr = name.toString();
if (!ItemType.REGISTRY.keySet().contains(nameStr)) {
ItemType.REGISTRY.register(nameStr, new ItemType(nameStr));
@ -232,14 +227,6 @@ public class ForgeWorldEdit {
}
}
public static ItemStack toForgeItemStack(BaseItemStack item) {
NBTTagCompound forgeCompound = null;
if (item.getNbtData() != null) {
forgeCompound = NBTConverter.toNative(item.getNbtData());
}
return new ItemStack(Item.REGISTRY.get(new ResourceLocation(item.getType().getId())), item.getAmount(), 0, forgeCompound);
}
/**
* Get the configuration.
*

View File

@ -25,12 +25,12 @@ import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
import org.lwjgl.input.Keyboard;
import org.lwjgl.glfw.GLFW;
public class KeyHandler {
private static Minecraft mc = Minecraft.getInstance();
private static KeyBinding mainKey = new KeyBinding("WorldEdit Reference", Keyboard.KEY_L, "WorldEdit");
private static KeyBinding mainKey = new KeyBinding("WorldEdit Reference", GLFW.GLFW_KEY_L, "WorldEdit");
public KeyHandler() {
ClientRegistry.registerKeyBinding(mainKey);

View File

@ -23,6 +23,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
import java.util.Collections;
import java.util.HashSet;
@ -56,7 +57,7 @@ public class ThreadSafeCache {
if (now - lastRefresh > REFRESH_DELAY) {
Set<UUID> onlineIds = new HashSet<>();
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
if (server == null || server.getPlayerList() == null) {
return;
}

View File

@ -37,14 +37,14 @@ public class GuiReferenceCard extends GuiScreen {
}
@Override
public void drawScreen(int mouseX, int mouseY, float par3) {
public void render(int mouseX, int mouseY, float par3) {
int x = (this.width - this.backgroundWidth) / 2;
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.drawTexturedModalRect(x, y, 0, 0, this.backgroundWidth, this.backgroundHeight);
super.drawScreen(mouseX, mouseY, par3);
super.render(mouseX, mouseY, par3);
}
@Override