Skip to content

Commit 1cdf9c6

Browse files
committed
Finish config implementation
1 parent d2a0949 commit 1cdf9c6

File tree

8 files changed

+310
-136
lines changed

8 files changed

+310
-136
lines changed

src/main/java/com/therainbowville/minegasm/client/ClientEventHandler.java

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.therainbowville.minegasm.client;
22

33
import com.mojang.authlib.GameProfile;
4-
import com.sun.media.jfxmedia.logging.Logger;
54
import com.therainbowville.minegasm.common.Minegasm;
65
import net.minecraft.client.Minecraft;
76
import net.minecraft.client.entity.player.ClientPlayerEntity;
@@ -15,8 +14,7 @@
1514
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
1615
import net.minecraftforge.event.entity.EntityLeaveWorldEvent;
1716
import net.minecraftforge.event.entity.living.LivingHurtEvent;
18-
import net.minecraftforge.event.entity.player.PlayerEvent;
19-
import net.minecraftforge.event.entity.player.PlayerXpEvent;
17+
import net.minecraftforge.event.entity.player.*;
2018
import net.minecraftforge.event.world.BlockEvent;
2119
import net.minecraftforge.event.world.WorldEvent;
2220
import net.minecraftforge.eventbus.api.SubscribeEvent;
@@ -50,7 +48,11 @@ public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
5048
if (event.phase == TickEvent.Phase.END) {
5149
tickCounter = (tickCounter + 1) % 24000;
5250

53-
if (tickCounter % 20 == 0) {
51+
if (tickCounter % (5 * 20) == 0) { // 5 secs
52+
LOGGER.debug("Idle: " + event.player.getIdleTime());
53+
LOGGER.debug("Health: " + event.player.getHealth());
54+
LOGGER.debug("Food: " + event.player.getFoodStats().getFoodLevel());
55+
//TODO on full health and food, low vibrate
5456
LOGGER.debug("Tick " + tickCounter / 20 + ": " + toyLevel[tickCounter / 20]);
5557
}
5658
}
@@ -71,13 +73,33 @@ public static void onClientTick(TickEvent.ClientTickEvent event) {
7173
}
7274

7375
if (paused) {
74-
LOGGER.debug("Paused");
76+
//LOGGER.debug("Paused");
7577
}
7678
}
7779
}
7880
}
7981
}
8082

