|
|
|
@ -3,13 +3,19 @@ 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;
|
|
|
|
@ -35,11 +41,12 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
|
|
|
|
|
generateBus(world, pos);
|
|
|
|
|
if (!world.isClient) {
|
|
|
|
|
generateBus((ServerWorld) 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)
|
|
|
|
@ -57,7 +64,7 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void generateBus(World world, BlockPos pos){
|
|
|
|
|
public void generateBus(ServerWorld world, BlockPos pos){
|
|
|
|
|
Block worldBlock = world.getBlockState(pos).getBlock();
|
|
|
|
|
if(world.getBlockEntity(pos) instanceof Peripheral){
|
|
|
|
|
Peripheral entityBlock = (Peripheral) world.getBlockEntity(pos);
|
|
|
|
@ -69,20 +76,9 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
private void floodBus(RCWorldBus bus, ServerWorld world, BlockPos pos) {
|
|
|
|
|
this.setBus(world,pos,bus);
|
|
|
|
|
FloodFill.INSTANCE.blockFloodFiller(world,pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|