Fluid rendering, no more wasted block states

This commit is contained in:
modmuss50 2015-12-05 19:37:42 +00:00
parent 60d7b63d5b
commit 20af49394f
10 changed files with 64 additions and 22 deletions

View file

@ -361,22 +361,19 @@ public abstract class BlockMachineBase extends BaseTileBlock implements IBlockTe
@Override
public IBlockState getStateFromMeta(int meta) {
boolean active = false;
if(meta > 6){
active = true;
meta =- 6;
}
int facingInt = meta;
EnumFacing facing = EnumFacing.getFront(facingInt);
if(facing == EnumFacing.DOWN || facing == EnumFacing.UP){
facing = EnumFacing.NORTH;
if(facingInt > 3){
active = true;
facingInt = facingInt - 3;
}
EnumFacing facing = getSideFromint(facingInt);
return this.getDefaultState().withProperty(FACING, facing).withProperty(ACTIVE, active);
}
@Override
public int getMetaFromState(IBlockState state) {
int facingInt = state.getValue(FACING).getIndex();
int activeInt = state.getValue(ACTIVE) ? 0 : 6;
int facingInt = getSideFromEnum(state.getValue(FACING));
int activeInt = state.getValue(ACTIVE) ? 0 : 3;
return facingInt + activeInt;
}
@ -396,8 +393,35 @@ public abstract class BlockMachineBase extends BaseTileBlock implements IBlockTe
public void setActive(Boolean active, World world, BlockPos pos){
world.setBlockState(pos, world.getBlockState(pos).withProperty(ACTIVE, active));
}
@Override
public int amoutOfVariants() {
return 12; //six for Facing, and then 2 for eatch of them for if active
public int amountOfVariants() {
return 8; //0-3 off nsew, 4-8 on nsew
}
public EnumFacing getSideFromint(int i){
if(i == 0){
return EnumFacing.NORTH;
} else if(i == 1){
return EnumFacing.SOUTH;
}else if(i == 2){
return EnumFacing.EAST;
}else if(i == 3){
return EnumFacing.WEST;
}
return EnumFacing.NORTH;
}
public int getSideFromEnum(EnumFacing facing){
if(facing == EnumFacing.NORTH){
return 0;
} else if(facing == EnumFacing.SOUTH){
return 1;
}else if(facing == EnumFacing.EAST){
return 2;
}else if(facing == EnumFacing.WEST){
return 3;
}
return 0;
}
}

View file

@ -105,7 +105,7 @@ public class BlockMachineCasing extends BlockMultiblockBase implements IBlockTex
}
@Override
public int amoutOfVariants() {
public int amountOfVariants() {
return types.length;
}
}

View file

@ -63,7 +63,7 @@ public class BlockMachineFrame extends BaseBlock implements IBlockTextureProvide
}
@Override
public int amoutOfVariants() {
public int amountOfVariants() {
return types.length;
}
@ -79,7 +79,7 @@ public class BlockMachineFrame extends BaseBlock implements IBlockTextureProvide
protected BlockState createBlockState() {
METADATA = PropertyInteger.create("Type", 0, types.length);
METADATA = PropertyInteger.create("Type", 0, types.length -1);
return new BlockState(this, METADATA);
}
}

View file

@ -158,7 +158,7 @@ public class BlockOre extends BaseBlock implements IBlockTextureProvider {
}
@Override
public int amoutOfVariants() {
public int amountOfVariants() {
return types.length;
}

View file

@ -128,7 +128,7 @@ public class BlockPlayerDetector extends BaseTileBlock implements IBlockTextureP
}
@Override
public int amoutOfVariants() {
public int amountOfVariants() {
return types.length;
}
@ -144,7 +144,7 @@ public class BlockPlayerDetector extends BaseTileBlock implements IBlockTextureP
protected BlockState createBlockState() {
METADATA = PropertyInteger.create("Type", 0, types.length);
METADATA = PropertyInteger.create("Type", 0, types.length -1);
return new BlockState(this, METADATA);
}
}

View file

@ -73,7 +73,7 @@ public class BlockStorage extends BaseBlock implements IBlockTextureProvider {
}
@Override
public int amoutOfVariants() {
public int amountOfVariants() {
return types.length;
}
@ -89,7 +89,7 @@ public class BlockStorage extends BaseBlock implements IBlockTextureProvider {
protected BlockState createBlockState() {
METADATA = PropertyInteger.create("Type", 0, types.length);
METADATA = PropertyInteger.create("Type", 0, types.length -1);
return new BlockState(this, METADATA);
}
}

View file

@ -71,7 +71,7 @@ public class BlockStorage2 extends BaseBlock implements IBlockTextureProvider {
}
@Override
public int amoutOfVariants() {
public int amountOfVariants() {
return types.length;
}
@ -87,7 +87,7 @@ public class BlockStorage2 extends BaseBlock implements IBlockTextureProvider {
protected BlockState createBlockState() {
METADATA = PropertyInteger.create("Type", 0, types.length);
METADATA = PropertyInteger.create("Type", 0, types.length -1);
return new BlockState(this, METADATA);
}
}

View file

@ -6,6 +6,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidClassic;
import net.minecraftforge.fluids.Fluid;
import reborncore.api.TextureRegistry;
import techreborn.client.TechRebornCreativeTabMisc;
public class BlockFluidBase extends BlockFluidClassic {
@ -13,6 +14,7 @@ public class BlockFluidBase extends BlockFluidClassic {
public BlockFluidBase(Fluid fluid, Material material) {
super(fluid, material);
setCreativeTab(TechRebornCreativeTabMisc.instance);
TextureRegistry.registerFluid(this);
}

View file

@ -2,12 +2,20 @@ package techreborn.blocks.fluid;
import net.minecraft.block.material.Material;
import net.minecraftforge.fluids.Fluid;
import reborncore.api.IFluidTextureProvider;
public class BlockFluidTechReborn extends BlockFluidBase {
public class BlockFluidTechReborn extends BlockFluidBase implements IFluidTextureProvider {
String name;
public BlockFluidTechReborn(Fluid fluid, Material material, String name) {
super(fluid, material);
setUnlocalizedName(name);
this.name = name;
}
@Override
public String getTextureName() {
return "techreborn:blocks/fluids/" + name.replaceAll("techreborn.", "") + "_flowing";
}
}

View file

@ -1,6 +1,9 @@
package techreborn.items;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import reborncore.api.IItemTexture;
import techreborn.lib.ModInfo;
@ -9,4 +12,9 @@ public abstract class ItemTextureBase extends ItemTR implements IItemTexture {
public String getModID() {
return ModInfo.MOD_ID;
}
@Override
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining) {
return new ModelResourceLocation(ModInfo.MOD_ID + ":" + stack.getItem().getUnlocalizedName(stack).substring(5), "inventory");
}
}