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;
|
|
|
|
|
2019-12-22 01:31:40 +01:00
|
|
|
import com.simibubi.create.foundation.block.IHaveColoredVertices;
|
2020-01-13 20:23:44 +01:00
|
|
|
import com.simibubi.create.foundation.block.connected.CTModel;
|
|
|
|
import com.simibubi.create.foundation.block.connected.IHaveConnectedTextures;
|
|
|
|
import com.simibubi.create.foundation.block.render.ColoredVertexModel;
|
|
|
|
import com.simibubi.create.foundation.block.render.SpriteShiftEntry;
|
2019-11-23 22:17:37 +01:00
|
|
|
import com.simibubi.create.foundation.utility.SuperByteBufferCache;
|
2019-10-29 19:02:20 +01:00
|
|
|
import com.simibubi.create.modules.contraptions.WrenchModel;
|
2019-11-23 22:17:37 +01:00
|
|
|
import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer;
|
2019-12-12 11:58:29 +01:00
|
|
|
import com.simibubi.create.modules.contraptions.components.contraptions.ContraptionRenderer;
|
2020-01-26 23:58:55 +01:00
|
|
|
import com.simibubi.create.modules.curiosities.blockzapper.BlockzapperModel;
|
2019-10-30 02:05:26 +01:00
|
|
|
import com.simibubi.create.modules.curiosities.deforester.DeforesterModel;
|
2019-09-24 14:40:01 +02:00
|
|
|
import com.simibubi.create.modules.curiosities.partialWindows.WindowInABlockModel;
|
|
|
|
import com.simibubi.create.modules.curiosities.symmetry.client.SymmetryWandModel;
|
2020-01-26 23:58:55 +01:00
|
|
|
import com.simibubi.create.modules.curiosities.tools.SandPaperItemRenderer.SandPaperModel;
|
2019-09-03 08:34:02 +02:00
|
|
|
import com.simibubi.create.modules.schematics.ClientSchematicLoader;
|
|
|
|
import com.simibubi.create.modules.schematics.client.SchematicAndQuillHandler;
|
|
|
|
import com.simibubi.create.modules.schematics.client.SchematicHandler;
|
|
|
|
import com.simibubi.create.modules.schematics.client.SchematicHologram;
|
|
|
|
|
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;
|
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.state.properties.BlockStateProperties;
|
|
|
|
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-10 22:51:26 +02:00
|
|
|
import net.minecraftforge.fml.config.ModConfig;
|
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 SchematicHologram schematicHologram;
|
|
|
|
public static SchematicAndQuillHandler schematicAndQuillHandler;
|
2019-11-23 22:17:37 +01:00
|
|
|
public static SuperByteBufferCache bufferCache;
|
2019-10-29 19:02:20 +01:00
|
|
|
public static int renderTicks;
|
2019-11-17 21:25:59 +01:00
|
|
|
|
2019-09-10 22:51:26 +02:00
|
|
|
public static ModConfig config;
|
2019-09-22 20:23:26 +02: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::createConfigs);
|
|
|
|
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);
|
2019-12-05 23:42:01 +01:00
|
|
|
modEventBus.addListener(AllParticles::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();
|
|
|
|
schematicHologram = new SchematicHologram();
|
2019-09-03 23:03:52 +02:00
|
|
|
schematicAndQuillHandler = new SchematicAndQuillHandler();
|
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();
|
|
|
|
AllContainers.registerScreenFactories();
|
|
|
|
AllTileEntities.registerRenderers();
|
|
|
|
AllItems.registerColorHandlers();
|
2019-09-13 18:36:18 +02:00
|
|
|
AllBlocks.registerColorHandlers();
|
2019-10-05 19:00:43 +02:00
|
|
|
AllEntities.registerRenderers();
|
2019-09-22 20:23:26 +02:00
|
|
|
|
|
|
|
IResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
|
|
|
|
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
|
|
|
}
|
2019-09-22 20:23:26 +02:00
|
|
|
|
2019-09-10 22:51:26 +02:00
|
|
|
public static void createConfigs(ModConfig.ModConfigEvent event) {
|
|
|
|
if (event.getConfig().getSpec() == CreateConfig.specification)
|
|
|
|
return;
|
2019-09-22 20:23:26 +02:00
|
|
|
|
2019-09-10 22:51:26 +02:00
|
|
|
config = event.getConfig();
|
|
|
|
}
|
2019-09-03 08:34:02 +02:00
|
|
|
|
|
|
|
public static void gameTick() {
|
|
|
|
schematicSender.tick();
|
|
|
|
schematicAndQuillHandler.tick();
|
|
|
|
schematicHandler.tick();
|
|
|
|
schematicHologram.tick();
|
|
|
|
}
|
|
|
|
|
2019-11-17 21:25:59 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
public static void onTextureStitch(TextureStitchEvent.Pre event) {
|
|
|
|
if (!event.getMap().getBasePath().equals("textures"))
|
|
|
|
return;
|
2020-01-20 13:41:41 +01:00
|
|
|
|
|
|
|
event.addSprite(new ResourceLocation(Create.ID, "block/belt_animated"));
|
2019-11-17 21:25:59 +01:00
|
|
|
for (AllBlocks allBlocks : AllBlocks.values()) {
|
2019-12-05 23:42:01 +01:00
|
|
|
Block block = allBlocks.get();
|
|
|
|
if (!(block instanceof IHaveConnectedTextures))
|
2019-11-17 21:25:59 +01:00
|
|
|
continue;
|
2020-01-13 21:59:26 +01:00
|
|
|
for (SpriteShiftEntry spriteShiftEntry : ((IHaveConnectedTextures) block).getBehaviour().getAllCTShifts())
|
2019-12-05 23:42:01 +01:00
|
|
|
event.addSprite(spriteShiftEntry.getTargetResourceLocation());
|
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();
|
|
|
|
|
2019-11-17 21:25:59 +01:00
|
|
|
for (AllBlocks allBlocks : AllBlocks.values()) {
|
2019-12-05 23:42:01 +01:00
|
|
|
Block block = allBlocks.get();
|
|
|
|
if (block == null)
|
2019-11-17 21:25:59 +01:00
|
|
|
continue;
|
2019-12-05 23:42:01 +01:00
|
|
|
|
|
|
|
List<ModelResourceLocation> blockModelLocations = getAllBlockStateModelLocations(allBlocks);
|
|
|
|
if (block instanceof IHaveConnectedTextures)
|
|
|
|
swapModels(modelRegistry, blockModelLocations, t -> new CTModel(t, (IHaveConnectedTextures) block));
|
2019-12-22 01:31:40 +01:00
|
|
|
if (block instanceof IHaveColoredVertices)
|
2019-12-05 23:42:01 +01:00
|
|
|
swapModels(modelRegistry, blockModelLocations,
|
2019-12-22 01:31:40 +01:00
|
|
|
t -> new ColoredVertexModel(t, (IHaveColoredVertices) block));
|
2019-12-05 23:42:01 +01:00
|
|
|
|
2019-11-17 21:25:59 +01:00
|
|
|
}
|
|
|
|
|
2020-01-26 23:58:55 +01:00
|
|
|
swapModels(modelRegistry, getItemModelLocation(AllItems.SAND_PAPER),
|
|
|
|
t -> new SandPaperModel(t));
|
|
|
|
swapModels(modelRegistry, getItemModelLocation(AllItems.RED_SAND_PAPER),
|
|
|
|
t -> new SandPaperModel(t));
|
|
|
|
|
2019-09-24 14:40:01 +02:00
|
|
|
swapModels(modelRegistry, getItemModelLocation(AllItems.SYMMETRY_WAND),
|
|
|
|
t -> new SymmetryWandModel(t).loadPartials(event));
|
|
|
|
swapModels(modelRegistry, getItemModelLocation(AllItems.PLACEMENT_HANDGUN),
|
2020-01-26 23:58:55 +01:00
|
|
|
t -> new BlockzapperModel(t).loadPartials(event));
|
2019-11-17 21:25:59 +01:00
|
|
|
swapModels(modelRegistry, getItemModelLocation(AllItems.WRENCH), t -> new WrenchModel(t).loadPartials(event));
|
2019-10-30 02:05:26 +01:00
|
|
|
swapModels(modelRegistry, getItemModelLocation(AllItems.DEFORESTER),
|
|
|
|
t -> new DeforesterModel(t).loadPartials(event));
|
2019-09-24 14:40:01 +02:00
|
|
|
swapModels(modelRegistry,
|
|
|
|
getBlockModelLocation(AllBlocks.WINDOW_IN_A_BLOCK,
|
|
|
|
BlockModelShapes
|
|
|
|
.getPropertyMapString(AllBlocks.WINDOW_IN_A_BLOCK.get().getDefaultState().getValues())),
|
|
|
|
WindowInABlockModel::new);
|
|
|
|
swapModels(modelRegistry,
|
|
|
|
getBlockModelLocation(AllBlocks.WINDOW_IN_A_BLOCK,
|
|
|
|
BlockModelShapes.getPropertyMapString(AllBlocks.WINDOW_IN_A_BLOCK.get().getDefaultState()
|
|
|
|
.with(BlockStateProperties.WATERLOGGED, true).getValues())),
|
|
|
|
WindowInABlockModel::new);
|
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) {
|
|
|
|
for (String location : SymmetryWandModel.getCustomModelLocations())
|
|
|
|
ModelLoader.addSpecialModel(new ResourceLocation(Create.ID, "item/" + location));
|
2020-01-26 23:58:55 +01:00
|
|
|
for (String location : BlockzapperModel.getCustomModelLocations())
|
2019-10-21 23:45:16 +02:00
|
|
|
ModelLoader.addSpecialModel(new ResourceLocation(Create.ID, "item/" + location));
|
2019-10-29 19:02:20 +01:00
|
|
|
for (String location : WrenchModel.getCustomModelLocations())
|
|
|
|
ModelLoader.addSpecialModel(new ResourceLocation(Create.ID, "item/" + location));
|
2019-10-30 02:05:26 +01:00
|
|
|
for (String location : DeforesterModel.getCustomModelLocations())
|
|
|
|
ModelLoader.addSpecialModel(new ResourceLocation(Create.ID, "item/" + location));
|
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) {
|
|
|
|
return new ModelResourceLocation(item.item.getRegistryName(), "inventory");
|
|
|
|
}
|
|
|
|
|
2019-12-05 23:42:01 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
protected static List<ModelResourceLocation> getAllBlockStateModelLocations(AllBlocks block) {
|
|
|
|
List<ModelResourceLocation> models = new ArrayList<>();
|
|
|
|
block.get().getStateContainer().getValidStates().forEach(state -> {
|
|
|
|
models.add(getBlockModelLocation(block, BlockModelShapes.getPropertyMapString(state.getValues())));
|
|
|
|
});
|
|
|
|
return models;
|
|
|
|
}
|
|
|
|
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-09-24 14:40:01 +02:00
|
|
|
protected static ModelResourceLocation getBlockModelLocation(AllBlocks block, String suffix) {
|
|
|
|
return new ModelResourceLocation(block.block.getRegistryName(), suffix);
|
|
|
|
}
|
|
|
|
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
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)));
|
|
|
|
}
|
|
|
|
|
2019-12-05 23:42:01 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
protected static <T extends IBakedModel> void swapModels(Map<ResourceLocation, IBakedModel> modelRegistry,
|
|
|
|
List<ModelResourceLocation> locations, Function<IBakedModel, T> factory) {
|
|
|
|
locations.forEach(location -> {
|
|
|
|
swapModels(modelRegistry, location, factory);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|