Skip to content

Commit

Permalink
Fixed a few dist errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
LtxProgrammer committed Oct 11, 2024
1 parent 2d1d258 commit e7e2a71
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.world.entity.LivingEntity;

import javax.annotation.Nullable;
import java.util.Optional;

public class GrabEntityAbility extends AbstractAbility<GrabEntityAbilityInstance> {
public GrabEntityAbility() {
Expand All @@ -32,4 +33,10 @@ public static boolean isEntityNoControl(Entity entity) {

return IAbstractChangedEntity.forEither(ext.getGrabbedBy());
}

public static Optional<IAbstractChangedEntity> getGrabberSafe(LivingEntity grabbed) {
if (!(grabbed instanceof LivingEntityDataExtension ext)) return Optional.empty();

return Optional.ofNullable(IAbstractChangedEntity.forEither(ext.getGrabbedBy()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ public void tick() {
if (this.getController().getHoldTicks() >= 40) {
if (suited) {
this.grabEntity(this.grabbedEntity);
Changed.PACKET_HANDLER.sendToServer(GrabEntityPacket.initialGrab((Player)entity.getEntity(), this.grabbedEntity));
if (this.entity.getLevel().isClientSide)
Changed.PACKET_HANDLER.sendToServer(GrabEntityPacket.initialGrab((Player)entity.getEntity(), this.grabbedEntity));
this.suitTransition = 0.0f;
} else
this.releaseEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import javax.annotation.Nullable;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

public interface IAbstractChangedEntity {
Expand Down Expand Up @@ -87,6 +88,10 @@ else if (getTransfurVariant() != null && getTransfurVariant().getEntityType() ==
return doesAbsorption;
}

default <T extends AbstractAbilityInstance> Optional<T> getAbilityInstanceSafe(AbstractAbility<T> ability) {
return Optional.ofNullable(getAbilityInstance(ability));
}

static IAbstractChangedEntity forPlayer(Player player) {
Cacheable<TransfurVariantInstance<?>> instance = Cacheable.of(() -> ProcessTransfur.getPlayerTransfurVariant(player));
Cacheable<ChangedEntity> latex = Cacheable.of(() -> instance.get().getChangedEntity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.datafixers.util.Pair;
import net.ltxprogrammer.changed.Changed;
import net.ltxprogrammer.changed.ability.AbstractAbility;
import net.ltxprogrammer.changed.ability.GrabEntityAbility;
import net.ltxprogrammer.changed.client.gui.ContentWarningScreen;
import net.ltxprogrammer.changed.client.renderer.layers.DarkLatexMaskLayer;
import net.ltxprogrammer.changed.client.renderer.layers.GasMaskLayer;
Expand Down Expand Up @@ -164,6 +165,14 @@ public void onInputEvent(InputEvent.ClickInputEvent event) {
}
});
});

GrabEntityAbility.getGrabberSafe(localPlayer).flatMap(entity -> entity.getAbilityInstanceSafe(ChangedAbilities.GRAB_ENTITY_ABILITY.get()))
.ifPresent(ability -> {
if (ability.grabbedHasControl) return;

event.setCanceled(true);
event.setSwingHand(false);
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.pathfinder.Path;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.common.ForgeMod;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.EntityEvent;
Expand Down Expand Up @@ -364,19 +363,6 @@ public static void onBlockLeftClick(PlayerInteractEvent.LeftClickBlock event) {
});
}

@SubscribeEvent
public static void onClick(InputEvent.ClickInputEvent event) {
if (!(UniversalDist.getLocalPlayer() instanceof LivingEntityDataExtension ext)) return;

AbstractAbility.getAbilityInstanceSafe(ext.getGrabbedBy(), ChangedAbilities.GRAB_ENTITY_ABILITY.get())
.ifPresent(ability -> {
if (ability.grabbedHasControl) return;

event.setCanceled(true);
event.setSwingHand(false);
});
}

@SubscribeEvent
public static void onLivingFallEvent(LivingFallEvent event) {
TransfurVariant<?> variant = TransfurVariant.getEntityVariant(event.getEntityLiving());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.ltxprogrammer.changed.init.ChangedTags;
import net.ltxprogrammer.changed.process.ProcessTransfur;
import net.ltxprogrammer.changed.util.EntityUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.commands.CommandSource;
import net.minecraft.core.BlockPos;
import net.minecraft.tags.FluidTags;
Expand Down Expand Up @@ -99,7 +98,7 @@ public void getPassengersRidingOffset(CallbackInfoReturnable<Double> callback) {
@Inject(method = "getEyePosition()Lnet/minecraft/world/phys/Vec3;", at = @At("HEAD"), cancellable = true)
public final void getEyePosition(CallbackInfoReturnable<Vec3> callback) {
ProcessTransfur.ifPlayerTransfurred(EntityUtil.playerOrNull(asEntity()), (player, variant) -> {
float z = Mth.lerp(variant.getMorphProgression(Minecraft.getInstance().getDeltaFrameTime()), 0.0f, variant.getParent().cameraZOffset);
float z = Mth.lerp(variant.getMorphProgression(), 0.0f, variant.getParent().cameraZOffset);
var vec = new Vec3(player.getX(), player.getEyeY(), player.getZ());
var look = player.getLookAngle().multiply(1.0, 0.0, 1.0).normalize();
if (Math.abs(look.x()) < 0.0001f && Math.abs(look.z()) < 0.0001f)
Expand All @@ -111,7 +110,7 @@ public final void getEyePosition(CallbackInfoReturnable<Vec3> callback) {
@Inject(method = "getEyePosition(F)Lnet/minecraft/world/phys/Vec3;", at = @At("HEAD"), cancellable = true)
public final void getEyePosition(float v, CallbackInfoReturnable<Vec3> callback) {
ProcessTransfur.ifPlayerTransfurred(EntityUtil.playerOrNull(asEntity()), (player, variant) -> {
float z = Mth.lerp(variant.getMorphProgression(Minecraft.getInstance().getDeltaFrameTime()), 0.0f, variant.getParent().cameraZOffset);
float z = Mth.lerp(variant.getMorphProgression(), 0.0f, variant.getParent().cameraZOffset);
if (Math.abs(z) < 0.0001f) return;
var look = player.getLookAngle().multiply(1.0, 0.0, 1.0).normalize();
if (Math.abs(look.x()) < 0.0001f && Math.abs(look.z()) < 0.0001f)
Expand Down

0 comments on commit e7e2a71

Please sign in to comment.