features added

Man kriegt jetzt essen und der Block wird kleiner
This commit is contained in:
Paula 2024-06-02 11:16:06 +02:00
parent c8cdce2c06
commit 6214c2c6b7
2 changed files with 130 additions and 0 deletions

View File

@ -0,0 +1,127 @@
package modchest.event;
import modchest.block.custom.suspiciousBlockMinusEins;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items;
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.world.World;
public class useBlockCallback implements UseBlockCallback {
@Override
public ActionResult interact(PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) {
BlockPos pos = hitResult.getBlockPos();
BlockState state = world.getBlockState(hitResult.getBlockPos());
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString()
.equals("Block{modchest:suspicious_block}")) {
if (player.getMainHandStack().getItem().equals(Items.BOWL)) {
player.getMainHandStack().decrement(1);
player.giveItemStack(Items.SUSPICIOUS_STEW.getDefaultStack()); // bis hierhin ok
int stateId = suspiciousBlockMinusEins.getRawIdFromState(state);
BlockState stateSus = suspiciousBlockMinusEins.getStateFromRawId(stateId + 1);
// BlockState susState = hitResult.getClass().;
world.setBlockState(pos, stateSus);
return ActionResult.SUCCESS;
}
}
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString()
.equals("Block{modchest:suspicious_block_minus_eins}")) {
if (player.getMainHandStack().getItem().equals(Items.BOWL)) {
player.getMainHandStack().decrement(1);
player.giveItemStack(Items.SUSPICIOUS_STEW.getDefaultStack()); // bis hierhin ok
int stateId1 = suspiciousBlockMinusEins.getRawIdFromState(state);
BlockState stateSus1 = suspiciousBlockMinusEins.getStateFromRawId(stateId1 + 1);
// BlockState susState = hitResult.getClass().;
world.setBlockState(pos, stateSus1);
return ActionResult.SUCCESS;
}
}
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString()
.equals("Block{modchest:suspicious_block_minus_zwei}")) {
if (player.getMainHandStack().getItem().equals(Items.BOWL)) {
player.getMainHandStack().decrement(1);
player.giveItemStack(Items.SUSPICIOUS_STEW.getDefaultStack()); // bis hierhin ok
int stateId2 = suspiciousBlockMinusEins.getRawIdFromState(state);
BlockState stateSus2 = suspiciousBlockMinusEins.getStateFromRawId(stateId2 + 1);
// BlockState susState = hitResult.getClass().;
world.setBlockState(pos, stateSus2);
return ActionResult.SUCCESS;
}
}
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString()
.equals("Block{modchest:suspicious_block_minus_drei}")) {
if (player.getMainHandStack().getItem().equals(Items.BOWL)) {
player.getMainHandStack().decrement(1);
player.giveItemStack(Items.SUSPICIOUS_STEW.getDefaultStack()); // bis hierhin ok
int stateId3 = suspiciousBlockMinusEins.getRawIdFromState(state);
BlockState stateSus3 = suspiciousBlockMinusEins.getStateFromRawId(stateId3 + 1);
// BlockState susState = hitResult.getClass().;
world.setBlockState(pos, stateSus3);
return ActionResult.SUCCESS;
}
}
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString()
.equals("Block{modchest:suspicious_block_minus_vier}")) {
if (player.getMainHandStack().getItem().equals(Items.BOWL)) {
player.getMainHandStack().decrement(1);
player.giveItemStack(Items.SUSPICIOUS_STEW.getDefaultStack()); // bis hierhin ok
int stateId4 = suspiciousBlockMinusEins.getRawIdFromState(state);
BlockState stateSus4 = suspiciousBlockMinusEins.getStateFromRawId(stateId4 + 1);
// BlockState susState = hitResult.getClass().;
world.setBlockState(pos, stateSus4);
return ActionResult.SUCCESS;
}
}
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString()
.equals("Block{modchest:suspicious_block_minus_fuenf}")) {
if (player.getMainHandStack().getItem().equals(Items.BOWL)) {
player.getMainHandStack().decrement(1);
player.giveItemStack(Items.SUSPICIOUS_STEW.getDefaultStack()); // bis hierhin ok
int stateId5 = suspiciousBlockMinusEins.getRawIdFromState(state);
BlockState stateSus5 = suspiciousBlockMinusEins.getStateFromRawId(stateId5 + 1);
// BlockState susState = hitResult.getClass().;
world.setBlockState(pos, stateSus5);
return ActionResult.SUCCESS;
}
}
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString()
.equals("Block{modchest:suspicious_block_minus_sechs}")) {
if (player.getMainHandStack().getItem().equals(Items.BOWL)) {
player.getMainHandStack().decrement(1);
player.giveItemStack(Items.SUSPICIOUS_STEW.getDefaultStack()); // bis hierhin ok
int stateId6 = suspiciousBlockMinusEins.getRawIdFromState(state);
BlockState stateSus6 = suspiciousBlockMinusEins.getStateFromRawId(stateId6 + 1);
// BlockState susState = hitResult.getClass().;
world.setBlockState(pos, stateSus6);
return ActionResult.SUCCESS;
}
}
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString()
.equals("Block{modchest:suspicious_block_minus_sieben}")) {
if (player.getMainHandStack().getItem().equals(Items.BOWL)) {
player.getMainHandStack().decrement(1);
player.giveItemStack(Items.SUSPICIOUS_STEW.getDefaultStack()); // bis hierhin ok
//int stateId7 = suspiciousBlockMinusEins.getRawIdFromState(state);
//BlockState stateSus7 = suspiciousBlockMinusEins.getStateFromRawId(stateId7 + 1);
// BlockState susState = hitResult.getClass().;
BlockState stateAir = Blocks.AIR.getDefaultState();
world.setBlockState(pos, stateAir);
return ActionResult.SUCCESS;
}
}
player.getMainHandStack().decrement(1);
return ActionResult.PASS;
}
}

View File

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