Jump to content

Recommended Posts

Posted

When it comes to adding new block and items, there are plenty of guides and tutorials, but I'm having a really hard time finding out how to properly edit blocks and items from Vanilla Minecraft. I just found how to remove old recipes, because all my searches lead to tutorials for new blocks and items because of keywords.

 

Anyways, here's what I want to do next:

  • Change the icons of Iron tools and armour to something new, since I will be using those for Steel tools and armour.
  • Change old tools and armour to new toolMaterials and armorMaterials (which I have already added)
  • Change old blocks to different harvestLevels (I have added pickaxes with levels 4 and 5)
  • Change Obsidian to drop a certain quantity of items

 

I don't think these should be too difficult to actually code, I'm just having a real hard time searching for this specific information in the ocean of basic tutorials. If anyone can point me in the right direction, that'd be awesome.

 

Thanks!

  • Like 1
Posted

When it comes to adding new block and items, there are plenty of guides and tutorials, but I'm having a really hard time finding out how to properly edit blocks and items from Vanilla Minecraft. I just found how to remove old recipes, because all my searches lead to tutorials for new blocks and items because of keywords.

 

Anyways, here's what I want to do next:

  • Change the icons of Iron tools and armour to something new, since I will be using those for Steel tools and armour.
  • Change old tools and armour to new toolMaterials and armorMaterials (which I have already added)
  • Change old blocks to different harvestLevels (I have added pickaxes with levels 4 and 5)
  • Change Obsidian to drop a certain quantity of items

 

I don't think these should be too difficult to actually code, I'm just having a real hard time searching for this specific information in the ocean of basic tutorials. If anyone can point me in the right direction, that'd be awesome.

 

Thanks!

  • Like 1
Posted

The first two can easily be done without editing base classes (which you should avoid at any cost unless it is 100% necessary.) All you have to do is make new tools and armor extending the vanilla tools and armor, and then change the vanilla recipes to output the new tools and armor.

 

By harvest levels, I'm assuming you mean hardness. You can easily change hardness by using the Block class. It has a list of all the blocks in the game and you can use setHardness() on any of them.

Example:

Block.obsidian.setHardness(25);

25 is half the vanilla hardness of obsidian, so it'll take half the time to harvest it.

 

I'm not 100% sure about changing block drops, but there's probably an event or hook somewhere you can look into. Don't forget to check the source code in Eclipse. The stuff in there is more useful than you may realize. Specifically, look in the package hierarchy net.minecraftforge.event.

width=336 height=83http://img836.imageshack.us/img836/1237/cooltext624963071.png[/img]

I make games, minecraft mods/plugins, and some graphic art.

 

Current Project: LoECraft - An industrial minecraft server with its own modpack and custom launcher.

Posted

The first two can easily be done without editing base classes (which you should avoid at any cost unless it is 100% necessary.) All you have to do is make new tools and armor extending the vanilla tools and armor, and then change the vanilla recipes to output the new tools and armor.

 

By harvest levels, I'm assuming you mean hardness. You can easily change hardness by using the Block class. It has a list of all the blocks in the game and you can use setHardness() on any of them.

Example:

Block.obsidian.setHardness(25);

25 is half the vanilla hardness of obsidian, so it'll take half the time to harvest it.

 

I'm not 100% sure about changing block drops, but there's probably an event or hook somewhere you can look into. Don't forget to check the source code in Eclipse. The stuff in there is more useful than you may realize. Specifically, look in the package hierarchy net.minecraftforge.event.

width=336 height=83http://img836.imageshack.us/img836/1237/cooltext624963071.png[/img]

I make games, minecraft mods/plugins, and some graphic art.

 

Current Project: LoECraft - An industrial minecraft server with its own modpack and custom launcher.

Posted

The first two can easily be done without editing base classes (which you should avoid at any cost unless it is 100% necessary.) All you have to do is make new tools and armor extending the vanilla tools and armor, and then change the vanilla recipes to output the new tools and armor.

Wouldn't that be creating new items? I just want to change the icons for iron armor, tools, and ingots, and change their EnumToolMaterial and EnumArmorMaterial, not create replacements and recreate all the recipes.

 

By harvest levels, I'm assuming you mean hardness. You can easily change hardness by using the Block class. It has a list of all the blocks in the game and you can use setHardness() on any of them.

Example:

Block.obsidian.setHardness(25);

25 is half the vanilla hardness of obsidian, so it'll take half the time to harvest it.

Harvest Level is like what quality tool you need to harvest it. In the code it's set up like this:

0: Wood, Gold

1: Stone

2: Iron

3: Diamond

 

I have made my own materials that use levels 4 and 5. Here's what I made:

0: Wood

1: Stone

2: Bronze, Silver, Gold

3: Iron

4: Steel

5: Diamond, Obsidian

 

So now some blocks need to change their harvest levels so that you can't mine Obsidian with my new Iron.

 

