Add writer block

This commit is contained in:
Raoul Van den Berge
2016-11-11 14:31:28 +01:00
parent 66ee91b722
commit d633771708
5 changed files with 131 additions and 0 deletions

View File

@@ -28,4 +28,5 @@ public final class RSBlocks {
public static final BlockFluidStorage FLUID_STORAGE = new BlockFluidStorage(); public static final BlockFluidStorage FLUID_STORAGE = new BlockFluidStorage();
public static final BlockDiskManipulator DISK_MANIPULATOR = new BlockDiskManipulator(); public static final BlockDiskManipulator DISK_MANIPULATOR = new BlockDiskManipulator();
public static final BlockReader READER = new BlockReader(); public static final BlockReader READER = new BlockReader();
public static final BlockWriter WRITER = new BlockWriter();
} }

View File

@@ -0,0 +1,40 @@
package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.tile.TileWriter;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockWriter extends BlockNode {
public BlockWriter() {
super("writer");
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
player.openGui(RS.INSTANCE, RSGui.READER_WRITER, world, pos.getX(), pos.getY(), pos.getZ());
((TileWriter) world.getTileEntity(pos)).onOpened(player);
}
return true;
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new TileWriter();
}
@Override
public EnumPlacementType getPlacementType() {
return EnumPlacementType.ANY;
}
}

View File

@@ -132,6 +132,7 @@ public class ProxyCommon {
registerTile(TileFluidStorage.class, "fluid_storage"); registerTile(TileFluidStorage.class, "fluid_storage");
registerTile(TileDiskManipulator.class, "disk_manipulator"); registerTile(TileDiskManipulator.class, "disk_manipulator");
registerTile(TileReader.class, "reader"); registerTile(TileReader.class, "reader");
registerTile(TileWriter.class, "writer");
registerBlock(RSBlocks.CONTROLLER); registerBlock(RSBlocks.CONTROLLER);
registerBlock(RSBlocks.GRID); registerBlock(RSBlocks.GRID);
@@ -158,6 +159,7 @@ public class ProxyCommon {
registerBlock(RSBlocks.NETWORK_RECEIVER); registerBlock(RSBlocks.NETWORK_RECEIVER);
registerBlock(RSBlocks.DISK_MANIPULATOR); registerBlock(RSBlocks.DISK_MANIPULATOR);
registerBlock(RSBlocks.READER); registerBlock(RSBlocks.READER);
registerBlock(RSBlocks.WRITER);
registerItem(RSItems.QUARTZ_ENRICHED_IRON); registerItem(RSItems.QUARTZ_ENRICHED_IRON);
registerItem(RSItems.STORAGE_DISK); registerItem(RSItems.STORAGE_DISK);

View File

@@ -0,0 +1,86 @@
package com.raoulvdberge.refinedstorage.tile;
import com.raoulvdberge.refinedstorage.RSBlocks;
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IWriter;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.math.BlockPos;
public class TileWriter extends TileNode implements IWriter, IReaderWriter {
private int redstoneStrength;
private int lastRedstoneStrength;
@Override
public int getEnergyUsage() {
return 0; // @TODO
}
@Override
public void update() {
super.update();
if (!worldObj.isRemote && redstoneStrength != lastRedstoneStrength) {
lastRedstoneStrength = redstoneStrength;
worldObj.notifyNeighborsOfStateChange(pos, RSBlocks.WRITER);
}
}
@Override
public void updateNode() {
}
@Override
public int getRedstoneStrength() {
return connected ? redstoneStrength : 0;
}
@Override
public void setRedstoneStrength(int strength) {
redstoneStrength = strength;
}
@Override
public boolean hasStackUpgrade() {
return false; // @TODO
}
@Override
public String getTitle() {
return "gui.refinedstorage:writer";
}
@Override
public void onAdd(String name) {
if (network != null && !name.isEmpty()) {
network.addReaderWriterChannel(name);
network.sendReaderWriterChannelUpdate();
}
}
@Override
public void onRemove(String name) {
if (network != null && !name.isEmpty()) {
network.removeReaderWriterChannel(name);
network.sendReaderWriterChannelUpdate();
}
}
@Override
public BlockPos getNetworkPosition() {
return network != null ? network.getPosition() : null;
}
@Override
public boolean hasConnectivityState() {
return true;
}
public void onOpened(EntityPlayer entity) {
if (isConnected()) {
network.sendReaderWriterChannelUpdate((EntityPlayerMP) entity);
}
}
}

View File

@@ -53,6 +53,7 @@ gui.refinedstorage:crafting_preview.circular=Circular dependency!
gui.refinedstorage:crafting_preview.loop=Loop in processing... gui.refinedstorage:crafting_preview.loop=Loop in processing...
gui.refinedstorage:crafting_preview.force_start=Press CTRL + SHIFT to start anyway gui.refinedstorage:crafting_preview.force_start=Press CTRL + SHIFT to start anyway
gui.refinedstorage:reader=Reader gui.refinedstorage:reader=Reader
gui.refinedstorage:writer=Writer
misc.refinedstorage:energy_stored=%d / %d RS misc.refinedstorage:energy_stored=%d / %d RS
misc.refinedstorage:energy_usage=Usage: %d RS/t misc.refinedstorage:energy_usage=Usage: %d RS/t
@@ -181,6 +182,7 @@ block.refinedstorage:fluid_storage.2.name=256k Fluid Storage Block
block.refinedstorage:fluid_storage.3.name=512k Fluid Storage Block block.refinedstorage:fluid_storage.3.name=512k Fluid Storage Block
block.refinedstorage:fluid_storage.4.name=Creative Fluid Storage Block block.refinedstorage:fluid_storage.4.name=Creative Fluid Storage Block
block.refinedstorage:reader.name=Reader block.refinedstorage:reader.name=Reader
block.refinedstorage:writer.name=Writer
item.refinedstorage:storage_disk.0.name=1k Storage Disk item.refinedstorage:storage_disk.0.name=1k Storage Disk
item.refinedstorage:storage_disk.1.name=4k Storage Disk item.refinedstorage:storage_disk.1.name=4k Storage Disk