Alloy furnace - More reliance on vanilla TE updates
This commit is contained in:
parent
f09e8f2125
commit
b68a081350
6 changed files with 77 additions and 43 deletions
Binary file not shown.
|
@ -5,7 +5,6 @@ import mmm.materials.MAlloyRecipe;
|
|||
import mmm.utils.UContainers;
|
||||
import mmm.utils.UInventoryDisplay;
|
||||
import mmm.utils.UInventoryGrid;
|
||||
import mmm.utils.URegistry;
|
||||
import mmm.utils.slots.USDisplay;
|
||||
import mmm.utils.slots.USFuel;
|
||||
import mmm.utils.slots.USOutput;
|
||||
|
@ -84,9 +83,8 @@ public class TBAlloyFurnaceContainer
|
|||
|
||||
public void setCurrentRecipe( final ResourceLocation name , final boolean confirm )
|
||||
{
|
||||
MAlloyRecipe recipe = MAlloyRecipe.REGISTRY.getRecipe( name );
|
||||
final MAlloyRecipe recipe = MAlloyRecipe.REGISTRY.getRecipe( name );
|
||||
if ( recipe == null ) {
|
||||
// XXX log
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -97,8 +95,7 @@ public class TBAlloyFurnaceContainer
|
|||
this.recipe.setInventorySlotContents( 6 , recipe.output );
|
||||
|
||||
if ( confirm ) {
|
||||
this.tileEntity.recipe = recipe;
|
||||
URegistry.network.sendToAll( new TBAlloyFurnaceMessage( this.position , name , true ) );
|
||||
this.tileEntity.setRecipe( name );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,18 +2,12 @@ package mmm.tech.base;
|
|||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import mmm.materials.MAlloyRecipe;
|
||||
import mmm.utils.I_UMessage;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
|
||||
|
||||
|
@ -60,36 +54,14 @@ public class TBAlloyFurnaceMessage
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public void handleOnClient( final EntityPlayerSP player )
|
||||
{
|
||||
World world = player.getEntityWorld( );
|
||||
TileEntity te = world.getTileEntity( this.blockPos );
|
||||
if ( ! ( te instanceof TBAlloyFurnaceTileEntity ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
TBAlloyFurnaceTileEntity afte = (TBAlloyFurnaceTileEntity) te;
|
||||
MAlloyRecipe recipe = MAlloyRecipe.REGISTRY.getRecipe( selected );
|
||||
if ( recipe == null ) {
|
||||
recipe = MAlloyRecipe.REGISTRY.getRecipes( ).get( 0 );
|
||||
}
|
||||
afte.recipe = recipe;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleOnServer( final EntityPlayerMP player )
|
||||
{
|
||||
final Container curCont = player.openContainer;
|
||||
if ( ! ( curCont instanceof TBAlloyFurnaceContainer ) ) {
|
||||
// XXX log?
|
||||
return;
|
||||
}
|
||||
|
||||
if ( curCont instanceof TBAlloyFurnaceContainer ) {
|
||||
final TBAlloyFurnaceContainer container = (TBAlloyFurnaceContainer) curCont;
|
||||
container.setCurrentRecipe( this.selected , this.confirm );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,10 @@ package mmm.tech.base;
|
|||
|
||||
import mmm.materials.MAlloyRecipe;
|
||||
import mmm.utils.UInventoryGrid;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
|
@ -17,6 +20,7 @@ public class TBAlloyFurnaceTileEntity
|
|||
public final UInventoryGrid input;
|
||||
public final UInventoryGrid fuel;
|
||||
public final UInventoryGrid output;
|
||||
|
||||
public MAlloyRecipe recipe;
|
||||
|
||||
|
||||
|
@ -36,11 +40,7 @@ public class TBAlloyFurnaceTileEntity
|
|||
this.input.deserializeNBT( compound.getTagList( "Input" , NBT.TAG_COMPOUND ) );
|
||||
this.fuel.deserializeNBT( compound.getTagList( "Fuel" , NBT.TAG_COMPOUND ) );
|
||||
this.output.deserializeNBT( compound.getTagList( "Output" , NBT.TAG_COMPOUND ) );
|
||||
String recipeName = compound.getString( "Recipe" );
|
||||
this.recipe = MAlloyRecipe.REGISTRY.getRecipe( new ResourceLocation( recipeName ) );
|
||||
if ( this.recipe == null ) {
|
||||
this.recipe = MAlloyRecipe.REGISTRY.getRecipes( ).get( 0 );
|
||||
}
|
||||
this.readSyncData( compound );
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,8 +51,74 @@ public class TBAlloyFurnaceTileEntity
|
|||
compound.setTag( "Input" , this.input.serializeNBT( ) );
|
||||
compound.setTag( "Fuel" , this.fuel.serializeNBT( ) );
|
||||
compound.setTag( "Output" , this.output.serializeNBT( ) );
|
||||
compound.setString( "Recipe" , this.recipe.name.toString( ) );
|
||||
this.writeSyncData( compound );
|
||||
System.err.println( "tag " + compound.toString( ) );
|
||||
return compound;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SPacketUpdateTileEntity getUpdatePacket( )
|
||||
{
|
||||
final NBTTagCompound compound = new NBTTagCompound( );
|
||||
this.writeSyncData( compound );
|
||||
return new SPacketUpdateTileEntity( this.pos , 0 , compound );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getUpdateTag( )
|
||||
{
|
||||
final NBTTagCompound compound = new NBTTagCompound( );
|
||||
this.writeToNBT( compound );
|
||||
return compound;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDataPacket( final NetworkManager net , final SPacketUpdateTileEntity pkt )
|
||||
{
|
||||
if ( this.worldObj.isRemote ) {
|
||||
this.readSyncData( pkt.getNbtCompound( ) );
|
||||
final IBlockState state = this.worldObj.getBlockState( this.pos );
|
||||
this.worldObj.notifyBlockUpdate( this.pos , state , state , 3 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setRecipe( final ResourceLocation location )
|
||||
{
|
||||
MAlloyRecipe recipe = MAlloyRecipe.REGISTRY.getRecipe( location );
|
||||
if ( recipe == null ) {
|
||||
recipe = MAlloyRecipe.REGISTRY.getRecipes( ).get( 0 );
|
||||
}
|
||||
|
||||
if ( recipe == this.recipe ) {
|
||||
return;
|
||||
}
|
||||
this.recipe = recipe;
|
||||
|
||||
if ( !this.worldObj.isRemote ) {
|
||||
this.markDirty( );
|
||||
final IBlockState state = this.worldObj.getBlockState( this.pos );
|
||||
this.worldObj.notifyBlockUpdate( this.pos , state , state , 3 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void readSyncData( final NBTTagCompound compound )
|
||||
{
|
||||
final String recipeName = compound.getString( "Recipe" );
|
||||
this.recipe = MAlloyRecipe.REGISTRY.getRecipe( new ResourceLocation( recipeName ) );
|
||||
if ( this.recipe == null ) {
|
||||
this.recipe = MAlloyRecipe.REGISTRY.getRecipes( ).get( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void writeSyncData( final NBTTagCompound compound )
|
||||
{
|
||||
compound.setString( "Recipe" , this.recipe.name.toString( ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ public class TechBase
|
|||
GameRegistry.registerTileEntity( TBAlloyFurnaceTileEntity.class , "mmm:tech/base/alloy_furnace" );
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler( Mmm.get( ) , new TBAlloyFurnaceGuiHandler( ) );
|
||||
URegistry.addServerMessage( TBAlloyFurnaceMessage.class );
|
||||
URegistry.addClientMessage( TBAlloyFurnaceMessage.class );
|
||||
|
||||
// FIXME test, remove this later
|
||||
MAlloyRecipe.build( ).setName( "test" ).setBurnTime( 200 ).setExperience( .05f )
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Reference in a new issue