Skip to content

Commit

Permalink
Add option to disable mod for survival mode
Browse files Browse the repository at this point in the history
  • Loading branch information
RatzzFatzz committed Nov 30, 2021
1 parent 2834273 commit 58d4a69
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
plugins {
id 'maven-publish'
id 'fabric-loom' version '0.8.17'
id 'fabric-loom' version '0.10.62'
}

sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

archivesBaseName = 'flymod'
version = '1.7.1'
version = '1.7.2'
group = 'at.pcgf.flymod'

repositories {
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/at/pcgf/flymod/gui/FlyModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.TranslatableText;

import java.io.ObjectInputFilter;

public class FlyModConfig {

@Expose
public boolean mouseControl = true;

@Expose
public boolean onlyForCreative = false;

@Expose
public float flyUpDownBlocks = 0.4f;

Expand All @@ -50,7 +55,8 @@ static Screen createConfigScreen(Screen parent) {
.addEntry(ConfigEntryBuilder.create().startFloatField(ConfigTexts.FLY_SPEED_MULTIPLIER, config.flySpeedMultiplier).setDefaultValue(3f).setSaveConsumer(b -> config.flySpeedMultiplier = b).build())
.addEntry(ConfigEntryBuilder.create().startFloatField(ConfigTexts.RUN_SPEED_MULTIPLIER, config.runSpeedMultiplier).setDefaultValue(2f).setSaveConsumer(b -> config.runSpeedMultiplier = b).build())
.addEntry(ConfigEntryBuilder.create().startBooleanToggle(ConfigTexts.MULTIPLY_UP_DOWN1, config.multiplyUpDown).setDefaultValue(true).setSaveConsumer(b -> config.multiplyUpDown = b).build())
.addEntry(ConfigEntryBuilder.create().startBooleanToggle(ConfigTexts.FADE_MOVEMENT, config.fadeMovement).setDefaultValue(true).setSaveConsumer(b -> config.fadeMovement = b).build());
.addEntry(ConfigEntryBuilder.create().startBooleanToggle(ConfigTexts.FADE_MOVEMENT, config.fadeMovement).setDefaultValue(true).setSaveConsumer(b -> config.fadeMovement = b).build())
.addEntry(ConfigEntryBuilder.create().startBooleanToggle(ConfigTexts.CREATIVE_ONLY, config.onlyForCreative).setDefaultValue(true).setSaveConsumer(b -> config.onlyForCreative = b).build());
builder.setSavingRunnable((FlyModConfigManager::save));
return builder.build();
}
Expand All @@ -59,6 +65,7 @@ private static class ConfigTexts {
static final TranslatableText TITLE = createTranslatableText("text.%s.title");
static final TranslatableText CATEGORY = createTranslatableText("text.%s.category.default");
static final TranslatableText MOUSE_CONTROL = createTranslatableText("text.%s.option.mouseControl");
static final TranslatableText CREATIVE_ONLY = createTranslatableText("text.%s.option.creativeOnly");
static final TranslatableText FLY_UP_DOWN_BLOCKS = createTranslatableText("text.%s.option.flyUpDownBlocks");
static final TranslatableText FLY_SPEED_MULTIPLIER = createTranslatableText("text.%s.option.flySpeedMultiplier");
static final TranslatableText RUN_SPEED_MULTIPLIER = createTranslatableText("text.%s.option.runSpeedMultiplier");
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/at/pcgf/flymod/mixin/PlayerEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.tag.Tag;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Quaternion;
import net.minecraft.util.math.Vec3d;
Expand All @@ -46,7 +42,7 @@ protected PlayerEntityMixin(World world, BlockPos blockPos, float f, GameProfile
public void move(MovementType type, Vec3d vec3d) {
toggleFlying();

if (getAbilities().flying) {
if (getAbilities().flying && isActiveForCurrentGamemode()) {
boolean backwards = MinecraftClient.getInstance().options.keyBack.isPressed();
boolean forwards = MinecraftClient.getInstance().options.keyForward.isPressed();
boolean left = MinecraftClient.getInstance().options.keyLeft.isPressed();
Expand All @@ -61,7 +57,7 @@ public void move(MovementType type, Vec3d vec3d) {
setSprinting(false);
super.move(type, vec);

} else if (!getAbilities().flying) {
} else if (!getAbilities().flying && isActiveForCurrentGamemode()) {
Vec3d vec = vec3d;
if (MinecraftClient.getInstance().options.keySprint.isPressed()) {
setSwimming(isSubmergedInWater);
Expand All @@ -75,6 +71,10 @@ public void move(MovementType type, Vec3d vec3d) {
}

private void toggleFlying() {
if (!isActiveForCurrentGamemode()) {
return;
}

if (flyingState == FLYING) {
getAbilities().flying = true;
} else if (flyingState == NEUTRAL) {
Expand All @@ -83,9 +83,14 @@ private void toggleFlying() {
} else if (flyingState == NOT_FLYING && getAbilities().flying) {
flyingState = FLYING;
}

sendAbilitiesUpdate();
}

private boolean isActiveForCurrentGamemode() {
return !(FlyModConfigManager.getConfig().onlyForCreative && !getAbilities().creativeMode);
}

private Vec3d mouseControlMovement(Vec3d vec3d, boolean backwards, boolean forwards, boolean left, boolean right) {
if (FlyModConfigManager.getConfig().mouseControl) {
float pitch = prevPitch;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/flymod/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"text.flymod.title": "Fly Mod Einstellungen",
"text.flymod.category.default": "Allgemein",
"text.flymod.option.mouseControl": "Ein / Aus von Maussteuerung",
"text.flymod.option.creativeOnly": "Nur im Kreativ-Modus verwenden",
"text.flymod.option.flyUpDownBlocks": "Anzahl an Blöcken die pro Tick hoch- / runtergeflogen wird",
"text.flymod.option.flySpeedMultiplier": "Fluggeschwindigkeitsmultiplikator",
"text.flymod.option.runSpeedMultiplier": "Renngeschwindigkeitsmultiplikator",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/flymod/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"text.flymod.title": "Fly Mod Configuration",
"text.flymod.category.default": "Main",
"text.flymod.option.mouseControl": "Toggle mouse control",
"text.flymod.option.creativeOnly": "Use only in creative mode",
"text.flymod.option.flyUpDownBlocks": "Amount of blocks to fly up or down per tick",
"text.flymod.option.flySpeedMultiplier": "Fly speed multiplier",
"text.flymod.option.runSpeedMultiplier": "Run speed multiplier",
Expand Down

0 comments on commit 58d4a69

Please sign in to comment.