Very unstable improved machine searching part7

This commit is contained in:
Raoul Van den Berge
2016-05-14 15:04:05 +02:00
parent 3d83d7366a
commit dd7cee8c8b
8 changed files with 46 additions and 25 deletions

View File

@@ -90,7 +90,7 @@ public abstract class BlockBase extends Block {
((TileBase) tile).setDirection(EnumFacing.getFront(newDir)); ((TileBase) tile).setDirection(EnumFacing.getFront(newDir));
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 2 | 4); RefinedStorageUtils.reRenderBlock(world, pos);
return true; return true;
} }

View File

@@ -1,17 +1,19 @@
package refinedstorage.block; package refinedstorage.block;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import refinedstorage.RefinedStorageBlocks; import refinedstorage.RefinedStorageBlocks;
import refinedstorage.tile.TileCable;
import refinedstorage.tile.TileMachine; import refinedstorage.tile.TileMachine;
public class BlockCable extends BlockBase { public class BlockCable extends BlockMachine {
public static final AxisAlignedBB CABLE_AABB = new AxisAlignedBB(4 * (1F / 16F), 4 * (1F / 16F), 4 * (1F / 16F), 1 - 4 * (1F / 16F), 1 - 4 * (1F / 16F), 1 - 4 * (1F / 16F)); public static final AxisAlignedBB CABLE_AABB = new AxisAlignedBB(4 * (1F / 16F), 4 * (1F / 16F), 4 * (1F / 16F), 1 - 4 * (1F / 16F), 1 - 4 * (1F / 16F), 1 - 4 * (1F / 16F));
public static final PropertyBool NORTH = PropertyBool.create("north"); public static final PropertyBool NORTH = PropertyBool.create("north");
@@ -27,10 +29,16 @@ public class BlockCable extends BlockBase {
setHardness(0.6F); setHardness(0.6F);
} }
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new TileCable();
}
@Override @Override
protected BlockStateContainer createBlockState() { protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[]{ return new BlockStateContainer(this, new IProperty[]{
DIRECTION, DIRECTION,
CONNECTED,
NORTH, NORTH,
EAST, EAST,
SOUTH, SOUTH,
@@ -52,9 +60,7 @@ public class BlockCable extends BlockBase {
} }
public static boolean hasConnectionWith(IBlockAccess world, BlockPos pos) { public static boolean hasConnectionWith(IBlockAccess world, BlockPos pos) {
Block block = world.getBlockState(pos).getBlock(); return world.getBlockState(pos).getBlock() == RefinedStorageBlocks.CONTROLLER || world.getTileEntity(pos) instanceof TileMachine;
return (block == RefinedStorageBlocks.CABLE || block == RefinedStorageBlocks.CONTROLLER) || world.getTileEntity(pos) instanceof TileMachine;
} }
@Override @Override

View File

@@ -86,13 +86,6 @@ public class BlockController extends BlockBase {
return true; return true;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
((TileController) world.getTileEntity(pos)).onDestroyed();
super.breakBlock(world, pos, state);
}
@Override @Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack itemStack) { public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack itemStack) {
super.onBlockPlacedBy(world, pos, state, player, itemStack); super.onBlockPlacedBy(world, pos, state, player, itemStack);

View File

@@ -79,6 +79,7 @@ public class CommonProxy {
GameRegistry.registerTileEntity(TileWirelessTransmitter.class, ID + ":wireless_transmitter"); GameRegistry.registerTileEntity(TileWirelessTransmitter.class, ID + ":wireless_transmitter");
GameRegistry.registerTileEntity(TileCrafter.class, ID + ":crafter"); GameRegistry.registerTileEntity(TileCrafter.class, ID + ":crafter");
GameRegistry.registerTileEntity(TileProcessingPatternEncoder.class, ID + ":processing_pattern_encoder"); GameRegistry.registerTileEntity(TileProcessingPatternEncoder.class, ID + ":processing_pattern_encoder");
GameRegistry.registerTileEntity(TileCable.class, ID + ":cable");
registerBlock(RefinedStorageBlocks.CONTROLLER); registerBlock(RefinedStorageBlocks.CONTROLLER);
registerBlock(RefinedStorageBlocks.GRID); registerBlock(RefinedStorageBlocks.GRID);

View File

@@ -1,11 +1,9 @@
package refinedstorage.tile; package refinedstorage.tile;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import refinedstorage.RefinedStorageBlocks;
import java.util.Set; import java.util.Set;
@@ -21,11 +19,7 @@ public class ControllerSearcher {
if (tile instanceof TileController) { if (tile instanceof TileController) {
return (TileController) tile; return (TileController) tile;
} } else if (tile instanceof TileMachine) {
Block block = world.getBlockState(current).getBlock();
if (tile instanceof TileMachine || block == RefinedStorageBlocks.CABLE) {
// We need to have visited more than 1 tile so that the relay can find a controller for itself // We need to have visited more than 1 tile so that the relay can find a controller for itself
if (visited.size() > 1 && tile instanceof TileRelay && !((TileRelay) tile).isConnected()) { if (visited.size() > 1 && tile instanceof TileRelay && !((TileRelay) tile).isConnected()) {
return null; return null;

View File

@@ -0,0 +1,19 @@
package refinedstorage.tile;
import net.minecraft.inventory.Container;
public class TileCable extends TileMachine {
@Override
public int getEnergyUsage() {
return 0;
}
@Override
public void updateMachine() {
}
@Override
public Class<? extends Container> getContainer() {
return null;
}
}

View File

@@ -211,11 +211,13 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
if (lastEnergy != energy.getEnergyStored()) { if (lastEnergy != energy.getEnergyStored()) {
worldObj.updateComparatorOutputLevel(pos, RefinedStorageBlocks.CONTROLLER); worldObj.updateComparatorOutputLevel(pos, RefinedStorageBlocks.CONTROLLER);
if (System.currentTimeMillis() - lastEnergyUpdate > 3000) { if (System.currentTimeMillis() - lastEnergyUpdate > 3000L) {
RefinedStorageUtils.sendToAllAround(worldObj, pos, new MessageControllerEnergyUpdate(this)); RefinedStorageUtils.sendToAllAround(worldObj, pos, new MessageControllerEnergyUpdate(this));
lastEnergyUpdate = System.currentTimeMillis(); lastEnergyUpdate = System.currentTimeMillis();
} }
} else if (ticks < 10) {
RefinedStorageUtils.sendToAllAround(worldObj, pos, new MessageControllerEnergyUpdate(this));
} }
} }
} }
@@ -232,10 +234,6 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
return wirelessGridRange; return wirelessGridRange;
} }
public void onDestroyed() {
disconnectAll();
}
private void disconnectAll() { private void disconnectAll() {
for (TileMachine machine : machines) { for (TileMachine machine : machines) {
machine.onDisconnected(); machine.onDisconnected();
@@ -474,6 +472,8 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
energy.readFromNBT(nbt);
if (nbt.hasKey(RedstoneMode.NBT)) { if (nbt.hasKey(RedstoneMode.NBT)) {
redstoneMode = RedstoneMode.getById(nbt.getInteger(RedstoneMode.NBT)); redstoneMode = RedstoneMode.getById(nbt.getInteger(RedstoneMode.NBT));
} }
@@ -500,6 +500,8 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
energy.writeToNBT(nbt);
nbt.setInteger(RedstoneMode.NBT, redstoneMode.id); nbt.setInteger(RedstoneMode.NBT, redstoneMode.id);
NBTTagList list = new NBTTagList(); NBTTagList list = new NBTTagList();

View File

@@ -70,6 +70,12 @@
}, },
"down": { "down": {
} }
},
"connected": {
"true": {
},
"false": {
}
} }
} }
} }