Say it with me, not even close
This commit is contained in:
parent
eecac8ac7c
commit
024d00049e
29 changed files with 1451 additions and 433 deletions
|
@ -1,59 +1,54 @@
|
|||
package su.a71.tardim_ic.tardim_ic;
|
||||
|
||||
import com.swdteam.tardim.common.command.*;
|
||||
import com.swdteam.tardim.common.init.TRDDimensions;
|
||||
import com.swdteam.tardim.main.Config;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimIDMap;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
import com.swdteam.tardim.tardim.TardimSaveHandler;
|
||||
import com.swdteam.tardim.util.world.SchematicUtils;
|
||||
import com.swdteam.tardim.common.block.BlockTardimDoors;
|
||||
import com.swdteam.tardim.common.block.BlockTardimFloor;
|
||||
import com.swdteam.tardim.common.block.BlockTardimRoof;
|
||||
import com.swdteam.tardim.common.init.TardimRegistry;
|
||||
import com.swdteam.tardim.tileentity.TileEntityTardim;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
|
||||
import com.mojang.datafixers.types.Type;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.util.datafix.fixes.References;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
|
||||
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
||||
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
|
||||
import su.a71.tardim_ic.tardim_ic.digital_interface.DigitalInterfaceBlock;
|
||||
import su.a71.tardim_ic.tardim_ic.digital_interface.DigitalInterfacePeripheralProvider;
|
||||
import su.a71.tardim_ic.tardim_ic.digital_interface.DigitalInterfaceTileEntity;
|
||||
|
||||
import su.a71.tardim_ic.tardim_ic.redstone_input.RedstoneInputBlock;
|
||||
import su.a71.tardim_ic.tardim_ic.redstone_input.RedstoneInputTileEntity;
|
||||
|
||||
import su.a71.tardim_ic.tardim_ic.Constants;
|
||||
import su.a71.tardim_ic.tardim_ic.registration.CommandInit;
|
||||
import su.a71.tardim_ic.tardim_ic.tardim_dock.DockManager;
|
||||
import su.a71.tardim_ic.tardim_ic.tardim_dock.TardimDockBlock;
|
||||
import su.a71.tardim_ic.tardim_ic.tardim_dock.TardimDockBlockEntity;
|
||||
|
||||
import com.swdteam.tardim.tileentity.TileEntityFuelStorage;
|
||||
import com.swdteam.tardim.common.block.BlockFuelStorage;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import su.a71.tardim_ic.tardim_ic.soviet_chronobox.SovietChronoboxTileEntity;
|
||||
|
||||
|
||||
public class Registration {
|
||||
// Blocks
|
||||
public static Block DOOR_SOVIET_CHRONOBOX;
|
||||
public static Block ROOF_SOVIET_CHRONOBOX;
|
||||
public static Block FLOOR_SOVIET_CHRONOBOX;
|
||||
public static BlockEntityType<TileEntityTardim> TILE_SOVIET_CHRONOBOX;
|
||||
|
||||
public static final Block DIGITAL_TARDIM_INTERFACE = new DigitalInterfaceBlock();
|
||||
public static final Block REDSTONE_TARDIM_INPUT = new RedstoneInputBlock();
|
||||
public static final Block TARDIM_DOCK = new TardimDockBlock();
|
||||
|
||||
// Tile Entities
|
||||
public static final BlockEntityType<RedstoneInputTileEntity> REDSTONE_TARDIM_INPUT_TILEENTITY = Registry.register(
|
||||
|
@ -68,12 +63,6 @@ public class Registration {
|
|||
FabricBlockEntityTypeBuilder.create(RedstoneInputTileEntity::new, DIGITAL_TARDIM_INTERFACE).build()
|
||||
);
|
||||
|
||||
public static final BlockEntityType<TardimDockBlockEntity> TARDIM_DOCK_BLOCKENTITY = Registry.register(
|
||||
Registry.BLOCK_ENTITY_TYPE,
|
||||
new ResourceLocation("tardim_ic", "tardim_dock"),
|
||||
FabricBlockEntityTypeBuilder.create(TardimDockBlockEntity::new, TARDIM_DOCK).build()
|
||||
);
|
||||
|
||||
private static final CreativeModeTab TARDIM_IC_TAB = FabricItemGroupBuilder
|
||||
.create(new ResourceLocation("tardim_ic"))
|
||||
.icon(() -> new ItemStack(DIGITAL_TARDIM_INTERFACE))
|
||||
|
@ -83,6 +72,12 @@ public class Registration {
|
|||
public static final ResourceLocation CLOISTER_SOUND = new ResourceLocation("tardim_ic:cloister");
|
||||
public static SoundEvent CLOISTER_SOUND_EVENT = new SoundEvent(CLOISTER_SOUND);
|
||||
|
||||
public static TardimRegistry.TardimBuilder TARDIM_TYPE_SOVIET;
|
||||
|
||||
private static <T extends BlockEntity> BlockEntityType<T> createTardimTile(String string, FabricBlockEntityTypeBuilder<T> builder) {
|
||||
Type<?> type = Util.fetchChoiceType(References.BLOCK_ENTITY, string);
|
||||
return (BlockEntityType)Registry.register(Registry.BLOCK_ENTITY_TYPE, new ResourceLocation(Constants.MOD_ID, string), builder.build(type));
|
||||
}
|
||||
|
||||
// Register our stuff
|
||||
public static void register() {
|
||||
|
@ -92,33 +87,25 @@ public class Registration {
|
|||
Registry.register(Registry.BLOCK, new ResourceLocation(Constants.MOD_ID, "digital_tardim_interface"), DIGITAL_TARDIM_INTERFACE);
|
||||
Registry.register(Registry.ITEM, new ResourceLocation(Constants.MOD_ID, "digital_tardim_interface"), new BlockItem(DIGITAL_TARDIM_INTERFACE, new FabricItemSettings().tab(TARDIM_IC_TAB)));
|
||||
|
||||
Registry.register(Registry.BLOCK, new ResourceLocation(Constants.MOD_ID, "tardim_dock"), TARDIM_DOCK);
|
||||
Registry.register(Registry.ITEM, new ResourceLocation(Constants.MOD_ID, "tardim_dock"), new BlockItem(TARDIM_DOCK, new FabricItemSettings().tab(TARDIM_IC_TAB)));
|
||||
|
||||
Registry.register(Registry.SOUND_EVENT, CLOISTER_SOUND, CLOISTER_SOUND_EVENT);
|
||||
|
||||
FLOOR_SOVIET_CHRONOBOX = Registry.register(Registry.BLOCK, new ResourceLocation(Constants.MOD_ID, "tardim_floor_soviet"), new BlockTardimFloor(FabricBlockSettings.of(Material.WOOD).sounds(SoundType.WOOD).strength(-1.0F, 3600000.0F).noLootTable().noOcclusion(), new BlockTardimFloor.TardimTileData() {
|
||||
public BlockEntityType<TileEntityTardim> getType() {
|
||||
return TILE_SOVIET_CHRONOBOX;
|
||||
}
|
||||
public BlockEntityTicker<? super TileEntityTardim> getTicker() {
|
||||
return TileEntityTardim::serverTick;
|
||||
}
|
||||
public BlockEntity createBlockEntity(BlockPos var1, BlockState var2) {
|
||||
return new SovietChronoboxTileEntity(var1, var2);
|
||||
}
|
||||
}));
|
||||
TILE_SOVIET_CHRONOBOX = createTardimTile("tardim_soviet_chronobox", FabricBlockEntityTypeBuilder.create(SovietChronoboxTileEntity::new, new Block[]{FLOOR_SOVIET_CHRONOBOX}));
|
||||
DOOR_SOVIET_CHRONOBOX = Registry.register(Registry.BLOCK, new ResourceLocation(Constants.MOD_ID, "tardim_door_soviet"), new BlockTardimDoors(FabricBlockSettings.of(Material.WOOD).sounds(SoundType.WOOD).strength(-1.0F, 3600000.0F).noLootTable().noOcclusion()));
|
||||
ROOF_SOVIET_CHRONOBOX = Registry.register(Registry.BLOCK, new ResourceLocation(Constants.MOD_ID, "tardim_roof_soviet"), new BlockTardimRoof(FabricBlockSettings.of(Material.WOOD).sounds(SoundType.WOOD).strength(-1.0F, 3600000.0F).noLootTable().noOcclusion()));
|
||||
TARDIM_TYPE_SOVIET = new TardimRegistry.TardimBuilder(new ResourceLocation(Constants.MOD_ID, "tardim_soviet_chronobox"), "TARDIM Soviet Chronobox", ROOF_SOVIET_CHRONOBOX, DOOR_SOVIET_CHRONOBOX, FLOOR_SOVIET_CHRONOBOX);
|
||||
|
||||
ComputerCraftAPI.registerPeripheralProvider(new DigitalInterfacePeripheralProvider());
|
||||
CommandInit.init();
|
||||
|
||||
ServerLifecycleEvents.SERVER_STARTING.register((server) -> {
|
||||
DockManager.server = server;
|
||||
DockManager.clearCahce();
|
||||
|
||||
try {
|
||||
DockManager.load();
|
||||
} catch (Exception var2) {
|
||||
var2.printStackTrace();
|
||||
}
|
||||
});
|
||||
ServerWorldEvents.UNLOAD.register((server, world) -> {
|
||||
try {
|
||||
if (DockManager.server == null) {
|
||||
return;
|
||||
}
|
||||
DockManager.save();
|
||||
} catch (Exception var5) {
|
||||
var5.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -45,7 +45,6 @@ public class DigitalInterfacePeripheral implements IPeripheral {
|
|||
|
||||
private final List<IComputerAccess> connectedComputers = new ArrayList<>(); // List of computers connected to the peripheral
|
||||
private final IDigitalInterfaceEntity tileEntity; // Peripheral's BlockEntity, used for accessing coordinates
|
||||
|
||||
/**
|
||||
* @param tileEntity the tile entity of this peripheral
|
||||
* @hidden
|
||||
|
@ -111,7 +110,7 @@ public class DigitalInterfacePeripheral implements IPeripheral {
|
|||
* @throws LuaException if the peripheral is not in a TARDIM
|
||||
* @hidden
|
||||
*/
|
||||
public TardimData getTardimData() throws LuaException {
|
||||
public TardimData getTardimDataInitial() {
|
||||
int X = getTileEntity().getPos().getX(), Z = getTileEntity().getPos().getZ();
|
||||
|
||||
int index = 0;
|
||||
|
@ -154,17 +153,26 @@ public class DigitalInterfacePeripheral implements IPeripheral {
|
|||
}
|
||||
|
||||
// We really don't want to access a ghost TARDIM, do we?
|
||||
// If we fail checks here are not inside a TARDIM
|
||||
if (!found) {
|
||||
throw new LuaException("Peripheral is not inside a TARDIM");
|
||||
return null;
|
||||
}
|
||||
TardimData T = TardimManager.getTardim(index);
|
||||
if (T.getCurrentLocation() == null || T.getOwnerName() == null) {
|
||||
throw new LuaException("Peripheral is not inside a TARDIM");
|
||||
return null;
|
||||
}
|
||||
|
||||
return T;
|
||||
}
|
||||
|
||||
public TardimData getTardimData() throws LuaException {
|
||||
TardimData data = this.getTileEntity().getTardim();
|
||||
if (data == null || data.getCurrentLocation() == null || data.getOwnerName() == null) {
|
||||
throw new LuaException("Peripheral is not inside a TARDIM");
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
// Peripheral methods ===============================================================
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,24 +1,96 @@
|
|||
package su.a71.tardim_ic.tardim_ic.digital_interface;
|
||||
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import su.a71.tardim_ic.tardim_ic.Registration;
|
||||
|
||||
|
||||
public class DigitalInterfaceTileEntity extends BlockEntity implements IDigitalInterfaceEntity {
|
||||
public class DigitalInterfaceTileEntity extends BlockEntity {//implements IDigitalInterfaceEntity {
|
||||
//public TardimData data; // Our TARDIM
|
||||
|
||||
|
||||
public DigitalInterfaceTileEntity(BlockPos pos, BlockState state) {
|
||||
super(Registration.DIGITAL_TARDIM_INTERFACE_TILEENTITY, pos, state);
|
||||
//this.data = getTardimDataInitial();
|
||||
}
|
||||
|
||||
public BlockPos getPos() {
|
||||
return this.worldPosition;
|
||||
}
|
||||
// public BlockPos getPos() {
|
||||
// return this.worldPosition;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public TardimData getTardim() {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
/**
|
||||
* The peripheral
|
||||
*/
|
||||
protected DigitalInterfacePeripheral peripheral = new DigitalInterfacePeripheral(this);
|
||||
// /**
|
||||
// * The peripheral
|
||||
// */
|
||||
// protected DigitalInterfacePeripheral peripheral = new DigitalInterfacePeripheral(this);
|
||||
|
||||
// public TardimData getTardimDataInitial() {
|
||||
// int X = this.getPos().getX(), Z = this.getPos().getZ();
|
||||
//
|
||||
// int index = 0;
|
||||
// int x = 0;
|
||||
// int y = 0;
|
||||
// int dx = 0;
|
||||
// int dy = 1;
|
||||
// int segment_length = 1;
|
||||
// int segment_passed = 0;
|
||||
// boolean found = false;
|
||||
// long timecheck = System.currentTimeMillis();
|
||||
//
|
||||
// while(true) {
|
||||
// if (System.currentTimeMillis() - timecheck > 10000L) {
|
||||
// System.out.println("Finding ID from XZ Coordinates is taking too long!");
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// if (X >= x * TardimManager.INTERIOR_BOUNDS
|
||||
// && X <= TardimManager.INTERIOR_BOUNDS + x * TardimManager.INTERIOR_BOUNDS
|
||||
// && Z >= y * TardimManager.INTERIOR_BOUNDS
|
||||
// && Z <= TardimManager.INTERIOR_BOUNDS + y * TardimManager.INTERIOR_BOUNDS) {
|
||||
// found = true;
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// x += dx;
|
||||
// y += dy;
|
||||
// if (++segment_passed == segment_length) {
|
||||
// segment_passed = 0;
|
||||
// int buffer = dy;
|
||||
// dy = -dx;
|
||||
// dx = buffer;
|
||||
// if (buffer == 0) {
|
||||
// ++segment_length;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ++index;
|
||||
// }
|
||||
//
|
||||
// // We really don't want to access a ghost TARDIM, do we?
|
||||
// // If we fail checks here are not inside a TARDIM
|
||||
// if (!found) {
|
||||
// return null;
|
||||
// }
|
||||
// TardimData T = TardimManager.getTardim(index);
|
||||
// if (T.getCurrentLocation() == null || T.getOwnerName() == null) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// return T;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void load(CompoundTag tag) {
|
||||
// super.load(tag);
|
||||
// this.data = getTardimDataInitial();
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
package su.a71.tardim_ic.tardim_ic.digital_interface;
|
||||
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public class FakeDigitalInterfaceTileEntity implements IDigitalInterfaceEntity {
|
||||
public BlockPos blockPos;
|
||||
public Level level;
|
||||
public TardimData data; // Our TARDIM
|
||||
|
||||
|
||||
FakeDigitalInterfaceTileEntity(BlockPos in_block, Level in_level) {
|
||||
this.blockPos = in_block;
|
||||
this.level = in_level;
|
||||
this.data = getTardimDataInitial();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getPos() {
|
||||
return this.blockPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Level getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TardimData getTardim() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public TardimData getTardimDataInitial() {
|
||||
int X = this.getPos().getX(), Z = this.getPos().getZ();
|
||||
|
||||
int index = 0;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int dx = 0;
|
||||
int dy = 1;
|
||||
int segment_length = 1;
|
||||
int segment_passed = 0;
|
||||
boolean found = false;
|
||||
long timecheck = System.currentTimeMillis();
|
||||
|
||||
while(true) {
|
||||
if (System.currentTimeMillis() - timecheck > 10000L) {
|
||||
System.out.println("Finding ID from XZ Coordinates is taking too long!");
|
||||
break;
|
||||
}
|
||||
|
||||
if (X >= x * TardimManager.INTERIOR_BOUNDS
|
||||
&& X <= TardimManager.INTERIOR_BOUNDS + x * TardimManager.INTERIOR_BOUNDS
|
||||
&& Z >= y * TardimManager.INTERIOR_BOUNDS
|
||||
&& Z <= TardimManager.INTERIOR_BOUNDS + y * TardimManager.INTERIOR_BOUNDS) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
x += dx;
|
||||
y += dy;
|
||||
if (++segment_passed == segment_length) {
|
||||
segment_passed = 0;
|
||||
int buffer = dy;
|
||||
dy = -dx;
|
||||
dx = buffer;
|
||||
if (buffer == 0) {
|
||||
++segment_length;
|
||||
}
|
||||
}
|
||||
|
||||
++index;
|
||||
}
|
||||
|
||||
// We really don't want to access a ghost TARDIM, do we?
|
||||
// If we fail checks here are not inside a TARDIM
|
||||
if (!found) {
|
||||
return null;
|
||||
}
|
||||
TardimData T = TardimManager.getTardim(index);
|
||||
if (T.getCurrentLocation() == null || T.getOwnerName() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return T;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package su.a71.tardim_ic.tardim_ic.digital_interface;
|
||||
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public interface IDigitalInterfaceEntity {
|
||||
public BlockPos getPos();
|
||||
public Level getLevel();
|
||||
|
||||
public TardimData getTardim();
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package su.a71.tardim_ic.tardim_ic.soviet_chronobox;
|
||||
|
||||
import com.swdteam.tardim.common.init.TRDTiles;
|
||||
import com.swdteam.tardim.tileentity.TileEntityTardim;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import su.a71.tardim_ic.tardim_ic.Registration;
|
||||
|
||||
public class SovietChronoboxTileEntity extends TileEntityTardim {
|
||||
public SovietChronoboxTileEntity(BlockPos pos, BlockState state) {
|
||||
super(Registration.TILE_SOVIET_CHRONOBOX, pos, state);
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package su.a71.tardim_ic.tardim_ic.tardim_dock;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public class DockData {
|
||||
public String name;
|
||||
public BlockPos blockPos;
|
||||
public Level level;
|
||||
public boolean active = true;
|
||||
public boolean occupied = false;
|
||||
|
||||
public DockData(BlockPos blockPos) {
|
||||
this.blockPos = blockPos;
|
||||
this.name = DockManager.addDock(this);
|
||||
}
|
||||
|
||||
public void setActive(boolean setting) {
|
||||
this.active = setting;
|
||||
DockManager.updateDock(this.name, this);
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
package su.a71.tardim_ic.tardim_ic.tardim_dock;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.swdteam.tardim.main.Config;
|
||||
import com.swdteam.tardim.main.Tardim;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
import com.swdteam.tardim.tardim.TardimSaveHandler;
|
||||
import com.swdteam.tardim.tardim.TardimIDMap;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DockManager {
|
||||
private static Map<String, DockData> DOCK_DATA = new HashMap<>();
|
||||
static Gson gson = new Gson();
|
||||
public static MinecraftServer server;
|
||||
|
||||
|
||||
public DockManager() {
|
||||
}
|
||||
|
||||
public static DockData getDock(String name) {
|
||||
return DOCK_DATA.get(name);
|
||||
}
|
||||
|
||||
public static String addDock(DockData dockData) {
|
||||
int new_id = DOCK_DATA.size();
|
||||
while (DOCK_DATA.containsKey(Integer.toString(new_id))) {
|
||||
System.out.println(new_id + "Was taken so we try another");
|
||||
new_id++;
|
||||
}
|
||||
System.out.println("PICKED ID: " + new_id);
|
||||
|
||||
DOCK_DATA.put(Integer.toString(new_id), dockData);
|
||||
return Integer.toString(new_id);
|
||||
}
|
||||
|
||||
public static void removeDock(String name) {
|
||||
DOCK_DATA.remove(name);
|
||||
}
|
||||
|
||||
public static void updateDock(String name, DockData dockData) {
|
||||
DOCK_DATA.put(name, dockData);
|
||||
}
|
||||
|
||||
public static void load() throws Exception {
|
||||
File file = new File(server.getWorldPath(LevelResource.ROOT) + "/tardim_ic/dock_map.json");
|
||||
|
||||
// Check if file exists
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
FileWriter writer = new FileWriter(file);
|
||||
writer.write(gson.toJson(new HashMap<Integer, DockData>()));
|
||||
writer.close();
|
||||
return;
|
||||
}
|
||||
|
||||
Type typeOfDockMap = new TypeToken<Map<Integer, DockData>>() { }.getType();
|
||||
|
||||
JsonReader reader = new JsonReader(new FileReader(file));
|
||||
String json = gson.fromJson(reader, String.class);
|
||||
DOCK_DATA = gson.fromJson(json, typeOfDockMap);
|
||||
|
||||
System.out.println("Loaded TARDIM: IC docks");
|
||||
}
|
||||
|
||||
public static void save() throws Exception {
|
||||
File file = new File(server.getWorldPath(LevelResource.ROOT) + "/tardim_ic/dock_map.json");
|
||||
|
||||
// Check if file exists
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(DOCK_DATA);
|
||||
JsonWriter writer = new JsonWriter(new FileWriter(file));
|
||||
writer.jsonValue(json);
|
||||
writer.close();
|
||||
|
||||
System.out.println("Saved TARDIM: IC docks");
|
||||
}
|
||||
|
||||
public static void clearCahce() {
|
||||
DOCK_DATA.clear();
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
package su.a71.tardim_ic.tardim_ic.tardim_dock;
|
||||
|
||||
import com.swdteam.tardim.common.init.TRDDimensions;
|
||||
import com.swdteam.tardim.common.init.TRDSounds;
|
||||
import com.swdteam.tardim.network.NetworkHandler;
|
||||
import com.swdteam.tardim.network.PacketOpenEditGui;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
import com.swdteam.tardim.tileentity.TileEntityBaseTardimPanel;
|
||||
import com.swdteam.tardim.tileentity.TileEntityTardim;
|
||||
import com.swdteam.tardim.tileentity.tardim.TardimType96TileEntity;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.DebugPackets;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.a71.tardim_ic.tardim_ic.Registration;
|
||||
import su.a71.tardim_ic.tardim_ic.redstone_input.RedstoneInputTileEntity;
|
||||
import su.a71.tardim_ic.tardim_ic.utils.FakePlayer;
|
||||
|
||||
import net.minecraft.world.level.block.RedstoneLampBlock;
|
||||
|
||||
public class TardimDockBlock extends Block implements EntityBlock {
|
||||
public TardimDockBlock() {
|
||||
super(FabricBlockSettings.of(Material.METAL).strength(2, 4).noOcclusion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult use(BlockState blockState, Level w, BlockPos blockPos, Player player, InteractionHand hand, BlockHitResult p_60508_) {
|
||||
if (!w.isClientSide) {
|
||||
BlockEntity be = w.getBlockEntity(blockPos);
|
||||
if (be instanceof TardimDockBlockEntity) {
|
||||
|
||||
player.displayClientMessage(
|
||||
Component.literal("Dock name: '" + ((TardimDockBlockEntity) be).data.name + "'").withStyle(ChatFormatting.DARK_AQUA).withStyle(ChatFormatting.BOLD), true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
|
||||
public boolean canSurvive(BlockState blockState, LevelReader levelReader, BlockPos blockPos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Un-register the dock when breaking
|
||||
@Override
|
||||
public void destroy(LevelAccessor levelAccessor, BlockPos blockPos, BlockState blockState) {
|
||||
super.destroy(levelAccessor, blockPos, blockState);
|
||||
BlockEntity be = levelAccessor.getBlockEntity(blockPos);
|
||||
if (be instanceof TardimDockBlockEntity) {
|
||||
DockManager.removeDock(((TardimDockBlockEntity) be).data.name);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||
return Registration.TARDIM_DOCK_BLOCKENTITY.create(blockPos, blockState);
|
||||
}
|
||||
|
||||
|
||||
public void neighborChanged(BlockState blockState, Level level, BlockPos blockPos, Block block, BlockPos fromPos, boolean isMoving) {
|
||||
DebugPackets.sendNeighborsUpdatePacket(level, blockPos);
|
||||
|
||||
BlockEntity be = level.getBlockEntity(blockPos);
|
||||
if (!(be instanceof TardimDockBlockEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get redstone signal
|
||||
if (level.hasNeighborSignal(blockPos)) {
|
||||
if (!((TardimDockBlockEntity) be).isPowered) {
|
||||
((TardimDockBlockEntity) be).isPowered = true;
|
||||
}
|
||||
}
|
||||
else if (((TardimDockBlockEntity) be).isPowered) {
|
||||
((TardimDockBlockEntity) be).isPowered = false;
|
||||
}
|
||||
((TardimDockBlockEntity) be).updateActive();
|
||||
|
||||
// Check stuff
|
||||
((TardimDockBlockEntity) be).data.occupied = (level.getBlockEntity(blockPos.above()) instanceof TileEntityTardim);
|
||||
if ((level.getBlockEntity(blockPos.above()) instanceof TileEntityTardim)) {
|
||||
System.out.println("Oooo TARDIM docked!!!!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package su.a71.tardim_ic.tardim_ic.tardim_dock;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.world.level.block.ComparatorBlock;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.entity.ComparatorBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import su.a71.tardim_ic.tardim_ic.Registration;
|
||||
|
||||
public class TardimDockBlockEntity extends BlockEntity {
|
||||
public boolean isPowered = false;
|
||||
public DockData data;
|
||||
private BlockPos blockPos;
|
||||
|
||||
public TardimDockBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||
super(Registration.TARDIM_DOCK_BLOCKENTITY, blockPos, blockState);
|
||||
this.blockPos = blockPos;
|
||||
this.data = new DockData(blockPos);
|
||||
}
|
||||
|
||||
public void updateActive() {
|
||||
this.data.setActive(this.isPowered);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAdditional(CompoundTag tag) {
|
||||
tag.putString("data_name", data.name);
|
||||
tag.putBoolean("data_active", data.active);
|
||||
super.saveAdditional(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag tag) {
|
||||
super.load(tag);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue