From adaeb5f30424f2dccec23b1292cc70860c9bb902 Mon Sep 17 00:00:00 2001 From: Andrey Nikitin Date: Sat, 28 Jan 2023 23:20:23 +0300 Subject: [PATCH] Ghost Monument fix --- README.md | 2 +- .../srendi/cctutorial/cctutorial/CCBlock.java | 2 +- .../cctutorial/cctutorial/CCPeripheral.java | 97 +++++++++++++++--- .../blocks/digital_tardim_interface.png | Bin 0 -> 1705 bytes 4 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 src/main/resources/assets/cctutorial/textures/blocks/digital_tardim_interface.png diff --git a/README.md b/README.md index d9de1b9..5f21d7e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This mod is an addon for the [TARDIM mod](https://www.curseforge.com/minecraft/m * Connect a computer to the peripheral using a wired modem and wrap it with `peripheral.wrap()`. * Call one of the many methods available to you. -All the methods can be found in the [API documentation](https:/google.com), and there are some examples in the [examples folder](/examples) +All the methods can be found in the [API documentation](https:/google.com), and there are some examples in the [examples folder](examples) ### Example usecases * Monitor to display fuel levels, current location, and other information on a screen in a nice way. diff --git a/src/main/java/de/srendi/cctutorial/cctutorial/CCBlock.java b/src/main/java/de/srendi/cctutorial/cctutorial/CCBlock.java index ac9187b..3c9f315 100644 --- a/src/main/java/de/srendi/cctutorial/cctutorial/CCBlock.java +++ b/src/main/java/de/srendi/cctutorial/cctutorial/CCBlock.java @@ -16,7 +16,7 @@ import javax.annotation.Nullable; public class CCBlock extends Block implements EntityBlock { public CCBlock() { - super(Properties.of(Material.METAL).strength(5, 5)); + super(Properties.of(Material.METAL).strength(5, 5).noOcclusion()); } /** diff --git a/src/main/java/de/srendi/cctutorial/cctutorial/CCPeripheral.java b/src/main/java/de/srendi/cctutorial/cctutorial/CCPeripheral.java index 682cd48..0c55a14 100644 --- a/src/main/java/de/srendi/cctutorial/cctutorial/CCPeripheral.java +++ b/src/main/java/de/srendi/cctutorial/cctutorial/CCPeripheral.java @@ -1,5 +1,8 @@ package de.srendi.cctutorial.cctutorial; +import com.swdteam.common.command.tardim.CommandTardimBase; +import com.swdteam.common.command.tardim.CommandTravel; +import com.swdteam.common.data.DimensionMapReloadListener; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.peripheral.IPeripheral; @@ -7,6 +10,9 @@ import dan200.computercraft.api.lua.ObjectLuaTable; import dan200.computercraft.api.lua.LuaException; import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.Level; @@ -113,24 +119,28 @@ public class CCPeripheral implements IPeripheral { ++index; } - // We really don't want to create a new TARDIM if we are not inside one, do we? + // We really don't want to access a ghost TARDIM, do we? if (!found) { throw new LuaException("Peripheral is not inside a TARDIM"); } + TardimData T = TardimManager.getTardim(index); + if (T.getCurrentLocation() == null || T.getOwnerName() == null) { + throw new LuaException("Peripheral is not inside a TARDIM"); + } - return TardimManager.getTardim(index); + return T; } // Peripheral methods =============================================================== // Get amount of fuel we have (Out of 100) @LuaFunction(mainThread = true) - public final double get_fuel() throws LuaException { + public final double getFuel() throws LuaException { return getTardimData().getFuel(); } @LuaFunction(mainThread = true) - public final double calculate_fuel() throws LuaException { + public final double calculateFuelForJourney() throws LuaException { TardimData data = getTardimData(); if (data.getTravelLocation() == null) return 0; @@ -150,41 +160,40 @@ public class CCPeripheral implements IPeripheral { // Check whether the TARDIM is locked @LuaFunction(mainThread = true) - public final boolean is_locked() throws LuaException { + public final boolean isLocked() throws LuaException { return getTardimData().isLocked(); } // Check whether the TARDIM is in flight @LuaFunction(mainThread = true) - public final boolean is_in_flight() throws LuaException { return getTardimData().isInFlight(); } + public final boolean isInFlight() throws LuaException { return getTardimData().isInFlight(); } // Supposedly gets UNIX timestamp of when we entered flight @LuaFunction(mainThread = true) - public final long get_time_entered_flight() throws LuaException { + public final long getTimeEnteredFlight() throws LuaException { TardimData data = getTardimData(); if (!data.isInFlight()) { return -1; - // ???? } return data.getTimeEnteredFlight(); } // Get username of the TARDIM's owner @LuaFunction(mainThread = true) - public final String get_owner_name() throws LuaException { + public final String getOwnerName() throws LuaException { TardimData data = getTardimData(); return data.getOwnerName(); } // Lock/Unlock the TARDIM @LuaFunction(mainThread = true) - public final void set_locked(boolean locked) throws LuaException { + public final void setLocked(boolean locked) throws LuaException { getTardimData().setLocked(locked); } // Returns table with current TARDIM location @LuaFunction(mainThread = true) - public final ObjectLuaTable get_current_location() throws LuaException { + public final ObjectLuaTable getCurrentLocation() throws LuaException { Location loc = getTardimData().getCurrentLocation(); return new ObjectLuaTable(Map.of( "dimension", loc.getLevel().location().toString(), @@ -199,7 +208,7 @@ public class CCPeripheral implements IPeripheral { // Returns flight destination (or null if there isn't one) @LuaFunction(mainThread = true) - public final ObjectLuaTable get_flight_location() throws LuaException { + public final ObjectLuaTable getTravelLocation() throws LuaException { TardimData data = getTardimData(); if (data.getTravelLocation() != null) { Location loc = data.getTravelLocation(); @@ -216,4 +225,68 @@ public class CCPeripheral implements IPeripheral { return null; } } + + // Returns table with all companions of this TARDIM's owner + @LuaFunction(mainThread = true) + public final ObjectLuaTable getCompanions() throws LuaException { + TardimData data = getTardimData(); + ObjectLuaTable companions = new ObjectLuaTable(Map.of()); + for (int i = 0; i < data.getCompanions().size(); i++) { + companions.put(i + 1, data.getCompanions().get(i).getUsername()); + } + return companions; + } + + // Supposed to set dimension of the destination + // TODO: This looks like a hazard if someone inserts a dimension that doesn't exist + @LuaFunction(mainThread = true) + public final void setDimension(String dimension) throws LuaException { + TardimData data = getTardimData(); + + + String key = dimension; + dimension = DimensionMapReloadListener.toTitleCase(dimension); + if (TardimManager.DIMENSION_MAP.containsKey(dimension)) { + key = (String)TardimManager.DIMENSION_MAP.get(dimension); + } else { + dimension = dimension.toLowerCase(); + } + + if (!CommandTravel.isValidPath(key)) { + throw new LuaException("Invalid dimension"); + } else { + ResourceKey dim = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(dimension)); + if (data.getTravelLocation() == null) { + data.setTravelLocation(new Location(data.getCurrentLocation())); + } + + data.getTravelLocation().setLocation(dim); + } + } + + // Set X, Y and Z of travel destination + @LuaFunction(mainThread = true) + public final void setTravelLocation(int x, int y, int z) throws LuaException { + TardimData data = getTardimData(); + if (data.getTravelLocation() == null) { + data.setTravelLocation(new Location(data.getCurrentLocation())); + } + + data.getTravelLocation().setPosition(x, y, z); + } + + /* + @LuaFunction(mainThread = true) + public final void demat() throws LuaException { + TardimData data = getTardimData(); + data.setInFlight(true); + } + + @LuaFunction(mainThread = true) + public final void remat() throws LuaException { + TardimData data = getTardimData(); + data.setInFlight(false); + } + + */ } diff --git a/src/main/resources/assets/cctutorial/textures/blocks/digital_tardim_interface.png b/src/main/resources/assets/cctutorial/textures/blocks/digital_tardim_interface.png new file mode 100644 index 0000000000000000000000000000000000000000..d430bc6ddaadb8099d1287982091a014fc1e3c84 GIT binary patch literal 1705 zcmV;a23GlrP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1|&&DK~#8N?VI0g zTtyVeXP0JolbUp!wh2jtZ9)`(6a!K*6)E^olz;^C7*IhU6;XV!FDmGR`XKhf;*$mc zfjn3UMM1$-jA$Ba8x;*rt8HSECSCJ;v*PM^_I@|#&d%NJ-o354a6d52oO5Sx?m6>& zW)o8eeSLlTR4S!5Ha4`pxVWgY*{n(?lUg1f9d(uI@9)neZm6%s83zUiTn?C; zno^san>w9HB-Hr$c!>itx0coF+M1(rlg$>&CX)#rlidvsD!sQ+JK*QbTTa>EvP<2Z z`&-8n>JXFrkJJ|(@X_f{bVXF_fVdMEq2WNLVLV%bi8LMt%K%`!lo6W_gE0sPTIy8q zQ~Oo-!)aHb4l#ns_1~{KsV%-f|3e;u&aqMA006^jJd7@9yaa}sHNCl+EgBAF8nC$| zMoU1LypXYm(Q`L-AZAzj=BxAS$BP#oN$K>*r%qd)Lt7MSx>gBdMH9wcrwF~3E*mp=jGsg;!F(($TsVAQ8P?ygAsap%Xf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