mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 14:52:58 +00:00
Gravitational Modulating Unit backport
This commit is contained in:
18 files changed
+413
-12
No files matched your search
@@ -16,6 +16,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.obj.OBJLoader;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -24,6 +25,7 @@ public final class MekaSuitClientProxy extends MekaSuitCommonProxy {
|
||||
|
||||
@Override
|
||||
public void registerClientHandlers() {
|
||||
ClientRegistry.registerKeyBinding(MekaSuitJetpackClientHandler.boostKey);
|
||||
MinecraftForge.EVENT_BUS.register(MekaSuitVisionHandler.INSTANCE);
|
||||
MinecraftForge.EVENT_BUS.register(MekaSuitJetpackClientHandler.INSTANCE);
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ import mekanism.common.MekanismSounds;
|
||||
import mekanism.mekasuit.api.gear.ModuleData;
|
||||
import mekanism.mekasuit.api.gear.ModuleTarget;
|
||||
import mekanism.mekasuit.common.MekanismMekaSuit;
|
||||
import mekanism.mekasuit.common.content.gear.MekaSuitGravitationalHelper;
|
||||
import mekanism.mekasuit.common.content.gear.MekaSuitJetpackHelper;
|
||||
import mekanism.mekasuit.common.content.gear.MekaSuitModules;
|
||||
import mekanism.mekasuit.common.content.gear.ModuleContainer;
|
||||
import mekanism.mekasuit.common.item.ItemMekaSuitBodyarmor;
|
||||
import mekanism.mekasuit.common.network.PacketMekaSuitBoostState;
|
||||
import mekanism.mekasuit.common.network.PacketMekaSuitGravitationalMode;
|
||||
import mekanism.mekasuit.common.network.PacketMekaSuitModeChange;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -23,14 +27,18 @@ import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
/** Local input synchronization, movement prediction, and armor-mode switching for the Jetpack Unit. */
|
||||
/** Local input synchronization, movement prediction, and armor-mode switching for bodyarmor flight units. */
|
||||
@SideOnly(Side.CLIENT)
|
||||
public final class MekaSuitJetpackClientHandler {
|
||||
|
||||
public static final MekaSuitJetpackClientHandler INSTANCE = new MekaSuitJetpackClientHandler();
|
||||
public static final KeyBinding boostKey = new KeyBinding(
|
||||
"mekanism.key.boost", Keyboard.KEY_LCONTROL, MekanismKeyHandler.keybindCategory);
|
||||
|
||||
private boolean modeKeyDown;
|
||||
private boolean boostKeyDown;
|
||||
|
||||
private MekaSuitJetpackClientHandler() {
|
||||
}
|
||||
@@ -44,6 +52,7 @@ public final class MekaSuitJetpackClientHandler {
|
||||
EntityPlayer player = minecraft.player;
|
||||
if (player == null) {
|
||||
modeKeyDown = false;
|
||||
boostKeyDown = false;
|
||||
return;
|
||||
}
|
||||
ItemStack bodyarmor = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
|
||||
@@ -53,6 +62,21 @@ public final class MekaSuitJetpackClientHandler {
|
||||
changeMode(player, bodyarmor);
|
||||
}
|
||||
modeKeyDown = currentModeKey;
|
||||
|
||||
boolean currentBoostKey = minecraft.currentScreen == null && boostKey.isKeyDown();
|
||||
if (currentBoostKey != boostKeyDown) {
|
||||
boostKeyDown = currentBoostKey;
|
||||
MekanismMekaSuit.network.sendToServer(new PacketMekaSuitBoostState(currentBoostKey));
|
||||
}
|
||||
|
||||
ModuleData gravitational = wearingBodyarmor
|
||||
? MekaSuitGravitationalHelper.getModule(bodyarmor) : null;
|
||||
if (gravitational != null && gravitational.isEnabled() && currentBoostKey
|
||||
&& player.capabilities.isFlying && !player.capabilities.isCreativeMode && !player.isSpectator()
|
||||
&& MekaSuitGravitationalHelper.canBoost(bodyarmor, gravitational)) {
|
||||
MekaSuitGravitationalHelper.applyBoost(player,
|
||||
MekaSuitGravitationalHelper.getSpeedBoost(gravitational));
|
||||
}
|
||||
if (!wearingBodyarmor || !MekaSuitJetpackHelper.hasModule(bodyarmor)) {
|
||||
return;
|
||||
}
|
||||
@@ -71,16 +95,29 @@ public final class MekaSuitJetpackClientHandler {
|
||||
private static void changeMode(EntityPlayer player, ItemStack bodyarmor) {
|
||||
ModuleContainer container = ModuleContainer.fromStack(bodyarmor, ModuleTarget.BODYARMOR);
|
||||
ModuleData module = container.get(MekaSuitModules.JETPACK_UNIT);
|
||||
if (module == null) {
|
||||
if (module != null) {
|
||||
String mode = player.isSneaking() ? MekaSuitJetpackHelper.DISABLED
|
||||
: module.getType().cycleMode(module.getMode(), module.getInstalledCount(), 1);
|
||||
if (container.setMode(MekaSuitModules.JETPACK_UNIT, mode)) {
|
||||
container.save(bodyarmor);
|
||||
MekanismMekaSuit.network.sendToServer(new PacketMekaSuitModeChange(mode));
|
||||
player.sendMessage(new TextComponentTranslation("tooltip.mekasuit.jetpack.modeChanged",
|
||||
new TextComponentTranslation("module.mode." + mode)));
|
||||
SoundHandler.playSound(MekanismSounds.HYDRAULIC);
|
||||
}
|
||||
return;
|
||||
}
|
||||
String mode = player.isSneaking() ? MekaSuitJetpackHelper.DISABLED
|
||||
: module.getType().cycleMode(module.getMode(), module.getInstalledCount(), 1);
|
||||
if (container.setMode(MekaSuitModules.JETPACK_UNIT, mode)) {
|
||||
|
||||
module = container.get(MekaSuitModules.GRAVITATIONAL_MODULATING_UNIT);
|
||||
if (module != null) {
|
||||
boolean enabled = !module.isEnabled();
|
||||
if (!container.setEnabled(MekaSuitModules.GRAVITATIONAL_MODULATING_UNIT, enabled)) {
|
||||
return;
|
||||
}
|
||||
container.save(bodyarmor);
|
||||
MekanismMekaSuit.network.sendToServer(new PacketMekaSuitModeChange(mode));
|
||||
player.sendMessage(new TextComponentTranslation("tooltip.mekasuit.jetpack.modeChanged",
|
||||
new TextComponentTranslation("module.mode." + mode)));
|
||||
MekanismMekaSuit.network.sendToServer(new PacketMekaSuitGravitationalMode(enabled));
|
||||
player.sendMessage(new TextComponentTranslation("tooltip.mekasuit.gravitational.modeChanged",
|
||||
new TextComponentTranslation(enabled ? "gui.mekasuit.on" : "gui.mekasuit.off")));
|
||||
SoundHandler.playSound(MekanismSounds.HYDRAULIC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import mekanism.mekasuit.common.MekanismMekaSuit;
|
||||
import mekanism.mekasuit.common.content.gear.MekaSuitVisionHelper;
|
||||
import mekanism.mekasuit.common.content.gear.MekaSuitNutritionalHelper;
|
||||
import mekanism.mekasuit.common.content.gear.MekaSuitJetpackHelper;
|
||||
import mekanism.mekasuit.common.content.gear.MekaSuitGravitationalHelper;
|
||||
import mekanism.mekasuit.common.item.ItemMekaSuitBodyarmor;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -40,6 +41,8 @@ public final class MekaSuitVisionHandler {
|
||||
MekanismMekaSuit.MODID, "gui/hud/vision_enhancement_unit.png");
|
||||
private static final ResourceLocation NUTRITION_ICON = new ResourceLocation(
|
||||
MekanismMekaSuit.MODID, "gui/hud/nutritional_injection_unit.png");
|
||||
private static final ResourceLocation GRAVITATIONAL_ICON = new ResourceLocation(
|
||||
MekanismMekaSuit.MODID, "gui/hud/gravitational_modulation_unit.png");
|
||||
|
||||
private boolean visionApplied;
|
||||
|
||||
@@ -139,8 +142,9 @@ public final class MekaSuitVisionHandler {
|
||||
ModuleData nutrition = MekaSuitNutritionalHelper.getModule(helmet);
|
||||
ItemStack bodyarmor = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
|
||||
ModuleData jetpack = MekaSuitJetpackHelper.getModule(bodyarmor);
|
||||
ModuleData gravitational = MekaSuitGravitationalHelper.getModule(bodyarmor);
|
||||
if (module == null && (nutrition == null || !nutrition.isEnabled())
|
||||
&& (jetpack == null || !jetpack.isEnabled())) {
|
||||
&& (jetpack == null || !jetpack.isEnabled()) && gravitational == null) {
|
||||
return;
|
||||
}
|
||||
ScaledResolution resolution = new ScaledResolution(minecraft);
|
||||
@@ -158,6 +162,13 @@ public final class MekaSuitVisionHandler {
|
||||
drawHudElement(minecraft, NUTRITION_ICON, iconX, y, percent, 0xEB6CA3, 1F);
|
||||
y -= 20;
|
||||
}
|
||||
if (gravitational != null) {
|
||||
boolean enabled = gravitational.isEnabled();
|
||||
String status = I18n.format(enabled ? "gui.mekasuit.on" : "gui.mekasuit.off");
|
||||
drawHudElement(minecraft, GRAVITATIONAL_ICON, iconX, y, status,
|
||||
enabled ? 0x86E7FF : 0x777777, enabled ? 1F : 0.5F);
|
||||
y -= 20;
|
||||
}
|
||||
if (jetpack != null && jetpack.isEnabled() && bodyarmor.getItem() instanceof ItemMekaSuitBodyarmor) {
|
||||
ItemMekaSuitBodyarmor item = (ItemMekaSuitBodyarmor) bodyarmor.getItem();
|
||||
int capacity = item.getMaxGas(bodyarmor);
|
||||
|
||||
@@ -4,6 +4,8 @@ import mekanism.common.base.IGuiProvider;
|
||||
import mekanism.mekasuit.common.inventory.ContainerModificationStation;
|
||||
import mekanism.mekasuit.common.network.PacketModificationStationAction;
|
||||
import mekanism.mekasuit.common.network.PacketMekaSuitModeChange;
|
||||
import mekanism.mekasuit.common.network.PacketMekaSuitBoostState;
|
||||
import mekanism.mekasuit.common.network.PacketMekaSuitGravitationalMode;
|
||||
import mekanism.mekasuit.common.tile.TileEntityModificationStation;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
@@ -27,6 +29,10 @@ public class MekaSuitCommonProxy implements IGuiProvider {
|
||||
PacketModificationStationAction.class, 0, Side.SERVER);
|
||||
MekanismMekaSuit.network.registerMessage(PacketMekaSuitModeChange.Handler.class,
|
||||
PacketMekaSuitModeChange.class, 1, Side.SERVER);
|
||||
MekanismMekaSuit.network.registerMessage(PacketMekaSuitGravitationalMode.Handler.class,
|
||||
PacketMekaSuitGravitationalMode.class, 2, Side.SERVER);
|
||||
MekanismMekaSuit.network.registerMessage(PacketMekaSuitBoostState.Handler.class,
|
||||
PacketMekaSuitBoostState.class, 3, Side.SERVER);
|
||||
}
|
||||
|
||||
public void registerClientHandlers() {
|
||||
|
||||
@@ -76,13 +76,16 @@ public final class MekaSuitItems {
|
||||
public static final ItemMekaModule ChargeDistributionUnit = init(
|
||||
new ItemMekaModule(MekaSuitModules.CHARGE_DISTRIBUTION_UNIT, EnumRarity.RARE),
|
||||
"module_charge_distribution_unit", "ModuleChargeDistributionUnit");
|
||||
public static final ItemMekaModule GravitationalModulatingUnit = init(
|
||||
new ItemMekaModule(MekaSuitModules.GRAVITATIONAL_MODULATING_UNIT, EnumRarity.EPIC),
|
||||
"module_gravitational_modulating_unit", "ModuleGravitationalModulatingUnit");
|
||||
|
||||
private static final List<Item> ITEMS = Collections.unmodifiableList(Arrays.asList(
|
||||
MekaTool, MekaSuitHelmet, MekaSuitBodyarmor, MekaSuitPants, MekaSuitBoots, ModuleBase, EnergyUnit,
|
||||
ExcavationEscalationUnit, AttackAmplificationUnit, FarmingUnit, ShearingUnit, SilkTouchUnit, FortuneUnit,
|
||||
BlastingUnit, VeinMiningUnit, TeleportationUnit, ElectrolyticBreathingUnit,
|
||||
InhalationPurificationUnit, VisionEnhancementUnit, NutritionalInjectionUnit, JetpackUnit,
|
||||
ChargeDistributionUnit));
|
||||
ChargeDistributionUnit, GravitationalModulatingUnit));
|
||||
|
||||
private MekaSuitItems() {
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import mekanism.mekasuit.common.content.gear.MekaSuitModules;
|
||||
import mekanism.mekasuit.common.content.gear.MekaSuitInhalationHelper;
|
||||
import mekanism.mekasuit.common.content.gear.MekaSuitJetpackHandler;
|
||||
import mekanism.mekasuit.common.content.gear.MekaSuitChargeDistributionHandler;
|
||||
import mekanism.mekasuit.common.content.gear.MekaSuitGravitationalHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
@@ -74,6 +75,7 @@ public final class MekanismMekaSuit implements IModule {
|
||||
MinecraftForge.EVENT_BUS.register(MekaSuitInhalationHelper.INSTANCE);
|
||||
MinecraftForge.EVENT_BUS.register(MekaSuitJetpackHandler.INSTANCE);
|
||||
MinecraftForge.EVENT_BUS.register(MekaSuitChargeDistributionHandler.INSTANCE);
|
||||
MinecraftForge.EVENT_BUS.register(MekaSuitGravitationalHandler.INSTANCE);
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(this, new MekaSuitGuiHandler());
|
||||
proxy.registerTileEntities();
|
||||
Mekanism.logger.info("Loaded Mekanism MekaSuit beta module.");
|
||||
|
||||
@@ -22,6 +22,7 @@ public final class MekaSuitConfig {
|
||||
public static final int DEFAULT_SUIT_JETPACK_STORAGE = 24_000;
|
||||
public static final int DEFAULT_SUIT_JETPACK_TRANSFER_RATE = 256;
|
||||
public static final long DEFAULT_SUIT_INVENTORY_CHARGE_RATE = 10_000L;
|
||||
public static final long DEFAULT_SUIT_GRAVITATIONAL_MODULATION_USAGE = 1_000L;
|
||||
public static final long DEFAULT_TOOL_MINING_USAGE = 10L;
|
||||
public static final long DEFAULT_TOOL_SILK_MINING_USAGE = 100L;
|
||||
public static final long DEFAULT_TOOL_WEAPON_USAGE = 2_000L;
|
||||
@@ -52,6 +53,7 @@ public final class MekaSuitConfig {
|
||||
public static int suitJetpackStorage = DEFAULT_SUIT_JETPACK_STORAGE;
|
||||
public static int suitJetpackTransferRate = DEFAULT_SUIT_JETPACK_TRANSFER_RATE;
|
||||
public static long suitInventoryChargeRate = DEFAULT_SUIT_INVENTORY_CHARGE_RATE;
|
||||
public static long suitGravitationalModulationUsage = DEFAULT_SUIT_GRAVITATIONAL_MODULATION_USAGE;
|
||||
public static long toolMiningUsage = DEFAULT_TOOL_MINING_USAGE;
|
||||
public static long toolSilkMiningUsage = DEFAULT_TOOL_SILK_MINING_USAGE;
|
||||
public static long toolWeaponUsage = DEFAULT_TOOL_WEAPON_USAGE;
|
||||
@@ -144,6 +146,9 @@ public final class MekaSuitConfig {
|
||||
suitInventoryChargeRate = getLong(config, "mekasuit", "inventoryChargeRate",
|
||||
DEFAULT_SUIT_INVENTORY_CHARGE_RATE, 1,
|
||||
"Maximum energy transferred from the Charge Distribution Unit into inventory items per tick.");
|
||||
suitGravitationalModulationUsage = getLong(config, "mekasuit", "gravitationalModulation",
|
||||
DEFAULT_SUIT_GRAVITATIONAL_MODULATION_USAGE, 0,
|
||||
"Energy used per tick while flying with the Gravitational Modulating Unit. Boosting uses four times this amount.");
|
||||
modificationStationCapacity = getLong(config, "modification_station", "energyCapacity",
|
||||
DEFAULT_MODIFICATION_STATION_CAPACITY, 1, "Modification Station energy capacity in Joules.");
|
||||
modificationStationUsage = getLong(config, "modification_station", "energyPerTick",
|
||||
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
package mekanism.mekasuit.common.content.gear;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mekanism.mekasuit.api.gear.ModuleData;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
/** Server-authoritative survival flight and boost controller for the Gravitational Modulating Unit. */
|
||||
public final class MekaSuitGravitationalHandler {
|
||||
|
||||
public static final MekaSuitGravitationalHandler INSTANCE = new MekaSuitGravitationalHandler();
|
||||
|
||||
private final Set<UUID> grantedFlight = new HashSet<>();
|
||||
private final Set<UUID> boostingPlayers = new HashSet<>();
|
||||
|
||||
private MekaSuitGravitationalHandler() {
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerTick(PlayerTickEvent event) {
|
||||
if (event.phase != Phase.END || event.side != Side.SERVER) {
|
||||
return;
|
||||
}
|
||||
EntityPlayer player = event.player;
|
||||
UUID playerId = player.getUniqueID();
|
||||
if (player.capabilities.isCreativeMode || player.isSpectator()) {
|
||||
// Creative and spectator own their flight capability; never revoke it.
|
||||
grantedFlight.remove(playerId);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack bodyarmor = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
|
||||
boolean canProvideFlight = MekaSuitGravitationalHelper.canProvideFlight(bodyarmor);
|
||||
updateFlightCapability(player, canProvideFlight);
|
||||
if (!canProvideFlight || !player.capabilities.isFlying) {
|
||||
return;
|
||||
}
|
||||
|
||||
ModuleData module = MekaSuitGravitationalHelper.getModule(bodyarmor);
|
||||
boolean boosting = boostingPlayers.contains(playerId)
|
||||
&& MekaSuitGravitationalHelper.canBoost(bodyarmor, module);
|
||||
long usage = MekaSuitGravitationalHelper.getBaseEnergyUsage();
|
||||
if (boosting) {
|
||||
MekaSuitGravitationalHelper.applyBoost(player,
|
||||
MekaSuitGravitationalHelper.getSpeedBoost(module));
|
||||
usage = MekaSuitGravitationalHelper.getBoostEnergyUsage();
|
||||
}
|
||||
MekaSuitGravitationalHelper.useEnergy(bodyarmor, usage);
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
((EntityPlayerMP) player).connection.floatingTickCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLogout(PlayerLoggedOutEvent event) {
|
||||
UUID playerId = event.player.getUniqueID();
|
||||
grantedFlight.remove(playerId);
|
||||
boostingPlayers.remove(playerId);
|
||||
}
|
||||
|
||||
public void setBoosting(EntityPlayer player, boolean boosting) {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
if (boosting) {
|
||||
boostingPlayers.add(player.getUniqueID());
|
||||
} else {
|
||||
boostingPlayers.remove(player.getUniqueID());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateFlightCapability(EntityPlayer player, boolean shouldAllow) {
|
||||
UUID playerId = player.getUniqueID();
|
||||
boolean changed = false;
|
||||
if (shouldAllow) {
|
||||
if (!player.capabilities.allowFlying) {
|
||||
player.capabilities.allowFlying = true;
|
||||
grantedFlight.add(playerId);
|
||||
changed = true;
|
||||
}
|
||||
} else if (grantedFlight.remove(playerId)) {
|
||||
if (player.capabilities.allowFlying) {
|
||||
player.capabilities.allowFlying = false;
|
||||
changed = true;
|
||||
}
|
||||
if (player.capabilities.isFlying) {
|
||||
player.capabilities.isFlying = false;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed && player instanceof EntityPlayerMP) {
|
||||
((EntityPlayerMP) player).sendPlayerAbilities();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package mekanism.mekasuit.common.content.gear;
|
||||
|
||||
import mekanism.mekasuit.api.gear.ModuleData;
|
||||
import mekanism.mekasuit.api.gear.ModuleTarget;
|
||||
import mekanism.mekasuit.common.config.MekaSuitConfig;
|
||||
import mekanism.mekasuit.common.item.ItemMekaSuitBodyarmor;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
/** Stable Gravitational Modulating Unit energy and movement rules adapted to 1.12 flight capabilities. */
|
||||
public final class MekaSuitGravitationalHelper {
|
||||
|
||||
public static final String SPEED_BOOST_CONFIG = "speed_boost";
|
||||
public static final int BOOST_ENERGY_MULTIPLIER = 4;
|
||||
|
||||
private MekaSuitGravitationalHelper() {
|
||||
}
|
||||
|
||||
public static ModuleData getModule(ItemStack stack) {
|
||||
if (stack == null || stack.isEmpty() || !(stack.getItem() instanceof ItemMekaSuitBodyarmor)) {
|
||||
return null;
|
||||
}
|
||||
return ModuleContainer.fromStack(stack, ModuleTarget.BODYARMOR)
|
||||
.get(MekaSuitModules.GRAVITATIONAL_MODULATING_UNIT);
|
||||
}
|
||||
|
||||
public static boolean canProvideFlight(ItemStack stack) {
|
||||
ModuleData module = getModule(stack);
|
||||
return module != null && module.isEnabled() && hasEnergy(stack, getBaseEnergyUsage());
|
||||
}
|
||||
|
||||
public static boolean canBoost(ItemStack stack, ModuleData module) {
|
||||
return module != null && module.isEnabled() && getSpeedBoost(module) > 0F
|
||||
&& hasEnergy(stack, getBoostEnergyUsage());
|
||||
}
|
||||
|
||||
public static float getSpeedBoost(ModuleData module) {
|
||||
if (module == null) {
|
||||
return 0F;
|
||||
}
|
||||
String value = module.getEnumConfig(SPEED_BOOST_CONFIG);
|
||||
if ("low".equals(value)) {
|
||||
return 0.05F;
|
||||
} else if ("med".equals(value)) {
|
||||
return 0.1F;
|
||||
} else if ("high".equals(value)) {
|
||||
return 0.25F;
|
||||
} else if ("ultra".equals(value)) {
|
||||
return 0.5F;
|
||||
}
|
||||
return 0F;
|
||||
}
|
||||
|
||||
public static long getBaseEnergyUsage() {
|
||||
return Math.max(0L, MekaSuitConfig.suitGravitationalModulationUsage);
|
||||
}
|
||||
|
||||
public static long getBoostEnergyUsage() {
|
||||
long base = getBaseEnergyUsage();
|
||||
return base > Long.MAX_VALUE / BOOST_ENERGY_MULTIPLIER
|
||||
? Long.MAX_VALUE : base * BOOST_ENERGY_MULTIPLIER;
|
||||
}
|
||||
|
||||
public static boolean hasEnergy(ItemStack stack, long amount) {
|
||||
return stack != null && !stack.isEmpty() && stack.getItem() instanceof ItemMekaSuitBodyarmor
|
||||
&& ((ItemMekaSuitBodyarmor) stack.getItem()).getEnergy(stack) >= Math.max(0L, amount);
|
||||
}
|
||||
|
||||
public static void useEnergy(ItemStack stack, long amount) {
|
||||
if (stack != null && !stack.isEmpty() && stack.getItem() instanceof ItemMekaSuitBodyarmor) {
|
||||
ItemMekaSuitBodyarmor armor = (ItemMekaSuitBodyarmor) stack.getItem();
|
||||
armor.setEnergy(stack, armor.getEnergy(stack) - Math.max(0L, amount));
|
||||
}
|
||||
}
|
||||
|
||||
/** Matches modern moveRelative(0, 0, 1) boost direction without changing vertical velocity. */
|
||||
public static void applyBoost(EntityPlayer player, float boost) {
|
||||
if (player == null || boost <= 0F) {
|
||||
return;
|
||||
}
|
||||
float yaw = player.rotationYaw * 0.017453292F;
|
||||
player.motionX -= MathHelper.sin(yaw) * boost;
|
||||
player.motionZ += MathHelper.cos(yaw) * boost;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,9 @@ public final class MekaSuitModules {
|
||||
public static final ModuleType CHARGE_DISTRIBUTION_UNIT = type("charge_distribution_unit", ModuleTarget.BODYARMOR)
|
||||
.booleanConfig("charge_suit", true).booleanConfig("charge_inventory", false).build();
|
||||
public static final ModuleType GRAVITATIONAL_MODULATING_UNIT = type("gravitational_modulating_unit", ModuleTarget.BODYARMOR)
|
||||
.handlesModeChange().exclusive(ModuleExclusive.OVERRIDE_JUMP).build();
|
||||
.handlesModeChange()
|
||||
.enumConfig("speed_boost", 4, "low", "off", "low", "med", "high", "ultra")
|
||||
.exclusive(ModuleExclusive.OVERRIDE_JUMP).build();
|
||||
public static final ModuleType ELYTRA_UNIT = type("elytra_unit", ModuleTarget.BODYARMOR)
|
||||
.handlesModeChange().disabledByDefault().build();
|
||||
|
||||
|
||||
+7
-1
@@ -72,7 +72,13 @@ public final class ModificationStationOperations {
|
||||
ModuleContainer container = getContainerForKnownType(host, moduleId);
|
||||
ModuleType type = ModuleRegistry.getInstance().get(moduleId);
|
||||
ModuleData data = container == null || type == null ? null : container.get(type);
|
||||
if (data == null || !container.setEnabled(type, !data.isEnabled())) {
|
||||
return data != null && setEnabled(host, moduleId, !data.isEnabled());
|
||||
}
|
||||
|
||||
public static boolean setEnabled(ItemStack host, ResourceLocation moduleId, boolean enabled) {
|
||||
ModuleContainer container = getContainerForKnownType(host, moduleId);
|
||||
ModuleType type = ModuleRegistry.getInstance().get(moduleId);
|
||||
if (container == null || type == null || !container.setEnabled(type, enabled)) {
|
||||
return false;
|
||||
}
|
||||
container.save(host);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package mekanism.mekasuit.common.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import mekanism.mekasuit.common.content.gear.MekaSuitGravitationalHandler;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
/** Synchronizes the module-local boost key without extending Core's legacy key map. */
|
||||
public final class PacketMekaSuitBoostState implements IMessage {
|
||||
|
||||
private boolean boosting;
|
||||
|
||||
public PacketMekaSuitBoostState() {
|
||||
}
|
||||
|
||||
public PacketMekaSuitBoostState(boolean boosting) {
|
||||
this.boosting = boosting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf data) {
|
||||
boosting = data.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf data) {
|
||||
data.writeBoolean(boosting);
|
||||
}
|
||||
|
||||
public static final class Handler implements IMessageHandler<PacketMekaSuitBoostState, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketMekaSuitBoostState message, MessageContext context) {
|
||||
EntityPlayerMP player = context.getServerHandler().player;
|
||||
player.getServerWorld().addScheduledTask(() ->
|
||||
MekaSuitGravitationalHandler.INSTANCE.setBoosting(player, message.boosting));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package mekanism.mekasuit.common.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import mekanism.mekasuit.common.content.gear.MekaSuitModules;
|
||||
import mekanism.mekasuit.common.content.gear.ModificationStationOperations;
|
||||
import mekanism.mekasuit.common.item.ItemMekaSuitBodyarmor;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
/** Server-validated armor-mode hotkey toggle for the Gravitational Modulating Unit. */
|
||||
public final class PacketMekaSuitGravitationalMode implements IMessage {
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
public PacketMekaSuitGravitationalMode() {
|
||||
}
|
||||
|
||||
public PacketMekaSuitGravitationalMode(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf data) {
|
||||
enabled = data.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf data) {
|
||||
data.writeBoolean(enabled);
|
||||
}
|
||||
|
||||
public static final class Handler implements IMessageHandler<PacketMekaSuitGravitationalMode, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketMekaSuitGravitationalMode message, MessageContext context) {
|
||||
EntityPlayerMP player = context.getServerHandler().player;
|
||||
player.getServerWorld().addScheduledTask(() -> {
|
||||
ItemStack bodyarmor = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
|
||||
if (!bodyarmor.isEmpty() && bodyarmor.getItem() instanceof ItemMekaSuitBodyarmor) {
|
||||
ModificationStationOperations.setEnabled(bodyarmor,
|
||||
MekaSuitModules.GRAVITATIONAL_MODULATING_UNIT.getId(), message.enabled);
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 446 B |
@@ -20,6 +20,7 @@ item.ModuleVisionEnhancementUnit.name=Vision Enhancement Unit
|
||||
item.ModuleNutritionalInjectionUnit.name=Nutritional Injection Unit
|
||||
item.ModuleJetpackUnit.name=Jetpack Unit
|
||||
item.ModuleChargeDistributionUnit.name=Charge Distribution Unit
|
||||
item.ModuleGravitationalModulatingUnit.name=Gravitational Modulating Unit
|
||||
tile.ModificationStation.name=Modification Station
|
||||
tooltip.ModificationStation=Installs and configures modules for the Meka-Tool and MekaSuit.
|
||||
gui.mekasuit.remove=Remove
|
||||
@@ -34,6 +35,8 @@ tooltip.mekasuit.maxInstalled=Maximum Installed
|
||||
tooltip.mekasuit.supportedGear=Supported Gear
|
||||
tooltip.mekasuit.hydrogen=Stored Hydrogen
|
||||
tooltip.mekasuit.jetpack.modeChanged=Jetpack mode: %s
|
||||
tooltip.mekasuit.gravitational.modeChanged=Gravitational modulation: %s
|
||||
mekanism.key.boost=Boost
|
||||
module.target.meka_tool=Meka-Tool
|
||||
module.target.helmet=Helmet
|
||||
module.target.bodyarmor=Bodyarmor
|
||||
@@ -125,6 +128,7 @@ module.config.jetpack_mult=Thrust Multiplier
|
||||
module.config.jetpack_mult.hover=Hover Thrust Multiplier
|
||||
module.config.charge_suit=Charge Suit
|
||||
module.config.charge_inventory=Charge Inventory
|
||||
module.config.speed_boost=Speed Boost
|
||||
module.config.short.extended=E
|
||||
module.config.short.teleportation_requires_block=T
|
||||
module.config.short.fill_held=H
|
||||
@@ -135,13 +139,24 @@ module.config.short.jetpack_mult=T
|
||||
module.config.short.jetpack_mult.hover=H
|
||||
module.config.short.charge_suit=S
|
||||
module.config.short.charge_inventory=I
|
||||
module.config.short.speed_boost=B
|
||||
module.config.value.half=0.5x
|
||||
module.config.value.normal=1x
|
||||
module.config.value.fast=2x
|
||||
module.config.value.faster=3x
|
||||
module.config.value.fastest=4x
|
||||
module.config.value.off=0
|
||||
module.config.value.low=0.05
|
||||
module.config.value.med=0.1
|
||||
module.config.value.high=0.25
|
||||
module.config.value.ultra=0.5
|
||||
module.config.value.short.half=.5
|
||||
module.config.value.short.normal=1
|
||||
module.config.value.short.fast=2
|
||||
module.config.value.short.faster=3
|
||||
module.config.value.short.fastest=4
|
||||
module.config.value.short.off=0
|
||||
module.config.value.short.low=.05
|
||||
module.config.value.short.med=.1
|
||||
module.config.value.short.high=.25
|
||||
module.config.value.short.ultra=.5
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "mekanismmekasuit:items/module_gravitational_modulating_unit"
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"type": "mekanism:ore_shaped",
|
||||
"result": {
|
||||
"item": "mekanismmekasuit:module_gravitational_modulating_unit"
|
||||
},
|
||||
"pattern": [
|
||||
"A#A",
|
||||
"EPE",
|
||||
"HHH"
|
||||
],
|
||||
"key": {
|
||||
"A": {"type": "forge:ore_dict", "ore": "alloyUltimate"},
|
||||
"#": {"item": "minecraft:nether_star"},
|
||||
"E": {
|
||||
"type": "mekanism:item_nbt",
|
||||
"item": "mekanism:basicblock2",
|
||||
"data": 4,
|
||||
"nbt": {"tier": 3}
|
||||
},
|
||||
"P": {"item": "mekanismmekasuit:module_base"},
|
||||
"H": {"type": "forge:ore_dict", "ore": "pelletAntimatter"}
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 427 B |
Reference in new issue
Block a user