Skip to content

Commit

Permalink
feat: Quicksoil system
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepalesque committed Jun 2, 2024
1 parent c1b04ee commit ba2a947
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 25 deletions.
17 changes: 0 additions & 17 deletions src/main/java/net/zepalesque/redux/Redux.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package net.zepalesque.redux;

import com.aetherteam.aether.Aether;
import com.aetherteam.aether.data.AetherData;
import com.aetherteam.aether.data.generators.AetherRegistrySets;
import com.mojang.logging.LogUtils;
import net.minecraft.DetectedVersion;
import net.minecraft.SharedConstants;
Expand All @@ -23,11 +21,8 @@
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.DistExecutor;
import net.neoforged.fml.ModList;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.neoforge.common.data.DatapackBuiltinEntriesProvider;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
Expand All @@ -41,9 +36,7 @@
import net.zepalesque.redux.client.ReduxColors;
import net.zepalesque.redux.config.ReduxConfig;
import net.zepalesque.redux.config.ReduxConfigHandler;
import net.zepalesque.redux.data.ReduxDataMaps;
import net.zepalesque.redux.data.gen.ReduxBlockStateGen;
import net.zepalesque.redux.data.gen.ReduxDataMapGen;
import net.zepalesque.redux.data.gen.ReduxItemModelGen;
import net.zepalesque.redux.data.gen.ReduxLanguageGen;
import net.zepalesque.redux.data.gen.ReduxLootGen;
Expand All @@ -57,18 +50,8 @@
import net.zepalesque.redux.tile.ReduxTiles;
import net.zepalesque.redux.world.biome.tint.ReduxBiomeTints;
import net.zepalesque.redux.world.feature.gen.ReduxFeatures;
import net.zepalesque.zenith.api.biometint.BiomeTints;
import net.zepalesque.zenith.api.blockset.AbstractStoneSet;
import net.zepalesque.zenith.api.blockset.AbstractWoodSet;
import net.zepalesque.zenith.api.condition.ConditionElements;
import net.zepalesque.zenith.api.condition.ConfigCondition;
import net.zepalesque.zenith.api.condition.config.ConfigSerializer;
import net.zepalesque.zenith.loot.condition.ZenithLootConditions;
import net.zepalesque.zenith.recipe.condition.ZenithRecipeConditions;
import net.zepalesque.zenith.world.density.ZenithDensityFunctions;
import net.zepalesque.zenith.world.feature.gen.ZenithFeatures;
import net.zepalesque.zenith.world.feature.placement.ZenithPlacementModifiers;
import net.zepalesque.zenith.world.state.ZenithStateProviders;
import org.slf4j.Logger;

import java.nio.file.Path;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/zepalesque/redux/block/ReduxBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import net.neoforged.neoforge.registries.DeferredRegister;
import net.zepalesque.redux.Redux;
import net.zepalesque.redux.block.natural.AetherShortGrassBlock;
import net.zepalesque.redux.event.hook.ToolModifyHooks;
import net.zepalesque.redux.event.hook.ToolActionHooks;
import net.zepalesque.redux.item.ReduxItems;
import net.zepalesque.zenith.mixin.mixins.common.accessor.FireAccessor;

Expand Down Expand Up @@ -43,6 +43,6 @@ public static void registerFlammability() {
}

public static void registerToolConversions() {
Redux.WOOD_SETS.forEach(set -> set.setupStrippables(ToolModifyHooks.STRIPPABLES));
Redux.WOOD_SETS.forEach(set -> set.setupStrippables(ToolActionHooks.STRIPPABLES));
}
}
15 changes: 15 additions & 0 deletions src/main/java/net/zepalesque/redux/client/event/hook/KeyHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.zepalesque.redux.client.event.hook;

import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.ToggleKeyMapping;
import net.minecraft.world.entity.LivingEntity;

