Jump to content

1.7.10 Custom crafting recipes on the server side


robbo

Recommended Posts

I am attempting to register a few custom crafting recipes in a server sided mod in 1.7.10

 

When putting the items in the crafting table, no item appears in the result slot. However when the seemingly empty result slot is clicked, the crafting happens successfully.

 

Is there any way I can fix this solely on the server side? Maybe using packets or something?

 

CustomRecipes class:

The register() method is called in the FMLServerStartingEvent

The LOTRItems references are non-vanilla items from another mod

import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;

public class CustomRecipes {	
	public static void register() {
		GameRegistry.addRecipe(new ItemStack(Blocks.dropper),
				"AAA",
				"A A",
				"ABA",
				'A', Blocks.cobblestone,
				'B', LOTRItems.rope
		);
		
		GameRegistry.addRecipe(new ItemStack(Blocks.dispenser),
				"AAA",
				"ACA",
				"ABA",
				'A', Blocks.cobblestone,
				'B', LOTRItems.rope,
				'C', Items.bow
		);
		
		GameRegistry.addRecipe(new ItemStack(Blocks.piston),
				"AAA",
				"BCB",
				"BDB",
				'A', Blocks.planks,
				'B', Blocks.cobblestone,
				'C', Items.iron_ingot,
				'D', LOTRItems.rope
		);
	}
}

 

Link to comment
Share on other sites

1.7.10 is no longer supported here.

 

But the reason this probably doesn't work is because the client needs the recipe too.

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.

Link to comment
Share on other sites

15 minutes ago, robbo said:

I am attempting to register a few custom crafting recipes in a server sided mod in 1.7.10

1.7.10 is no longer supported on this forum, update to receive assistance.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Nevermind, figured out a workaround and it works now, using packets

 

Code:

import java.util.HashMap;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.ContainerWorkbench;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.network.play.server.S2FPacketSetSlot;

public class CustomRecipes {
	public static void register() {
		GameRegistry.addRecipe(new ItemStack(Blocks.dropper),
				"AAA",
				"A A",
				"ABA",
				'A', Blocks.cobblestone,
				'B', LOTRItems.rope
		);
		
		GameRegistry.addRecipe(new ItemStack(Blocks.dispenser),
				"AAA",
				"ACA",
				"ABA",
				'A', Blocks.cobblestone,
				'B', LOTRItems.rope,
				'C', Items.bow
		);
		
		GameRegistry.addRecipe(new ItemStack(Blocks.piston),
				"AAA",
				"BCB",
				"BDB",
				'A', Blocks.planks,
				'B', Blocks.cobblestone,
				'C', Items.iron_ingot,
				'D', LOTRItems.rope
		);
	}
	
	private static HashMap<EntityPlayerMP, int[]> synced = new HashMap<EntityPlayerMP, int[]>();
	
	public static void tick(EntityPlayerMP player) {
		if (player.openContainer instanceof ContainerWorkbench) {
			final ContainerWorkbench crafting = (ContainerWorkbench) player.openContainer;
			final ItemStack result = CraftingManager.getInstance().findMatchingRecipe(crafting.craftMatrix, player.worldObj);
			
			if (result != null) {
				if (synced.containsKey(player)) {
					final int[] info = synced.get(player);
					
					if (info[0] == player.currentWindowId && info[1] == Item.getIdFromItem(result.getItem())) {
						return;
					}
				}
				
				player.playerNetServerHandler.sendPacket(new S2FPacketSetSlot(crafting.windowId, 0, result));
				synced.put(player, new int[] {player.currentWindowId, Item.getIdFromItem(result.getItem())});
			}
		}
	}
	
	@SubscribeEvent
	public void logOut(PlayerLoggedOutEvent event) {
		synced.remove(event.player);
	}
}

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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