I'm not 100% sure about changing block drops, but there's probably an event or hook somewhere you can look into. Don't forget to check the source code in Eclipse. The stuff in there is more useful than you may realize. Specifically, look in the package hierarchy net.minecraftforge.event.

 

Thanks, that's what I'll do. I'm sure most of the stuff is relatively simple, it's just knowing the right keywords (like hook and reflection).

 

Thanks, again.

 

Posted

The first two can easily be done without editing base classes (which you should avoid at any cost unless it is 100% necessary.) All you have to do is make new tools and armor extending the vanilla tools and armor, and then change the vanilla recipes to output the new tools and armor.

Wouldn't that be creating new items? I just want to change the icons for iron armor, tools, and ingots, and change their EnumToolMaterial and EnumArmorMaterial, not create replacements and recreate all the recipes.

 

By harvest levels, I'm assuming you mean hardness. You can easily change hardness by using the Block class. It has a list of all the blocks in the game and you can use setHardness() on any of them.

Example:

Block.obsidian.setHardness(25);

25 is half the vanilla hardness of obsidian, so it'll take half the time to harvest it.

Harvest Level is like what quality tool you need to harvest it. In the code it's set up like this:

0: Wood, Gold

1: Stone

2: Iron

3: Diamond

 

I have made my own materials that use levels 4 and 5. Here's what I made:

0: Wood

1: Stone

2: Bronze, Silver, Gold

3: Iron

4: Steel

5: Diamond, Obsidian

 

So now some blocks need to change their harvest levels so that you can't mine Obsidian with my new Iron.

 

I'm not 100% sure about changing block drops, but there's probably an event or hook somewhere you can look into. Don't forget to check the source code in Eclipse. The stuff in there is more useful than you may realize. Specifically, look in the package hierarchy net.minecraftforge.event.

 

Thanks, that's what I'll do. I'm sure most of the stuff is relatively simple, it's just knowing the right keywords (like hook and reflection).

 

Thanks, again.

 

  • 4 weeks later...
  • 2 months later...
Posted

I just found how to remove old recipes

 

what's the code for that?

 

 

Edit: nvm, i got it

 

A nifty method for removing vanilla recipes.

 

 

 

 

import net.minecraft.item.crafting.CraftingManager;

 

public static void RemoveRecipe(ItemStack resultItem)

{

ItemStack recipeResult = null;

ArrayList recipes = (ArrayList) CraftingManager.getInstance().getRecipeList();

for (int scan = 0; scan < recipes.size(); scan++)

{

IRecipe tmpRecipe = (IRecipe) recipes.get(scan);

recipeResult = tmpRecipe.getRecipeOutput();

if (recipeResult != null) {

if (recipeResult.itemID == resultItem.itemID && recipeResult.getItemDamage() == resultItem.getItemDamage())

{

System.out.println("Removed Recipe: " + recipes.get(scan) + " -> " + recipeResult);

recipes.remove(scan);

scan--; //list is shifted after remove! Adjust index, so next time we will check this value again.

}

}

}

}

 

// Then call the method e.g. like this:

RemoveRecipe(new ItemStack(Item.bed));  // It's gonna be a looong night ;)

 

 

 

 

Oh you solved it. Ok. Well then this might be an alternate way of doing it :)

Posted

What I would like to know is how to override vanilla GUI's? Or at least remove the block/item completely and then make my own.

 

My problem is that I want to att heat to furnaces. Sure I can remove the recipe for it, but it will still spawn in villages. So I need to replace it's GUI.

 

Any tips anyone?

Posted

I don't think that anything you mentioned is possible without bytecode modifications.

 

Hmm yeah that's what I hear people say most of the time. But it's always "I think..." or "I'm not sure but...", and so on. So I still have hopes that there is an easier way through Forge. And it should, since the two fundamental things you do if you wanna mod minecraft are 1. Adding stuff  2. Modifying vanilla stuff.

 

The most important to me is modifying vanilla stuff (coremodding), since just adding new stuff don't make that much of a difference to gameplay. Food is easily retained though wheat/potatoes and cattle (which is all too simple, in my opinion, so no new food is worth adding). Armor is capped with diamond material, so you can't make anything stronger (except for more durability). Dig straight down below Y:18 and search around for diamonds for a while and you have the best tools and armor the game can offer. So in order to make new tools worth the harvestLevel of diamonds must be increased.

 

Well, I guess you get my point. Sorry for yabbing, got carried away there :)

 

Thanks for the tip! I think the time has come to finally grab the bull by the horns and get into this bytecoding stuff. Feels like it's gonna be a huge time consumer (for me at least).

 

Btw, found something interesting here: https://github.com/MC-Adventure/Torch-Burnout/tree/master/tb_common/com/jjtcomkid/tb

He is using a "OverrideHandler", but left out the code for it  >:(  made me VERY disappointed! I would give my left leg to get a glimpse of that code!

Posted

You are not "2. Modifying vanilla stuff". You are removing them, since they are hardcoded in vanilla but you want to make it your own code.

Unless you know the entire Minecraft code (and most of Forge too) you shouldn't do that. You wouldn't know the consequences of such a modification.

Coding wise, it is stupid to change/remove things when they don't belong to you. (I am aware reflection exists, but its primary goal isn't to remove private things)

