diff --git a/common/src/main/java/whocraft/tardis_refined/common/block/shell/GlobalShellBlock.java b/common/src/main/java/whocraft/tardis_refined/common/block/shell/GlobalShellBlock.java index 81120f921..13462641c 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/block/shell/GlobalShellBlock.java +++ b/common/src/main/java/whocraft/tardis_refined/common/block/shell/GlobalShellBlock.java @@ -73,23 +73,6 @@ public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { return new GlobalShellBlockEntity(blockPos, blockState); } - @Override - public void onProjectileHit(Level level, BlockState blockState, BlockHitResult blockHitResult, Projectile projectile) { - super.onProjectileHit(level, blockState, blockHitResult, projectile); - if(level instanceof ServerLevel serverLevel){ - TardisLevelOperator.get(serverLevel).ifPresent(tardisLevelOperator -> tardisLevelOperator.getTardisHADSManager().activateHads(serverLevel, blockHitResult.getBlockPos())); - } - } - - - @Override - public void wasExploded(Level level, BlockPos blockPos, Explosion explosion) { - if (level instanceof ServerLevel serverLevel) { - TardisLevelOperator.get(serverLevel).ifPresent(tardisLevelOperator -> tardisLevelOperator.getTardisHADSManager().activateHads(serverLevel, blockPos)); - } - super.wasExploded(level, blockPos, explosion); - } - @Override public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) { diff --git a/common/src/main/java/whocraft/tardis_refined/common/capability/TardisLevelOperator.java b/common/src/main/java/whocraft/tardis_refined/common/capability/TardisLevelOperator.java index 232caf7ee..e67f03510 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/capability/TardisLevelOperator.java +++ b/common/src/main/java/whocraft/tardis_refined/common/capability/TardisLevelOperator.java @@ -41,9 +41,9 @@ public class TardisLevelOperator { private final TardisFlightEventManager tardisFlightEventManager; private final TardisClientData tardisClientData; private final UpgradeHandler upgradeHandler; - private final TardisHADSManager tardisHADSManager; private final AestheticHandler aestheticHandler; + public TardisLevelOperator(Level level) { this.level = level; this.exteriorManager = new TardisExteriorManager(this); @@ -53,7 +53,6 @@ public TardisLevelOperator(Level level) { this.tardisFlightEventManager = new TardisFlightEventManager(this); this.tardisClientData = new TardisClientData(level.dimension()); this.upgradeHandler = new UpgradeHandler(this); - this.tardisHADSManager = new TardisHADSManager(this); this.aestheticHandler = new AestheticHandler(this); } @@ -65,10 +64,6 @@ public TardisClientData tardisClientData() { return tardisClientData; } - public TardisHADSManager getTardisHADSManager() { - return tardisHADSManager; - } - public AestheticHandler getAestheticHandler() { return aestheticHandler; } @@ -93,7 +88,6 @@ public CompoundTag serializeNBT() { compoundTag = this.tardisWaypointManager.saveData(compoundTag); compoundTag = this.tardisFlightEventManager.saveData(compoundTag); compoundTag = this.upgradeHandler.saveData(compoundTag); - compoundTag = this.tardisHADSManager.saveData(compoundTag); compoundTag = this.aestheticHandler.saveData(compoundTag); return compoundTag; @@ -116,7 +110,6 @@ public void deserializeNBT(CompoundTag tag) { this.tardisFlightEventManager.loadData(tag); this.tardisWaypointManager.loadData(tag); this.upgradeHandler.loadData(tag); - this.tardisHADSManager.loadData(tag); this.aestheticHandler.loadData(tag); tardisClientData.sync(); } @@ -129,7 +122,6 @@ public void tick(ServerLevel level) { interiorManager.tick(level); pilotingManager.tick(level); tardisFlightEventManager.tick(); - tardisHADSManager.tick(); var shouldSync = level.getGameTime() % 40 == 0; if (shouldSync) { diff --git a/common/src/main/java/whocraft/tardis_refined/common/notification/NotifcationService.java b/common/src/main/java/whocraft/tardis_refined/common/notification/NotifcationService.java new file mode 100644 index 000000000..1d0f336e5 --- /dev/null +++ b/common/src/main/java/whocraft/tardis_refined/common/notification/NotifcationService.java @@ -0,0 +1,26 @@ +package whocraft.tardis_refined.common.notification; + +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; + +import java.util.logging.Level; + +public class NotifcationService { + + public static boolean canPlayerBeNotified(Player player, ResourceKey tardis) { + Inventory inventory = player.getInventory(); + for (ItemStack item : inventory.items) { + if (item.getItem() instanceof NotifiableItem notifiableItem) { + if (notifiableItem.containsIntendedTardis(item, tardis)) { + return true; + } + } + } + return false; + } + + + +} diff --git a/common/src/main/java/whocraft/tardis_refined/common/notification/NotifiableItem.java b/common/src/main/java/whocraft/tardis_refined/common/notification/NotifiableItem.java new file mode 100644 index 000000000..3584ccdb8 --- /dev/null +++ b/common/src/main/java/whocraft/tardis_refined/common/notification/NotifiableItem.java @@ -0,0 +1,14 @@ +package whocraft.tardis_refined.common.notification; + +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; + +import java.util.logging.Level; + +public interface NotifiableItem { + + boolean containsIntendedTardis(ItemStack stack, ResourceKey tardis); + +} diff --git a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisHADSManager.java b/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisHADSManager.java deleted file mode 100644 index 1264511ad..000000000 --- a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisHADSManager.java +++ /dev/null @@ -1,89 +0,0 @@ -package whocraft.tardis_refined.common.tardis.manager; - -import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.RandomSource; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import whocraft.tardis_refined.TardisRefined; -import whocraft.tardis_refined.common.blockentity.shell.GlobalShellBlockEntity; -import whocraft.tardis_refined.common.capability.TardisLevelOperator; -import whocraft.tardis_refined.common.capability.upgrades.UpgradeHandler; -import whocraft.tardis_refined.common.capability.upgrades.Upgrades; -import whocraft.tardis_refined.common.tardis.TardisNavLocation; - -public class TardisHADSManager extends BaseHandler { - - private static final int MAX_DISTANCE = 1000; - private static final int RETURN_DELAY_MIN = 12000; - private static final int RETURN_DELAY_MAX = 24000; - - private int timeTillReturn = 0; - - private TardisLevelOperator tardisLevelOperator; - - public TardisHADSManager(TardisLevelOperator tardisLevelOperator) { - this.tardisLevelOperator = tardisLevelOperator; - } - - public void tick() { - if (timeTillReturn > 0) { - timeTillReturn = timeTillReturn - 1; - // Check if it's time to return - if (timeTillReturn == 0 && tardisLevelOperator.getLevel() instanceof ServerLevel serverLevel) { - returnToPreviousPosition(serverLevel); - } - } - } - - public void loadData(CompoundTag tag) { - this.timeTillReturn = tag.getInt("timeTillReturn"); - } - - public CompoundTag saveData(CompoundTag tag) { - tag.putInt("timeTillReturn", this.timeTillReturn); - return tag; - } - - public int getTimeTillReturn() { - return timeTillReturn; - } - - public void activateHads(Level level, BlockPos blockPos) { - timeTillReturn = 0; - if (level instanceof ServerLevel serverLevel && timeTillReturn == 0) { - // Set the time until return - timeTillReturn = serverLevel.random.nextInt(RETURN_DELAY_MIN, RETURN_DELAY_MAX); - - BlockEntity blockEntity = serverLevel.getBlockEntity(blockPos); - if (blockEntity instanceof GlobalShellBlockEntity globalShellBlockEntity && globalShellBlockEntity.getTardisId() != null) { - RandomSource random = serverLevel.random; - UpgradeHandler upgradeHandler = tardisLevelOperator.getUpgradeHandler(); - - if (!Upgrades.HOSTILE_DISPLACEMENT.get().isUnlocked(upgradeHandler)) { - return; - } - - TardisNavLocation lastKnown = tardisLevelOperator.getExteriorManager().getLastKnownLocation(); - int maxX = (int) lastKnown.getLevel().getWorldBorder().getMaxX(); - int maxZ = (int) lastKnown.getLevel().getWorldBorder().getMaxZ(); - BlockPos newLocation = new BlockPos(random.nextInt(maxX - MAX_DISTANCE), lastKnown.getPosition().getY(), random.nextInt(maxZ - MAX_DISTANCE)); - - tardisLevelOperator.getPilotingManager().setTargetPosition(newLocation); - tardisLevelOperator.getPilotingManager().beginFlight(true); - //TODO Debug Code removal - TardisRefined.LOGGER.info("New destination set. Returning in " + (timeTillReturn / 20) + " seconds. " + newLocation.toShortString()); - } - } - } - - public void returnToPreviousPosition(ServerLevel serverLevel) { - TardisLevelOperator.get(serverLevel).ifPresent(tardisLevelOperator -> { - TardisPilotingManager pilotingManager = tardisLevelOperator.getPilotingManager(); - pilotingManager.preloadFastReturn(); - pilotingManager.beginFlight(true); - timeTillReturn = 0; - }); - } -}