The Masters Dalek Plan
This commit is contained in:
parent
f6a2fa93f2
commit
9e9412e53e
25 changed files with 492 additions and 139 deletions
|
@ -1,8 +1,11 @@
|
|||
package su.a71.tardim_ic.tardim_ic;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
@ -26,6 +29,10 @@ import su.a71.tardim_ic.tardim_ic.registration.CommandInit;
|
|||
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;
|
||||
|
||||
|
||||
public class Registration {
|
||||
// Blocks
|
||||
|
||||
|
@ -58,6 +65,10 @@ public class Registration {
|
|||
.icon(() -> new ItemStack(DIGITAL_TARDIM_INTERFACE))
|
||||
.build();
|
||||
|
||||
// Cloister bell
|
||||
public static final ResourceLocation CLOISTER_SOUND = new ResourceLocation("tardim_ic:cloister");
|
||||
public static SoundEvent CLOISTER_SOUND_EVENT = new SoundEvent(CLOISTER_SOUND);
|
||||
|
||||
|
||||
// Register our stuff
|
||||
public static void register() {
|
||||
|
@ -70,6 +81,8 @@ public class Registration {
|
|||
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);
|
||||
|
||||
ComputerCraftAPI.registerPeripheralProvider(new DigitalInterfacePeripheralProvider());
|
||||
CommandInit.init();
|
||||
}
|
||||
|
|
|
@ -4,16 +4,13 @@ import com.swdteam.tardim.common.command.tardim.CommandTardimBase;
|
|||
import com.swdteam.tardim.common.command.tardim.ICommand;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
import com.swdteam.tardim.common.init.TRDDimensions;
|
||||
import net.minecraft.world.level.Level;
|
||||
import su.a71.tardim_ic.tardim_ic.Registration;
|
||||
|
||||
//import static com.swdteam.common.command.tardim.CommandTardimBase.sendResponse;
|
||||
import su.a71.tardim_ic.tardim_ic.Registration;
|
||||
|
||||
public class CommandCloisterBell implements ICommand {
|
||||
@Override
|
||||
|
@ -34,8 +31,6 @@ public class CommandCloisterBell implements ICommand {
|
|||
1f
|
||||
);
|
||||
}
|
||||
|
||||
CommandTardimBase.sendResponse(player, "<Insert Cloister bell>", CommandTardimBase.ResponseType.COMPLETE, source);
|
||||
} catch (Exception var9) {
|
||||
CommandTardimBase.sendResponse(player, "There was an error", CommandTardimBase.ResponseType.FAIL, source);
|
||||
}
|
||||
|
@ -55,7 +50,7 @@ public class CommandCloisterBell implements ICommand {
|
|||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "cloister-bell";
|
||||
return "/cloister-bell";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package su.a71.tardim_ic.tardim_ic.mixin;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.ComparatorBlock;
|
||||
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 org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.swdteam.tardim.tileentity.TileEntityFuelStorage;
|
||||
|
||||
//@Mixin(TileEntityFuelStorage.class)
|
||||
//public class FuelTank extends BlockEntity, ComparatorBlockEntity {
|
||||
//
|
||||
// public ExampleMixin(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
|
||||
// super(blockEntityType, blockPos, blockState);
|
||||
// }
|
||||
//
|
||||
// @Inject(at = @At("HEAD"), method = "init()V")
|
||||
// private void init(CallbackInfo info) {
|
||||
//
|
||||
// Constants.LOG.info("This line is printed by an example mod mixin from Fabric!");
|
||||
// Constants.LOG.info("MC Version: {}", Minecraft.getInstance().getVersionType());
|
||||
// Constants.LOG.info("Classloader: {}", this.getClass().getClassLoader());
|
||||
// }
|
||||
//}
|
||||
//public class FuelTank {
|
||||
//}
|
|
@ -16,7 +16,6 @@ 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.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
@ -24,21 +23,20 @@ import net.minecraft.world.entity.player.Player;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
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.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.a71.tardim_ic.tardim_ic.Registration;
|
||||
import su.a71.tardim_ic.tardim_ic.utils.FakePlayer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class RedstoneInputBlock extends BlockBaseTardimPanel implements EntityBlock {
|
||||
private boolean isPowered = false;
|
||||
private Player lastPlayer = null;
|
||||
public RedstoneInputBlock() {
|
||||
super(FabricBlockSettings.of(Material.METAL).strength(2, 4)); // No occlusion?
|
||||
}
|
||||
|
@ -56,10 +54,10 @@ public class RedstoneInputBlock extends BlockBaseTardimPanel implements EntityBl
|
|||
w.playSound(null, blockPos, TRDSounds.TARDIM_BEEP, SoundSource.BLOCKS, 0.3F, 0.5F);
|
||||
|
||||
BlockEntity be = w.getBlockEntity(blockPos);
|
||||
if (be instanceof TileEntityBaseTardimPanel && w.dimension() == TRDDimensions.TARDIS) {
|
||||
if (be instanceof RedstoneInputTileEntity && w.dimension() == TRDDimensions.TARDIS) {
|
||||
TardimData data = TardimManager.getFromPos(blockPos);
|
||||
if (data != null && data.hasPermission(player)) {
|
||||
this.lastPlayer = player;
|
||||
((RedstoneInputTileEntity) be).lastPlayer = player.getGameProfile().getId();
|
||||
NetworkHandler.sendTo((ServerPlayer)player, new PacketOpenEditGui(blockPos, 1));
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
|
@ -80,22 +78,26 @@ public class RedstoneInputBlock extends BlockBaseTardimPanel implements EntityBl
|
|||
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 RedstoneInputTileEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get redstone signal
|
||||
Direction direction = blockState.getValue(FACING);
|
||||
int redstoneSignal = level.getSignal(blockPos, direction);
|
||||
if (redstoneSignal > 0 && !isPowered) {
|
||||
isPowered = true;
|
||||
BlockEntity be = level.getBlockEntity(blockPos);
|
||||
if (be instanceof TileEntityBaseTardimPanel && level.dimension() == TRDDimensions.TARDIS) {
|
||||
if (redstoneSignal > 0 && !((RedstoneInputTileEntity) be).isPowered) {
|
||||
((RedstoneInputTileEntity) be).isPowered = true;
|
||||
if (level.dimension() == TRDDimensions.TARDIS) {
|
||||
TardimData data = TardimManager.getFromPos(blockPos);
|
||||
if (data != null && !level.isClientSide && this.lastPlayer != null) {
|
||||
if (data != null && !level.isClientSide && ((RedstoneInputTileEntity) be).lastPlayer != null) {
|
||||
if (((TileEntityBaseTardimPanel)be).hasCommand()) {
|
||||
((TileEntityBaseTardimPanel)be).execute(this.lastPlayer);
|
||||
((TileEntityBaseTardimPanel)be).execute(new FakePlayer(level, blockPos, ((RedstoneInputTileEntity) be).lastPlayer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (redstoneSignal == 0 && isPowered)
|
||||
isPowered = false;
|
||||
} else if (redstoneSignal == 0 && ((RedstoneInputTileEntity) be).isPowered)
|
||||
((RedstoneInputTileEntity) be).isPowered = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,17 @@ package su.a71.tardim_ic.tardim_ic.redstone_input;
|
|||
import com.swdteam.tardim.tileentity.TileEntityBaseTardimPanel;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import su.a71.tardim_ic.tardim_ic.Registration;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class RedstoneInputTileEntity extends TileEntityBaseTardimPanel {
|
||||
public boolean isPowered = false;
|
||||
public UUID lastPlayer = null;
|
||||
|
||||
public RedstoneInputTileEntity(BlockPos pos, BlockState state) {
|
||||
super(Registration.REDSTONE_TARDIM_INPUT_TILEENTITY, pos, state);
|
||||
}
|
||||
|
@ -15,4 +21,21 @@ public class RedstoneInputTileEntity extends TileEntityBaseTardimPanel {
|
|||
public BlockPos getPos() {
|
||||
return this.worldPosition;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void saveAdditional(CompoundTag tag) {
|
||||
tag.putBoolean("is_powered", isPowered);
|
||||
if (lastPlayer != null) {
|
||||
tag.putUUID("last_player", lastPlayer);
|
||||
}
|
||||
super.saveAdditional(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag tag) {
|
||||
super.load(tag);
|
||||
isPowered = tag.getBoolean("is_powered");
|
||||
lastPlayer = tag.getUUID("last_player");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
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 DockData(int id, Level level, BlockPos blockPos) {
|
||||
this.level = level;
|
||||
this.blockPos = blockPos;
|
||||
this.name = DockManager.addDock(this);
|
||||
}
|
||||
|
||||
public void setActive(boolean setting) {
|
||||
this.active = setting;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
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 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<>();
|
||||
Gson gson = new Gson();
|
||||
|
||||
|
||||
public DockManager() {
|
||||
}
|
||||
|
||||
public static DockData getDock(String name) {
|
||||
return DOCK_DATA.get(name);
|
||||
}
|
||||
|
||||
public static String addDock(DockData dockData) {
|
||||
String new_id = Integer.toString(DOCK_DATA.size());
|
||||
DOCK_DATA.put(new_id, dockData);
|
||||
return new_id;
|
||||
}
|
||||
|
||||
public void toggleActive(String name, boolean active) {
|
||||
DockData dockData = DOCK_DATA.get(name);
|
||||
dockData.setActive(active);
|
||||
}
|
||||
|
||||
public void updateDock(String name, DockData dockData) {
|
||||
DOCK_DATA.put(name, dockData);
|
||||
}
|
||||
|
||||
public void load(MinecraftServer server) 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 void save(MinecraftServer server) 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");
|
||||
}
|
||||
}
|
|
@ -35,15 +35,9 @@ import su.a71.tardim_ic.tardim_ic.Registration;
|
|||
|
||||
public class TardimDockBlock extends Block implements EntityBlock {
|
||||
public TardimDockBlock() {
|
||||
super(FabricBlockSettings.of(Material.METAL).strength(2, 4).noOcclusion()); // No occlusion?
|
||||
super(FabricBlockSettings.of(Material.METAL).strength(2, 4).noOcclusion());
|
||||
}
|
||||
|
||||
// @Nullable
|
||||
// @Override
|
||||
// public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) {
|
||||
// return Registration.REDSTONE_TARDIM_INPUT_TILEENTITY.create(pos, state);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public InteractionResult use(BlockState blockState, Level w, BlockPos blockPos, Player player, InteractionHand hand, BlockHitResult p_60508_) {
|
||||
if (!w.isClientSide) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import su.a71.tardim_ic.tardim_ic.Registration;
|
|||
|
||||
public class TardimDockBlockEntity extends BlockEntity {
|
||||
public int dock_id;
|
||||
public DockData data;
|
||||
|
||||
public TardimDockBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||
super(Registration.TARDIM_DOCK_BLOCKENTITY, blockPos, blockState);
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
"su.a71.tardim_ic.tardim_ic.TardimInControl"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"tardim_ic.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.10",
|
||||
|
|
14
Fabric/src/main/resources/tardim_ic.mixins.json
Normal file
14
Fabric/src/main/resources/tardim_ic.mixins.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "su.a71.tardim_ic.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"FuelTank"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue