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

Fix platform registration, config setup

Dieser Commit ist enthalten in:
Kenzie Togami 2019-03-04 19:36:06 -08:00
Ursprung f719063aca
Commit 4878f38250
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 5D200B325E157A81
3 geänderte Dateien mit 48 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -43,6 +43,8 @@ import java.util.logging.Logger;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
public class LegacyMapper {
private static final Logger log = Logger.getLogger(LegacyMapper.class.getCanonicalName());
@ -100,6 +102,7 @@ public class LegacyMapper {
try {
String id = itemEntry.getKey();
ItemType type = ItemTypes.get(itemEntry.getValue());
checkNotNull(type);
itemToStringMap.put(type, id);
stringToItemMap.put(id, type);
} catch (Exception e) {

Datei anzeigen

@ -134,8 +134,10 @@ public final class ForgeAdapter {
.collect(Collectors.toList()));
}
if (property instanceof net.minecraft.state.EnumProperty) {
// Note: do not make x.getName a method reference.
// It will cause runtime bootstrap exceptions.
return new EnumProperty(property.getName(), ((net.minecraft.state.EnumProperty<?>) property).getAllowedValues().stream()
.map(IStringSerializable::getName)
.map(x -> x.getName())
.collect(Collectors.toList()));
}
return new IPropertyAdapter<>(property);

Datei anzeigen

@ -36,26 +36,34 @@ import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.item.ItemCategory;
import com.sk89q.worldedit.world.item.ItemType;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
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.eventbus.api.Event;
import net.minecraftforge.eventbus.api.IEventBus;
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.SidedProvider;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLCommonLaunchHandler;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.FMLPaths;
import net.minecraftforge.registries.ForgeRegistries;
import org.apache.logging.log4j.LogManager;
@ -92,13 +100,15 @@ public class ForgeWorldEdit {
public ForgeWorldEdit() {
inst = this;
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::init);
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
modBus.addListener(this::init);
modBus.addListener(this::load);
MinecraftForge.EVENT_BUS.register(ThreadSafeCache.getInstance());
MinecraftForge.EVENT_BUS.register(this);
}
public void init(FMLCommonSetupEvent event) {
private void init(FMLCommonSetupEvent event) {
this.container = ModLoadingContext.get().getActiveContainer();
// Setup working directory
@ -111,9 +121,6 @@ public class ForgeWorldEdit {
}
}
config = new ForgeConfiguration(this);
config.load();
WECUIPacketHandler.init();
InternalPacketHandler.init();
proxy.registerHandlers();
@ -121,6 +128,14 @@ public class ForgeWorldEdit {
LOGGER.info("WorldEdit for Forge (version " + getInternalVersion() + ") is loaded");
}
private void load(FMLLoadCompleteEvent event) {
if (FMLLoader.getDist() == Dist.CLIENT) {
// we want to setup platform before we hit the main menu
// but this event is async -- so we must delay until the first game loop:
Minecraft.getInstance().addScheduledTask(this::setupPlatform);
}
}
@SubscribeEvent
public void serverAboutToStart(FMLServerAboutToStartEvent event) {
if (this.platform != null) {
@ -128,6 +143,10 @@ public class ForgeWorldEdit {
WorldEdit.getInstance().getPlatformManager().unregister(platform);
}
setupPlatform();
}
private void setupPlatform() {
this.platform = new ForgePlatform(this);
WorldEdit.getInstance().getPlatformManager().register(platform);
@ -139,30 +158,43 @@ public class ForgeWorldEdit {
// }
setupRegistries();
config = new ForgeConfiguration(this);
config.load();
}
private void setupRegistries() {
// Blocks
for (ResourceLocation name : ForgeRegistries.BLOCKS.getKeys()) {
if (BlockType.REGISTRY.get(name.toString()) == null) {
BlockType.REGISTRY.register(name.toString(), new BlockType(name.toString(),
input -> ForgeAdapter.adapt(ForgeAdapter.adapt(input.getBlockType()).getDefaultState())));
}
}
// Items
for (ResourceLocation name : ForgeRegistries.ITEMS.getKeys()) {
if (ItemType.REGISTRY.get(name.toString()) == null) {
ItemType.REGISTRY.register(name.toString(), new ItemType(name.toString()));
}
}
// Entities
for (ResourceLocation name : ForgeRegistries.ENTITIES.getKeys()) {
if (EntityType.REGISTRY.get(name.toString()) == null) {
EntityType.REGISTRY.register(name.toString(), new EntityType(name.toString()));
}
}
// Tags
for (ResourceLocation name : BlockTags.getCollection().getRegisteredTags()) {
if (BlockCategory.REGISTRY.get(name.toString()) == null) {
BlockCategory.REGISTRY.register(name.toString(), new BlockCategory(name.toString()));
}
}
for (ResourceLocation name : ItemTags.getCollection().getRegisteredTags()) {
if (ItemCategory.REGISTRY.get(name.toString()) == null) {
ItemCategory.REGISTRY.register(name.toString(), new ItemCategory(name.toString()));
}
}
}
@SubscribeEvent
public void serverStopping(FMLServerStoppingEvent event) {