Skip to content

Commit 84cf5e3

Browse files
YoungOnionMCYoungOnionMCSpicierspace153
authored
Add a SpeedBoost When Walking on Concrete (#3985)
Co-authored-by: YoungOnionMC <[email protected]> Co-authored-by: Spicierspace153 <[email protected]>
1 parent 2a0149d commit 84cf5e3

File tree

8 files changed

+171
-0
lines changed

8 files changed

+171
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"values": [
3+
"gtceu:white_studs",
4+
"gtceu:orange_studs",
5+
"gtceu:magenta_studs",
6+
"gtceu:light_blue_studs",
7+
"gtceu:yellow_studs",
8+
"gtceu:lime_studs",
9+
"gtceu:pink_studs",
10+
"gtceu:gray_studs",
11+
"gtceu:light_gray_studs",
12+
"gtceu:cyan_studs",
13+
"gtceu:purple_studs",
14+
"gtceu:blue_studs",
15+
"gtceu:brown_studs",
16+
"gtceu:green_studs",
17+
"gtceu:red_studs",
18+
"gtceu:black_studs"
19+
]
20+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"values": [
3+
"gtceu:light_concrete",
4+
"gtceu:dark_concrete",
5+
"gtceu:light_concrete",
6+
"gtceu:light_concrete_cobblestone",
7+
"gtceu:mossy_light_concrete_cobblestone",
8+
"gtceu:polished_light_concrete",
9+
"gtceu:light_concrete_bricks",
10+
"gtceu:cracked_light_concrete_bricks",
11+
"gtceu:mossy_light_concrete_bricks",
12+
"gtceu:chiseled_light_concrete",
13+
"gtceu:light_concrete_tile",
14+
"gtceu:light_concrete_small_tile",
15+
"gtceu:light_concrete_windmill_a",
16+
"gtceu:light_concrete_windmill_b",
17+
"gtceu:small_light_concrete_bricks",
18+
"gtceu:square_light_concrete_bricks",
19+
"gtceu:dark_concrete",
20+
"gtceu:dark_concrete_cobblestone",
21+
"gtceu:mossy_dark_concrete_cobblestone",
22+
"gtceu:polished_dark_concrete",
23+
"gtceu:dark_concrete_bricks",
24+
"gtceu:cracked_dark_concrete_bricks",
25+
"gtceu:mossy_dark_concrete_bricks",
26+
"gtceu:chiseled_dark_concrete",
27+
"gtceu:dark_concrete_tile",
28+
"gtceu:dark_concrete_small_tile",
29+
"gtceu:dark_concrete_windmill_a",
30+
"gtceu:dark_concrete_windmill_b",
31+
"gtceu:small_dark_concrete_bricks",
32+
"gtceu:square_dark_concrete_bricks"
33+
]
34+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.gregtechceu.gtceu.api.block;
2+
3+
import java.util.UUID;
4+
5+
public class BlockAttributes {
6+
7+
public static final UUID BLOCK_SPEED_BOOST = UUID.fromString("b14c1720-b06f-40f6-98fd-625af4ed1076");
8+
}

src/main/java/com/gregtechceu/gtceu/client/forge/ForgeClientEventListener.java

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

33
import com.gregtechceu.gtceu.GTCEu;
44
import com.gregtechceu.gtceu.api.GTValues;
5+
import com.gregtechceu.gtceu.api.block.BlockAttributes;
56
import com.gregtechceu.gtceu.api.cosmetics.CapeRegistry;
67
import com.gregtechceu.gtceu.api.item.tool.ToolHelper;
78
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
@@ -21,6 +22,9 @@
2122
import net.minecraft.core.BlockPos;
2223
import net.minecraft.resources.ResourceLocation;
2324
import net.minecraft.world.entity.Entity;
25+
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
26+
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
27+
import net.minecraft.world.entity.ai.attributes.Attributes;
2428
import net.minecraft.world.entity.player.Player;
2529
import net.minecraft.world.level.block.entity.BlockEntity;
2630
import net.minecraft.world.phys.BlockHitResult;
@@ -82,6 +86,49 @@ public static void onPlayerRender(RenderPlayerEvent.Pre event) {
8286
}
8387
}
8488

89+
@SubscribeEvent
90+
public static void updateFOV(ComputeFovModifierEvent event) {
91+
Player player = event.getPlayer();
92+
93+
AttributeInstance moveSpeed = player.getAttribute(Attributes.MOVEMENT_SPEED);
94+
if (moveSpeed == null || moveSpeed.getModifier(BlockAttributes.BLOCK_SPEED_BOOST) == null) return;
95+
boolean flying = player.getAbilities().flying;
96+
float originalFov = flying ? 1.1F : 1.0F;
97+
float walkSpeed = player.getAbilities().getWalkingSpeed();
98+
99+
originalFov *= ((float) moveSpeed.getBaseValue() / walkSpeed + 1.0F) / 2.0F;
100+
if (walkSpeed == 0.0F || Float.isNaN(originalFov) ||
101+
Float.isInfinite(originalFov)) {
102+
return;
103+
}
104+
105+
float newFov = flying ? 1.1F : 1.0F;
106+
newFov *= ((float) getValueWithoutWalkingBoost(moveSpeed) / walkSpeed + 1.0F) /
107+
2.0F;
108+
109+
event.setNewFovModifier(originalFov / newFov);
110+
}
111+
112+
private static double getValueWithoutWalkingBoost(AttributeInstance attrib) {
113+
double base = attrib.getBaseValue();
114+
115+
for (AttributeModifier mod : attrib.getModifiers(AttributeModifier.Operation.ADDITION)) {
116+
base += mod.getAmount();
117+
}
118+
119+
double applied = base;
120+
for (AttributeModifier mod : attrib.getModifiers(AttributeModifier.Operation.MULTIPLY_BASE)) {
121+
if (mod.getId() == BlockAttributes.BLOCK_SPEED_BOOST) continue;
122+
applied += base * mod.getAmount();
123+
}
124+
125+
for (AttributeModifier mod : attrib.getModifiers(AttributeModifier.Operation.MULTIPLY_TOTAL)) {
126+
applied *= 1 + mod.getAmount();
127+
}
128+
129+
return attrib.getAttribute().sanitizeValue(applied);
130+
}
131+
85132
@SubscribeEvent
86133
public static void onBlockHighlightEvent(RenderHighlightEvent.Block event) {
87134
BlockHighlightRenderer.renderBlockHighlight(event.getPoseStack(), event.getCamera(), event.getTarget(),

src/main/java/com/gregtechceu/gtceu/core/MixinHelpers.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ public static <T> void generateGTDynamicTags(Map<ResourceLocation, List<TagLoade
176176
}
177177
}
178178
}
179+
180+
if (entry.tagPrefix() == TagPrefix.frameGt) {
181+
tagMap.computeIfAbsent(CustomTags.SLOW_WALKABLE_BLOCKS.location(), path -> new ArrayList<>())
182+
.addAll(entries);
183+
}
179184
});
180185

