the hammer be squeaky

main
Walker Fowlkes 7 months ago
parent 40b92fb87f
commit e89a27ccd7

@ -1 +1 @@
Subproject commit c127f1a2e5873ee3333b4dac05459cdbf002c662 Subproject commit f5416177b806650d8014201a3e12c24d6e1c8747

@ -17,6 +17,7 @@ import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.resource.Resource; import net.minecraft.resource.Resource;
@ -46,9 +47,11 @@ public class RedControl implements ModInitializer {
//Items //Items
//Block Entities //Block Entities
public static final BlockEntityType<CpuEntity> CPU_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, new Identifier("redcontrol", "cpu_block_entity"), FabricBlockEntityTypeBuilder.create(CpuEntity::new, CPU).build()); public static final BlockEntityType<CpuEntity> CPU_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, modloc("cpu_block_entity"), FabricBlockEntityTypeBuilder.create(CpuEntity::new, CPU).build());
public static final BlockEntityType<MonitorEntity> MONITOR_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, new Identifier("redcontrol", "monitor_block_entity"), FabricBlockEntityTypeBuilder.create(MonitorEntity::new, MONITOR).build()); public static final BlockEntityType<MonitorEntity> MONITOR_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, modloc("monitor_block_entity"), FabricBlockEntityTypeBuilder.create(MonitorEntity::new, MONITOR).build());
public static final BlockEntityType<DriveEntity> DRIVE_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, new Identifier("redcontrol", "drive_block_entity"), FabricBlockEntityTypeBuilder.create(DriveEntity::new, DRIVE).build()); public static final BlockEntityType<DriveEntity> DRIVE_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, modloc("drive_block_entity"), FabricBlockEntityTypeBuilder.create(DriveEntity::new, DRIVE).build());
public static final Item SQUEAKY_HAMMER = new Item(new FabricItemSettings());
@Override @Override
public void onInitialize() { public void onInitialize() {
@ -80,12 +83,13 @@ public class RedControl implements ModInitializer {
}); });
LOGGER.info("Initializing RedControl!"); LOGGER.info("Initializing RedControl!");
Registry.register(Registries.BLOCK, new Identifier("redcontrol", "cpu"), CPU); Registry.register(Registries.BLOCK, modloc("cpu"), CPU);
Registry.register(Registries.BLOCK, new Identifier("redcontrol", "monitor"), MONITOR); Registry.register(Registries.BLOCK, modloc("monitor"), MONITOR);
Registry.register(Registries.BLOCK, new Identifier("redcontrol", "disk_drive"), DRIVE); Registry.register(Registries.BLOCK, modloc("disk_drive"), DRIVE);
Registry.register(Registries.ITEM, new Identifier("redcontrol", "cpu"), new BlockItem(CPU, new FabricItemSettings())); Registry.register(Registries.ITEM, modloc("cpu"), new BlockItem(CPU, new FabricItemSettings()));
Registry.register(Registries.ITEM, new Identifier("redcontrol", "monitor"), new BlockItem(MONITOR, new FabricItemSettings())); Registry.register(Registries.ITEM, modloc("monitor"), new BlockItem(MONITOR, new FabricItemSettings()));
Registry.register(Registries.ITEM, new Identifier("redcontrol", "disk_drive"), new BlockItem(DRIVE, new FabricItemSettings())); Registry.register(Registries.ITEM, modloc("disk_drive"), new BlockItem(DRIVE, new FabricItemSettings()));
Registry.register(Registries.ITEM, modloc("squeaky_hammer"), SQUEAKY_HAMMER);
//Packets //Packets
ServerPlayNetworking.registerGlobalReceiver(RedControlNetworking.CPU_START, ((server, player, handler, buf, responseSender) -> { ServerPlayNetworking.registerGlobalReceiver(RedControlNetworking.CPU_START, ((server, player, handler, buf, responseSender) -> {
@ -114,6 +118,7 @@ public class RedControl implements ModInitializer {
LOGGER.info("Resetting cpu at {}", blockPos); LOGGER.info("Resetting cpu at {}", blockPos);
}); });
})); }));
} }
static Identifier modloc(String path) {return new Identifier("redcontrol",path);}
} }

