|
|
|
@ -3,6 +3,7 @@ package net.brokenmoon.redcontrol.blockentities;
|
|
|
|
|
import com.simon816.j65el02.device.DiskDriver;
|
|
|
|
|
import net.brokenmoon.redcontrol.RedControl;
|
|
|
|
|
import net.brokenmoon.redcontrol.api.DriveFactory;
|
|
|
|
|
import net.brokenmoon.redcontrol.item.FloppyDisk;
|
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
@ -14,6 +15,7 @@ import net.minecraft.util.math.BlockPos;
|
|
|
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
public class DriveEntity extends Peripheral{
|
|
|
|
|
|
|
|
|
@ -128,7 +130,7 @@ public class DriveEntity extends Peripheral{
|
|
|
|
|
|
|
|
|
|
public ActionResult onUse(PlayerEntity player, Hand hand) {
|
|
|
|
|
if(!world.isClient) {
|
|
|
|
|
if (disk == ItemStack.EMPTY) {
|
|
|
|
|
if (disk == ItemStack.EMPTY && player.getStackInHand(hand).getItem() instanceof FloppyDisk) {
|
|
|
|
|
return loadDisk(player, hand);
|
|
|
|
|
} else if (player.getStackInHand(hand) == ItemStack.EMPTY) {
|
|
|
|
|
return ejectDisk(player, hand);
|
|
|
|
@ -138,7 +140,6 @@ public class DriveEntity extends Peripheral{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ActionResult ejectDisk(PlayerEntity player, Hand hand) {
|
|
|
|
|
RedControl.LOGGER.info("Trying to eject!");
|
|
|
|
|
player.setStackInHand(hand, disk.copy());
|
|
|
|
|
disk = ItemStack.EMPTY;
|
|
|
|
|
this.driver = null;
|
|
|
|
@ -149,7 +150,13 @@ public class DriveEntity extends Peripheral{
|
|
|
|
|
private ActionResult loadDisk(PlayerEntity player, Hand hand) {
|
|
|
|
|
disk = player.getStackInHand(hand).copy();
|
|
|
|
|
player.setStackInHand(hand, ItemStack.EMPTY);
|
|
|
|
|
RedControl.LOGGER.info("Loading with " + disk.getNbt().get("uri"));
|
|
|
|
|
if(!disk.hasNbt()){
|
|
|
|
|
NbtCompound newNbt = new NbtCompound();
|
|
|
|
|
String newUUID = UUID.randomUUID().toString();
|
|
|
|
|
newNbt.putString("uri", "save://" + newUUID + ".img");
|
|
|
|
|
newNbt.putString("serial", newUUID);
|
|
|
|
|
disk.setNbt(newNbt);
|
|
|
|
|
}
|
|
|
|
|
this.driver = DriveFactory.INSTANCE.createDriver(URI.create(disk.getNbt().getString("uri")), String.valueOf(disk.getName()), disk.getNbt().getString("serial"));
|
|
|
|
|
this.buffer = ByteBuffer.allocateDirect(SECTOR_SIZE);
|
|
|
|
|
return ActionResult.SUCCESS;
|
|
|
|
@ -158,13 +165,11 @@ public class DriveEntity extends Peripheral{
|
|
|
|
|
@Override
|
|
|
|
|
protected void writeNbt(NbtCompound nbt) {
|
|
|
|
|
//SUPER DUPER NOT DONE TODO: FINISH THIS.
|
|
|
|
|
disk.writeNbt(nbt);
|
|
|
|
|
super.writeNbt(nbt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void readNbt(NbtCompound nbt) {
|
|
|
|
|
disk = ItemStack.fromNbt(nbt);
|
|
|
|
|
super.readNbt(nbt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|