Skip to content

Commit

Permalink
transdimensional summoning
Browse files Browse the repository at this point in the history
(but STILL not able to keep your request when you go through a portal because Neo Doesn't Love Me. but whatever it's naturally incompatible of course you can't maintain a summon target if it gets summoned elsewhere, there's no way to keep track of these kinds of things. it's fine this is intended behavior. I WANTED THIS. i'll maybe figure it out later or maybe beg for salvation from someone else but it's not that big a deal, seems unlikely that you'd go through a portal while having a request and want to keep that request
  • Loading branch information
afamiliarquiet committed Oct 31, 2024
1 parent 1db3a1f commit f2289eb
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,11 @@
import io.github.afamiliarquiet.familiar_magic.item.NameTagDispenseItemBehavior;
import io.github.afamiliarquiet.familiar_magic.network.FamiliarPacketeering;
import io.github.afamiliarquiet.familiar_magic.network.HattedPayload;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Position;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.dispenser.BlockSource;
import net.minecraft.core.dispenser.DefaultDispenseItemBehavior;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ItemUtils;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AABB;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.ModContainer;
Expand All @@ -40,7 +25,6 @@
import net.neoforged.neoforge.event.entity.living.LivingDropsEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.network.PacketDistributor;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

import static io.github.afamiliarquiet.familiar_magic.FamiliarTricks.getHat;
Expand Down Expand Up @@ -87,6 +71,7 @@ public static class ImReallyGonnaDoItImGonnaExplode {

@SubscribeEvent
private static void mrwPlayerEventStartTracking(PlayerEvent.StartTracking event) {
// why do i gotta do this. why don't the attachments just do this for you. wargh.
Entity theEntity = event.getTarget();
ItemStack hat = getHat(theEntity);
if (theEntity instanceof HatWearer && !hat.isEmpty()) {
Expand All @@ -111,5 +96,36 @@ private static void mrwLivingDropsEvent(LivingDropsEvent event) {
private static void mrwRegisterCommandsEvent(RegisterCommandsEvent event) {
PlaceCandlesCommand.register(event.getDispatcher());
}

// @SubscribeEvent
// private static void mrwNOTEXCLAMATIONMARKPlayerEventClone(EntityTravelToDimensionEvent event) {
// // this player event clone thing has comments for dimension change but doesn't even fire on dimension change.
// // and then entitytraveltodimensionevent doesn't give me before and after!!
// if (!(event.getEntity() instanceof ServerPlayer player)) {
// // this shouldn't happen because clone only happens on server, but i may as well check since i'm casting
// // well now it happens because it's not always a player!!! GRAH
// return;
// }
//
// // oh neat the instanceof variable can carry out beyond a ! return. feels wrong though
// // anyway last ditch effort. we can maybe survive one dimension transition if the packet isn't Instantaneous
// // doesn't seem to work on dev env, maybe because packet is Instantaneous but like. whatever. let it break
// // as you well know, teleportation is not compatible with other teleportation. hard to keep a good lock on the target
// // GUARDS!! comment out their entire existence
// if (hasRequest(player)) {
// PacketDistributor.sendToPlayer(player, new SummoningRequestPayload(getRequest(player), false));
// }
//
// if (hasRequest(event.getOriginal())) {
// SummoningRequestData requestData = getRequest(event.getOriginal());
// if (event.isWasDeath()) {
// // player here shouldn't even get used really
// SummoningResponsePayload.eatRequestResponse(requestData, false, event.getEntity());
// } else {
// setRequest(event.getEntity(), requestData);
// PacketDistributor.sendToPlayer((ServerPlayer) event.getEntity(), new SummoningRequestPayload(requestData, false));
// }
// }
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
Expand All @@ -31,6 +32,8 @@
import org.lwjgl.glfw.GLFW;

import static io.github.afamiliarquiet.familiar_magic.FamiliarMagic.MOD_ID;
import static io.github.afamiliarquiet.familiar_magic.FamiliarTricks.getRequest;
import static io.github.afamiliarquiet.familiar_magic.FamiliarTricks.hasRequest;

@Mod(value = "familiar_magic", dist = Dist.CLIENT)
public class FamiliarMagicClient {
Expand Down Expand Up @@ -156,7 +159,7 @@ private static void mrwClientTickEventPost(ClientTickEvent.Pre event) {
}

// accept/reject summoning (a little bit weird to snag option keys isDown but..)
if (focusedNow && player.hasData(FamiliarAttachments.FAMILIAR_SUMMONING_DESTINATION)) {
if (focusedNow && hasRequest(player)) {
if (options.keyShift.isDown()) {
sendReply(player, false);
} else if (options.keyJump.isDown()) {
Expand All @@ -170,18 +173,9 @@ private static void mrwClientTickEventPost(ClientTickEvent.Pre event) {
}
}

public static void sendReply(LocalPlayer player, boolean accepted) {
PacketDistributor.sendToServer(new SummoningResponsePayload(player.getData(FamiliarAttachments.FAMILIAR_SUMMONING_DESTINATION), accepted));
private static void sendReply(Player player, boolean accepted) {
// assumes player hasdata. server will probably just ignore request if it pulls default data though
PacketDistributor.sendToServer(new SummoningResponsePayload(getRequest(player), accepted));
}

// @SubscribeEvent
// private static void mrwLivingEventLivingJumpEvent(LivingEvent.LivingJumpEvent event) {
// // i feel like i shouldn't need to look at every single entity jump event but whatever, if it works it works
// if (event.getEntity() instanceof LocalPlayer player) {
// if (player.getData(FamiliarAttachments.FOCUSED) && player.hasData(FamiliarAttachments.FAMILIAR_SUMMONING_DESTINATION)) {
// PacketDistributor.sendToServer(new SummoningResponsePayload(player.getData(FamiliarAttachments.FAMILIAR_SUMMONING_DESTINATION)));
// }
// }
// }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package io.github.afamiliarquiet.familiar_magic;

import io.github.afamiliarquiet.familiar_magic.data.FamiliarAttachments;
import io.github.afamiliarquiet.familiar_magic.data.SummoningRequestData;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.UUIDUtil;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

Expand All @@ -14,7 +19,9 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class FamiliarTricks {
// yea ill uhhh kill a quarter byte
// todo - configurize?
public static final int SUMMONING_TIME_SECONDS = 30;

public static final char[] I_TAKE_A_BYTE = { // todo - for fun maybe make this configurable
'd', // 0
'o', // 1
Expand All @@ -34,6 +41,7 @@ public class FamiliarTricks {
'h', // f
};

// yea ill uhhh kill a quarter byte
public static final byte[] OW_IVE_BEEN_BYTTEN = new byte[256];
static {
Arrays.fill(OW_IVE_BEEN_BYTTEN, (byte) -1);
Expand Down Expand Up @@ -93,4 +101,37 @@ public static boolean hasHat(Entity entity) {
public static ItemStack getHat(Entity entity) {
return entity.getData(FamiliarAttachments.HAT).getStackInSlot(0);
}

public static @Nullable LivingEntity findTargetByUuid(UUID uuid, MinecraftServer server) {
LivingEntity livingTarget = null;
for (ServerLevel possibleLevel : server.getAllLevels()) {
Entity possibleTarget = possibleLevel.getEntity(uuid);
if (possibleTarget instanceof LivingEntity) {
livingTarget = (LivingEntity) possibleTarget;
break;
}
}
return livingTarget;
}

public static boolean hasRequest(Player player) {
return player.hasData(FamiliarAttachments.SUMMONING_REQUEST);
}

public static SummoningRequestData getRequest(Player player) {
return player.getData(FamiliarAttachments.SUMMONING_REQUEST);
}

public static void setRequest(Player player, SummoningRequestData requestData) {
player.setData(FamiliarAttachments.SUMMONING_REQUEST, requestData);
}

public static void removeRequest(Player player, SummoningRequestData cancellingPayloadData) {
if (hasRequest(player)) {
SummoningRequestData currentData = getRequest(player);
if (cancellingPayloadData.isSameRequester(currentData)) {
player.removeData(FamiliarAttachments.SUMMONING_REQUEST);
}
}
}
}
Loading

0 comments on commit f2289eb

Please sign in to comment.