Would you remove part of Forge if you didn't like them ?

Posted

You are not "2. Modifying vanilla stuff". You are removing them, since they are hardcoded in vanilla but you want to make it your own code.

Unless you know the entire Minecraft code (and most of Forge too) you shouldn't do that. You wouldn't know the consequences of such a modification.

Coding wise, it is stupid to change/remove things when they don't belong to you. (I am aware reflection exists, but its primary goal isn't to remove private things)

Would you remove part of Forge if you didn't like them ?

 

Well if you're gonna get technical on me... sure I'm "removing stuff"... since we want to avoid changing the vanilla code directly, to "modify stuff" in it we can  remove and replace. A fine example is "Block.blocksList[ x ]=null; Block.blocksList[ x ]=Block.myBlock;" Remove and replace my friend, now we have made a MODIFICATION so to speak. So instead of criticizing and saying stupid this, stupid that. Try to be a little more constructive and see the big picture in what I'm saying/asking instead of marking single lines or words. I understand that you mean well, and want to warn me of messing with stuff I don't fully grasp.

 

Hey, I like coding, I'm not an ace in any way. But I like to experiment, see what happens, see if it's possible, see what I can do. And if the program crashes, so be it, then I revert and try something else. So if I see an opportunity to improve something, I'll do it! And that includes Forge (to answer your question), if I see a way to improve it I would.

 

Pheew... this was a waste of time.... please, no more talk of this. I am aware that a program can crash or bug out with bad code. I learned that a looong time ago  :) ... actually I would say that is the first thing you learn about coding. Then you learn to fix the bugs. And when it works, you get your rush. That's why we love programming, problem solving!

 

So anyway, no handy way of overriding e.g. the furnace GUI anyone?

 

Posted

Found a solution!

 

Still, if anyone knows a solution please post. Perhaps it's a better way. Or at least we can learn something from it.

Posted

Actually I mentioned it above. It was the "Block.blocksList[ x ]=null; Block.blocksList[ x ]=Block.myBlock;" part. I have simply replaced the furnace block in the blocksList with my own furnace. I had to go find a village with a blacksmith to ensure that the furnaces were replaced. Seems bulletproof so far. It's even gone from the creative block/item index (well of course it is when the object is completely removed).

 

So we'll see from here how this turns out.

 

Off topic, I made my own biome (using the standard Forge GameRegistry-method). As usual when it comes to me, it's not enough. Do you know of a way to generate the custom blocks (forming the ground) futher down than just the top 3 layers?

  • 2 months later...
Posted

You are not "2. Modifying vanilla stuff". You are removing them, since they are hardcoded in vanilla but you want to make it your own code.

Unless you know the entire Minecraft code (and most of Forge too) you shouldn't do that. You wouldn't know the consequences of such a modification.

Coding wise, it is stupid to change/remove things when they don't belong to you. (I am aware reflection exists, but its primary goal isn't to remove private things)

Would you remove part of Forge if you didn't like them ?

 

Well if you're gonna get technical on me... sure I'm "removing stuff"... since we want to avoid changing the vanilla code directly, to "modify stuff" in it we can  remove and replace. A fine example is "Block.blocksList[ x ]=null; Block.blocksList[ x ]=Block.myBlock;" Remove and replace my friend, now we have made a MODIFICATION so to speak. So instead of criticizing and saying stupid this, stupid that. Try to be a little more constructive and see the big picture in what I'm saying/asking instead of marking single lines or words. I understand that you mean well, and want to warn me of messing with stuff I don't fully grasp.

 

Hey, I like coding, I'm not an ace in any way. But I like to experiment, see what happens, see if it's possible, see what I can do. And if the program crashes, so be it, then I revert and try something else. So if I see an opportunity to improve something, I'll do it! And that includes Forge (to answer your question), if I see a way to improve it I would.

 

Pheew... this was a waste of time.... please, no more talk of this. I am aware that a program can crash or bug out with bad code. I learned that a looong time ago  :) ... actually I would say that is the first thing you learn about coding. Then you learn to fix the bugs. And when it works, you get your rush. That's why we love programming, problem solving!

 

So anyway, no handy way of overriding e.g. the furnace GUI anyone?

 

Thank you for posting this question. I had found that I needed Block.blocklist[x] = this.myblock, but no where did it tell me anything about the Block.blocklist[x] = null. After finding this post I was able to make my custom sand, which acts exactly like normal sand, replace the vanilla sand. The only difference is that now the sand doesn't drop its self it drops my custom item.

 

Again thank you so much. Now on the my other issue that seems unsolvable. That is making a custom sapling grow my custom huge tree. In theory it should work the same as a jungle sapling, but it doesn't seem to be working.

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
  • Topics

×
×
  • Create New...

Important Information

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