83+
@SubscribeEvent
84+
public static void onAttack(AttackEntityEvent event)
85+
{
86+
Entity entity = event.getEntityLiving();
87+
if (entity instanceof PlayerEntity) {
88+
PlayerEntity player = (PlayerEntity) entity;
89+
GameProfile profile = player.getGameProfile();
90+
91+
if (profile.getId().equals(playerID)) {
92+
ToyController.vibrate();
93+
}
94+
}
95+
}
96+
97+
@SubscribeEvent
98+
public static void onCriticalHit(CriticalHitEvent event)
99+
{
100+
LOGGER.debug("Critical: " + event.isVanillaCritical());
101+
}
102+
81103
@SubscribeEvent
82104
public static void onHurt(LivingHurtEvent event)
83105
{
@@ -95,28 +117,48 @@ public static void onHurt(LivingHurtEvent event)
95117
@SubscribeEvent
96118
public static void onHarvest(PlayerEvent.HarvestCheck event)
97119
{
98-
LOGGER.info(event.canHarvest());
99-
LOGGER.info(event.getTargetBlock().getBlockState().getValues().toString());
120+
LOGGER.debug("Harvest: " + event.canHarvest() + "[" + event.getTargetBlock().getBlock().getDefaultState().getBlockHardness(null, null) + "]");
121+
//TODO if true, low vibrate
122+
123+
//LOGGER.info(event.canHarvest());
124+
//LOGGER.info(event.getTargetBlock().getBlockState().getValues().toString());
100125
}
101126

102127
@SubscribeEvent
103128
public static void onBreaking(PlayerEvent.BreakSpeed event)
104129
{
105-
LOGGER.info("OLD SPEED" + event.getOriginalSpeed());
130+
//LOGGER.info("OLD SPEED" + event.getOriginalSpeed());
106131
//LOGGER.info("NEW SPEED" + event.getNewSpeed());
107132
}
108133

109134
@SubscribeEvent
110135
public static void onBreak(BlockEvent.BreakEvent event)
111136
{
112-
LOGGER.info(event.getState().toString());
113-
LOGGER.info(event.getExpToDrop());
137+
LOGGER.info("Breaking: " + event.getState().getBlock().toString());
138+
//TODO vibrate
139+
LOGGER.info("XP to drop: " + event.getExpToDrop());
140+
}
141+
142+
@SubscribeEvent
143+
public static void onItemPickup(EntityItemPickupEvent event)
144+
{
145+
LOGGER.info("Pickup item: " + event.getItem().toString());
146+
}
147+
148+
@SubscribeEvent
149+
public static void onXpPickup(PlayerXpEvent.PickupXp event)
150+
{
151+
//LOGGER.info("Pickup XP: " + event.getOrb().xpValue);
114152
}
115153

116154
@SubscribeEvent
117155
public static void onXpChange(PlayerXpEvent.XpChange event)
118156
{
119-
LOGGER.info("XP CHANGE" + event.getAmount());
157+
int xpChange = event.getAmount();
158+
long duration = Math.round(Math.ceil(Math.log(xpChange+0.5)));
159+
160+
LOGGER.info("XP CHANGE: " + xpChange);
161+
LOGGER.debug("duration: " + duration);
120162
}
121163

122164
@SubscribeEvent

src/main/java/com/therainbowville/minegasm/common/Minegasm.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.therainbowville.minegasm.config.ConfigHolder;
44
import com.therainbowville.minegasm.config.ConfigScreen;
5-
import com.therainbowville.minegasm.config.MinegasmConfig;
65
import net.minecraftforge.eventbus.api.IEventBus;
76
import net.minecraftforge.fml.ExtensionPoint;
87
import net.minecraftforge.fml.ModLoadingContext;
Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,90 @@
11
package com.therainbowville.minegasm.config;
22

33
import com.therainbowville.minegasm.common.Minegasm;
4-
import net.minecraft.item.DyeColor;
54
import net.minecraftforge.common.ForgeConfigSpec;
65

7-
import java.util.ArrayList;
8-
import java.util.List;
6+
import java.util.Objects;
97

108
final class ClientConfig {
119
final ForgeConfigSpec.ConfigValue<String> serverUrl;
12-
final ForgeConfigSpec.BooleanValue clientBoolean;
13-
final ForgeConfigSpec.BooleanValue modelTranslucency;
14-
final ForgeConfigSpec.DoubleValue modelScale;
10+
11+
final ForgeConfigSpec.BooleanValue vibrate;
12+
final ForgeConfigSpec.EnumValue<GameplayMode> mode;
13+
final ForgeConfigSpec.IntValue attackIntensity;
14+
final ForgeConfigSpec.IntValue hurtIntensity;
15+
final ForgeConfigSpec.IntValue mineIntensity;
16+
final ForgeConfigSpec.IntValue xpChangeIntensity;
17+
final ForgeConfigSpec.IntValue harvestIntensity;
18+
final ForgeConfigSpec.IntValue vitalityIntensity;
1519

1620
ClientConfig(final ForgeConfigSpec.Builder builder) {
17-
builder.push("general");
21+
builder.push("buttplug");
22+
1823
serverUrl = builder
1924
.translation(Minegasm.MOD_ID + ".config.serverUrl")
2025
.define("serverUrl", "ws://localhost:12345/buttplug");
21-
clientBoolean = builder
22-
.comment("An example boolean in the client config")
23-
.translation(Minegasm.MOD_ID + ".config.clientBoolean")
24-
.define("clientBoolean", true);
25-
modelTranslucency = builder
26-
.comment("If the model should be rendered translucent")
27-
.translation(Minegasm.MOD_ID + ".config.modelTranslucency")
28-
.define("modelTranslucency", true);
29-
modelScale = builder
30-
.comment("The scale to render the model at")
31-
.translation(Minegasm.MOD_ID + ".config.modelScale")
32-
.defineInRange("modelScale", 0.0625F, 0.0001F, 100F);
26+
27+
builder.pop();
28+
29+
builder.push("general");
30+
31+
vibrate = builder
32+
.comment("Enable vibration")
33+
.translation(Minegasm.MOD_ID + ".config.vibrate")
34+
.define(
35+
"vibrate", true);
36+
mode = builder
37+
.comment("Gameplay mode")
38+
.translation(Minegasm.MOD_ID + ".config.mode")
39+
.defineEnum("mode", GameplayMode.NORMAL);
40+
41+
attackIntensity = builder
42+
.comment("Vibration intensity when attacking on custom mode")
43+
.translation(Minegasm.MOD_ID + ".config.intensity.attack")
44+
.defineInRange("attackIntensity", 60, 0, 100);
45+
46+
hurtIntensity = builder
47+
.comment("Vibration intensity when hurting on custom mode")
48+
.translation(Minegasm.MOD_ID + ".config.intensity.hurt")
49+
.defineInRange("hurtIntensity", 0, 0, 100);
50+
51+
mineIntensity = builder
52+
.comment("Vibration intensity when mining on custom mode")
53+
.translation(Minegasm.MOD_ID + ".config.intensity.mine")
54+
.defineInRange("mineIntensity", 80, 0, 100);
55+
56+
xpChangeIntensity = builder
57+
.comment("Vibration intensity when gaining XP on custom mode")
58+
.translation(Minegasm.MOD_ID + ".config.intensity.xp_change")
59+
.defineInRange("xpChangeIntensity", 100, 0, 100);
60+
61+
harvestIntensity = builder
62+
.comment("Vibration intensity when harvesting on custom mode")
63+
.translation(Minegasm.MOD_ID + ".config.intensity.harvest")
64+
.defineInRange("harvestIntensity", 20, 0, 100);
65+
66+
vitalityIntensity = builder
67+
.comment("Vibration intensity on high level of player's vitality on custom mode")
68+
.translation(Minegasm.MOD_ID + ".config.intensity.vitality")
69+
.defineInRange("vitalityIntensity", 40, 0, 100);
70+
3371
builder.pop();
3472
}
73+
public enum GameplayMode {
74+
NORMAL("gui." + Minegasm.MOD_ID + ".config.mode.normal"),
75+
MASOCHIST("gui." + Minegasm.MOD_ID + ".config.mode.masochist"),
76+
HEDONIST("gui." + Minegasm.MOD_ID + ".config.mode.hedonist"),
77+
CUSTOM("gui." + Minegasm.MOD_ID + ".config.mode.custom");
78+
79+
private final String translateKey;
3580

81+
GameplayMode(String translateKey) {
82+
this.translateKey =
83+
Objects.requireNonNull(translateKey, "translateKey");
84+
}
85+
86+
public String getTranslateKey() {
87+
return this.translateKey;
88+
}
89+
}
3690
}
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package com.therainbowville.minegasm.config;
22

3-
import com.therainbowville.minegasm.common.Minegasm;
4-
import net.minecraftforge.fml.config.ModConfig;
5-
63
public final class ConfigHelper {
74

8-
public static void bakeClient(final ModConfig config) {
5+
public static void bakeClient() {
96
MinegasmConfig.serverUrl = ConfigHolder.CLIENT.serverUrl.get();
10-
MinegasmConfig.clientBoolean = ConfigHolder.CLIENT.clientBoolean.get();
11-
MinegasmConfig.modelTranslucency = ConfigHolder.CLIENT.modelTranslucency.get();
12-
MinegasmConfig.modelScale = ConfigHolder.CLIENT.modelScale.get().floatValue();
7+
MinegasmConfig.vibrate = ConfigHolder.CLIENT.vibrate.get();
8+
MinegasmConfig.mode = ConfigHolder.CLIENT.mode.get();
9+
MinegasmConfig.attackIntensity = ConfigHolder.CLIENT.attackIntensity.get();
10+
MinegasmConfig.hurtIntensity = ConfigHolder.CLIENT.hurtIntensity.get();
11+
MinegasmConfig.mineIntensity = ConfigHolder.CLIENT.mineIntensity.get();
12+
MinegasmConfig.xpChangeIntensity = ConfigHolder.CLIENT.xpChangeIntensity.get();
13+
MinegasmConfig.harvestIntensity = ConfigHolder.CLIENT.harvestIntensity.get();
14+
MinegasmConfig.vitalityIntensity = ConfigHolder.CLIENT.vitalityIntensity.get();
1315
}
1416

15-
public static void bakeServer(final ModConfig config) {
16-
MinegasmConfig.serverBoolean = ConfigHolder.SERVER.serverBoolean.get();
17-
MinegasmConfig.electricFurnaceEnergySmeltCostPerTick = ConfigHolder.SERVER.electricFurnaceEnergySmeltCostPerTick.get();
18-
MinegasmConfig.heatCollectorTransferAmountPerTick = ConfigHolder.SERVER.heatCollectorTransferAmountPerTick.get();
17+
public static void bakeServer() {
1918
}
2019

2120
}

0 commit comments

Comments
 (0)