Network stuff moved to separate class
This commit is contained in:
parent
18b484741a
commit
ebfc4c6da6
7 changed files with 75 additions and 46 deletions
|
@ -6,7 +6,7 @@ import java.util.Set;
|
|||
import io.netty.buffer.ByteBuf;
|
||||
import mmm.Mmm;
|
||||
import mmm.utils.I_UMessage;
|
||||
import mmm.utils.URegistry;
|
||||
import mmm.utils.UNetwork;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.passive.EntityAnimal;
|
||||
|
@ -175,7 +175,7 @@ public class FMilkable
|
|||
}
|
||||
final Entity entity = event.getTarget( );
|
||||
if ( entity.hasCapability( FMilkable.CAPABILITY , null ) ) {
|
||||
URegistry.network.sendTo( new Message( entity ) , (EntityPlayerMP) player );
|
||||
UNetwork.sendTo( new Message( entity ) , (EntityPlayerMP) player );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,7 @@ public class FMilkable
|
|||
|
||||
// Send updates to players
|
||||
if ( !player.worldObj.isRemote ) {
|
||||
URegistry.network.sendToAll( new Message( animal ) );
|
||||
UNetwork.sendToAll( new Message( animal ) );
|
||||
}
|
||||
|
||||
// Actually milk the animal
|
||||
|
@ -252,7 +252,7 @@ public class FMilkable
|
|||
{
|
||||
CapabilityManager.INSTANCE.register( FMilkable.class , new Storage( ) , FMilkable::new );
|
||||
MinecraftForge.EVENT_BUS.register( new EventHandler( ) );
|
||||
URegistry.addClientMessage( Message.class );
|
||||
UNetwork.addClientMessage( Message.class );
|
||||
}
|
||||
|
||||
// *************************************************************************************************************
|
||||
|
|
|
@ -2,7 +2,7 @@ package mmm.tech.base;
|
|||
|
||||
|
||||
import mmm.tech.base.alloy_furnace.AlloyFurnace;
|
||||
import mmm.utils.URegistry;
|
||||
import mmm.utils.UNetwork;
|
||||
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ public class TechBase
|
|||
public static final AlloyFurnace ALLOY_FURNACE;
|
||||
|
||||
static {
|
||||
URegistry.addServerMessage( TBActivationModeMessage.class );
|
||||
UNetwork.addServerMessage( TBActivationModeMessage.class );
|
||||
ALLOY_FURNACE = AlloyFurnace.INSTANCE;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package mmm.tech.base.alloy_furnace;
|
|||
|
||||
import mmm.Mmm;
|
||||
import mmm.tech.base.TBAlloyFurnaceGuiHandler;
|
||||
import mmm.utils.UNetwork;
|
||||
import mmm.utils.URegistry;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlockSpecial;
|
||||
|
@ -35,7 +36,7 @@ public enum AlloyFurnace {
|
|||
GameRegistry.registerTileEntity( TBAFTileEntity.class , "mmm:tech/base/alloy_furnace" );
|
||||
// FIXME
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler( Mmm.get( ) , new TBAlloyFurnaceGuiHandler( ) );
|
||||
URegistry.addServerMessage( TBAFMessage.class );
|
||||
UNetwork.addServerMessage( TBAFMessage.class );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import mmm.tech.base.I_TBConfigurableActivation;
|
|||
import mmm.tech.base.TBActivationModeMessage;
|
||||
import mmm.utils.UInventoryDisplay;
|
||||
import mmm.utils.UInventoryGrid;
|
||||
import mmm.utils.URegistry;
|
||||
import mmm.utils.UNetwork;
|
||||
import mmm.utils.gui.UGContainer;
|
||||
import mmm.utils.gui.UGSlotDisplay;
|
||||
import mmm.utils.gui.UGSlotFuel;
|
||||
|
@ -172,7 +172,7 @@ public class TBAFContainer
|
|||
if ( te instanceof TBAFTileEntity ) {
|
||||
( (TBAFTileEntity) te ).setActivationMode( mode );
|
||||
}
|
||||
URegistry.network.sendToServer( new TBActivationModeMessage( mode ) );
|
||||
UNetwork.sendToServer( new TBActivationModeMessage( mode ) );
|
||||
} else {
|
||||
this.tileEntity.setActivationMode( mode );
|
||||
this.tileEntity.forceUpdate( );
|
||||
|
@ -196,7 +196,7 @@ public class TBAFContainer
|
|||
final TileEntity te = this.world.getTileEntity( this.position );
|
||||
if ( te instanceof TBAFTileEntity ) {
|
||||
( (TBAFTileEntity) te ).flags = flags;
|
||||
URegistry.network.sendToServer( new TBAFMessage( flags ) );
|
||||
UNetwork.sendToServer( new TBAFMessage( flags ) );
|
||||
}
|
||||
} else {
|
||||
this.tileEntity.flags = flags;
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.ArrayList;
|
|||
|
||||
import mmm.Mmm;
|
||||
import mmm.materials.MAlloyRecipe;
|
||||
import mmm.utils.URegistry;
|
||||
import mmm.utils.UNetwork;
|
||||
import mmm.utils.gui.A_UGTab;
|
||||
import mmm.utils.gui.A_UGTabbedContainerScreen;
|
||||
import mmm.utils.gui.UGArrowButton;
|
||||
|
@ -176,7 +176,7 @@ public class TBAFGui
|
|||
gui.setRecipe( gui.currentRecipe - 1 );
|
||||
} else if ( button == this.bConfirm ) {
|
||||
final MAlloyRecipe recipe = gui.recipes.get( gui.currentRecipe );
|
||||
URegistry.network.sendToServer( new TBAFMessage( recipe.name , true ) );
|
||||
UNetwork.sendToServer( new TBAFMessage( recipe.name , true ) );
|
||||
gui.container.tileEntity.recipe = recipe;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -353,7 +353,7 @@ public class TBAFGui
|
|||
}
|
||||
|
||||
this.container.setCurrentRecipe( rName , false );
|
||||
URegistry.network.sendToServer( new TBAFMessage( rName , false ) );
|
||||
UNetwork.sendToServer( new TBAFMessage( rName , false ) );
|
||||
( (RecipeTab) this.tabs[ 1 ] ).enableButtons( );
|
||||
}
|
||||
|
||||
|
|
61
src/java/mmm/utils/UNetwork.java
Normal file
61
src/java/mmm/utils/UNetwork.java
Normal file
|
@ -0,0 +1,61 @@
|
|||
package mmm.utils;
|
||||
|
||||
|
||||
import mmm.Mmm;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.IThreadListener;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
|
||||
|
||||
public class UNetwork
|
||||
{
|
||||
private static final SimpleNetworkWrapper NET = new SimpleNetworkWrapper( Mmm.ID );
|
||||
private static int nextPacketDiscriminator = 0;
|
||||
|
||||
|
||||
public static void addClientMessage( final Class< ? extends I_UMessage > message )
|
||||
{
|
||||
UNetwork.NET.registerMessage( //
|
||||
( final I_UMessage m , final MessageContext ctx ) -> {
|
||||
final IThreadListener main = Minecraft.getMinecraft( );
|
||||
main.addScheduledTask( ( ) -> m.handleOnClient( Minecraft.getMinecraft( ).thePlayer ) );
|
||||
return null;
|
||||
} , //
|
||||
message , UNetwork.nextPacketDiscriminator++ , Side.CLIENT );
|
||||
}
|
||||
|
||||
|
||||
public static void addServerMessage( final Class< ? extends I_UMessage > message )
|
||||
{
|
||||
UNetwork.NET.registerMessage( //
|
||||
( final I_UMessage m , final MessageContext ctx ) -> {
|
||||
final IThreadListener main = (WorldServer) ctx.getServerHandler( ).playerEntity.worldObj;
|
||||
main.addScheduledTask( ( ) -> m.handleOnServer( ctx.getServerHandler( ).playerEntity ) );
|
||||
return null;
|
||||
} , //
|
||||
message , UNetwork.nextPacketDiscriminator++ , Side.SERVER );
|
||||
}
|
||||
|
||||
|
||||
public static void sendToServer( final I_UMessage msg )
|
||||
{
|
||||
UNetwork.NET.sendToServer( msg );
|
||||
}
|
||||
|
||||
|
||||
public static void sendTo( final I_UMessage msg , final EntityPlayerMP player )
|
||||
{
|
||||
UNetwork.NET.sendTo( msg , player );
|
||||
}
|
||||
|
||||
|
||||
public static void sendToAll( final I_UMessage msg )
|
||||
{
|
||||
UNetwork.NET.sendToAll( msg );
|
||||
}
|
||||
}
|
|
@ -9,21 +9,15 @@ import java.util.Map;
|
|||
|
||||
import mmm.Mmm;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IThreadListener;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.common.IFuelHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.common.registry.IForgeRegistryEntry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import scala.actors.threadpool.Arrays;
|
||||
|
||||
|
||||
|
@ -51,9 +45,6 @@ public class URegistry
|
|||
|
||||
}
|
||||
|
||||
public static final SimpleNetworkWrapper network = new SimpleNetworkWrapper( Mmm.ID );
|
||||
private static int nextPacketDiscriminator = 0;
|
||||
|
||||
private static final HashSet< I_URecipeRegistrar > RECIPE_REGISTRARS = new HashSet<>( );
|
||||
private static final HashSet< I_UOreGenerationRegistrar > ORE_GEN_REGISTRARS = new HashSet<>( );
|
||||
private static final HashMap< Item , Boolean > ITEMS = new HashMap< Item , Boolean >( );
|
||||
|
@ -204,30 +195,6 @@ public class URegistry
|
|||
}
|
||||
|
||||
|
||||
public static void addClientMessage( final Class< ? extends I_UMessage > message )
|
||||
{
|
||||
URegistry.network.registerMessage( //
|
||||
( final I_UMessage m , final MessageContext ctx ) -> {
|
||||
final IThreadListener main = Minecraft.getMinecraft( );
|
||||
main.addScheduledTask( ( ) -> m.handleOnClient( Minecraft.getMinecraft( ).thePlayer ) );
|
||||
return null;
|
||||
} , //
|
||||
message , URegistry.nextPacketDiscriminator++ , Side.CLIENT );
|
||||
}
|
||||
|
||||
|
||||
public static void addServerMessage( final Class< ? extends I_UMessage > message )
|
||||
{
|
||||
URegistry.network.registerMessage( //
|
||||
( final I_UMessage m , final MessageContext ctx ) -> {
|
||||
final IThreadListener main = (WorldServer) ctx.getServerHandler( ).playerEntity.worldObj;
|
||||
main.addScheduledTask( ( ) -> m.handleOnServer( ctx.getServerHandler( ).playerEntity ) );
|
||||
return null;
|
||||
} , //
|
||||
message , URegistry.nextPacketDiscriminator++ , Side.SERVER );
|
||||
}
|
||||
|
||||
|
||||
public static void setupItemModels( )
|
||||
{
|
||||
for ( final Map.Entry< Item , Boolean > entry : URegistry.ITEMS.entrySet( ) ) {
|
||||
|
|
Reference in a new issue