-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 2.0.0: Move mechanic package into api pack; added CustomPathB…
…lock to lib.block; added VelocityCommand
- Loading branch information
1 parent
be480c6
commit 9ff3270
Showing
11 changed files
with
182 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...teract/axe/v1/CustomAxeBlockInteract.java → ...teract/axe/v1/CustomAxeBlockInteract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ct/result/v1/ToolBlockInteractResult.java → ...ct/result/v1/ToolBlockInteractResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../shovel/v1/CustomShovelBlockInteract.java → .../shovel/v1/CustomShovelBlockInteract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/net/rotgruengelb/quirl/internal/command/CommandNodes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/net/rotgruengelb/quirl/internal/command/VelocityCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/net/rotgruengelb/quirl/lib/block/CustomPathBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters