This commit is contained in:
parent
6d92651623
commit
891f2c2fa8
@ -1,14 +1,10 @@
|
||||
package com.thebrokenrail.energonrelics.block.entity;
|
||||
|
||||
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
||||
import com.thebrokenrail.energonrelics.energy.core.EnergyProviderBlockEntity;
|
||||
import com.thebrokenrail.energonrelics.energy.core.util.EnergyTickable;
|
||||
import com.thebrokenrail.energonrelics.energy.helper.EnergyGeneratorBlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.LightType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CreativeEnergySourceBlockEntity extends EnergyGeneratorBlockEntity {
|
||||
public CreativeEnergySourceBlockEntity(BlockEntityType<?> type) {
|
||||
@ -21,7 +17,7 @@ public class CreativeEnergySourceBlockEntity extends EnergyGeneratorBlockEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EnergyProviderBlockEntity> startTick() {
|
||||
public List<EnergyTickable> startTick() {
|
||||
setEnergy(getDisplayEnergy());
|
||||
return super.startTick();
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.thebrokenrail.energonrelics.block.entity;
|
||||
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
||||
import com.thebrokenrail.energonrelics.energy.core.EnergyProviderBlockEntity;
|
||||
import com.thebrokenrail.energonrelics.energy.core.util.Action;
|
||||
import com.thebrokenrail.energonrelics.energy.core.util.EnergyTickable;
|
||||
import com.thebrokenrail.energonrelics.energy.helper.EnergyGenerator;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
@ -50,7 +51,7 @@ public class LightningRodBlockEntity extends EnergyProviderBlockEntity implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EnergyProviderBlockEntity> startTick() {
|
||||
public List<EnergyTickable> startTick() {
|
||||
if (cooldown <= 0) {
|
||||
energy = 0;
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.thebrokenrail.energonrelics.block.entity;
|
||||
|
||||
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
||||
import com.thebrokenrail.energonrelics.energy.core.EnergyProviderBlockEntity;
|
||||
import com.thebrokenrail.energonrelics.energy.core.util.EnergyTickable;
|
||||
import com.thebrokenrail.energonrelics.energy.helper.EnergyGeneratorBlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.math.Direction;
|
||||
@ -39,7 +40,7 @@ public class SolarPanelBlockEntity extends EnergyGeneratorBlockEntity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EnergyProviderBlockEntity> startTick() {
|
||||
public List<EnergyTickable> startTick() {
|
||||
setEnergy(getDisplayEnergy());
|
||||
return super.startTick();
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.thebrokenrail.energonrelics.block.battery.PassiveBatteryControllerBlo
|
||||
import com.thebrokenrail.energonrelics.block.entity.battery.PassiveBatteryControllerBlockEntity;
|
||||
import com.thebrokenrail.energonrelics.block.reactor.ReactorControllerBlock;
|
||||
import com.thebrokenrail.energonrelics.energy.core.EnergyProviderBlockEntity;
|
||||
import com.thebrokenrail.energonrelics.energy.core.util.EnergyTickable;
|
||||
import com.thebrokenrail.energonrelics.energy.helper.EnergyGeneratorBlockEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
@ -33,7 +34,7 @@ public class ReactorControllerBlockEntity extends EnergyGeneratorBlockEntity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EnergyProviderBlockEntity> startTick() {
|
||||
public List<EnergyTickable> startTick() {
|
||||
if (getCachedState().get(ReactorControllerBlock.POWERED)) {
|
||||
Reactor reactor = getReactor();
|
||||
if (reactor != null && !reactor.core.isReacting()) {
|
||||
|
@ -4,6 +4,7 @@ import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
||||
import com.thebrokenrail.energonrelics.EnergonRelics;
|
||||
import com.thebrokenrail.energonrelics.component.NetworkComponent;
|
||||
import com.thebrokenrail.energonrelics.energy.core.util.Action;
|
||||
import com.thebrokenrail.energonrelics.energy.core.util.EnergyTickable;
|
||||
import com.thebrokenrail.energonrelics.energy.core.util.EnergyTicker;
|
||||
import com.thebrokenrail.energonrelics.util.BlockPosWithDimension;
|
||||
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
|
||||
@ -24,7 +25,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntityClientSerializable, Tickable {
|
||||
public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntityClientSerializable, Tickable, EnergyTickable {
|
||||
public EnergyProviderBlockEntity(BlockEntityType<?> type) {
|
||||
super(type);
|
||||
}
|
||||
@ -80,10 +81,12 @@ public class EnergyProviderBlockEntity extends BlockEntity implements BlockEntit
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logicTick() {
|
||||
}
|
||||
|
||||
public List<EnergyProviderBlockEntity> startTick() {
|
||||
@Override
|
||||
public List<EnergyTickable> startTick() {
|
||||
if (isEnergyProvider()) {
|
||||
NetworkComponent component = NetworkComponent.getInstance((ServerWorld) Objects.requireNonNull(getWorld()));
|
||||
List<BlockPosWithDimension> sources = component.getSourcePos(EnergonRelics.NETWORK_CHIP_ITEM.getID(stack));
|
||||
|
@ -2,6 +2,7 @@ package com.thebrokenrail.energonrelics.energy.core;
|
||||
|
||||
import com.thebrokenrail.energonrelics.component.NetworkComponent;
|
||||
import com.thebrokenrail.energonrelics.energy.core.util.Action;
|
||||
import com.thebrokenrail.energonrelics.energy.core.util.EnergyTickable;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
@ -46,10 +47,10 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EnergyProviderBlockEntity> startTick() {
|
||||
public List<EnergyTickable> startTick() {
|
||||
sent.clear();
|
||||
|
||||
List<EnergyProviderBlockEntity> list = new ArrayList<>(super.startTick());
|
||||
List<EnergyTickable> list = new ArrayList<>(super.startTick());
|
||||
|
||||
ServerWorld world = (ServerWorld) getWorld();
|
||||
assert world != null;
|
||||
|
@ -0,0 +1,8 @@
|
||||
package com.thebrokenrail.energonrelics.energy.core.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EnergyTickable {
|
||||
List<EnergyTickable> startTick();
|
||||
void logicTick();
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.thebrokenrail.energonrelics.energy.core.util;
|
||||
|
||||
import com.thebrokenrail.energonrelics.energy.core.EnergyProviderBlockEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -9,22 +8,20 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class EnergyTicker {
|
||||
private static final List<EnergyProviderBlockEntity> scheduled = new ArrayList<>();
|
||||
private static final List<EnergyTickable> scheduled = new ArrayList<>();
|
||||
|
||||
public static void schedule(EnergyProviderBlockEntity provider) {
|
||||
scheduled.add(provider);
|
||||
public static void schedule(EnergyTickable tickable) {
|
||||
scheduled.add(tickable);
|
||||
}
|
||||
|
||||
public static void tick(World world) {
|
||||
if (Objects.requireNonNull(world.getServer()).getThread() != Thread.currentThread()) {
|
||||
scheduled.clear();
|
||||
} else {
|
||||
List<EnergyProviderBlockEntity> started = new ArrayList<>();
|
||||
if (Objects.requireNonNull(world.getServer()).getThread() == Thread.currentThread()) {
|
||||
List<EnergyTickable> started = new ArrayList<>();
|
||||
|
||||
List<EnergyProviderBlockEntity> temp = new ArrayList<>(scheduled);
|
||||
List<EnergyProviderBlockEntity> temp2 = new ArrayList<>();
|
||||
List<EnergyTickable> temp = new ArrayList<>(scheduled);
|
||||
List<EnergyTickable> temp2 = new ArrayList<>();
|
||||
while (!temp.isEmpty()) {
|
||||
for (EnergyProviderBlockEntity provider : temp) {
|
||||
for (EnergyTickable provider : temp) {
|
||||
if (!started.contains(provider)) {
|
||||
temp2.addAll(provider.startTick());
|
||||
started.add(provider);
|
||||
@ -36,11 +33,10 @@ public class EnergyTicker {
|
||||
}
|
||||
|
||||
Collections.shuffle(started);
|
||||
for (EnergyProviderBlockEntity provider : started) {
|
||||
for (EnergyTickable provider : started) {
|
||||
provider.logicTick();
|
||||
}
|
||||
|
||||
}
|
||||
scheduled.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
{
|
||||
"parent": "energonrelics:holographic_sky_off"
|
||||
"parent": "energonrelics:block/holographic_sky_off"
|
||||
}
|
||||
|
Reference in New Issue
Block a user