mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
Fix platform registration, config setup
This commit is contained in:
parent
f719063aca
commit
4878f38250
@ -43,6 +43,8 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
public class LegacyMapper {
|
public class LegacyMapper {
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger(LegacyMapper.class.getCanonicalName());
|
private static final Logger log = Logger.getLogger(LegacyMapper.class.getCanonicalName());
|
||||||
@ -100,6 +102,7 @@ public class LegacyMapper {
|
|||||||
try {
|
try {
|
||||||
String id = itemEntry.getKey();
|
String id = itemEntry.getKey();
|
||||||
ItemType type = ItemTypes.get(itemEntry.getValue());
|
ItemType type = ItemTypes.get(itemEntry.getValue());
|
||||||
|
checkNotNull(type);
|
||||||
itemToStringMap.put(type, id);
|
itemToStringMap.put(type, id);
|
||||||
stringToItemMap.put(id, type);
|
stringToItemMap.put(id, type);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -134,8 +134,10 @@ public final class ForgeAdapter {
|
|||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
if (property instanceof net.minecraft.state.EnumProperty) {
|
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()
|
return new EnumProperty(property.getName(), ((net.minecraft.state.EnumProperty<?>) property).getAllowedValues().stream()
|
||||||
.map(IStringSerializable::getName)
|
.map(x -> x.getName())
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
return new IPropertyAdapter<>(property);
|
return new IPropertyAdapter<>(property);
|
||||||
|
@ -36,26 +36,34 @@ import com.sk89q.worldedit.world.block.BlockType;
|
|||||||
import com.sk89q.worldedit.world.entity.EntityType;
|
import com.sk89q.worldedit.world.entity.EntityType;
|
||||||
import com.sk89q.worldedit.world.item.ItemCategory;
|
import com.sk89q.worldedit.world.item.ItemCategory;
|
||||||
import com.sk89q.worldedit.world.item.ItemType;
|
import com.sk89q.worldedit.world.item.ItemType;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.tags.BlockTags;
|
import net.minecraft.tags.BlockTags;
|
||||||
import net.minecraft.tags.ItemTags;
|
import net.minecraft.tags.ItemTags;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.CommandEvent;
|
import net.minecraftforge.event.CommandEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickEmpty;
|
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.IEventBus;
|
||||||
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.ModContainer;
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
import net.minecraftforge.fml.ModLoadingContext;
|
||||||
|
import net.minecraftforge.fml.SidedProvider;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
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.FMLCommonSetupEvent;
|
||||||
|
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
|
||||||
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
|
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
|
||||||
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
|
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
|
||||||
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
|
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
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.fml.loading.FMLPaths;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -92,13 +100,15 @@ public class ForgeWorldEdit {
|
|||||||
public ForgeWorldEdit() {
|
public ForgeWorldEdit() {
|
||||||
inst = this;
|
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(ThreadSafeCache.getInstance());
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(FMLCommonSetupEvent event) {
|
private void init(FMLCommonSetupEvent event) {
|
||||||
this.container = ModLoadingContext.get().getActiveContainer();
|
this.container = ModLoadingContext.get().getActiveContainer();
|
||||||
|
|
||||||
// Setup working directory
|
// Setup working directory
|
||||||
@ -111,9 +121,6 @@ public class ForgeWorldEdit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config = new ForgeConfiguration(this);
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
WECUIPacketHandler.init();
|
WECUIPacketHandler.init();
|
||||||
InternalPacketHandler.init();
|
InternalPacketHandler.init();
|
||||||
proxy.registerHandlers();
|
proxy.registerHandlers();
|
||||||
@ -121,6 +128,14 @@ public class ForgeWorldEdit {
|
|||||||
LOGGER.info("WorldEdit for Forge (version " + getInternalVersion() + ") is loaded");
|
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
|
@SubscribeEvent
|
||||||
public void serverAboutToStart(FMLServerAboutToStartEvent event) {
|
public void serverAboutToStart(FMLServerAboutToStartEvent event) {
|
||||||
if (this.platform != null) {
|
if (this.platform != null) {
|
||||||
@ -128,6 +143,10 @@ public class ForgeWorldEdit {
|
|||||||
WorldEdit.getInstance().getPlatformManager().unregister(platform);
|
WorldEdit.getInstance().getPlatformManager().unregister(platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupPlatform();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupPlatform() {
|
||||||
this.platform = new ForgePlatform(this);
|
this.platform = new ForgePlatform(this);
|
||||||
|
|
||||||
WorldEdit.getInstance().getPlatformManager().register(platform);
|
WorldEdit.getInstance().getPlatformManager().register(platform);
|
||||||
@ -139,28 +158,41 @@ public class ForgeWorldEdit {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
setupRegistries();
|
setupRegistries();
|
||||||
|
|
||||||
|
config = new ForgeConfiguration(this);
|
||||||
|
config.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupRegistries() {
|
private void setupRegistries() {
|
||||||
// Blocks
|
// Blocks
|
||||||
for (ResourceLocation name : ForgeRegistries.BLOCKS.getKeys()) {
|
for (ResourceLocation name : ForgeRegistries.BLOCKS.getKeys()) {
|
||||||
BlockType.REGISTRY.register(name.toString(), new BlockType(name.toString(),
|
if (BlockType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
BlockType.REGISTRY.register(name.toString(), new BlockType(name.toString(),
|
||||||
input -> ForgeAdapter.adapt(ForgeAdapter.adapt(input.getBlockType()).getDefaultState())));
|
input -> ForgeAdapter.adapt(ForgeAdapter.adapt(input.getBlockType()).getDefaultState())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Items
|
// Items
|
||||||
for (ResourceLocation name : ForgeRegistries.ITEMS.getKeys()) {
|
for (ResourceLocation name : ForgeRegistries.ITEMS.getKeys()) {
|
||||||
ItemType.REGISTRY.register(name.toString(), new ItemType(name.toString()));
|
if (ItemType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
ItemType.REGISTRY.register(name.toString(), new ItemType(name.toString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Entities
|
// Entities
|
||||||
for (ResourceLocation name : ForgeRegistries.ENTITIES.getKeys()) {
|
for (ResourceLocation name : ForgeRegistries.ENTITIES.getKeys()) {
|
||||||
EntityType.REGISTRY.register(name.toString(), new EntityType(name.toString()));
|
if (EntityType.REGISTRY.get(name.toString()) == null) {
|
||||||
|
EntityType.REGISTRY.register(name.toString(), new EntityType(name.toString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Tags
|
// Tags
|
||||||
for (ResourceLocation name : BlockTags.getCollection().getRegisteredTags()) {
|
for (ResourceLocation name : BlockTags.getCollection().getRegisteredTags()) {
|
||||||
BlockCategory.REGISTRY.register(name.toString(), new BlockCategory(name.toString()));
|
if (BlockCategory.REGISTRY.get(name.toString()) == null) {
|
||||||
|
BlockCategory.REGISTRY.register(name.toString(), new BlockCategory(name.toString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (ResourceLocation name : ItemTags.getCollection().getRegisteredTags()) {
|
for (ResourceLocation name : ItemTags.getCollection().getRegisteredTags()) {
|
||||||
ItemCategory.REGISTRY.register(name.toString(), new ItemCategory(name.toString()));
|
if (ItemCategory.REGISTRY.get(name.toString()) == null) {
|
||||||
|
ItemCategory.REGISTRY.register(name.toString(), new ItemCategory(name.toString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user