grid Block - first attempt

Grid Block kann BlockState vom Block in der Hand annehmen
Fehlt: Liste in der alle grid Blöcke gespeichert werden, um ihn nicht mehr abbauen zu können
This commit is contained in:
Paula 2024-03-09 18:54:41 +01:00
parent 72c43fac54
commit 14d79f9491
7 changed files with 143 additions and 64 deletions

View File

@ -1,11 +1,13 @@
package modchest;
import modchest.block.modBlocks;
import net.fabricmc.api.ClientModInitializer;
public class REServerModClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
}
}

View File

@ -1,11 +1,12 @@
package modchest;
import modchest.block.entity.modBlockEntities;
import modchest.event.attackBlockCallback;
import modchest.event.useBlockCallback;
import modchest.block.modBlocks;
import modchest.item.modItemGroup;
import modchest.item.modItems;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -13,6 +14,7 @@ import org.slf4j.LoggerFactory;
public class REServerMod implements ModInitializer {
public static final String MOD_ID = "modchest";
public static final Logger LOGGER = LoggerFactory.getLogger("modchest"); // Erster Error Logger
@Override
public void onInitialize() {
@ -21,7 +23,11 @@ public class REServerMod implements ModInitializer {
modItems.setItems(); // die Items werden erstellt
modBlocks.setBlocks(); // Hier werden die Blöcke erstellt
modBlockEntities.registerBlockEntities(); // Die Interaktionsmenüs für die Blöcke werden erstellt
useBlockCallback.EVENT.register(new useBlockCallback());
attackBlockCallback.EVENT.register(new attackBlockCallback());
LOGGER.info("Modchest erfolgreich geladen!");
}
}

View File

@ -1,76 +1,22 @@
package modchest.block.custom;
import org.jetbrains.annotations.Nullable;
import modchest.block.entity.gridBlockEntity;
import modchest.block.entity.modBlockEntities;
import modchest.block.entity.steeringWheelEntity;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.NamedScreenHandlerFactory;
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 gridBlock extends BlockWithEntity implements BlockEntityProvider {
public class gridBlock extends Block {
BlockState state;
public gridBlock(Settings settings) {
super(settings);
}
@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new gridBlockEntity (pos, state);
}
// bei Rechtsklick mit anderem Block in der Hand überprüfen ob Block (außer mit Werkzeug)
//Texture von Block in Hand holen -> Texture von Grid Block zu dieser Textur setzen
/**UseBlockCallback.EVENT();
private boolean isBlock(){
if (player.Block==Block) {
return true;
} else {
return false;
}
}
public void changeTexture(){
if (isBlock()==true) {
Block.getTexture;
gridBlockBlock.setTexture;
}
}**/
}

View File

@ -1,5 +1,4 @@
package modchest.block;
import modchest.block.custom.gridBlock;
import modchest.block.custom.steeringWheelBlock;
import modchest.item.modItemGroup;

View File

@ -0,0 +1,21 @@
package modchest.event;
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
public class attackBlockCallback implements AttackBlockCallback{
@Override
public ActionResult interact(PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) {
return ActionResult.PASS;
}
}

View File

@ -0,0 +1,104 @@
package modchest.event;
import static net.minecraft.block.Block.getBlockFromItem;
import org.jetbrains.annotations.ApiStatus.OverrideOnly;
import org.spongepowered.asm.mixin.Overwrite;
import modchest.block.custom.gridBlock;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stat.Stat;
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.Direction;
import net.minecraft.world.BlockRenderView;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import net.minecraft.world.event.GameEvent.Emitter;
public class useBlockCallback implements UseBlockCallback {
@Override
public ActionResult interact(PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) {
Item ItemInHand = player.getMainHandStack().getItem();
Block BlockInHand = getBlockFromItem(ItemInHand);
//ItemStack ItemStackInHand = player.getMainHandStack();
player.sendMessage(Text.of(world.getBlockState(hitResult.getBlockPos()).getBlock().toString()));
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString().equals("Block{modchest:grid_block}")) {
if (player.isSpectator() == false) {
if (BlockInHand instanceof gridBlock) {
return ActionResult.PASS;
} else {
player.sendMessage(Text.of("es hat funktioniert"));
/* BlockState StateInHand = BlockInHand.getDefaultState();
BlockPos gridBlockPos = hitResult.getBlockPos();
world.setBlockState(gridBlockPos, StateInHand);*/
//hitResult.getBlockPos().getClass();
player.getMainHandStack().decrement(1);
//minecraft:blockid
/* if (player.getMainHandStack().equals("") ){ //TODO: wenn Werkzeuge in MainHand NICHT den MainHandStack reduzieren
player.getMainHandStack().decrement(1); //TODO: sobald Hammer existiert darf gridBlock nur noch von diesem abgebaut werden können
} else {
}*/
// BlockState gridBlockState = world.getBlockState(hitResult.getBlockPos());
// Block gridBlock = gridBlockState.getBlock();
//BlockRenderType gridBlockRender = gridBlock.getRenderType(gridBlockState);
// BlockRenderType inHandRenderType = BlockInHand.getRenderType(StateInHand);
// gridBlock.getAppearance(gridBlockState, BlockRenderView renderView,
// gridBlockPos, Direction side, BlockState sourceState, BlockPos sourcePos);
/*
* if (inHandRenderType == gridBlockRender){
* player.sendMessage(Text.of("Das MODEL ist das MODEL - Scheiße"));
* }
*/
// player.sendMessage(Text.of(world.getBlockState(hitResult.getBlockPos()).getBlock().getRenderType(gridBlockState).toString()));
// BlockRenderType inHandRenderType;
// BlockRenderType griBlockRenderType;
// BlockRenderType griBlockRenderType = BlockInHand.getRenderType(StateInHand);
}
}
} else {
return ActionResult.PASS;
}
return ActionResult.SUCCESS;
}// mit SUCCESS; FAIL wird kein Block mehr gesetzt
// mit PASS; CONSUME; CONSUME_PARTIAL werden immer Blöcke gesetzt
}

View File

@ -1,5 +1,6 @@
{
"variants":{
"": {"model": "modchest:block/grid_block"}
}
}