Jump to content

Recommended Posts

Posted (edited)

 

hi,

I am a beginner in creating mods. I have used this tutorial for the first steps:
https://shadowfacts.net/tutorials/forge-modding-1102/

 

It woked very well now I want to go the next step. While i want to create a litte street mod for my group of players. Therefor I have to rotate the top texture depending on the side from which the player places it. (North default, East +90°, South +180°, West +270°)

Here is my blogstate test file for a test block. the red texture has an arrow facing north. The testfile is working. How can I get the red texture to rotate?

 

{
    "forge_marker": 1,
    "defaults": {
        "textures": {
            "all": "mcaadditions:blocks/oreCopper",
            "up": "mcaadditions:blocks/red",
            "down": "mcaadditions:blocks/blue",
            "north": "mcaadditions:blocks/green",
            "east": "mcaadditions:blocks/orange",
            "south": "mcaadditions:blocks/black",
            "west": "mcaadditions:blocks/violet"
        }
    },
    "variants": {
        "normal": {
            "model": "cube_all"
        },
        "inventory": {
            "model": "cube_all"
        }
    }
}

 

Additional Questions:

1) is it better to rotate the whole block or only the top texture?

2) why have I to declare a "all" texture, otherwise when the block is destroyed the animation has no texture.

3) If there are several ways to reach the goal, which is best for forge dynmap rendering of blocks, so that the street arrows and lines are facing the right direction on the online map.

 

********************** EDITIED **********************

Quote

Answers:

1) rotate the block is the better option

2) forgot to add particles texture in blockstates. Its needed for the texture of the destruction animation

3) got no answer on this, will tell you when i found out if this is a dynmap compatible solution

**********************************************************

I hope some can help. Please keep in mind I am a beginner :D

2017-02-17_15.08.32.png

Edited by GregoriMarow
Posted

I wanted basically the same question answered a while ago. You may find it helpful to look here.

Posted

Basically, add a PropertyFacing property to your block, make your blockstate have states for each facing value, and in each you would rotate it using a "y" value (an angle) in each blockstate when it is facing a certain way. Also, make it point to a model called "orientable" instead of "cube_all". Hope this helps.

Posted (edited)

Well it helps partitally.

If you are an absolute beginner and you even get crazy when reading the forge documentation thats not so easy.

To imagine on what state I am, before I started the first tutorial I used MCreator :$

That was usable for easy things (currency mod) until the block rotation was needed.

I will try it step by step.

I have three classes: BlockBase, ModBlocks, BlockStreet:

Block Base:

package mcaddicts.modpack.blocks.example;

import mcaddicts.modpack.McaAdditionsMod;
import mcaddicts.modpack.item.ItemModelProvider;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;

public class BlockBase extends Block implements ItemModelProvider{

	protected String name;
	
	public BlockBase(Material materialIn, String name) {
		super(materialIn);
		this.name = name;
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(McaAdditionsMod.creativeTab);
	}
	
	@Override
	public void registerItemModel(Item itemBlock) {
		McaAdditionsMod.proxy.registerItemRenderer(itemBlock, 0, name);
		
	}
	
	 @Override
	 public BlockBase setCreativeTab(CreativeTabs tab) {
		 super.setCreativeTab(tab);
		 return this;
	 }

	
}

 

ModBlocks:

package mcaddicts.modpack.blocks.example;

import mcaddicts.modpack.item.ItemModelProvider;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ModBlocks {

public static BlockOre oreCopper;
public static BlockStreet streetTest;

 public static void init() {
	 oreCopper = register(new BlockOre("oreCopper"));
	 streetTest = register(new BlockStreet("streetTest"));

 }
 

 private static <T extends Block> T register (T block, ItemBlock itemBlock) {
 
 GameRegistry.register(block);
 if(itemBlock != null) {
 GameRegistry.register(itemBlock);
 }
 
 if(block instanceof ItemModelProvider) {
 ((ItemModelProvider)block).registerItemModel(itemBlock);
 }
 
 return block;
 }
 
 private static <T extends Block> T register(T block) {
 ItemBlock itemBlock = new ItemBlock(block);
 itemBlock.setRegistryName(block.getRegistryName());
 return register(block, itemBlock);
 }
}

 

BlockStreet:

package mcaddicts.modpack.blocks.example;

import mcaddicts.modpack.McaAdditionsMod;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;


public class BlockStreet extends BlockBase {
	
public static final PropertyDirection FACING = BlockHorizontal.FACING;

 public BlockStreet(String name) {
 super(Material.ROCK, name);
 
 setHardness(3f);
 setResistance(5f);
 this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
 }
 
 @Override
 public BlockStreet setCreativeTab(CreativeTabs tab) {
 super.setCreativeTab(tab);
 return this;
 }
 
 @Override
 public BlockStateContainer createBlockState() {
     return new BlockStateContainer(this, FACING);
 }
 
 @Override
 public int getMetaFromState(IBlockState state) {
     return 0;
 }

 @Override
 public IBlockState getStateFromMeta(int meta) {
     return getDefaultState();
 }

 
 @Override
 public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack) {
     EnumFacing entityFacing = entity.getHorizontalFacing();

     if(!world.isRemote) {
         if(entityFacing == EnumFacing.NORTH) {
             entityFacing = EnumFacing.SOUTH;
         } else if(entityFacing == EnumFacing.EAST) {
             entityFacing = EnumFacing.WEST;
         } else if(entityFacing == EnumFacing.SOUTH) {
             entityFacing = EnumFacing.NORTH;
         } else if(entityFacing == EnumFacing.WEST) {
             entityFacing = EnumFacing.EAST;
         }

         world.setBlockState(pos, state.withProperty(FACING, entityFacing), 2);
     }
 }

}

 

In the last ones i put your overrides.  Have I missed anything?

The Blockstates file is a another thing, i dont even have tryed to modify it because I think the class file should work correct. Okay when I start the game i didnt get a crash and i have a untextured block. Not the worst result possible.

Animefan8888 wrote befor your last post:

 

Quote

You need to Override Block#getStateFromMeta and Block#getMetaFromState

 

You have not updated your code until that so i dont know what to do. I think this is definitely missing in the class file

Edited by GregoriMarow
Posted

For meta/state conversion, here's an example.

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/ores/block/BlockMillstone.java#L53-L61

Note that I'm using a custom enum property in place of BlockDirectional.FACING for my specific purpose.

 

Two-property example

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/ores/block/BlockAxel.java#L65-L77

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • 2 weeks later...
Posted (edited)

okay sry i dont get it.

It take me a lot of time to get it to work, but the state is not saved. When i leave the map it resets to default.

Can you please look at the code in my own posting above this here? What exactly is missing?

By the way this is my blockstates file:

{
"forge_marker": 1,
    "defaults": {
        "textures": {
            "up": "mcaadditions:blocks/red",
            "down": "mcaadditions:blocks/blue",
            "north": "mcaadditions:blocks/green",
            "east": "mcaadditions:blocks/orange",
            "south": "mcaadditions:blocks/black",
            "west": "mcaadditions:blocks/violet",
            "particle": "mcaadditions:blocks/red"
                }
          },
  "variants": {
    "normal": {
      "model": "orientable"
    },
    "inventory": {
      "model": "orientable"
    },
    "facing=north": {
      "model": "orientable"
    },
    "facing=east": {
      "model": "orientable",
      "y": 90
    },
    "facing=south": {
      "model": "orientable",
      "y": 180
    },
    "facing=west": {
      "model": "orientable",
      "y": 270
    }
    
  }
}

 

before.png

after.png

Edited by GregoriMarow
Posted

Did you pass the correct values to getMetafromState() and getStateFromMeta() ?

If you have still set it to "0" and "getDefaultState()" it won't save anything.

 

Draco18s explained it in a good example.

Posted (edited)

