Skip to content

Commit

Permalink
Add dimension blacklist for glider
Browse files Browse the repository at this point in the history
  • Loading branch information
GTNH-Colen authored and Dream-Master committed Oct 17, 2023
1 parent 9153ec7 commit 4d0f299
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/openblocks/OpenBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ public void preInit(FMLPreInitializationEvent evt) {
// needed first, to properly initialize delegates
FluidRegistry.registerFluid(Fluids.xpJuice);

ItemHangGlider.loadConfig(evt);

startupHelper.registerBlocksHolder(OpenBlocks.Blocks.class);
startupHelper.registerItemsHolder(OpenBlocks.Items.class);

Expand Down
89 changes: 88 additions & 1 deletion src/main/java/openblocks/common/item/ItemHangGlider.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,106 @@
package openblocks.common.item;

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

import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
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;
import openmods.infobook.BookDocumentation;

@BookDocumentation(hasVideo = true)
public class ItemHangGlider extends Item {

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

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

public ItemHangGlider() {
setCreativeTab(OpenBlocks.tabOpenBlocks);
}

// Configuration loading
// Outer Lands - 173
// The Last Millenium - 112
// Underdark - 100
// Mehen Belt - 95
// Seth - 94
// Horus - 93
// Anubis - 92
// Maahes - 91
// Neper - 90
// Miranda - 86
// T Ceti E - 85
// Vega B - 84
// Haumea - 83
// Barnarda F - 82
// Barnarda E - 81
// Saturn - 77
// Neptune - 74
// Jupiter - 71
// Mirror - 70
// Pocket Plane - 69
// Ross128b - 64
// Ross128ba - 63
// Bedrock - 60
// Torment - 56
// Spirit World - 55
// Space Station 54 - 54
// Storage Cell - 52
// Uranus - 51
// The Outer Lands - 50
// Pluto - 49
// Triton - 48
// Proteus - 47
// Oberon - 46
// Callisto - 45
// Titan - 44
// Ganymede - 43
// Ceres - 42
// Enceladus - 41
// Deimos - 40
// Venus - 39
// Phobos - 38
// Mercury - 37
// Io - 36
// Europa - 35
// Kuiper Belt - 33
// Barnarda C - 32
// α Centauri Bb - 31
// Asteroids - 30
// Mars - 29
// Moon - 28
// Makemake - 25
// dimensionDarkWorld - 227

public static void loadConfig(FMLPreInitializationEvent event) {
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
config.load();

int[] dimensionIDs = config.get(
"general",
"BlacklistedDimensions",
new int[] { 95, 94, 93, 92, 86, 85, 84, 83, 82, 81, 77, 74, 71, 69, 63, 54, 51, 49, 48, 47, 46, 45, 44,
43, 42, 41, 40, 39, 38, 37, 36, 35, 33, 32, 31, 30, 29, 28, 25 },
"List of dimension IDs where the glider doesn't work").getIntList();
for (int id : dimensionIDs) {
blacklistedDimensions.add(id);
}

config.save();
}

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
if (!world.isRemote && player != null) {
Expand All @@ -39,9 +117,18 @@ private static void despawnGlider(EntityPlayer player, EntityHangGlider glider)
}

private static void spawnGlider(EntityPlayer player) {
if (isInvalidDimension(player)) {
player.addChatMessage(new ChatComponentText(I18n.format("item.openblocks.hangglider.invalid_dimension")));
return;
}

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) {
return blacklistedDimensions.contains(player.dimension);
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/openblocks/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ item.openblocks.slimalyzer.name=Slimalyzer
item.openblocks.slimalyzer.description=Walk around with the slimalyzer in your hand and it'll light up whenever you're in a slime spawning chunk.

item.openblocks.hangglider.name=Hang Glider
item.openblocks.hangglider.invalid_dimension=It seems the glider doesn't work, perhaps the atmosphere is too thin?
item.openblocks.hangglider.description=The hang glider is self explanatory. Hold it in your hand and click to place it on your back. Now jump!\nTo increase your speed you can press shift while gliding, but watch out, you'll lose altitude faster!\n\nYour hang glider now also includes an acoustic variometer indicating vertical air movement. Press V to activate it and stay up forever (or until the sun goes down)!

item.openblocks.gliderwing.name=Glider Wing
Expand Down

0 comments on commit 4d0f299

Please sign in to comment.