2019-09-03 08:34:02 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
2021-04-08 19:22:11 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
2021-05-31 02:05:41 +02:00
|
|
|
import com.jozufozu.flywheel.core.PartialModel;
|
2020-05-23 14:02:38 +02:00
|
|
|
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
2021-02-18 19:43:22 +01:00
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher;
|
2020-12-02 21:49:57 +01:00
|
|
|
import com.simibubi.create.content.contraptions.relays.encased.CasingConnectivity;
|
2021-05-04 03:50:17 +02:00
|
|
|
import com.simibubi.create.content.curiosities.armor.CopperBacktankArmorLayer;
|
2021-06-26 16:32:56 +02:00
|
|
|
import com.simibubi.create.content.curiosities.weapons.PotatoCannonRenderHandler;
|
|
|
|
import com.simibubi.create.content.curiosities.zapper.ZapperRenderHandler;
|
2020-05-23 14:02:38 +02:00
|
|
|
import com.simibubi.create.content.schematics.ClientSchematicLoader;
|
|
|
|
import com.simibubi.create.content.schematics.client.SchematicAndQuillHandler;
|
|
|
|
import com.simibubi.create.content.schematics.client.SchematicHandler;
|
2021-04-06 00:05:29 +02:00
|
|
|
import com.simibubi.create.events.ClientEvents;
|
2020-05-23 14:02:38 +02:00
|
|
|
import com.simibubi.create.foundation.ResourceReloadHandler;
|
2020-05-13 21:56:46 +02:00
|
|
|
import com.simibubi.create.foundation.block.render.CustomBlockModels;
|
2020-05-15 01:23:27 +02:00
|
|
|
import com.simibubi.create.foundation.block.render.SpriteShifter;
|
2021-03-25 02:27:10 +01:00
|
|
|
import com.simibubi.create.foundation.config.AllConfigs;
|
2021-03-04 12:53:24 +01:00
|
|
|
import com.simibubi.create.foundation.gui.UIRenderHelper;
|
2021-06-05 06:26:25 +02:00
|
|
|
import com.simibubi.create.foundation.item.render.CustomItemModels;
|
|
|
|
import com.simibubi.create.foundation.item.render.CustomRenderedItems;
|
2021-02-16 19:35:26 +01:00
|
|
|
import com.simibubi.create.foundation.ponder.content.PonderIndex;
|
|
|
|
import com.simibubi.create.foundation.ponder.elements.WorldSectionElement;
|
2021-06-23 22:19:03 +02:00
|
|
|
import com.simibubi.create.foundation.render.AllMaterialSpecs;
|
|
|
|
import com.simibubi.create.foundation.render.CreateContexts;
|
2021-01-13 21:14:01 +01:00
|
|
|
import com.simibubi.create.foundation.render.SuperByteBufferCache;
|
2021-02-16 00:48:13 +01:00
|
|
|
import com.simibubi.create.foundation.utility.ghost.GhostBlocks;
|
2020-05-15 17:13:38 +02:00
|
|
|
import com.simibubi.create.foundation.utility.outliner.Outliner;
|
2021-04-08 19:22:11 +02:00
|
|
|
|
2019-12-05 23:42:01 +01:00
|
|
|
import net.minecraft.block.Block;
|
2019-09-22 20:23:26 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2019-09-24 14:40:01 +02:00
|
|
|
import net.minecraft.client.renderer.BlockModelShapes;
|
|
|
|
import net.minecraft.client.renderer.model.IBakedModel;
|
|
|
|
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
2021-03-25 02:27:10 +01:00
|
|
|
import net.minecraft.client.settings.GraphicsFanciness;
|
2020-05-13 01:11:07 +02:00
|
|
|
import net.minecraft.inventory.container.PlayerContainer;
|
2020-05-28 01:29:26 +02:00
|
|
|
import net.minecraft.item.Item;
|
2019-09-22 20:23:26 +02:00
|
|
|
import net.minecraft.resources.IReloadableResourceManager;
|
|
|
|
import net.minecraft.resources.IResourceManager;
|
2019-09-24 14:40:01 +02:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2021-03-25 02:27:10 +01:00
|
|
|
import net.minecraft.util.text.ChatType;
|
|
|
|
import net.minecraft.util.text.IFormattableTextComponent;
|
|
|
|
import net.minecraft.util.text.StringTextComponent;
|
|
|
|
import net.minecraft.util.text.TextComponentUtils;
|
|
|
|
import net.minecraft.util.text.TextFormatting;
|
|
|
|
import net.minecraft.util.text.event.ClickEvent;
|
|
|
|
import net.minecraft.util.text.event.HoverEvent;
|
2019-09-24 14:40:01 +02:00
|
|
|
import net.minecraftforge.client.event.ModelBakeEvent;
|
2019-10-21 23:45:16 +02:00
|
|
|
import net.minecraftforge.client.event.ModelRegistryEvent;
|
2019-11-17 21:25:59 +01:00
|
|
|
import net.minecraftforge.client.event.TextureStitchEvent;
|
2019-10-21 23:45:16 +02:00
|
|
|
import net.minecraftforge.client.model.ModelLoader;
|
2019-10-15 22:22:19 +02:00
|
|
|
import net.minecraftforge.eventbus.api.IEventBus;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
|
|
|
|
|
|
|
public class CreateClient {
|
|
|
|
|
2021-05-23 03:00:10 +02:00
|
|
|
public static final ClientSchematicLoader SCHEMATIC_SENDER = new ClientSchematicLoader();
|
|
|
|
public static final SchematicHandler SCHEMATIC_HANDLER = new SchematicHandler();
|
|
|
|
public static final SchematicAndQuillHandler SCHEMATIC_AND_QUILL_HANDLER = new SchematicAndQuillHandler();
|
|
|
|
public static final SuperByteBufferCache BUFFER_CACHE = new SuperByteBufferCache();
|
|
|
|
public static final Outliner OUTLINER = new Outliner();
|
|
|
|
public static final GhostBlocks GHOST_BLOCKS = new GhostBlocks();
|
2020-05-28 01:29:26 +02:00
|
|
|
|
2021-06-26 16:32:56 +02:00
|
|
|
public static final ZapperRenderHandler ZAPPER_RENDER_HANDLER = new ZapperRenderHandler();
|
|
|
|
public static final PotatoCannonRenderHandler POTATO_CANNON_RENDER_HANDLER = new PotatoCannonRenderHandler();
|
|
|
|
|
2020-05-13 21:56:46 +02:00
|
|
|
private static CustomBlockModels customBlockModels;
|
2020-05-28 01:29:26 +02:00
|
|
|
private static CustomItemModels customItemModels;
|
|
|
|
private static CustomRenderedItems customRenderedItems;
|
2020-12-02 21:49:57 +01:00
|
|
|
private static CasingConnectivity casingConnectivity;
|
2019-11-17 21:25:59 +01:00
|
|
|
|
2021-06-26 16:32:56 +02:00
|
|
|
public static void addClientListeners(IEventBus forgeEventBus, IEventBus modEventBus) {
|
2020-08-05 22:10:05 +02:00
|
|
|
modEventBus.addListener(CreateClient::clientInit);
|
|
|
|
modEventBus.addListener(CreateClient::onTextureStitch);
|
2021-05-23 03:00:10 +02:00
|
|
|
modEventBus.addListener(CreateClient::onModelRegistry);
|
|
|
|
modEventBus.addListener(CreateClient::onModelBake);
|
2020-08-05 22:10:05 +02:00
|
|
|
modEventBus.addListener(AllParticleTypes::registerFactories);
|
2021-04-06 00:05:29 +02:00
|
|
|
modEventBus.addListener(ClientEvents::loadCompleted);
|
2021-06-23 22:19:03 +02:00
|
|
|
modEventBus.addListener(CreateContexts::flwInit);
|
|
|
|
modEventBus.addListener(AllMaterialSpecs::flwInit);
|
2021-06-24 10:21:33 +02:00
|
|
|
modEventBus.addListener(ContraptionRenderDispatcher::invalidateOnGatherContext);
|
2021-06-26 16:32:56 +02:00
|
|
|
|
|
|
|
ZAPPER_RENDER_HANDLER.register(forgeEventBus);
|
|
|
|
POTATO_CANNON_RENDER_HANDLER.register(forgeEventBus);
|
2019-10-15 22:22:19 +02:00
|
|
|
}
|
2019-10-21 23:45:16 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
public static void clientInit(FMLClientSetupEvent event) {
|
2021-05-23 03:00:10 +02:00
|
|
|
BUFFER_CACHE.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE);
|
|
|
|
BUFFER_CACHE.registerCompartment(ContraptionRenderDispatcher.CONTRAPTION, 20);
|
|
|
|
BUFFER_CACHE.registerCompartment(WorldSectionElement.DOC_WORLD_SECTION, 20);
|
2021-02-16 00:48:13 +01:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
AllKeys.register();
|
2021-05-23 03:00:10 +02:00
|
|
|
// AllFluids.assignRenderLayers();
|
|
|
|
AllBlockPartials.clientInit();
|
2021-06-09 09:26:54 +02:00
|
|
|
AllStitchedTextures.init();
|
2021-05-23 03:00:10 +02:00
|
|
|
|
2021-02-16 19:35:26 +01:00
|
|
|
PonderIndex.register();
|
2021-03-04 12:53:24 +01:00
|
|
|
PonderIndex.registerTags();
|
|
|
|
|
|
|
|
UIRenderHelper.init();
|
2019-09-22 20:23:26 +02:00
|
|
|
|
2020-05-13 01:11:07 +02:00
|
|
|
IResourceManager resourceManager = Minecraft.getInstance()
|
2021-06-26 16:32:56 +02:00
|
|
|
.getResourceManager();
|
2019-09-22 20:23:26 +02:00
|
|
|
if (resourceManager instanceof IReloadableResourceManager)
|
2019-11-23 22:17:37 +01:00
|
|
|
((IReloadableResourceManager) resourceManager).addReloadListener(new ResourceReloadHandler());
|
2021-04-29 23:03:52 +02:00
|
|
|
|
2021-05-04 03:50:17 +02:00
|
|
|
event.enqueueWork(() -> {
|
|
|
|
CopperBacktankArmorLayer.register();
|
|
|
|
});
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
2020-05-28 01:29:26 +02:00
|
|
|
|
2019-11-17 21:25:59 +01:00
|
|
|
public static void onTextureStitch(TextureStitchEvent.Pre event) {
|
2020-05-13 21:56:46 +02:00
|
|
|
if (!event.getMap()
|
2021-06-26 16:32:56 +02:00
|
|
|
.getId()
|
|
|
|
.equals(PlayerContainer.BLOCK_ATLAS_TEXTURE))
|
2019-11-17 21:25:59 +01:00
|
|
|
return;
|
2020-05-15 01:23:27 +02:00
|
|
|
SpriteShifter.getAllTargetSprites()
|
2021-06-26 16:32:56 +02:00
|
|
|
.forEach(event::addSprite);
|
2019-11-17 21:25:59 +01:00
|
|
|
}
|
|
|
|
|
2021-05-23 03:00:10 +02:00
|
|
|
public static void onModelRegistry(ModelRegistryEvent event) {
|
|
|
|
PartialModel.onModelRegistry(event);
|
|
|
|
|
|
|
|
getCustomRenderedItems().foreach((item, modelFunc) -> modelFunc.apply(null)
|
2021-06-26 16:32:56 +02:00
|
|
|
.getModelLocations()
|
|
|
|
.forEach(ModelLoader::addSpecialModel));
|
2019-11-17 21:25:59 +01:00
|
|
|
}
|
|
|
|
|
2019-09-24 14:40:01 +02:00
|
|
|
public static void onModelBake(ModelBakeEvent event) {
|
|
|
|
Map<ResourceLocation, IBakedModel> modelRegistry = event.getModelRegistry();
|
2021-04-29 23:03:52 +02:00
|
|
|
PartialModel.onModelBake(event);
|
2019-09-24 14:40:01 +02:00
|
|
|
|
2020-05-13 21:56:46 +02:00
|
|
|
getCustomBlockModels()
|
2021-06-26 16:32:56 +02:00
|
|
|
.foreach((block, modelFunc) -> swapModels(modelRegistry, getAllBlockStateModelLocations(block), modelFunc));
|
2020-05-28 01:29:26 +02:00
|
|
|
getCustomItemModels()
|
2021-06-26 16:32:56 +02:00
|
|
|
.foreach((item, modelFunc) -> swapModels(modelRegistry, getItemModelLocation(item), modelFunc));
|
2020-05-28 01:29:26 +02:00
|
|
|
getCustomRenderedItems().foreach((item, modelFunc) -> {
|
|
|
|
swapModels(modelRegistry, getItemModelLocation(item), m -> modelFunc.apply(m)
|
|
|
|
.loadPartials(event));
|
|
|
|
});
|
2019-10-21 23:45:16 +02:00
|
|
|
}
|
2019-09-24 14:40:01 +02:00
|
|
|
|
2020-05-28 01:29:26 +02:00
|
|
|
protected static ModelResourceLocation getItemModelLocation(Item item) {
|
|
|
|
return new ModelResourceLocation(item.getRegistryName(), "inventory");
|
2019-09-24 14:40:01 +02:00
|
|
|
}
|
|
|
|
|
2020-05-13 21:56:46 +02:00
|
|
|
protected static List<ModelResourceLocation> getAllBlockStateModelLocations(Block block) {
|
2019-12-05 23:42:01 +01:00
|
|
|
List<ModelResourceLocation> models = new ArrayList<>();
|
2020-05-13 21:56:46 +02:00
|
|
|
block.getStateContainer()
|
|
|
|
.getValidStates()
|
|
|
|
.forEach(state -> {
|
|
|
|
models.add(getBlockModelLocation(block, BlockModelShapes.getPropertyMapString(state.getValues())));
|
|
|
|
});
|
2019-12-05 23:42:01 +01:00
|
|
|
return models;
|
|
|
|
}
|
|
|
|
|
2020-05-13 21:56:46 +02:00
|
|
|
protected static ModelResourceLocation getBlockModelLocation(Block block, String suffix) {
|
|
|
|
return new ModelResourceLocation(block.getRegistryName(), suffix);
|
2019-09-24 14:40:01 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 23:42:01 +01:00
|
|
|
protected static <T extends IBakedModel> void swapModels(Map<ResourceLocation, IBakedModel> modelRegistry,
|
2020-05-13 21:56:46 +02:00
|
|
|
List<ModelResourceLocation> locations, Function<IBakedModel, T> factory) {
|
2019-12-05 23:42:01 +01:00
|
|
|
locations.forEach(location -> {
|
|
|
|
swapModels(modelRegistry, location, factory);
|
|
|
|
});
|
|
|
|
}
|
2021-04-08 19:22:11 +02:00
|
|
|
|
2020-05-28 01:29:26 +02:00
|
|
|
protected static <T extends IBakedModel> void swapModels(Map<ResourceLocation, IBakedModel> modelRegistry,
|
|
|
|
ModelResourceLocation location, Function<IBakedModel, T> factory) {
|
|
|
|
modelRegistry.put(location, factory.apply(modelRegistry.get(location)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CustomItemModels getCustomItemModels() {
|
|
|
|
if (customItemModels == null)
|
|
|
|
customItemModels = new CustomItemModels();
|
|
|
|
return customItemModels;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CustomRenderedItems getCustomRenderedItems() {
|
|
|
|
if (customRenderedItems == null)
|
|
|
|
customRenderedItems = new CustomRenderedItems();
|
|
|
|
return customRenderedItems;
|
|
|
|
}
|
|
|
|
|
2020-05-13 21:56:46 +02:00
|
|
|
public static CustomBlockModels getCustomBlockModels() {
|
|
|
|
if (customBlockModels == null)
|
|
|
|
customBlockModels = new CustomBlockModels();
|
|
|
|
return customBlockModels;
|
|
|
|
}
|
2020-05-28 01:29:26 +02:00
|
|
|
|
2020-12-02 21:49:57 +01:00
|
|
|
public static CasingConnectivity getCasingConnectivity() {
|
|
|
|
if (casingConnectivity == null)
|
|
|
|
casingConnectivity = new CasingConnectivity();
|
|
|
|
return casingConnectivity;
|
|
|
|
}
|
2020-05-13 21:56:46 +02:00
|
|
|
|
2021-01-11 09:29:02 +01:00
|
|
|
public static void invalidateRenderers() {
|
2021-05-23 03:00:10 +02:00
|
|
|
BUFFER_CACHE.invalidate();
|
2021-03-15 23:58:41 +01:00
|
|
|
|
2021-01-18 07:18:31 +01:00
|
|
|
ContraptionRenderDispatcher.invalidateAll();
|
2021-01-11 09:29:02 +01:00
|
|
|
}
|
2021-03-25 02:27:10 +01:00
|
|
|
|
|
|
|
public static void checkGraphicsFanciness() {
|
|
|
|
Minecraft mc = Minecraft.getInstance();
|
|
|
|
if (mc.player == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mc.gameSettings.graphicsMode != GraphicsFanciness.FABULOUS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (AllConfigs.CLIENT.ignoreFabulousWarning.get())
|
|
|
|
return;
|
|
|
|
|
2021-04-08 19:22:11 +02:00
|
|
|
IFormattableTextComponent text = TextComponentUtils.bracketed(new StringTextComponent("WARN"))
|
|
|
|
.formatted(TextFormatting.GOLD)
|
|
|
|
.append(new StringTextComponent(
|
|
|
|
" Some of Create's visual features will not be available while Fabulous graphics are enabled!"))
|
|
|
|
.styled(style -> style
|
|
|
|
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/create dismissFabulousWarning"))
|
|
|
|
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
|
|
|
new StringTextComponent("Click here to disable this warning"))));
|
2021-03-25 02:27:10 +01:00
|
|
|
|
|
|
|
mc.ingameGUI.addChatMessage(ChatType.CHAT, text, mc.player.getUniqueID());
|
|
|
|
}
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|