connected state sync

This commit is contained in:
Raoul Van den Berge
2015-12-25 20:21:03 +01:00
parent caa6c3f5a3
commit 36d3303c5f
5 changed files with 26 additions and 9 deletions

View File

@@ -78,8 +78,6 @@ public class BlockController extends BlockBase implements ITileEntityProvider
@Override @Override
public int getComparatorInputOverride(World world, BlockPos pos) public int getComparatorInputOverride(World world, BlockPos pos)
{ {
TileController tile = (TileController) world.getTileEntity(pos); return (Integer) world.getBlockState(pos).getValue(ENERGY);
return tile.getEnergyScaled(15);
} }
} }

View File

@@ -9,12 +9,14 @@ import net.minecraft.block.state.IBlockState;
public abstract class BlockMachine extends BlockBase implements ITileEntityProvider public abstract class BlockMachine extends BlockBase implements ITileEntityProvider
{ {
public static final PropertyBool CONNECTED = PropertyBool.create("connected"); public static final PropertyBool CONNECTED = PropertyBool.create("connected");
public BlockMachine(String name) public BlockMachine(String name)
{ {
super(name); super(name);
this.setDefaultState(this.blockState.getBaseState().withProperty(CONNECTED, false));
} }
@Override @Override
protected BlockState createBlockState() protected BlockState createBlockState()
{ {
@@ -23,13 +25,13 @@ public abstract class BlockMachine extends BlockBase implements ITileEntityProvi
CONNECTED CONNECTED
}); });
} }
@Override @Override
public IBlockState getStateFromMeta(int meta) public IBlockState getStateFromMeta(int meta)
{ {
return getDefaultState().withProperty(CONNECTED, meta == 1 ? true : false); return getDefaultState().withProperty(CONNECTED, meta == 1 ? true : false);
} }
@Override @Override
public int getMetaFromState(IBlockState state) public int getMetaFromState(IBlockState state)
{ {

View File

@@ -1,5 +1,6 @@
package storagecraft.tile; package storagecraft.tile;
import net.minecraft.block.state.IBlockState;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager; import net.minecraft.network.NetworkManager;
@@ -7,7 +8,9 @@ import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.server.gui.IUpdatePlayerListBox; import net.minecraft.server.gui.IUpdatePlayerListBox;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint; import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
import storagecraft.StorageCraft; import storagecraft.StorageCraft;
import storagecraft.network.MessageTileUpdate; import storagecraft.network.MessageTileUpdate;
@@ -16,7 +19,7 @@ public abstract class TileBase extends TileEntity implements IUpdatePlayerListBo
{ {
public static final int UPDATE_RANGE = 256; public static final int UPDATE_RANGE = 256;
private EnumFacing direction; private EnumFacing direction = EnumFacing.NORTH;
protected int ticks; protected int ticks;
@@ -78,6 +81,12 @@ public abstract class TileBase extends TileEntity implements IUpdatePlayerListBo
direction = EnumFacing.getFront(packet.getNbtCompound().getInteger("Direction")); direction = EnumFacing.getFront(packet.getNbtCompound().getInteger("Direction"));
} }
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState)
{
return false;
}
public IInventory getDroppedInventory() public IInventory getDroppedInventory()
{ {
return null; return null;

View File

@@ -11,6 +11,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos; import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import storagecraft.StorageCraftBlocks; import storagecraft.StorageCraftBlocks;
import storagecraft.block.BlockController;
import storagecraft.storage.IStorage; import storagecraft.storage.IStorage;
import storagecraft.storage.IStorageProvider; import storagecraft.storage.IStorageProvider;
import storagecraft.storage.StorageItem; import storagecraft.storage.StorageItem;
@@ -116,6 +117,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
if (lastEnergy != energy.getEnergyStored()) if (lastEnergy != energy.getEnergyStored())
{ {
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockController.ENERGY, getEnergyScaled(15)));
worldObj.markBlockForUpdate(pos); worldObj.markBlockForUpdate(pos);
worldObj.notifyNeighborsOfStateChange(pos, StorageCraftBlocks.CONTROLLER); worldObj.notifyNeighborsOfStateChange(pos, StorageCraftBlocks.CONTROLLER);
} }
@@ -328,7 +330,8 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
public boolean isActive() public boolean isActive()
{ {
return energy.getEnergyStored() >= getEnergyUsage() && redstoneMode.isEnabled(worldObj, pos); return true;
// @TODO: return energy.getEnergyStored() >= getEnergyUsage() && redstoneMode.isEnabled(worldObj, pos);
} }
@Override @Override

View File

@@ -3,6 +3,7 @@ package storagecraft.tile;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.BlockPos; import net.minecraft.util.BlockPos;
import storagecraft.block.BlockMachine;
public abstract class TileMachine extends TileBase implements INetworkTile, IRedstoneModeSetting public abstract class TileMachine extends TileBase implements INetworkTile, IRedstoneModeSetting
{ {
@@ -18,11 +19,15 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
connected = true; connected = true;
controllerPos = controller.getPos(); controllerPos = controller.getPos();
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, true));
} }
public void onDisconnected() public void onDisconnected()
{ {
connected = false; connected = false;
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, false));
} }
@Override @Override