connected state sync
This commit is contained in:
@@ -78,8 +78,6 @@ public class BlockController extends BlockBase implements ITileEntityProvider
|
||||
@Override
|
||||
public int getComparatorInputOverride(World world, BlockPos pos)
|
||||
{
|
||||
TileController tile = (TileController) world.getTileEntity(pos);
|
||||
|
||||
return tile.getEnergyScaled(15);
|
||||
return (Integer) world.getBlockState(pos).getValue(ENERGY);
|
||||
}
|
||||
}
|
||||
|
@@ -9,12 +9,14 @@ import net.minecraft.block.state.IBlockState;
|
||||
public abstract class BlockMachine extends BlockBase implements ITileEntityProvider
|
||||
{
|
||||
public static final PropertyBool CONNECTED = PropertyBool.create("connected");
|
||||
|
||||
|
||||
public BlockMachine(String name)
|
||||
{
|
||||
super(name);
|
||||
|
||||
this.setDefaultState(this.blockState.getBaseState().withProperty(CONNECTED, false));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected BlockState createBlockState()
|
||||
{
|
||||
@@ -23,13 +25,13 @@ public abstract class BlockMachine extends BlockBase implements ITileEntityProvi
|
||||
CONNECTED
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
return getDefaultState().withProperty(CONNECTED, meta == 1 ? true : false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package storagecraft.tile;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
@@ -7,7 +8,9 @@ import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.server.gui.IUpdatePlayerListBox;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import storagecraft.StorageCraft;
|
||||
import storagecraft.network.MessageTileUpdate;
|
||||
@@ -16,7 +19,7 @@ public abstract class TileBase extends TileEntity implements IUpdatePlayerListBo
|
||||
{
|
||||
public static final int UPDATE_RANGE = 256;
|
||||
|
||||
private EnumFacing direction;
|
||||
private EnumFacing direction = EnumFacing.NORTH;
|
||||
|
||||
protected int ticks;
|
||||
|
||||
@@ -78,6 +81,12 @@ public abstract class TileBase extends TileEntity implements IUpdatePlayerListBo
|
||||
direction = EnumFacing.getFront(packet.getNbtCompound().getInteger("Direction"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public IInventory getDroppedInventory()
|
||||
{
|
||||
return null;
|
||||
|
@@ -11,6 +11,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import storagecraft.StorageCraftBlocks;
|
||||
import storagecraft.block.BlockController;
|
||||
import storagecraft.storage.IStorage;
|
||||
import storagecraft.storage.IStorageProvider;
|
||||
import storagecraft.storage.StorageItem;
|
||||
@@ -116,6 +117,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
|
||||
if (lastEnergy != energy.getEnergyStored())
|
||||
{
|
||||
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockController.ENERGY, getEnergyScaled(15)));
|
||||
worldObj.markBlockForUpdate(pos);
|
||||
worldObj.notifyNeighborsOfStateChange(pos, StorageCraftBlocks.CONTROLLER);
|
||||
}
|
||||
@@ -328,7 +330,8 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
|
||||
public boolean isActive()
|
||||
{
|
||||
return energy.getEnergyStored() >= getEnergyUsage() && redstoneMode.isEnabled(worldObj, pos);
|
||||
return true;
|
||||
// @TODO: return energy.getEnergyStored() >= getEnergyUsage() && redstoneMode.isEnabled(worldObj, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -3,6 +3,7 @@ package storagecraft.tile;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import storagecraft.block.BlockMachine;
|
||||
|
||||
public abstract class TileMachine extends TileBase implements INetworkTile, IRedstoneModeSetting
|
||||
{
|
||||
@@ -18,11 +19,15 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
||||
connected = true;
|
||||
|
||||
controllerPos = controller.getPos();
|
||||
|
||||
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, true));
|
||||
}
|
||||
|
||||
public void onDisconnected()
|
||||
{
|
||||
connected = false;
|
||||
|
||||
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user