@ -47,8 +47,16 @@ public class CpuBlock extends NetworkCarrier {
@Override @Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
super.onUse(state,world,pos,player,hand,hit);
if (!world.isClient) { if (!world.isClient) {
if (player.getStackInHand(hand).getItem() == RedControl.SQUEAKY_HAMMER) {
super.onUse(state,world,pos,player,hand,hit);
CpuEntity peripheral = (CpuEntity) world.getBlockEntity(pos);
player.sendMessage(Text.literal("Cpu Debug: "), false);
player.sendMessage(Text.literal(" " + Integer.toHexString(peripheral.getBus().hashCode())), false);
player.sendMessage(Text.literal(" " + Integer.toHexString(peripheral.core.cpu.getBus().getRedBus().hashCode())), false);
player.sendMessage(Text.literal(" " + Integer.toHexString(peripheral.i)), false);
player.sendMessage(Text.literal(" " + peripheral.core.isWaitingOnInterrupt()), false);
}
PacketByteBuf byteBuf = PacketByteBufs.create(); PacketByteBuf byteBuf = PacketByteBufs.create();
byteBuf.writeBlockPos(pos); byteBuf.writeBlockPos(pos);
ServerPlayNetworking.send((ServerPlayerEntity) player, RedControlNetworking.CPUGUI_PACKET_ID,byteBuf); ServerPlayNetworking.send((ServerPlayerEntity) player, RedControlNetworking.CPUGUI_PACKET_ID,byteBuf);

@ -1,12 +1,18 @@
package net.brokenmoon.redcontrol.blocks; package net.brokenmoon.redcontrol.blocks;
import com.mojang.serialization.MapCodec; import com.mojang.serialization.MapCodec;
import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.blockentities.DriveEntity; import net.brokenmoon.redcontrol.blockentities.DriveEntity;
import net.brokenmoon.redcontrol.blockentities.MonitorEntity; import net.brokenmoon.redcontrol.blockentities.MonitorEntity;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity; import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
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.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class DriveBlock extends NetworkCarrier{ public class DriveBlock extends NetworkCarrier{
@ -24,4 +30,13 @@ public class DriveBlock extends NetworkCarrier{
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new DriveEntity(pos, state); return new DriveEntity(pos, state);
} }
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (player.getStackInHand(hand).getItem() == RedControl.SQUEAKY_HAMMER) {
return super.onUse(state,world,pos,player,hand,hit);
} else {
return ActionResult.SUCCESS;
}
}
} }

@ -1,6 +1,7 @@
package net.brokenmoon.redcontrol.blocks; package net.brokenmoon.redcontrol.blocks;
import com.mojang.serialization.MapCodec; import com.mojang.serialization.MapCodec;
import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.RedControlNetworking; import net.brokenmoon.redcontrol.RedControlNetworking;
import net.brokenmoon.redcontrol.blockentities.MonitorEntity; import net.brokenmoon.redcontrol.blockentities.MonitorEntity;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
@ -39,14 +40,16 @@ public class MonitorBlock extends NetworkCarrier {
@Override @Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
super.onUse(state,world,pos,player,hand,hit);
if (!world.isClient) { if (!world.isClient) {
if (player.getStackInHand(hand).getItem() == RedControl.SQUEAKY_HAMMER) {
super.onUse(state,world,pos,player,hand,hit);
MonitorEntity monitor = (MonitorEntity) world.getBlockEntity(pos); MonitorEntity monitor = (MonitorEntity) world.getBlockEntity(pos);
player.sendMessage(Text.literal(String.valueOf(monitor.getBus().hashCode())), false); player.sendMessage(Text.literal(String.valueOf(monitor.getBus().hashCode())), false);
String[] text = monitor.getText(); String[] text = monitor.getText();
for (String s : text) { for (String s : text) {
player.sendMessage(Text.literal(s), false); player.sendMessage(Text.literal(s), false);
} }
}
PacketByteBuf byteBuf = PacketByteBufs.create(); PacketByteBuf byteBuf = PacketByteBufs.create();
byteBuf.writeBlockPos(pos); byteBuf.writeBlockPos(pos);
ServerPlayNetworking.send((ServerPlayerEntity) player, RedControlNetworking.MONITOR_PACKET_ID,byteBuf); ServerPlayNetworking.send((ServerPlayerEntity) player, RedControlNetworking.MONITOR_PACKET_ID,byteBuf);

Loading…
Cancel
Save