You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB
Java

package net.brokenmoon.redcontrol.api;
import com.simon816.j65el02.device.RedBus;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.NotNull;
/**
* a BlockEntity peripheral
*/
public abstract class Peripheral extends BlockEntity implements RedBus.Peripheral {
protected RedBus bus;
protected RCWorldBus worldBus;
protected int id;
public Peripheral(BlockEntityType<?> type, BlockPos pos, BlockState state, int id) {
super(type, pos, state);
this.id = id;
}
/**
* get the redbus (or creates a new one if it does not exists or is invalid)
* @return the redbus for this peripheral
*/
public RCWorldBus getBus(){
if (this.worldBus == null || !this.worldBus.getValid()) {
this.worldBus = new RCWorldBus(new RedBus(),world,getPos());
}
return this.worldBus;
}
/**
* sets the bus for this peripheral and attaches it's self to the bus
* @param bus
*/
public void setBus(@NotNull RCWorldBus bus){
this.bus = bus.getRedBus();
this.bus.setPeripheral(id, this);
this.worldBus = bus;
}
/**
* gets the ID of the peripheral
* @return the id of the periperal
*/
public int getId() {
return id;
}
}