public class KeyHooks {

public static void cancelKey(final LivingEntity entity, KeyMapping key) {
if (entity == Minecraft.getInstance().player) {
ToggleKeyMapping.set(key.getKey(), false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.zepalesque.redux.client.event.listener;

import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.LivingEntity;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.event.entity.living.LivingEvent;
import net.zepalesque.redux.client.event.hook.KeyHooks;
import net.zepalesque.redux.config.ReduxConfig;
import net.zepalesque.redux.event.hook.QuicksoilHooks;

public class ClientMobListener {

@SubscribeEvent
public static void cancelSneak(LivingEvent.LivingTickEvent event) {
final LivingEntity entity = event.getEntity();
if (ReduxConfig.SERVER.revamped_quicksoil_movement.get() && QuicksoilHooks.shouldAlterMovement(entity)) {
KeyHooks.cancelKey(entity, Minecraft.getInstance().options.keyShift);
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/net/zepalesque/redux/config/ReduxConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class Server extends DataSerializableConfig {

public final ModConfigSpec.ConfigValue<Boolean> redux_sky_colors;
public final ModConfigSpec.ConfigValue<Boolean> cloudbed;
public final ModConfigSpec.ConfigValue<Boolean> revamped_quicksoil_movement;

public Server(ModConfigSpec.Builder builder) {
super(() -> SERVER_SPEC, "redux_server");
Expand All @@ -20,6 +21,9 @@ public Server(ModConfigSpec.Builder builder) {
cloudbed = builder
.comment("Replace the Aether's large Aercloud features with a noise-based cloudbed")
.define("Cloudbed", true);
revamped_quicksoil_movement = builder
.comment("Changes quicksoil to make it use a better movement system, based on the way it worked in the Aether II: Highlands in 1.12")
.define("Revamped Quicksoil Movement", true);
builder.pop();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/zepalesque/redux/data/ReduxTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static class Blocks {
public static final TagKey<Block> BLIGHT_GRASS_BLOCKS = tag("blight_grass_blocks");
// Blocks that should make Short Aether Grass use its enchanted state
public static final TagKey<Block> ENCHANTED_GRASS_BLOCKS = tag("enchanted_grass_blocks");
// Blocks that should use the Highlands quicksoil system
public static final TagKey<Block> QUICKSOIL_BEHAVIOR = tag("quicksoil_behavior");

public static TagKey<Block> tag(String name) {
return TagKey.create(Registries.BLOCK, Redux.loc(name));
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/net/zepalesque/redux/event/hook/QuicksoilHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.zepalesque.redux.event.hook;

import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import net.zepalesque.redux.data.ReduxTags;
import net.zepalesque.redux.mixin.mixins.common.accessor.EntityAccessor;

public class QuicksoilHooks {

public static boolean shouldAlterMovement(final LivingEntity entity) {
return entity.onGround() &&
!entity.isInWater() &&
!(Math.abs(entity.getDeltaMovement().x + entity.getDeltaMovement().y + entity.getDeltaMovement().z) < 0.001D) &&
!entity.isSpectator()
&& entity.level().getBlockState(((EntityAccessor) entity).callGetBlockPosBelowThatAffectsMyMovement()).is(ReduxTags.Blocks.QUICKSOIL_BEHAVIOR);
}

public static void alterMovement(final LivingEntity entity) {
entity.setDeltaMovement(entity.getDeltaMovement().multiply(1.7D, 1D, 1.7D));
final double maxMotion = 1D;
double x;
double z;

x = Mth.clamp(entity.getDeltaMovement().x, -maxMotion, maxMotion);
z = Mth.clamp(entity.getDeltaMovement().z, -maxMotion, maxMotion);
entity.setDeltaMovement(x, entity.getDeltaMovement().y, z);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.HashMap;
import java.util.Map;

public class ToolModifyHooks {
public class ToolActionHooks {

public static final Map<Block, Block> STRIPPABLES = new HashMap<>();

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/net/zepalesque/redux/event/listener/MobListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.zepalesque.redux.event.listener;

import net.minecraft.world.entity.LivingEntity;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.event.entity.living.LivingEvent;
import net.zepalesque.redux.Redux;
import net.zepalesque.redux.config.ReduxConfig;
import net.zepalesque.redux.event.hook.QuicksoilHooks;

@Mod.EventBusSubscriber(modid = Redux.MODID)
public class MobListener {

@SubscribeEvent
public static void handleQuicksoilMovement(LivingEvent.LivingTickEvent event) {
final LivingEntity entity = event.getEntity();
if (ReduxConfig.SERVER.revamped_quicksoil_movement.get() && QuicksoilHooks.shouldAlterMovement(entity)) {
QuicksoilHooks.alterMovement(entity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
import net.neoforged.neoforge.common.ToolAction;
import net.neoforged.neoforge.event.level.BlockEvent;
import net.zepalesque.redux.Redux;
import net.zepalesque.redux.event.hook.ToolModifyHooks;
import net.zepalesque.redux.event.hook.ToolActionHooks;

@Mod.EventBusSubscriber(modid = Redux.MODID)
public class ToolModifyListener {
public class ToolActionListener {

@SubscribeEvent
public static void setupToolModifications(BlockEvent.BlockToolModificationEvent event) {
LevelAccessor levelAccessor = event.getLevel();
BlockPos pos = event.getPos();
BlockState oldState = event.getState();
ToolAction toolAction = event.getToolAction();
BlockState newState = ToolModifyHooks.setupToolActions(levelAccessor, pos, oldState, toolAction);
BlockState newState = ToolActionHooks.setupToolActions(levelAccessor, pos, oldState, toolAction);
if (newState != oldState && !event.isSimulated() && !event.isCanceled()) {
event.setFinalState(newState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import com.aetherteam.aether.client.AetherColorResolvers;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package net.zepalesque.redux.mixin.mixins.common;

import com.aetherteam.aether.block.natural.QuicksoilBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.zepalesque.redux.config.ReduxConfig;
import net.zepalesque.redux.mixin.mixins.common.base.BlockBehaviorMixin;
import net.zepalesque.redux.mixin.mixins.common.base.BlockMixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(QuicksoilBlock.class)
public class QuicksoilMixin extends BlockBehaviorMixin {

@Override
public void redux$pathFindable(BlockState state, BlockGetter level, BlockPos pos, PathComputationType type, CallbackInfoReturnable<Boolean> cir) {
if (ReduxConfig.SERVER.revamped_quicksoil_movement.get() && type == PathComputationType.LAND) {
cir.setReturnValue(false);
}
}


@Inject(method = "getFriction", at = @At("HEAD"), cancellable = true)
public void redux$getFriction(BlockState state, LevelReader level, BlockPos pos, Entity entity, CallbackInfoReturnable<Float> cir) {
if (ReduxConfig.SERVER.revamped_quicksoil_movement.get()) {
if (entity instanceof Boat) {
cir.setReturnValue(0.8F);
return;
}
cir.setReturnValue(0.6F);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.zepalesque.redux.mixin.mixins.common.accessor;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(Entity.class)
public interface EntityAccessor {
@Invoker
BlockPos callGetBlockPosBelowThatAffectsMyMovement();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.zepalesque.redux.mixin.mixins.common.base;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.pathfinder.PathComputationType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(BlockBehaviour.class)
public class BlockBehaviorMixin {

@Inject(method = "isPathfindable", at = @At("HEAD"), cancellable = true)
public void redux$pathFindable(BlockState state, BlockGetter level, BlockPos pos, PathComputationType type, CallbackInfoReturnable<Boolean> cir) {}
}
6 changes: 5 additions & 1 deletion src/main/resources/aether_redux.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"compatibilityLevel": "JAVA_17",
"refmap": "aether_redux.refmap.json",
"mixins": [
"common.accessor.WallBlockAccessor"
"common.QuicksoilMixin",
"common.accessor.EntityAccessor",
"common.accessor.WallBlockAccessor",
"common.base.BlockBehaviorMixin",
"common.base.BlockMixin"
],
"client": [
"client.color.AetherColorResolversMixin"
Expand Down

0 comments on commit ba2a947

Please sign in to comment.