I have attempted to update my mod to 1.10 from 1.7.10 however I cannot get textures to render in-game for my items (I haven't attempted to work on blocks yet). Most tutorials I have found only update to 1.8. I have been out of the loop community wise due to things in real life and was wondering if anyone could possibly point me in the right direction on getting item/block textures to render?
A question about how to update from 1.7.10 to 1.10.2 has been asked on the Forge forum last month - take a look here.
A post from Ernio in that thread pretty accurately sums up my initial response to you:
However pessimistic that might sound, if your mod is simple and you're only having problems with texture rendering then it shouldn't be too difficult. I would suggest cloning my Generic-Modrepository and seeing how I did it there. The mod is small and focused completely on being lightweight and instructional, which means that it only contains blocks of code needed to teach you the basics.
By Forge convention, Items and Blocks should be registered in CommonProxy. Before registration, initialize them in a similar manner like Minecraft does it; in an init package (example: ModItems). After you've initialized and registered your Items and Blocks, it's time to register their model files. The model files provide simple instructions on how to render the object. Conventionally this is done in ClientProxy (client-side only) with ModelLoader.setCustomModelResourceLocation. You can also use getRenderItem().getItemModeMesher().register to do the same thing, but this is generally discouraged these days (find out why here).
After you register your model files, Forge will look for them in /src/main/resources/assets/modid/models/item, so you need to keep all your model files in there, as can be seen here. Your textures should typically be located in /src/main/resources/assets/modid/textures/items, but do not need to follow that convention since model files are the ones who are telling Forge their location, and we create model files. Take a look at json files provided in the last link to see how to see examples of properly structured model files.
That's all I can think of for now, let me know if you need any more assistance.
Thank you so much! Have events and registering them changed much since 1.7.10? If so, how? What about ore generation?
EDIT:
I was able to load the item textures thanks to your assistance and example. Thank you!
Yes, that's exactly what I meant. Conventionally you should register them in your base mod class, and it doesn't really matter if it's in Init, preInit or postInit, as long as you register them before the registry events fire. Recently I've learned that if your custom event handler class contains only static methods and fields you can place a @Mod.EventBusSubscriber annotation above it to have it automatically subscribed to the Forge event bus at mod construction time (before preInit and registry events are fired), in which case you do need to register it with EVENT_BUS.
I attempted to add this event back in however ForgeDirection appears to no longer be a thing?
public class BlockEventHandler {
private Random random = new Random();
@SubscribeEvent
public void onBlockLeftClicked(PlayerInteractEvent event) {
Random rand = new Random();
if (event.action != PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) return;
ItemStack heldItem = event.entityPlayer.getHeldItem();
Block block = event.world.getBlock(event.x, event.y, event.z);
// If the block clicked was Stone, the player was holding an Iron Pickaxe and a random integer from 0 (inclusive) to 2 (exclusive) is 0 (50% chance)
if (block == Blocks.stone && heldItem != null && heldItem.getItem() == Items.iron_pickaxe && random.nextInt(1) == 0) {
ForgeDirection direction = ForgeDirection.getOrientation(event.face); // Convert the numeric face to a ForgeDirection
int fireX = event.x + direction.offsetX, fireY = event.y + direction.offsetY, fireZ = event.z + direction.offsetZ; // Offset the block's coordinates according to the direction
if (event.world.isAirBlock(fireX, fireY, fireZ)) { // If the block at the new coordinates is Air
int var = rand.nextInt(9);
if (var == 0) {
event.world.setBlock(fireX, fireY, fireZ, Blocks.fire); // Replace it with Fire
event.useBlock = Event.Result.DENY; // Prevent the Fire from being extinguished (also prevents Block#onBlockClicked from being called)
}
}
}
}
}
Also, does event.block no longer exist or?
public void onBlockBreak(BlockEvent.BreakEvent event)
{
Random rand = new Random();
if(event.block == Blocks.stone)
{// rest of code
I've also tried to list some of the changes that I've encountered that required for some common upgrades and this might give you enough idea to get you going. Note that if you're trying to go from 1.7.10 to 1.10.2 in one conversion you will need to look at both of the following:
I've also tried to list some of the changes that I've encountered that required for some common upgrades and this might give you enough idea to get you going. Note that if you're trying to go from 1.7.10 to 1.10.2 in one conversion you will need to look at both of the following:
Yes, that's exactly what I meant. Conventionally you should register them in your base mod class, and it doesn't really matter if it's in Init, preInit or postInit, as long as you register them before the registry events fire. Recently I've learned that if your custom event handler class contains only static methods and fields you can place a @Mod.EventBusSubscriber annotation above it to have it automatically subscribed to the Forge event bus at mod construction time (before preInit and registry events are fired), in which case you do need to register it with EVENT_BUS.
Do you know what event.block and event.getWorld().setBlock() were replaced by? I am attempting to update the BlockEvent.BreakEvent. @yooski
It's still there, located in the "net.minecraftforge.event.world" package.
To find which block is occupying a certain block position, you have to call World#getBlockState(BlockPos).getBlock(), and to get the block that's being broken from the BreakEvent, just call event.getState().getBlock().
On a side note, you could call event.getWorld().getBlockState(event.getPos()).getBlock() from the BreakEvent, but you would be taking the long road, because that event already has a BlockState getter for your convenience.
You should also bear in mind that you should only use events when absolutely necessary. Most events get called on both server and client side and some of them do so twice per side, that's an unnecessary performance hit. So if there is a way of dealing with whatever you are trying to accomplish without using events, you should try to find it.
Thank you for the help on that. What has event.getWorld().setBlock been replaced with?
And as for the performance, the mod I am updating contains a few events that are called at random. In this case, it is called at random so long as the block broken is stone (basically, full code is executed on average about 10% of the time) and replaced it with lava as a 'random event' of sorts.
Thank you!
Do you know what replaced event.action and ForgeDirection? Is ForgeDirection replaced by getPos()?
My goal with this handler is that if a player strikes stone with an iron pickaxe it has a chance of putting fire on top of the block hit. I know now how to replace the block but not to offset it above the current one.
@SubscribeEvent
public void onBlockLeftClicked(PlayerInteractEvent event) {
Random rand = new Random();
if (event.action != PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) return;
ItemStack heldItem = event.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND);
//Block block = event.getWorld().getBlock(event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
IBlockState block = event.getWorld().getBlockState(event.getPos());
// If the block clicked was Stone, the player was holding an Iron Pickaxe and a random integer from 0 (inclusive) to 2 (exclusive) is 0 (50% chance)
if (block == Blocks.STONE && heldItem != null && heldItem.getItem() == Items.IRON_PICKAXE && random.nextInt(1) == 0) {
ForgeDirection direction = ForgeDirection.getOrientation(event.face); // Convert the numeric face to a ForgeDirection
int fireX = event.x + direction.offsetX, fireY = event.y + direction.offsetY, fireZ = event.z + direction.offsetZ; // Offset the block's coordinates according to the direction
if (event.world.isAirBlock(fireX, fireY, fireZ)) { // If the block at the new coordinates is Air
int var = rand.nextInt(9);
if (var == 0) {
event.world.setBlock(fireX, fireY, fireZ, Blocks.fire); // Replace it with Fire
event.use = Event.Result.DENY; // Prevent the Fire from being extinguished (also prevents Block#onBlockClicked from being called)
}
}
}
}
Sorry for being absent the last few days, had lots of things to do. I've taken a look at your code and updated it to 1.10 standards, enjoy your new Iron Pickaxe of Inferno. I don't know about ForgeDirection, but x,y,z co-ordinates in world are represented by the BlockPos class and most objects in world have a getPos() getter for convenience sake.
Thank you for the code however I could not help but notice that it does not work? For testing purposes I set shouldSetOnFire to be true so it would light on fire every time however nothing happens? Even before I changed it one bit and I was testing I could not help but notice that no matter how many times I hit a stone block with an iron pickaxe, it never caught fire (what the mod is supposed to do). I did indeed register it in the main registery's preInit with the line
Oops, I didn't specify the exact event as PlayerInteractEvent.LeftClickBlock, it was declared as just plain PlayerInteractEvent. My mistake, I apologize for that as it was a really silly mistake. I've tested it again and the code should perform fine now. Link to the pickaxe in case you forgot where it is - here.
Thank you! That worked. Turns out the method header also couldn't have static in it, had to be
@SubscribeEvent
public void onBlockLeftClicked(PlayerInteractEvent.LeftClickBlock event)
I have attempted to update my mod to 1.10 from 1.7.10 however I cannot get textures to render in-game for my items (I haven't attempted to work on blocks yet). Most tutorials I have found only update to 1.8. I have been out of the loop community wise due to things in real life and was wondering if anyone could possibly point me in the right direction on getting item/block textures to render?
Thanks!
Thank you so much! Have events and registering them changed much since 1.7.10? If so, how? What about ore generation?
EDIT:
I was able to load the item textures thanks to your assistance and example. Thank you!
I noted from your linked example to append @Mod. to annotations and did that as well.
As for event handlers, do you mean (forgive if it is pseudo code, not currently at PC)?
MinecraftForge.EVENT_BUS.register(new EventHandler());
Also, would it be registered in preInit of the main mod file or CommonProxy like items and blocks?
Thank you so much for your help so far.
I attempted to add this event back in however ForgeDirection appears to no longer be a thing?
Also, does event.block no longer exist or?
For other tips on updating your mod you might want to check out my tutorials here:
General practices for converting which I explain in Jabelar's Updating Your Mod tutorial.
I've also tried to list some of the changes that I've encountered that required for some common upgrades and this might give you enough idea to get you going. Note that if you're trying to go from 1.7.10 to 1.10.2 in one conversion you will need to look at both of the following:
Do you know what event.block and event.getWorld().setBlock() were replaced by? I am attempting to update the BlockEvent.BreakEvent. @yooski
Thank you for the help on that. What has event.getWorld().setBlock been replaced with?
And as for the performance, the mod I am updating contains a few events that are called at random. In this case, it is called at random so long as the block broken is stone (basically, full code is executed on average about 10% of the time) and replaced it with lava as a 'random event' of sorts.
Thank you for your advice on that however.
Thank you!
Do you know what replaced event.action and ForgeDirection? Is ForgeDirection replaced by getPos()?
My goal with this handler is that if a player strikes stone with an iron pickaxe it has a chance of putting fire on top of the block hit. I know now how to replace the block but not to offset it above the current one.
Thank you for the code however I could not help but notice that it does not work? For testing purposes I set shouldSetOnFire to be true so it would light on fire every time however nothing happens? Even before I changed it one bit and I was testing I could not help but notice that no matter how many times I hit a stone block with an iron pickaxe, it never caught fire (what the mod is supposed to do). I did indeed register it in the main registery's preInit with the line .
Any ideas?
Thank you! That worked. Turns out the method header also couldn't have static in it, had to be