181186
GTRegistries.MACHINES.forEach(machine -> {

src/main/java/com/gregtechceu/gtceu/data/recipe/CustomTags.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ public class CustomTags {
198198

199199
public static final TagKey<Block> ENDSTONE_ORE_REPLACEABLES = TagUtil.createBlockTag("end_stone_ore_replaceables");
200200
public static final TagKey<Block> CONCRETE_BLOCK = TagUtil.createBlockTag("concretes");
201+
public static final TagKey<Block> VERY_FAST_WALKABLE_BLOCKS = TagUtil.createBlockTag("very_fast_walkable_blocks");
202+
public static final TagKey<Block> FAST_WALKABLE_BLOCKS = TagUtil.createBlockTag("fast_walkable_blocks");
203+
public static final TagKey<Block> SLOW_WALKABLE_BLOCKS = TagUtil.createBlockTag("slow_walkable_blocks");
201204
public static final TagKey<Block> CONCRETE_POWDER_BLOCK = TagUtil.createBlockTag("concrete_powders");
202205
public static final TagKey<Block> CLEANROOM_FLOORS = TagUtil.createModBlockTag("cleanroom_floors");
203206
public static final TagKey<Block> CHARCOAL_PILE_IGNITER_WALLS = TagUtil.createModBlockTag(

src/main/java/com/gregtechceu/gtceu/data/tags/BlockTagLoader.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.gregtechceu.gtceu.data.tags;
22

3+
import com.gregtechceu.gtceu.common.block.StoneTypes;
4+
import com.gregtechceu.gtceu.common.data.GTBlocks;
35
import com.gregtechceu.gtceu.common.data.GTMachines;
46
import com.gregtechceu.gtceu.common.data.GTMaterials;
57
import com.gregtechceu.gtceu.data.recipe.CustomTags;
@@ -28,6 +30,17 @@ public static void init(RegistrateTagsProvider.IntrinsicImpl<Block> provider) {
2830
Blocks.BROWN_CONCRETE_POWDER, Blocks.GREEN_CONCRETE_POWDER, Blocks.RED_CONCRETE_POWDER,
2931
Blocks.BLACK_CONCRETE_POWDER);
3032

33+
var speedConcretes = provider.addTag(CustomTags.VERY_FAST_WALKABLE_BLOCKS);
34+
speedConcretes.add(GTBlocks.LIGHT_CONCRETE.get(), GTBlocks.DARK_CONCRETE.get());
35+
36+
GTBlocks.STONE_BLOCKS.column(StoneTypes.CONCRETE_LIGHT)
37+
.forEach((type, block) -> speedConcretes.add(block.get()));
38+
GTBlocks.STONE_BLOCKS.column(StoneTypes.CONCRETE_DARK)
39+
.forEach((type, block) -> speedConcretes.add(block.get()));
40+
41+
var studs = provider.addTag(CustomTags.FAST_WALKABLE_BLOCKS);
42+
GTBlocks.STUDS.forEach((color, block) -> studs.add(block.get()));
43+
3144
provider.addTag(CustomTags.ENDSTONE_ORE_REPLACEABLES).add(Blocks.END_STONE);
3245

3346
provider.addTag(CustomTags.TALL_PLANTS)

src/main/java/com/gregtechceu/gtceu/forge/ForgeCommonEventListener.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.gregtechceu.gtceu.GTCEu;
44
import com.gregtechceu.gtceu.api.GTCEuAPI;
55
import com.gregtechceu.gtceu.api.GTValues;
6+
import com.gregtechceu.gtceu.api.block.BlockAttributes;
67
import com.gregtechceu.gtceu.api.block.MetaMachineBlock;
78
import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper;
89
import com.gregtechceu.gtceu.api.capability.IElectricItem;
@@ -68,6 +69,8 @@
6869
import net.minecraft.world.entity.Entity;
6970
import net.minecraft.world.entity.EquipmentSlot;
7071
import net.minecraft.world.entity.Mob;
72+
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
73+
import net.minecraft.world.entity.ai.attributes.Attributes;
7174
import net.minecraft.world.entity.monster.Zombie;
7275
import net.minecraft.world.entity.player.Player;
7376
import net.minecraft.world.item.Item;
@@ -371,6 +374,44 @@ public static void onEntityLivingFallEvent(LivingFallEvent event) {
371374
}
372375
}
373376

377+
@SubscribeEvent
378+
public static void playerTickEvent(TickEvent.PlayerTickEvent event) {
379+
Player player = event.player;
380+
if (event.phase == TickEvent.Phase.START && !player.level().isClientSide) {
381+
var speedAttrib = player.getAttribute(Attributes.MOVEMENT_SPEED);
382+
if (speedAttrib == null) return;
383+
var speedMod = speedAttrib.getModifier(BlockAttributes.BLOCK_SPEED_BOOST);
384+
385+
float speedBoost = 0.0f;
386+
if (!player.onGround() || player.isInWater() || player.isCrouching()) {
387+
speedBoost = 0.0f;
388+
} else {
389+
var state = player.level().getBlockState(player.getOnPos());
390+
if (state.is(CustomTags.VERY_FAST_WALKABLE_BLOCKS)) {
391+
speedBoost = 0.6f; // value that is added to the base MC speed
392+
} else if (state.is(CustomTags.FAST_WALKABLE_BLOCKS)) {
393+
speedBoost = 0.25f; // slower to walk on studs
394+
} else if (state.is(CustomTags.SLOW_WALKABLE_BLOCKS)) {
395+
speedBoost = -0.20f; // slower on frames
396+
}
397+
}
398+
if (speedMod != null) {
399+
if (speedBoost == speedMod.getAmount()) {
400+
return;
401+
} else {
402+
speedAttrib.removeModifier(BlockAttributes.BLOCK_SPEED_BOOST);
403+
}
404+
} else {
405+
if (speedBoost == 0.0f) return;
406+
}
407+
if (speedBoost != 0.0f) {
408+
speedAttrib.addTransientModifier(
409+
new AttributeModifier(BlockAttributes.BLOCK_SPEED_BOOST, "GT Block Speed Boost",
410+
speedBoost, AttributeModifier.Operation.MULTIPLY_BASE));
411+
}
412+
}
413+
}
414+
374415
@SubscribeEvent
375416
public static void stepAssistHandler(LivingEvent.LivingTickEvent event) {
376417
float MAGIC_STEP_HEIGHT = 1.0023f;

0 commit comments

Comments
 (0)