Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed glider requiring two clicks after scrolling away #25

Merged
merged 2 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions src/main/java/openblocks/common/entity/EntityHangGlider.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package openblocks.common.entity;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

Expand All @@ -12,8 +13,6 @@
import net.minecraft.world.World;
import net.minecraft.world.gen.NoiseGeneratorPerlin;

import com.google.common.collect.MapMaker;

import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand Down Expand Up @@ -48,7 +47,7 @@ public class EntityHangGlider extends Entity implements IEntityAdditionalSpawnDa

private static final int PROPERTY_DEPLOYED = 17;

private static Map<EntityPlayer, EntityHangGlider> gliderMap = new MapMaker().weakKeys().weakValues().makeMap();
private static HashMap<EntityPlayer, EntityHangGlider> gliderMap = new HashMap<EntityPlayer, EntityHangGlider>();
serenibyss marked this conversation as resolved.
Show resolved Hide resolved

private IVarioController varioControl = IVarioController.NULL;

Expand All @@ -62,6 +61,10 @@ public static boolean isGliderDeployed(Entity player) {
return glider != null && glider.isDeployed();
}

public static EntityHangGlider getEntityHangGlider(Entity player) {
return gliderMap.get(player);
}

private static boolean isGliderValid(EntityPlayer player, EntityHangGlider glider) {
if (player == null || player.isDead || glider == null || glider.isDead) return false;

Expand Down
10 changes: 1 addition & 9 deletions src/main/java/openblocks/common/item/ItemHangGlider.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package openblocks.common.item;

import java.util.HashSet;
import java.util.Map;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
Expand All @@ -10,8 +9,6 @@
import net.minecraft.world.World;
import net.minecraftforge.common.config.Configuration;

import com.google.common.collect.MapMaker;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import openblocks.OpenBlocks;
import openblocks.common.entity.EntityHangGlider;
Expand All @@ -20,9 +17,6 @@
@BookDocumentation(hasVideo = true)
public class ItemHangGlider extends Item {

private static final Map<EntityPlayer, EntityHangGlider> spawnedGlidersMap = new MapMaker().weakKeys().weakValues()
.makeMap();

private static HashSet<Integer> blacklistedDimensions = new HashSet<>();

public ItemHangGlider() {
Expand Down Expand Up @@ -103,7 +97,7 @@ public static void loadConfig(FMLPreInitializationEvent event) {
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
if (!world.isRemote && player != null) {
EntityHangGlider glider = spawnedGlidersMap.get(player);
EntityHangGlider glider = EntityHangGlider.getEntityHangGlider(player);
if (glider != null) despawnGlider(player, glider);
else spawnGlider(player);
}
Expand All @@ -112,7 +106,6 @@ public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer

private static void despawnGlider(EntityPlayer player, EntityHangGlider glider) {
glider.setDead();
spawnedGlidersMap.remove(player);
}

private static void spawnGlider(EntityPlayer player) {
Expand All @@ -124,7 +117,6 @@ private static void spawnGlider(EntityPlayer player) {
EntityHangGlider glider = new EntityHangGlider(player.worldObj, player);
glider.setPositionAndRotation(player.posX, player.posY, player.posZ, player.rotationPitch, player.rotationYaw);
player.worldObj.spawnEntityInWorld(glider);
spawnedGlidersMap.put(player, glider);
}

private static boolean isInvalidDimension(EntityPlayer player) {
Expand Down