Skip to content

Commit

Permalink
Version 2.0.0: Move mechanic package into api pack; added CustomPathB…
Browse files Browse the repository at this point in the history
…lock to lib.block; added VelocityCommand
  • Loading branch information
rotgruengelb committed Nov 4, 2023
1 parent be480c6 commit 9ff3270
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 18 deletions.
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ allprojects {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
mappings "net.fabricmc:yarn:${rootProject.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${rootProject.loader_version}"
include(modImplementation("net.fabricmc.fabric-api:fabric-command-api-v2:${project.fabric_command_api_version}"))
}

processResources {
Expand Down Expand Up @@ -59,9 +60,6 @@ allprojects {
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
withJavadocJar()
}
Expand All @@ -82,7 +80,7 @@ allprojects {

pom {
name = 'quirl'
description = 'A Minecraft FabricMC Library Mod providing general utility and tools that help with adding to existing Minecraft mechanics.'
description = 'A Minecraft FabricMC Library Mod providing general utility and tools that help with adding to existing Minecraft mechanic.'
url = 'https://github.com/rotgruengelb/quirl'
licenses {
license {
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ yarn_mappings=1.20+build.1
loader_version=0.14.22

# Mod Properties
mod_version=1.1.0
mod_version=2.0.0
mod_minecraft_base_version=1.20.X

# Maven/Publishing
maven_group=net.rotgruengelb
archives_base_name=quirl

# Dependencies
fabric_version=0.83.0+1.20
# fabric_version=0.83.0+1.20
fabric_command_api_version=2.2.9+fb8d95da7d
10 changes: 7 additions & 3 deletions src/main/java/net/rotgruengelb/quirl/Quirl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import net.minecraft.block.Blocks;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.rotgruengelb.quirl.mechanics.interact.axe.v1.CustomAxeBlockInteract;
import net.rotgruengelb.quirl.mechanics.interact.shovel.v1.CustomShovelBlockInteract;
import net.rotgruengelb.quirl.api.mechanic.interact.axe.v1.CustomAxeBlockInteract;
import net.rotgruengelb.quirl.api.mechanic.interact.shovel.v1.CustomShovelBlockInteract;
import net.rotgruengelb.quirl.internal.command.CommandNodes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -17,7 +18,10 @@ public class Quirl implements ModInitializer {
@Override
public void onInitialize() {

LOGGER.info("Hi, im a quirl");
CommandNodes.registerModCommandNodes();

LOGGER.info("Hi, im quirl \nDeveloped by rotgruengelb and quirl contributors.");

if (MOD_TEST_MODE) {
LOGGER.warn("quirl is in test mode! do not release with 'MOD_TEST_MOD = true'!");
CustomShovelBlockInteract.addResult(Blocks.ACACIA_PLANKS.getDefaultState(), Blocks.DIRT.getDefaultState(), SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.rotgruengelb.quirl.mechanics.interact.axe.v1;
package net.rotgruengelb.quirl.api.mechanic.interact.axe.v1;

import net.minecraft.block.BlockState;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.rotgruengelb.quirl.mechanics.interact.result.v1.ToolBlockInteractResult;
import net.rotgruengelb.quirl.api.mechanic.interact.result.v1.ToolBlockInteractResult;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.rotgruengelb.quirl.mechanics.interact.result.v1;
package net.rotgruengelb.quirl.api.mechanic.interact.result.v1;

import net.minecraft.block.BlockState;
import net.minecraft.sound.SoundCategory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.rotgruengelb.quirl.mechanics.interact.shovel.v1;
package net.rotgruengelb.quirl.api.mechanic.interact.shovel.v1;

import net.minecraft.block.BlockState;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.rotgruengelb.quirl.mechanics.interact.result.v1.ToolBlockInteractResult;
import net.rotgruengelb.quirl.api.mechanic.interact.result.v1.ToolBlockInteractResult;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.rotgruengelb.quirl.internal.command;

import com.mojang.brigadier.arguments.FloatArgumentType;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.CommandManager;

public class CommandNodes {

public static void registerModCommandNodes() {
CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> {

var floatArgType = FloatArgumentType.floatArg();

var velocityNode = CommandManager.literal("velocity").build();

var targetsArg = CommandManager.argument("targets", EntityArgumentType.entities()).build();

var addNode = CommandManager.literal("add").build();

var xAddArg = CommandManager.argument("x", floatArgType).build();
var yAddArg = CommandManager.argument("y", floatArgType).build();
var zAddArg = CommandManager.argument("z", floatArgType).executes(VelocityCommand::add).build();

var setNode = CommandManager.literal("set").build();

var xSetArg = CommandManager.argument("x", floatArgType).build();
var ySetArg = CommandManager.argument("y", floatArgType).build();
var zSetArg = CommandManager.argument("z", floatArgType).executes(VelocityCommand::set).build();

dispatcher.getRoot().addChild(velocityNode);
velocityNode.addChild(targetsArg);
targetsArg.addChild(addNode);
addNode.addChild(xAddArg);
xAddArg.addChild(yAddArg);
yAddArg.addChild(zAddArg);
targetsArg.addChild(setNode);
setNode.addChild(xSetArg);
xSetArg.addChild(ySetArg);
ySetArg.addChild(zSetArg);
}));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.rotgruengelb.quirl.internal.command;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.entity.Entity;
import net.minecraft.server.command.ServerCommandSource;

public class VelocityCommand implements Command<ServerCommandSource> {
public static int add(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
var entities = EntityArgumentType.getEntities(context, "targets");

float x = FloatArgumentType.getFloat(context, "x");
float y = FloatArgumentType.getFloat(context, "y");
float z = FloatArgumentType.getFloat(context, "z");

for (Entity entity : entities) {
entity.addVelocity(x, y, z);
entity.velocityModified = true;
}
return 1;
}

public static int set(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
var entities = EntityArgumentType.getEntities(context, "targets");

float x = FloatArgumentType.getFloat(context, "x");
float y = FloatArgumentType.getFloat(context, "y");
float z = FloatArgumentType.getFloat(context, "z");

for (Entity entity : entities) {
entity.setVelocity(x, y, z);
entity.velocityModified = true;
}
return 1;
}

@Override
public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package net.rotgruengelb.quirl.lib.block;

import net.minecraft.block.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import net.minecraft.world.event.GameEvent;
import org.jetbrains.annotations.Nullable;

public class CustomPathBlock extends Block {
protected static final VoxelShape SHAPE;
private static Block BASE_BLOCK;

static {
SHAPE = Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 15.0, 16.0);
}

protected CustomPathBlock(AbstractBlock.Settings settings, Block baseBlock) {
super(settings);
BASE_BLOCK = baseBlock;
}

public static void setToBaseBlock(@Nullable Entity entity, BlockState state, World world, BlockPos pos) {
BlockState blockState = pushEntitiesUpBeforeBlockChange(state, BASE_BLOCK.getDefaultState(), world, pos);
world.setBlockState(pos, blockState);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(entity, blockState));
}

public boolean hasSidedTransparency(BlockState state) {
return true;
}

public Block getBaseBlock() {
return BASE_BLOCK;
}

public BlockState getPlacementState(ItemPlacementContext ctx) {
return !this.getDefaultState().canPlaceAt(ctx.getWorld(), ctx.getBlockPos()) ? Block.pushEntitiesUpBeforeBlockChange(this.getDefaultState(), BASE_BLOCK.getDefaultState(), ctx.getWorld(), ctx.getBlockPos()) : super.getPlacementState(ctx);
}

public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (direction == Direction.UP && !state.canPlaceAt(world, pos)) {
world.scheduleBlockTick(pos, this, 1);
}

return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}

public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
setToBaseBlock(null, state, world, pos);
}

public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
BlockState blockState = world.getBlockState(pos.up());
return !blockState.isSolid() || blockState.getBlock() instanceof FenceGateBlock;
}

public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return SHAPE;
}

public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
return false;
}
}
4 changes: 2 additions & 2 deletions src/main/java/net/rotgruengelb/quirl/mixin/AxeItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import net.rotgruengelb.quirl.mechanics.interact.result.v1.ToolBlockInteractResult;
import net.rotgruengelb.quirl.api.mechanic.interact.result.v1.ToolBlockInteractResult;
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;

import static net.rotgruengelb.quirl.mechanics.interact.axe.v1.CustomAxeBlockInteract.CUSTOM_AXE_INTERACT_RESULTS;
import static net.rotgruengelb.quirl.api.mechanic.interact.axe.v1.CustomAxeBlockInteract.CUSTOM_AXE_INTERACT_RESULTS;

@Mixin(AxeItem.class)
public class AxeItemMixin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import net.rotgruengelb.quirl.mechanics.interact.result.v1.ToolBlockInteractResult;
import net.rotgruengelb.quirl.api.mechanic.interact.result.v1.ToolBlockInteractResult;
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;

import static net.rotgruengelb.quirl.mechanics.interact.shovel.v1.CustomShovelBlockInteract.CUSTOM_SHOVEL_INTERACT_RESULTS;
import static net.rotgruengelb.quirl.api.mechanic.interact.shovel.v1.CustomShovelBlockInteract.CUSTOM_SHOVEL_INTERACT_RESULTS;

@Mixin(ShovelItem.class)
public class ShovelItemMixin {
Expand Down

0 comments on commit 9ff3270

Please sign in to comment.