Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.client.event.ClientPlayerChangeGameTypeEvent;
import net.minecraftforge.client.event.ClientPlayerNetworkEvent.LoggingOut;
import net.minecraftforge.client.event.InputEvent.Key;
import net.minecraftforge.client.event.MovementInputUpdateEvent;
Expand All @@ -27,6 +30,8 @@
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import java.util.UUID;

public class ClientEventHandlers {
public static ClientEventHandlers instance = null;

Expand Down Expand Up @@ -191,6 +196,27 @@ public void onCameraSetup(ComputeCameraAngles event) {
}
}

@SubscribeEvent
public void onGameModeChange(ClientPlayerChangeGameTypeEvent event) {
Level level = Minecraft.getInstance().level;

if(level == null) return;

if(event.getNewGameType() == GameType.SPECTATOR) {
UUID profile = event.getInfo().getProfile().getId();
Player p = level.getPlayerByUUID(profile);

if (p == null) return;

int id = p.getId();

GrappleController controller = ClientControllerManager.controllers.get(id);

if (controller != null)
controller.unattach(false);
}
}

public ItemStack getKeypressStack(Player player) {
if (player != null) {
ItemStack stack = player.getItemInHand(InteractionHand.MAIN_HAND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
import com.yyon.grapplinghook.utils.GrapplemodUtils;
import com.yyon.grapplinghook.utils.Vec;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
Expand Down Expand Up @@ -93,16 +96,27 @@ public GrappleController(int grapplehookEntityId, int entityId, Level world, Vec
ClientProxyInterface.proxy.updateRocketRegen(custom.rocket_active_time, custom.rocket_refuel_ratio);
}
}



public void unattach() {
if (ClientProxyInterface.proxy.unregisterController(this.entityId) != null) {
this.attached = false;

if (this.controllerId != GrapplemodUtils.AIRID) {
CommonSetup.network.sendToServer(new GrappleEndMessage(this.entityId, this.grapplehookEntityIds));
ClientProxyInterface.proxy.createControl(GrapplemodUtils.AIRID, -1, this.entityId, this.entity.level(), new Vec(0,0,0), null, this.custom);
}
}
// old behaviour was always true to trigger air friction - retain this unless
// there's a good reason to change it.
this.unattach(true);
}

public void unattach(boolean allowFollowupControllers) {
if (ClientProxyInterface.proxy.unregisterController(this.entityId) == null)
return;

this.attached = false;

if (this.controllerId == GrapplemodUtils.AIRID)
return;

CommonSetup.network.sendToServer(new GrappleEndMessage(this.entityId, this.grapplehookEntityIds));

if(allowFollowupControllers)
ClientProxyInterface.proxy.createControl(GrapplemodUtils.AIRID, -1, this.entityId, this.entity.level(), new Vec(0,0,0), null, this.custom);
}


Expand Down