Nope did not pass the correct values, found the passage you mean.  But can not transform it to my use.  MILL_ORIENTATION and MillstoneOrientation, where is this defined why a separated class? Did it need it? I even dont understand what it did exactly. I assume one is reading meta data from block, and the other is writing meta data to block. But how can i rewrite it to my use?

When I understand it correct I have to write the facing direction in the meta data or read it from meta data? correct? but how?

 

Normally I learn new things with good commented code. With this examples I can not track the steps. :(

getMetaFromState:

//My code:
@Override
 public int getMetaFromState(IBlockState state) {
     return 0;
 }


//Draco18s Code:
@Override
	public int getMetaFromState(IBlockState state) {
		return state.getValue(Props.MILL_ORIENTATION).getOrdinal();
}

 

getStateFromMeta:

//My Code:
 @Override
 public IBlockState getStateFromMeta(int meta) {
     return getDefaultState();
 }

//Draco18s Code:
@Override
	public IBlockState getStateFromMeta(int meta) {
		return this.getDefaultState().withProperty(Props.MILL_ORIENTATION, MillstoneOrientation.values()[meta]);
}

 

POSITION READOUT?

@Override
 public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack) {
     EnumFacing entityFacing = entity.getHorizontalFacing();

     if(!world.isRemote) {
         if(entityFacing == EnumFacing.NORTH) {
             entityFacing = EnumFacing.NORTH;
         } else if(entityFacing == EnumFacing.EAST) {
             entityFacing = EnumFacing.EAST;
         } else if(entityFacing == EnumFacing.SOUTH) {
             entityFacing = EnumFacing.SOUTH;
         } else if(entityFacing == EnumFacing.WEST) {
             entityFacing = EnumFacing.WEST;
         }

         world.setBlockState(pos, state.withProperty(FACING, entityFacing), 2);
     }
 }

 

Edited by GregoriMarow
Posted

And instead of defining blockstates like this:

  ...
"variants": { 
	"normal": { 
		"model": "orientable" 
	}, 
	"inventory": { 
		"model": "orientable" 
	}, 
	"facing=north": { 
		"model": "orientable" 
	}, 
	"facing=east": { 
		"model": "orientable", 
		"y": 90 
	}, "facing=south": { 
		"model": "orientable", 
		"y": 180 
	}, 
	"facing=west": { 
		"model": "orientable", 
		"y": 270 
	}
  ...

 

Define them like this:

https://github.com/WiseOwl5/RobotiCraft/blob/master/1.11/src/main/resources/assets/roboticraft/blockstates/steam_engine.json#L11-L35

Posted

THANK YOU SO MUCH, THAT WAS THE MISSING PART :x

 

Here the solution for others:

@Override
    public int getMetaFromState(IBlockState state) {
        return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
}


// AND

 @Override
    public IBlockState getStateFromMeta(int meta) {
        return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
}

 

Posted (edited)

YES: Arrow is placed in the direction i am looking to. Now i just have to rewrite some litte things. e.g. remove setCreativeTab from the Block Base java, because i want different tabs for arrows, lines, sidewalks and so on. I will try to breakdown all possible options to the block base. Maybe i could also use the rotation code there because all blocks need to have this option. then i have only to create a class for where the tab is set and each type of blocks is registred.

 

Thanks also for the optimized blockstates file, I will correct it.

Edited by GregoriMarow
Posted

okay one question was coming up during first real used blocks.

I have installed worldedit for forge and i can not rotate the blocks. Mark it //copy, then //rotate 90.

The Blocks still have the same metadata [north=2,east=3,south= 0,west= 1] for orientation (see picture, readout with info tool).

I rotated from north 90° to the right so normally it should change from 2 to 3.

Have I to declare anything in the code so that worldedit knows metadata 2 = north and so on?

 

2017-02-27_15.00.49.png

  • 2 weeks later...
Posted
On 2/27/2017 at 9:03 AM, GregoriMarow said:

Have I to declare anything in the code so that worldedit knows metadata 2 = north and so on

that's a question for the developer of WorldEdit.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.