-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCommonProxy.java
More file actions
93 lines (72 loc) · 3.54 KB
/
CommonProxy.java
File metadata and controls
93 lines (72 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package ru.mcmodding.tutorial.common;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import ru.mcmodding.tutorial.McModding;
import ru.mcmodding.tutorial.common.container.ChestContainer;
import ru.mcmodding.tutorial.common.handler.*;
import ru.mcmodding.tutorial.common.handler.packet.ServerMessagePacket;
import ru.mcmodding.tutorial.common.handler.recipe.WhetstoneRecipe;
import ru.mcmodding.tutorial.common.tile.ChestTile;
public class CommonProxy implements IGuiHandler {
private static SimpleNetworkWrapper network;
private static PacketHandler packetHandler;
public static final int GUI_CHEST = 0;
public void preInit(FMLPreInitializationEvent event) {
// SimpleNetworkWrapper
network = new SimpleNetworkWrapper(McModding.MOD_ID);
network.registerMessage(new ServerMessagePacket.Handler(), ServerMessagePacket.class, 0, Side.SERVER);
// FMLEventChannel как альтернатива SimpleNetworkWrapper
// Вам нет никакой необходимости использовать сразу оба варианта в вашем моде!
packetHandler = new PacketHandler();
NetworkRegistry.INSTANCE.registerGuiHandler(McModding.instance, this);
FMLCommonHandler.instance().bus().register(new FMLEventListener());
MinecraftForge.EVENT_BUS.register(new ForgeEventListener());
ModBlocks.register();
ModEntities.register();
ModItems.register();
GameRegistry.registerFuelHandler(new FuelHandler());
MinecraftForge.EVENT_BUS.register(new BucketHandler());
}
public void init(FMLInitializationEvent event) {
}
public void postInit(FMLPostInitializationEvent event) {
GameRegistry.addShapedRecipe(new ItemStack(ModItems.RUBY_SWORD), " R ", " R ", " S ", 'R', ModItems.RUBY, 'S', Items.stick);
for (int damage = 0; damage < 15; damage++) {
GameRegistry.addShapelessRecipe(new ItemStack(ModItems.BALLOON, 1, damage), new ItemStack(Blocks.wool, 1, ~damage & 15), Items.string);
}
GameRegistry.addSmelting(ModBlocks.RUBY_ORE, new ItemStack(ModItems.RUBY), 5F);
GameRegistry.addRecipe(new WhetstoneRecipe());
}
public static SimpleNetworkWrapper getNetwork() {
return network;
}
public static PacketHandler getPacketHandler() {
return packetHandler;
}
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if (id == GUI_CHEST) {
return new ChestContainer((ChestTile) tile, player.inventory);
}
return null;
}
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
return null; // Реализован в ClientProxy
}
}