TechReborn/src/main/java/techreborn/proxies/ClientProxy.java

248 lines
9.9 KiB
Java
Raw Normal View History

/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
2015-04-23 21:29:26 +02:00
package techreborn.proxies;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
2016-04-25 12:10:06 +02:00
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.DefaultStateMapper;
2016-05-16 15:29:02 +02:00
import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
2016-03-13 12:50:46 +01:00
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
2016-04-25 12:10:06 +02:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
2016-04-25 12:10:06 +02:00
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextFormatting;
2016-04-25 12:10:06 +02:00
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
2015-11-23 20:19:18 +01:00
import net.minecraftforge.fml.client.registry.ClientRegistry;
2016-03-13 12:50:46 +01:00
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
2016-04-25 12:10:06 +02:00
import reborncore.RebornCore;
import reborncore.api.tile.IUpgradeable;
2016-12-11 07:53:02 +01:00
import reborncore.client.hud.StackInfoHUD;
2015-11-12 20:50:20 +01:00
import reborncore.client.multiblock.MultiblockRenderEvent;
2016-04-25 12:10:06 +02:00
import reborncore.common.blocks.BlockMachineBase;
2016-12-05 11:07:41 +01:00
import techreborn.Core;
import techreborn.blocks.BlockMachineCasing;
2016-12-05 11:17:39 +01:00
import techreborn.blocks.BlockMachineFrame;
2016-05-16 15:29:02 +02:00
import techreborn.blocks.BlockRubberLeaves;
2016-03-25 10:47:34 +01:00
import techreborn.client.ClientMultiBlocks;
import techreborn.client.IconSupplier;
import techreborn.client.RegisterItemJsons;
import techreborn.client.StackToolTipEvent;
import techreborn.client.gui.GuiBase;
import techreborn.client.keybindings.KeyBindings;
import techreborn.client.render.ModelDynamicCell;
2016-03-13 12:50:46 +01:00
import techreborn.client.render.entitys.RenderNukePrimed;
import techreborn.entitys.EntityNukePrimed;
2016-05-16 15:29:02 +02:00
import techreborn.init.ModBlocks;
2016-12-11 07:53:02 +01:00
import techreborn.items.ItemFrequencyTransmitter;
import techreborn.lib.ModInfo;
2016-04-23 14:52:50 +02:00
import techreborn.manual.loader.ManualLoader;
import java.io.File;
2016-10-08 21:46:16 +02:00
public class ClientProxy extends CommonProxy {
2016-03-25 10:47:34 +01:00
public static MultiblockRenderEvent multiblockRenderEvent;
public static ResourceLocation getItemLocation(Item item) {
Object o = item.getRegistryName();
if (o == null) {
return null;
}
return (ResourceLocation) o;
}
private static ResourceLocation registerIt(Item item, final ResourceLocation location) {
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return new ModelResourceLocation(location, "inventory");
}
});
ModelLoader.registerItemVariants(item, location);
return location;
}
2016-03-25 10:47:34 +01:00
@Override
2016-10-08 21:46:16 +02:00
public void preInit(FMLPreInitializationEvent event) {
2016-03-25 10:47:34 +01:00
super.preInit(event);
2016-12-11 07:53:02 +01:00
StackInfoHUD.registerElement(new ItemFrequencyTransmitter.StackInfoFreqTransmitter());
2016-03-25 10:47:34 +01:00
RenderingRegistry.registerEntityRenderingHandler(EntityNukePrimed.class, new RenderManagerNuke());
2016-04-23 14:52:50 +02:00
ManualLoader loader = new ManualLoader(new File(event.getModConfigurationDirectory(), "techreborn"));
2016-10-08 21:46:16 +02:00
// new Thread(() ->
// {
// try {
// loader.load();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }).start();
2016-04-25 12:10:06 +02:00
2016-10-08 21:46:16 +02:00
for (Object object : RebornCore.jsonDestroyer.objectsToDestroy) {
2016-04-25 12:10:06 +02:00
if (object instanceof BlockMachineBase) {
BlockMachineBase base = (BlockMachineBase) object;
registerItemModel(Item.getItemFromBlock(base));
}
}
2016-05-17 22:12:33 +02:00
2016-12-05 11:07:41 +01:00
for (int i = 0; i < BlockMachineCasing.types.length; i++) {
Core.proxy.registerSubBlockInventoryLocation(ModBlocks.MACHINE_CASINGS, i, "techreborn:machines/structure/machine_casing", "type=" + i);
2016-12-05 11:07:41 +01:00
}
2016-12-05 11:17:39 +01:00
for (int i = 0; i < BlockMachineFrame.types.length; i++) {
Core.proxy.registerSubBlockInventoryLocation(ModBlocks.MACHINE_FRAMES, i, "techreborn:machines/storage/machine_blocks", "type=" + i);
2016-12-05 11:17:39 +01:00
}
2016-12-05 11:07:41 +01:00
ModelDynamicCell.init();
RegisterItemJsons.registerModels();
2016-03-25 10:47:34 +01:00
}
2016-12-05 11:07:41 +01:00
@Override
public void registerSubItemInventoryLocation(Item item, int meta, String location, String name) {
ModelResourceLocation resourceLocation = new ModelResourceLocation(location, name);
ModelLoader.setCustomModelResourceLocation(item, meta, resourceLocation);
}
2016-03-25 10:47:34 +01:00
@Override
2016-10-08 21:46:16 +02:00
public void init(FMLInitializationEvent event) {
2016-03-25 10:47:34 +01:00
super.init(event);
MinecraftForge.EVENT_BUS.register(new IconSupplier());
2016-05-21 21:18:30 +02:00
//MinecraftForge.EVENT_BUS.register(new VersionCheckerClient());
2016-03-25 10:47:34 +01:00
MinecraftForge.EVENT_BUS.register(new StackToolTipEvent());
multiblockRenderEvent = new MultiblockRenderEvent();
MinecraftForge.EVENT_BUS.register(multiblockRenderEvent);
2016-03-25 10:47:34 +01:00
// TODO FIX ME
ClientRegistry.registerKeyBinding(KeyBindings.config);
ClientMultiBlocks.init();
2016-05-16 15:29:02 +02:00
StateMap rubberLeavesStateMap = new StateMap.Builder().ignore(BlockRubberLeaves.CHECK_DECAY, BlockRubberLeaves.DECAYABLE).build();
ModelLoader.setCustomStateMapper(ModBlocks.RUBBER_LEAVES, rubberLeavesStateMap);
2016-04-25 12:10:06 +02:00
}
protected void registerItemModel(ItemStack item, String name) {
// tell Minecraft which textures it has to load. This is resource-domain sensitive
ModelLoader.registerItemVariants(item.getItem(), new ResourceLocation(name));
// tell the game which model to use for this item-meta combination
ModelLoader.setCustomModelResourceLocation(item.getItem(), item
2016-10-08 21:46:16 +02:00
.getMetadata(), new ModelResourceLocation(name, "inventory"));
2016-04-25 12:10:06 +02:00
}
public ResourceLocation registerItemModel(Item item) {
ResourceLocation itemLocation = getItemLocation(item);
2016-10-08 21:46:16 +02:00
if (itemLocation == null) {
2016-04-25 12:10:06 +02:00
return null;
}
return registerIt(item, itemLocation);
}
@Override
public void registerFluidBlockRendering(Block block, String name) {
name = name.toLowerCase();
super.registerFluidBlockRendering(block, name);
final ModelResourceLocation fluidLocation = new ModelResourceLocation(ModInfo.MOD_ID.toLowerCase() + ":fluids", name);
// use a custom state mapper which will ignore the LEVEL property
2016-10-08 21:46:16 +02:00
ModelLoader.setCustomStateMapper(block, new StateMapperBase() {
@Override
2016-10-08 21:46:16 +02:00
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
return fluidLocation;
}
});
}
@Override
2016-11-28 13:54:44 +01:00
public void registerCustomBlockStateLocation(Block block, String resourceLocation) {
resourceLocation = resourceLocation.toLowerCase();
2016-11-28 13:54:44 +01:00
super.registerCustomBlockStateLocation(block, resourceLocation);
String finalResourceLocation = resourceLocation;
2016-10-08 21:46:16 +02:00
ModelLoader.setCustomStateMapper(block, new DefaultStateMapper() {
@Override
2016-10-08 21:46:16 +02:00
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
String resourceDomain = Block.REGISTRY.getNameForObject(state.getBlock()).getResourceDomain();
String propertyString = getPropertyString(state.getProperties());
return new ModelResourceLocation(resourceDomain + ':' + finalResourceLocation, propertyString);
}
});
String resourceDomain = Block.REGISTRY.getNameForObject(block).getResourceDomain();
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(resourceDomain + ':' + resourceLocation, "inventory"));
}
2016-11-28 13:54:44 +01:00
@Override
public void registerCustomBlockStateLocation(Block block, String resourceLocation, boolean item) {
resourceLocation = resourceLocation.toLowerCase();
super.registerCustomBlockStateLocation(block, resourceLocation, item);
String finalResourceLocation = resourceLocation;
ModelLoader.setCustomStateMapper(block, new DefaultStateMapper() {
@Override
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
String resourceDomain = Block.REGISTRY.getNameForObject(state.getBlock()).getResourceDomain();
String propertyString = getPropertyString(state.getProperties());
return new ModelResourceLocation(resourceDomain + ':' + finalResourceLocation, propertyString);
}
});
if (item) {
String resourceDomain = Block.REGISTRY.getNameForObject(block).getResourceDomain();
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(resourceDomain + ':' + resourceLocation, "inventory"));
}
}
@Override
public boolean isCTMAvailable() {
return isChiselAround;
}
public class RenderManagerNuke implements IRenderFactory<EntityNukePrimed> {
@Override
public Render<? super EntityNukePrimed> createRenderFor(RenderManager manager) {
return new RenderNukePrimed(manager);
}
}
@Override
public String getUpgradeConfigText() {
if(Minecraft.getMinecraft().currentScreen instanceof GuiBase){
GuiBase base = (GuiBase) Minecraft.getMinecraft().currentScreen;
if(base.tile instanceof IUpgradeable){
if(((IUpgradeable) base.tile).canBeUpgraded()){
return TextFormatting.LIGHT_PURPLE + "Right click to configure";
}
}
}
return super.getUpgradeConfigText();
}
2015-04-23 21:29:26 +02:00
}