2015-08-29 14:33:25 +02:00
/ *
2016-05-16 22:52:27 +02:00
* This file ( " ClientProxy.java " ) is part of the Actually Additions mod for Minecraft .
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http : //ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https : //github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015 - 2016 Ellpeck
2015-08-29 14:33:25 +02:00
* /
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.proxy ;
2014-12-03 21:55:53 +01:00
2015-02-20 22:45:33 +01:00
2016-01-16 23:14:10 +01:00
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI ;
import de.ellpeck.actuallyadditions.api.booklet.BookletPage ;
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter ;
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry ;
2016-02-20 15:23:03 +01:00
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderCompost ;
2016-06-06 21:27:09 +02:00
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderDisplayStand ;
2016-02-17 21:45:19 +01:00
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderReconstructorLens ;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderSmileyCloud ;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues ;
2016-07-03 20:57:00 +02:00
import de.ellpeck.actuallyadditions.mod.event.ClientEvents ;
2016-01-29 17:38:31 +01:00
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids ;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit ;
2016-02-17 21:45:19 +01:00
import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor ;
2016-02-20 15:23:03 +01:00
import de.ellpeck.actuallyadditions.mod.tile.TileEntityCompost ;
2016-06-06 21:27:09 +02:00
import de.ellpeck.actuallyadditions.mod.tile.TileEntityDisplayStand ;
2016-02-17 21:45:19 +01:00
import de.ellpeck.actuallyadditions.mod.tile.TileEntitySmileyCloud ;
2016-01-10 01:17:17 +01:00
import de.ellpeck.actuallyadditions.mod.util.FluidStateMapper ;
2016-03-19 15:10:20 +01:00
import de.ellpeck.actuallyadditions.mod.util.IColorProvidingItem ;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.util.ModUtil ;
2016-01-10 01:17:17 +01:00
import net.minecraft.block.Block ;
2015-09-22 23:32:19 +02:00
import net.minecraft.client.Minecraft ;
2016-03-18 23:47:22 +01:00
import net.minecraft.client.renderer.block.model.ModelResourceLocation ;
2016-01-16 23:14:10 +01:00
import net.minecraft.client.resources.IReloadableResourceManager ;
import net.minecraft.client.resources.IResourceManager ;
import net.minecraft.client.resources.IResourceManagerReloadListener ;
2016-01-08 16:52:53 +01:00
import net.minecraft.item.Item ;
import net.minecraft.item.ItemStack ;
2016-06-01 00:37:28 +02:00
import net.minecraft.util.ResourceLocation ;
2016-05-26 22:53:11 +02:00
import net.minecraft.util.text.TextFormatting ;
2016-01-10 01:17:17 +01:00
import net.minecraftforge.client.model.ModelLoader ;
import net.minecraftforge.fluids.Fluid ;
2016-02-17 21:45:19 +01:00
import net.minecraftforge.fml.client.registry.ClientRegistry ;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.common.event.FMLInitializationEvent ;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent ;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent ;
2015-03-07 02:23:31 +01:00
2016-05-26 22:49:47 +02:00
import java.io.BufferedWriter ;
2015-08-30 19:10:10 +02:00
import java.io.File ;
2016-05-26 22:49:47 +02:00
import java.io.FileWriter ;
2016-03-19 15:10:20 +01:00
import java.util.* ;
2015-08-30 19:10:10 +02:00
2014-12-03 21:55:53 +01:00
public class ClientProxy implements IProxy {
2016-06-01 00:39:35 +02:00
private static final List < Item > COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING = new ArrayList < Item > ( ) ;
private static final Map < ItemStack , ModelResourceLocation > MODEL_LOCATIONS_FOR_REGISTERING = new HashMap < ItemStack , ModelResourceLocation > ( ) ;
2015-10-18 19:56:18 +02:00
public static boolean pumpkinBlurPumpkinBlur ;
public static boolean jingleAllTheWay ;
2015-10-23 23:08:53 +02:00
public static boolean bulletForMyValentine ;
2016-01-16 23:14:10 +01:00
public static int bookletWordCount ;
public static int bookletCharCount ;
2016-03-19 15:10:20 +01:00
2016-02-01 20:39:11 +01:00
private static void countBookletWords ( ) {
bookletWordCount = 0 ;
bookletCharCount = 0 ;
2016-05-26 22:49:47 +02:00
String bookletText = " " ;
2016-02-01 20:39:11 +01:00
2016-05-19 20:05:12 +02:00
for ( IBookletEntry entry : ActuallyAdditionsAPI . BOOKLET_ENTRIES ) {
2016-05-26 23:05:08 +02:00
if ( entry ! = ActuallyAdditionsAPI . allAndSearch ) {
bookletWordCount + = entry . getLocalizedName ( ) . split ( " " ) . length ;
bookletCharCount + = entry . getLocalizedName ( ) . length ( ) ;
bookletText + = entry . getLocalizedName ( ) + " \ n \ n " ;
2016-05-26 22:49:47 +02:00
2016-05-26 23:05:08 +02:00
for ( IBookletChapter chapter : entry . getChapters ( ) ) {
bookletWordCount + = chapter . getLocalizedName ( ) . split ( " " ) . length ;
bookletCharCount + = chapter . getLocalizedName ( ) . length ( ) ;
bookletText + = chapter . getLocalizedName ( ) + " \ n " ;
2016-05-26 22:49:47 +02:00
2016-05-26 23:05:08 +02:00
for ( BookletPage page : chapter . getPages ( ) ) {
if ( page . getText ( ) ! = null ) {
bookletWordCount + = page . getText ( ) . split ( " " ) . length ;
bookletCharCount + = page . getText ( ) . length ( ) ;
bookletText + = page . getText ( ) + " \ n " ;
}
2016-02-01 20:39:11 +01:00
}
2016-05-26 23:05:08 +02:00
bookletText + = " \ n " ;
2016-05-26 22:49:47 +02:00
2016-05-26 23:05:08 +02:00
}
bookletText + = " \ n " ;
2016-05-26 22:49:47 +02:00
}
}
if ( ConfigBoolValues . BOOKLET_TEXT_TO_FILE . isEnabled ( ) ) {
File file = new File ( Minecraft . getMinecraft ( ) . mcDataDir , ModUtil . MOD_ID + " booklettext.txt " ) ;
try {
file . createNewFile ( ) ;
BufferedWriter writer = new BufferedWriter ( new FileWriter ( file ) ) ;
2016-05-26 22:53:11 +02:00
writer . write ( TextFormatting . getTextWithoutFormattingCodes ( bookletText ) ) ;
2016-05-26 22:49:47 +02:00
writer . close ( ) ;
ModUtil . LOGGER . info ( " Wrote booklet text to file! " ) ;
}
catch ( Exception e ) {
ModUtil . LOGGER . error ( " Couldn't write booklet text to file! " , e ) ;
2016-02-01 20:39:11 +01:00
}
}
}
2015-02-20 22:45:33 +01:00
@Override
2015-08-30 19:10:10 +02:00
public void preInit ( FMLPreInitializationEvent event ) {
2015-07-01 21:32:48 +02:00
ModUtil . LOGGER . info ( " PreInitializing ClientProxy... " ) ;
2015-06-15 22:06:07 +02:00
2015-10-24 12:18:42 +02:00
if ( ConfigBoolValues . ENABLE_SEASONAL . isEnabled ( ) ) {
Calendar c = Calendar . getInstance ( ) ;
pumpkinBlurPumpkinBlur = c . get ( Calendar . MONTH ) = = Calendar . OCTOBER ;
jingleAllTheWay = c . get ( Calendar . MONTH ) = = Calendar . DECEMBER & & c . get ( Calendar . DAY_OF_MONTH ) > = 6 & & c . get ( Calendar . DAY_OF_MONTH ) < = 26 ;
2016-05-10 18:48:35 +02:00
bulletForMyValentine = c . get ( Calendar . MONTH ) = = Calendar . FEBRUARY & & c . get ( Calendar . DAY_OF_MONTH ) > = 12 & & c . get ( Calendar . DAY_OF_MONTH ) < = 16 ;
2015-10-24 12:18:42 +02:00
}
else {
ModUtil . LOGGER . warn ( " You have turned Seasonal Mode off. Therefore, you are evil. " ) ;
}
2015-10-18 19:56:18 +02:00
2016-05-26 22:49:47 +02:00
for ( Map . Entry < ItemStack , ModelResourceLocation > entry : MODEL_LOCATIONS_FOR_REGISTERING . entrySet ( ) ) {
2016-05-03 18:29:02 +02:00
ModelLoader . setCustomModelResourceLocation ( entry . getKey ( ) . getItem ( ) , entry . getKey ( ) . getItemDamage ( ) , entry . getValue ( ) ) ;
2016-03-19 15:10:20 +01:00
}
2016-01-29 17:38:31 +01:00
this . registerCustomFluidBlockRenderer ( InitFluids . fluidCanolaOil ) ;
this . registerCustomFluidBlockRenderer ( InitFluids . fluidOil ) ;
2016-01-16 23:14:10 +01:00
IResourceManager manager = Minecraft . getMinecraft ( ) . getResourceManager ( ) ;
if ( manager instanceof IReloadableResourceManager ) {
( ( IReloadableResourceManager ) manager ) . registerReloadListener ( new IResourceManagerReloadListener ( ) {
@Override
2016-05-29 23:49:35 +02:00
public void onResourceManagerReload ( IResourceManager resourceManager ) {
2016-01-16 23:14:10 +01:00
countBookletWords ( ) ;
}
} ) ;
}
2016-01-10 01:17:17 +01:00
}
/ * *
* ( Excerpted from Tinkers ' Construct with permission , thanks guys ! )
* /
private void registerCustomFluidBlockRenderer ( Fluid fluid ) {
Block block = fluid . getBlock ( ) ;
Item item = Item . getItemFromBlock ( block ) ;
FluidStateMapper mapper = new FluidStateMapper ( fluid ) ;
ModelLoader . registerItemVariants ( item ) ;
ModelLoader . setCustomMeshDefinition ( item , mapper ) ;
ModelLoader . setCustomStateMapper ( block , mapper ) ;
2014-12-03 21:55:53 +01:00
}
2015-02-20 22:45:33 +01:00
@Override
2015-08-30 19:10:10 +02:00
public void init ( FMLInitializationEvent event ) {
2015-07-01 21:32:48 +02:00
ModUtil . LOGGER . info ( " Initializing ClientProxy... " ) ;
2015-03-30 18:42:14 +02:00
2016-07-03 20:57:00 +02:00
new ClientEvents ( ) ;
2015-09-02 20:06:34 +02:00
2016-02-20 15:23:03 +01:00
ClientRegistry . bindTileEntitySpecialRenderer ( TileEntityCompost . class , new RenderCompost ( ) ) ;
2016-02-17 21:45:19 +01:00
ClientRegistry . bindTileEntitySpecialRenderer ( TileEntityAtomicReconstructor . class , new RenderReconstructorLens ( ) ) ;
ClientRegistry . bindTileEntitySpecialRenderer ( TileEntitySmileyCloud . class , new RenderSmileyCloud ( ) ) ;
2016-06-06 21:27:09 +02:00
ClientRegistry . bindTileEntitySpecialRenderer ( TileEntityDisplayStand . class , new RenderDisplayStand ( ) ) ;
2016-02-17 21:45:19 +01:00
2016-06-17 23:50:38 +02:00
//VillagerRegistry.INSTANCE().registerVillagerSkin(ConfigIntValues.JAM_VILLAGER_ID.getValue(), new ResourceLocation(ModUtil.MOD_ID, "textures/entity/villager/jamVillager.png"));
2016-01-08 16:52:53 +01:00
2016-05-26 22:49:47 +02:00
for ( Item item : COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING ) {
2016-03-19 15:10:20 +01:00
if ( item instanceof IColorProvidingItem ) {
Minecraft . getMinecraft ( ) . getItemColors ( ) . registerItemColorHandler ( ( ( IColorProvidingItem ) item ) . getColor ( ) , item ) ;
}
2016-01-08 16:52:53 +01:00
}
2014-12-03 21:55:53 +01:00
}
2015-02-20 22:45:33 +01:00
@Override
2015-08-30 19:10:10 +02:00
public void postInit ( FMLPostInitializationEvent event ) {
2015-07-01 21:32:48 +02:00
ModUtil . LOGGER . info ( " PostInitializing ClientProxy... " ) ;
2015-11-02 22:37:44 +01:00
2016-07-03 20:57:00 +02:00
new SpecialRenderInit ( ) ;
2014-12-03 21:55:53 +01:00
}
2015-11-13 18:56:15 +01:00
2016-01-08 20:51:03 +01:00
@Override
2016-06-01 00:37:28 +02:00
public void addRenderRegister ( ItemStack stack , ResourceLocation location , String variant ) {
MODEL_LOCATIONS_FOR_REGISTERING . put ( stack , new ModelResourceLocation ( location , variant ) ) ;
2016-01-08 20:51:03 +01:00
}
2016-03-19 15:10:20 +01:00
@Override
public void addColoredItem ( Item item ) {
2016-05-26 22:49:47 +02:00
COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING . add ( item ) ;
2016-03-19 15:10:20 +01:00
}
2014-12-03 21:55:53 +01:00
}