Compare commits

..

No commits in common. '6d7e3b8f392d6f5c0e4518d80f7c202c69e16adb' and '230190d4ee52e4f32c949fad43b073f85479c765' have entirely different histories.

@ -189,10 +189,9 @@ public class RedControl implements ModInitializer {
((ServerWorld)world).spawnParticles(ParticleTypes.CRIT,center.x,center.y,center.z,30,0.1,0.1,0.1,0.1);
if (newState.isIn(TAG_BUSABLE)) {
//a bus-block was placed
FloodFill.INSTANCE.blockFloodFiller((ServerWorld) world, blockPos);
FloodFill.INSTANCE.blockFloodFiller((ServerWorld) world,blockPos);
} else {
//a bus block was removed
FloodFill.INSTANCE.blockBreakFloodFiller((ServerWorld) world, blockPos);
}
}
});

@ -2,7 +2,6 @@ package net.brokenmoon.redcontrol.api;
import com.simon816.j65el02.device.RedBus;
import net.brokenmoon.redcontrol.blocks.NetworkCarrier;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -22,7 +21,7 @@ public class RCWorldBus {
}
public void generateBus(ServerWorld world, BlockPos pos){
public void generateBus(World world, BlockPos pos){
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBus(world, pos);
}

@ -11,7 +11,6 @@ import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
@ -35,10 +34,10 @@ public class CpuEntity extends Peripheral{
}
public static void tick(World world, BlockPos pos, BlockState state, CpuEntity be) {
if(!world.isClient) {
if(be.worldBus == null || !be.worldBus.getValid()){
((NetworkCarrier)state.getBlock()).generateBus((ServerWorld) world, pos);
((NetworkCarrier)state.getBlock()).generateBus(world, pos);
}
if(!world.isClient) {
if (be.notTicked) {
be.notTicked = false;
}

@ -21,9 +21,6 @@ public abstract class Peripheral extends BlockEntity implements RedBus.Periphera
}
public RCWorldBus getBus(){
if (this.worldBus == null || !this.worldBus.getValid()) {
this.worldBus = new RCWorldBus(new RedBus(),world,getPos());
}
return this.worldBus;
}

@ -49,6 +49,8 @@ public class CpuBlock extends NetworkCarrier {
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);
player.sendMessage(Text.literal(" " + peripheral.core.cpu.getCpuState().toTraceEvent()));

@ -3,19 +3,13 @@ package net.brokenmoon.redcontrol.blocks;
import com.simon816.j65el02.device.RedBus;
import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.api.RCWorldBus;
import net.brokenmoon.redcontrol.blockentities.CpuEntity;
import net.brokenmoon.redcontrol.blockentities.Peripheral;
import net.brokenmoon.redcontrol.mixin.RedBusAccessor;
import net.brokenmoon.redcontrol.util.FloodFill;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.text.Text;
@ -41,12 +35,11 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
if (!world.isClient) {
generateBus((ServerWorld) world, pos);
}
generateBus(world, pos);
}
@Override
@SuppressWarnings("uses or overrides a deprecated API.")
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if(state.hasBlockEntity() && world.getBlockEntity(pos) instanceof Peripheral){
if(((Peripheral) world.getBlockEntity(pos)).getBus() != null)
@ -64,7 +57,7 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt
}
public void generateBus(ServerWorld world, BlockPos pos){
public void generateBus(World world, BlockPos pos){
Block worldBlock = world.getBlockState(pos).getBlock();
if(world.getBlockEntity(pos) instanceof Peripheral){
Peripheral entityBlock = (Peripheral) world.getBlockEntity(pos);
@ -76,9 +69,20 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt
}
private void floodBus(RCWorldBus bus, ServerWorld world, BlockPos pos) {
this.setBus(world,pos,bus);
FloodFill.INSTANCE.blockFloodFiller(world,pos);
private void floodBus(RCWorldBus bus, World world, BlockPos pos) {
replaceBus(bus, world, pos.north());
replaceBus(bus, world, pos.south());
replaceBus(bus, world, pos.east());
replaceBus(bus, world, pos.west());
replaceBus(bus, world, pos.up());
replaceBus(bus, world, pos.down());
}
private void replaceBus(RCWorldBus bus, World world, BlockPos pos) {
if(world.getBlockEntity(pos) instanceof Peripheral && ((Peripheral) world.getBlockEntity(pos)).getBus() != bus){
((Peripheral) world.getBlockEntity(pos)).setBus(bus);
floodBus(bus, world, pos);
}
}
@Override

@ -36,10 +36,11 @@ class TerminalBlock(settings: Settings) : NetworkCarrier(settings) {
if (!world.isClient) {
if (player.getStackInHand(hand).item === RedControl.SQUEAKY_HAMMER) {
super.onUse(state, world, pos, player, hand, hit)
//val text: Array<String> = monitor.getText()
//for (s in text) {
// player.sendMessage(Text.literal(s), false)
//}
player.sendMessage(Text.literal(java.lang.String.valueOf(monitor.bus.hashCode())), false)
val text: Array<String> = monitor.getText()
for (s in text) {
player.sendMessage(Text.literal(s), false)
}
}
val bbuf = PacketByteBufs.create()
bbuf.writeBlockPos(pos)

@ -1,8 +1,6 @@
package net.brokenmoon.redcontrol.util
import net.brokenmoon.redcontrol.RedControl
import net.brokenmoon.redcontrol.api.RCWorldBus
import net.brokenmoon.redcontrol.blocks.NetworkCarrier
import net.minecraft.particle.ParticleTypes
import net.minecraft.server.world.ServerWorld
import net.minecraft.util.math.BlockPos
@ -12,57 +10,16 @@ object FloodFill {
fun blockFloodFiller(world: ServerWorld, seed: BlockPos) {
val checkable = mutableListOf(seed)
val seen = mutableListOf<BlockPos>()
var bus: RCWorldBus? = null
while (checkable.isNotEmpty()) {
val pos = checkable.removeFirst()
if (pos in seen) {continue}
val state = world.getBlockState(pos)
if (!state.isIn(RedControl.TAG_BUSABLE)){continue}
val net = state.block as? NetworkCarrier
if (net != null) {
if (!world.getBlockState(pos).isIn(RedControl.TAG_BUSABLE)){continue}
val cpos = pos.toCenterPos()
world.spawnParticles(ParticleTypes.WAX_ON,cpos.x,cpos.y,cpos.z,20,0.6,0.6,0.6,0.2)
if (bus == null) {
bus = net.getBus(world,pos)
} else {
net.setBus(world,pos,bus)
}
}
//val cpos = pos.toCenterPos()
//world.spawnParticles(ParticleTypes.WAX_ON,cpos.x,cpos.y,cpos.z,20,0.2,0.2,0.2,0.2)
world.spawnParticles(ParticleTypes.CHERRY_LEAVES,cpos.x,cpos.y,cpos.z,20,0.2,0.2,0.2,0.2)
Direction.entries.forEach {
checkable.add(pos.add(it.offsetX,it.offsetY,it.offsetZ))
}
seen.add(pos)
}
}
fun blockBreakFloodFiller(world: ServerWorld, seed: BlockPos) {
val checkable = mutableListOf<BlockPos>()
Direction.entries.forEach {
checkable.add(seed.add(it.offsetX,it.offsetY,it.offsetZ))
}
val seen = mutableListOf<BlockPos>()
while (checkable.isNotEmpty()) {
val pos = checkable.removeFirst()
if (pos in seen) {
continue
}
val state = world.getBlockState(pos)
if (!state.isIn(RedControl.TAG_BUSABLE)) {
continue
}
Direction.entries.forEach {
checkable.add(pos.add(it.offsetX, it.offsetY, it.offsetZ))
}
seen.add(pos)
val nc = (state.block as? NetworkCarrier)
if (nc != null) {
nc.getBus(world,pos).valid = false
val cpos = pos.toCenterPos()
world.spawnParticles(ParticleTypes.WAX_OFF,cpos.x,cpos.y,cpos.z,20,0.6,0.6,0.6,0.2)
}
//val cpos = pos.toCenterPos()
//world.spawnParticles(ParticleTypes.WAX_OFF, cpos.x, cpos.y, cpos.z, 20, 0.2, 0.2, 0.2, 0.2)
}
}
}

@ -1,9 +1,4 @@
{
"replace": false,
"values": [
"minecraft:glass",
"redcontrol:cpu",
"redcontrol:disk_drive",
"redcontrol:monitor"
]
"values": ["minecraft:glass"]
}
Loading…
Cancel
Save