Files
TAIGA-OV/src/main/java/com/sosnitzka/taiga/proxy/ClientProxy.java
Giovanni Harting 826ab1cf3a [1.2] Material rework (#60)
* Developement tests for nbt data in traits

* Lot of trait changes and better balancing

* Traits reworked a bit, new traits added.

* First correction of NBT Data in Trait (Soulbound). Is shown twice. Still needs corrections.

* Few fixes in traits and new trait "catcher"

* Small fix, needs workaround

* fixed some catch issues

* Fixed Catcher and Reviving Traits, new Trait: Souleater. Updated build.gradle for new TiC Version.

* Splitted SoulEater to get the bad touch to an extra trait "Cursed". Added method for using nbt more easily. Changed declaration names of fluids

* Some minor changes in Traits, Registry and Utils.

* Iron_nugget is replaced with oreDict Item when not loaded via TAIGA.

* Beginning of new material  integration. Lot of names changed, lot more work to do here. Many null pointer exceptions and no changes of values up to now.

* Some Small changes in names, registry and recipes

* Some weird stuff I don't remember :D

* fixed some things I missed while merging

* Rollback to something

* More Stuff

* fixed some merging stuff

* Fixed some misspelled names. Actually working with lots of restrictions.

* Rearranged alloys, tried to add blocks / ingots for non-tinker-materials, but they won't work.

* Again tried to fix the melting issue, but non-tinker materials still are not able to be casted as a block, ingot or nugget...

* Fixed integration of materials without tools.

* changed IMC to direct lib calls

* removed more IMC, removed redundant code

* some reformatting

* Alloy integration reworked, needs to be balanced.

* updated deps, renamed some func's, added duplicate material check

* some more renaming

* some reformatting, fixed wrong import, fixed string cmp's

* Added images for blocks, ingots, nuggets and dust. Json changes do not work yet.

* some reformatting

* Removed old json files. Placeholder needed.

* Fixed block json, items not working yet.

* Fixed my own derp (missing json files)

* Reduced materials to ensure unique traits for most of them. Still 30 though, but reduced by 20 more :'( RIP

* Changed some generator stuff, not working properly right now!

* rewrote offset generation, added some debug command, fixed some stuff

* fixed on-surface-generation, made dependencies more flexible

* reverted gen-weight back to its normal value

* Meteor generator implemented.

* fixed generating on ground

* optimized a thing

* Replaced Uru with Osram, replaced Meteorite with Uru, added Meteorite again for Hull-Material and late game alloy.

* Some changes in generation of ores, not ready yet.

* Added Cobble Meteorite. Added debug command. Implemented rest of ore generation. Some minor fixes left for generation including balancing.

* Some changes for ore generation. Added 2 separate Generic Blocks for meteorite and their cobble variant.

* some cleanup in Generator class, added meteor world save handler

* Added Textures. Added blockstates and item models. Fixed fluid rendering.

* renamed world save data file to be little more specific, removed a unused method

* some preps for the upcoming release

* First attempt of well balancing material stats. Renamed TiberiumX to Triberium.

* Final changes... ready for beta testing

* Added missing alloys.

* Corrected balancing of ore generation. Still WIP

* removed some last debug out

* one last reformat
2016-12-05 20:34:02 +01:00

150 lines
6.1 KiB
Java

package com.sosnitzka.taiga.proxy;
import com.sosnitzka.taiga.Blocks;
import com.sosnitzka.taiga.Items;
import com.sosnitzka.taiga.TAIGA;
import com.sosnitzka.taiga.TAIGAConfiguration;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fluids.Fluid;
import slimeknights.tconstruct.library.client.MaterialRenderInfo;
import slimeknights.tconstruct.library.client.texture.MetalTextureTexture;
import slimeknights.tconstruct.library.materials.Material;
import javax.annotation.Nonnull;
import java.lang.reflect.Field;
import static com.sosnitzka.taiga.Fluids.*;
import static com.sosnitzka.taiga.MaterialTraits.*;
@SuppressWarnings("unused")
public class ClientProxy extends CommonProxy {
private static void registerBlockModel(Block block) {
registerItemModel(Item.getItemFromBlock(block));
}
private static void registerItemModel(Item item) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}
@Override
public void registerModels() {
Field[] itemFields = Items.class.getDeclaredFields();
for (Field field : itemFields) {
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
Class<?> targetType = field.getType();
try {
Item item = (Item) field.get(targetType);
registerItemModel(item);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
Field[] blockFields = Blocks.class.getDeclaredFields();
for (Field field : blockFields) {
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
Class<?> targetType = field.getType();
try {
Block block = (Block) field.get(targetType);
registerBlockModel(block);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
public void setRenderInfo(final Material material) {
if (material.equals(adamant)) metalRender(material, adamantFluid.getColor(), 1f, 0.8f, 0f);
else if (material.equals(duranite)) metalRender(material, duraniteFluid.getColor(), .4f, .4f, 0);
else if (material.equals(tiberium)) metalRender(material, tiberiumFluid.getColor(), 1f, .3f, 0f);
else if (material.equals(palladium)) metalRender(material, palladiumFluid.getColor(), .7f, .6f, 0f);
else if (material.equals(osram)) metalRender(material, osramFluid.getColor(), .7f, .6f, 0f);
else if (material.equals(tritonite)) metalRender(material, tritoniteFluid.getColor(), .3f, .3f, 0f);
else if (material.equals(nucleum)) metalRender(material, nucleumFluid.getColor(), .4f, .6f, .2f);
else if (material.equals(triberium)) metalRender(material, triberiumFluid.getColor(), 2f, 2f, 0.5f);
else if (material.equals(solarium)) metalRender(material, solariumFluid.getColor(), 1.5f, 1.5f, 0.5f);
else if (material.equals(uru)) metalRender(material, uruFluid.getColor(), 1.0f, 1.0f, 0.3f);
else if (material.equals(imperomite)) metalRender(material, imperomiteFluid.getColor(), 0.4f, 1.0f, 0.7f);
else if (material.equals(vibranium)) metalRender(material, vibraniumFluid.getColor(), 0.6f, .8f, 1f);
else if (material.equals(valyrium)) metalRender(material, valyriumFluid.getColor(), .8f, 1.5f, -0.1f);
else {
material.setRenderInfo(new MaterialRenderInfo.BlockTexture("taiga:blocks/block/" + material.getIdentifier()));
}
}
private void metalRender(final Material material, final int f, final float shine, final float brightness, final float hueshift) {
material.setRenderInfo(new MaterialRenderInfo.AbstractMaterialRenderInfo() {
@Override
public TextureAtlasSprite getTexture(TextureAtlasSprite baseTexture, String location) {
return new MetalTextureTexture("taiga:materials/" + material.getIdentifier(), baseTexture, location, f, shine, brightness, hueshift);
}
});
}
@Override
public void registerFluidModels(Fluid fluid) {
if (fluid == null) {
return;
}
Block block = fluid.getBlock();
if (block != null) {
Item item = Item.getItemFromBlock(block);
FluidStateMapper mapper = new FluidStateMapper(fluid);
// item-model
if (item != null) {
ModelLoader.registerItemVariants(item);
ModelLoader.setCustomMeshDefinition(item, mapper);
}
// block-model
ModelLoader.setCustomStateMapper(block, mapper);
}
}
@Override
public void initConfig() {
super.initConfig();
TAIGAConfiguration.clientPreInit();
}
public static class FluidStateMapper extends StateMapperBase implements ItemMeshDefinition {
public final Fluid fluid;
public final ModelResourceLocation location;
public FluidStateMapper(Fluid fluid) {
this.fluid = fluid;
// have each block hold its fluid per nbt? hm
this.location = new ModelResourceLocation(new ResourceLocation(TAIGA.MODID, "fluid_block"), fluid.getName());
}
@Nonnull
@Override
protected ModelResourceLocation getModelResourceLocation(@Nonnull IBlockState state) {
return location;
}
@Nonnull
@Override
public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack) {
return location;
}
}
}