gridBlockAbilities added

useBlockCallback Event hinzugefügt: bei benutzen vom gridBlock wird der Block zum Block den man in der Hand hatte, wie Blöcke platzieren, nur cooler
Ist nur ein Zwischenstadium, keine Sorge
This commit is contained in:
Paula 2024-04-25 21:20:07 +02:00
parent 58fc0d8147
commit 821928f865
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,45 @@
package modchest.event;
import static net.minecraft.block.Block.getBlockFromItem;
import java.util.LinkedList;
import java.util.List;
import modchest.block.custom.gridBlock;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Position;
import net.minecraft.world.World;
public class useBlockCallback implements UseBlockCallback{
@Override
public ActionResult interact(PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) {
Block BlockInHand = getBlockFromItem(player.getMainHandStack().getItem());
BlockState StateInHand = BlockInHand.getDefaultState();
BlockPos gridBlockPos = hitResult.getBlockPos();
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString().equals("Block{modchest:grid_block}") && player.isSpectator()==false) {
if (BlockInHand instanceof gridBlock) {
return ActionResult.PASS;
} else {
player.sendMessage(Text.of("gridBlock benutzt"));
world.setBlockState(gridBlockPos, StateInHand); //tauscht die Textur des "benutzten" gridBlocks mit der des Blocks in der Hand
player.getMainHandStack().decrement(1);
List<Position> gridBlockList = new LinkedList<Position>();
gridBlockList.add(hitResult.getPos());
}
} else {
return ActionResult.PASS;
}
return ActionResult.SUCCESS;
}
}

View File

@ -3,6 +3,7 @@ package modchest.util;
import modchest.block.entity.modBlockEntities;
import modchest.block.modBlocks;
import modchest.event.playerAfterRespawnEvent;
import modchest.event.useBlockCallback;
import modchest.item.modItemGroup;
import modchest.item.modItems;
import modchest.networking.modNetworkingServer;
@ -22,6 +23,7 @@ public class initializer {
public static void events() { //Events, bei denen custom Code ausgefuehrt wird, werden eingefuehrt
ServerPlayerEvents.AFTER_RESPAWN.register(new playerAfterRespawnEvent());
useBlockCallback.EVENT.register(new useBlockCallback());
}
public static void networking() { //Identifier unter denen der Server zuhoert werden registriert