2019-09-03 08:34:02 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
2019-12-05 23:42:01 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2019-09-24 14:40:01 +02:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
2020-05-23 14:02:38 +02:00
|
|
|
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.ChassisRangeDisplay;
|
|
|
|
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer;
|
2020-05-26 20:45:56 +02:00
|
|
|
import com.simibubi.create.content.contraptions.relays.belt.item.BeltConnectorHandler;
|
|
|
|
import com.simibubi.create.content.curiosities.zapper.ZapperRenderHandler;
|
|
|
|
import com.simibubi.create.content.curiosities.zapper.terrainzapper.TerrainZapperRenderHandler;
|
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;
|
|
|
|
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;
|
2020-02-03 16:47:58 +01:00
|
|
|
import com.simibubi.create.foundation.item.IHaveCustomItemModel;
|
2020-05-24 15:58:25 +02:00
|
|
|
import com.simibubi.create.foundation.tileEntity.behaviour.edgeInteraction.EdgeInteractionRenderer;
|
2020-05-23 14:02:38 +02:00
|
|
|
import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer;
|
|
|
|
import com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkRenderer;
|
|
|
|
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueRenderer;
|
2019-11-23 22:17:37 +01:00
|
|
|
import com.simibubi.create.foundation.utility.SuperByteBufferCache;
|
2020-05-15 17:13:38 +02:00
|
|
|
import com.simibubi.create.foundation.utility.outliner.Outliner;
|
2019-09-03 08:34:02 +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;
|
2020-05-13 01:11:07 +02:00
|
|
|
import net.minecraft.inventory.container.PlayerContainer;
|
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;
|
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
|
|
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;
|
|
|
|
import net.minecraftforge.fml.DistExecutor;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
|
|
|
|
|
|
|
public class CreateClient {
|
|
|
|
|
|
|
|
public static ClientSchematicLoader schematicSender;
|
|
|
|
public static SchematicHandler schematicHandler;
|
|
|
|
public static SchematicAndQuillHandler schematicAndQuillHandler;
|
2019-11-23 22:17:37 +01:00
|
|
|
public static SuperByteBufferCache bufferCache;
|
2020-05-15 17:13:38 +02:00
|
|
|
public static Outliner outliner;
|
2020-05-24 12:31:05 +02:00
|
|
|
|
2020-05-13 21:56:46 +02:00
|
|
|
private static CustomBlockModels customBlockModels;
|
2020-05-24 12:31:05 +02:00
|
|
|
private static AllColorHandlers colorHandlers;
|
2019-11-17 21:25:59 +01:00
|
|
|
|
2019-10-15 22:22:19 +02:00
|
|
|
public static void addListeners(IEventBus modEventBus) {
|
|
|
|
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
|
|
|
|
modEventBus.addListener(CreateClient::clientInit);
|
|
|
|
modEventBus.addListener(CreateClient::onModelBake);
|
2019-10-21 23:45:16 +02:00
|
|
|
modEventBus.addListener(CreateClient::onModelRegistry);
|
2019-11-17 21:25:59 +01:00
|
|
|
modEventBus.addListener(CreateClient::onTextureStitch);
|
2020-05-23 14:02:38 +02:00
|
|
|
modEventBus.addListener(AllParticleTypes::registerFactories);
|
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) {
|
|
|
|
schematicSender = new ClientSchematicLoader();
|
|
|
|
schematicHandler = new SchematicHandler();
|
2019-09-03 23:03:52 +02:00
|
|
|
schematicAndQuillHandler = new SchematicAndQuillHandler();
|
2020-05-15 17:13:38 +02:00
|
|
|
outliner = new Outliner();
|
2019-09-22 20:23:26 +02:00
|
|
|
|
2019-11-23 22:17:37 +01:00
|
|
|
bufferCache = new SuperByteBufferCache();
|
|
|
|
bufferCache.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE);
|
|
|
|
bufferCache.registerCompartment(ContraptionRenderer.CONTRAPTION, 20);
|
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
AllKeys.register();
|
2020-05-23 14:02:38 +02:00
|
|
|
AllContainerTypes.registerScreenFactories();
|
2019-09-03 08:34:02 +02:00
|
|
|
AllTileEntities.registerRenderers();
|
|
|
|
AllItems.registerColorHandlers();
|
2020-05-23 14:02:38 +02:00
|
|
|
AllEntityTypes.registerRenderers();
|
2020-05-24 12:31:05 +02:00
|
|
|
getColorHandler().init();
|
2019-09-22 20:23:26 +02:00
|
|
|
|
2020-05-13 01:11:07 +02:00
|
|
|
IResourceManager resourceManager = Minecraft.getInstance()
|
2020-05-13 21:56:46 +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());
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
2020-05-15 17:13:38 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
public static void gameTick() {
|
|
|
|
schematicSender.tick();
|
|
|
|
schematicAndQuillHandler.tick();
|
|
|
|
schematicHandler.tick();
|
2020-05-26 20:45:56 +02:00
|
|
|
BeltConnectorHandler.gameTick();
|
2020-05-16 17:51:29 +02:00
|
|
|
FilteringRenderer.tick();
|
|
|
|
LinkRenderer.tick();
|
|
|
|
ScrollValueRenderer.tick();
|
|
|
|
ChassisRangeDisplay.tick();
|
2020-05-24 15:58:25 +02:00
|
|
|
EdgeInteractionRenderer.tick();
|
2020-05-26 20:45:56 +02:00
|
|
|
TerrainZapperRenderHandler.tick();
|
|
|
|
ZapperRenderHandler.tick();
|
2020-05-15 17:13:38 +02:00
|
|
|
outliner.tickOutlines();
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
|
|
|
|
2019-11-17 21:25:59 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
public static void onTextureStitch(TextureStitchEvent.Pre event) {
|
2020-05-13 21:56:46 +02:00
|
|
|
if (!event.getMap()
|
|
|
|
.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()
|
|
|
|
.forEach(event::addSprite);
|
2019-11-17 21:25:59 +01:00
|
|
|
}
|
|
|
|
|
2019-09-24 14:40:01 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
public static void onModelBake(ModelBakeEvent event) {
|
|
|
|
Map<ResourceLocation, IBakedModel> modelRegistry = event.getModelRegistry();
|
2020-02-04 14:48:21 +01:00
|
|
|
AllBlockPartials.onModelBake(event);
|
2019-09-24 14:40:01 +02:00
|
|
|
|
2020-05-13 21:56:46 +02:00
|
|
|
getCustomBlockModels()
|
|
|
|
.foreach((block, modelFunc) -> swapModels(modelRegistry, getAllBlockStateModelLocations(block), modelFunc));
|
2019-11-17 21:25:59 +01:00
|
|
|
|
2020-05-13 21:56:46 +02:00
|
|
|
// todo modelswap for item registrate
|
2020-02-03 16:47:58 +01:00
|
|
|
for (AllItems item : AllItems.values()) {
|
2020-02-04 14:48:21 +01:00
|
|
|
if (item.get() instanceof IHaveCustomItemModel)
|
|
|
|
swapModels(modelRegistry, getItemModelLocation(item),
|
2020-05-13 21:56:46 +02:00
|
|
|
m -> ((IHaveCustomItemModel) item.get()).createModel(m)
|
|
|
|
.loadPartials(event));
|
2020-02-03 16:47:58 +01:00
|
|
|
}
|
2019-10-21 23:45:16 +02:00
|
|
|
}
|
2019-09-24 14:40:01 +02:00
|
|
|
|
2019-10-21 23:45:16 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
public static void onModelRegistry(ModelRegistryEvent event) {
|
2020-02-04 14:48:21 +01:00
|
|
|
AllBlockPartials.onModelRegistry(event);
|
|
|
|
|
2020-02-03 16:47:58 +01:00
|
|
|
// Register submodels for custom rendered item models
|
|
|
|
for (AllItems item : AllItems.values()) {
|
2020-02-04 14:48:21 +01:00
|
|
|
if (item.get() instanceof IHaveCustomItemModel)
|
2020-05-13 01:11:07 +02:00
|
|
|
((IHaveCustomItemModel) item.get()).createModel(null)
|
2020-05-13 21:56:46 +02:00
|
|
|
.getModelLocations()
|
|
|
|
.forEach(ModelLoader::addSpecialModel);
|
2020-02-03 16:47:58 +01:00
|
|
|
}
|
2019-09-24 14:40:01 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 23:42:01 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-09-24 14:40:01 +02:00
|
|
|
protected static ModelResourceLocation getItemModelLocation(AllItems item) {
|
2020-05-13 01:11:07 +02:00
|
|
|
return new ModelResourceLocation(item.get()
|
2020-05-13 21:56:46 +02:00
|
|
|
.getRegistryName(), "inventory");
|
2019-09-24 14:40:01 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 23:42:01 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
protected static <T extends IBakedModel> void swapModels(Map<ResourceLocation, IBakedModel> modelRegistry,
|
2020-05-13 21:56:46 +02:00
|
|
|
ModelResourceLocation location, Function<IBakedModel, T> factory) {
|
2019-09-24 14:40:01 +02:00
|
|
|
modelRegistry.put(location, factory.apply(modelRegistry.get(location)));
|
|
|
|
}
|
|
|
|
|
2019-12-05 23:42:01 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-13 21:56:46 +02:00
|
|
|
public static CustomBlockModels getCustomBlockModels() {
|
|
|
|
if (customBlockModels == null)
|
|
|
|
customBlockModels = new CustomBlockModels();
|
|
|
|
return customBlockModels;
|
|
|
|
}
|
2020-05-24 12:31:05 +02:00
|
|
|
|
|
|
|
public static AllColorHandlers getColorHandler() {
|
|
|
|
if (colorHandlers == null)
|
|
|
|
colorHandlers = new AllColorHandlers();
|
|
|
|
return colorHandlers;
|
|
|
|
}
|
2020-05-13 21:56:46 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|