Add Creative Energy Source
EnergonRelics/pipeline/head This commit looks good Details

This commit is contained in:
TheBrokenRail 2020-07-25 20:09:03 -04:00
parent 40ce3e75bd
commit 1981088444
11 changed files with 97 additions and 20 deletions

View File

@ -1,6 +1,7 @@
package com.thebrokenrail.energonrelics; package com.thebrokenrail.energonrelics;
import com.thebrokenrail.energonrelics.block.BlockBreakerBlock; import com.thebrokenrail.energonrelics.block.BlockBreakerBlock;
import com.thebrokenrail.energonrelics.block.CreativeEnergySourceBlock;
import com.thebrokenrail.energonrelics.block.DefensiveLaserBlock; import com.thebrokenrail.energonrelics.block.DefensiveLaserBlock;
import com.thebrokenrail.energonrelics.block.LightningRodBlock; import com.thebrokenrail.energonrelics.block.LightningRodBlock;
import com.thebrokenrail.energonrelics.block.VeridiumBlockBlock; import com.thebrokenrail.energonrelics.block.VeridiumBlockBlock;
@ -89,6 +90,8 @@ public class EnergonRelics implements ModInitializer {
private static final Identifier BEEP_SOUND_ID = new Identifier(NAMESPACE, "beep"); private static final Identifier BEEP_SOUND_ID = new Identifier(NAMESPACE, "beep");
private static final SoundEvent BEEP_SOUND_EVENT = new SoundEvent(BEEP_SOUND_ID); private static final SoundEvent BEEP_SOUND_EVENT = new SoundEvent(BEEP_SOUND_ID);
public static final CreativeEnergySourceBlock CREATIVE_ENERGY_SOURCE_BLOCK = new CreativeEnergySourceBlock();
@Override @Override
public void onInitialize() { public void onInitialize() {
NETWORK_CHIP_ITEM = Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "network_chip"), new NetworkChipItem()); NETWORK_CHIP_ITEM = Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "network_chip"), new NetworkChipItem());
@ -134,11 +137,13 @@ public class EnergonRelics implements ModInitializer {
FORCEFIELD_PROJECTOR_BLOCK.register("forcefield_projector"); FORCEFIELD_PROJECTOR_BLOCK.register("forcefield_projector");
Registry.register(Registry.SOUND_EVENT, BEEP_SOUND_ID, BEEP_SOUND_EVENT); Registry.register(Registry.SOUND_EVENT, BEEP_SOUND_ID, BEEP_SOUND_EVENT);
CREATIVE_ENERGY_SOURCE_BLOCK.register("creative_energy_source");
} }
public static void playBeep(World world, BlockPos pos) { public static void playBeep(World world, BlockPos pos) {
if (!world.isClient()) { if (!world.isClient()) {
world.playSound(null, pos, BEEP_SOUND_EVENT, SoundCategory.BLOCKS, 0.5f, 1f); world.playSound(null, pos, BEEP_SOUND_EVENT, SoundCategory.BLOCKS, 0.3f, 1f);
} }
} }
} }

View File

@ -0,0 +1,21 @@
package com.thebrokenrail.energonrelics.block;
import com.thebrokenrail.energonrelics.block.entity.CreativeEnergySourceBlockEntity;
import com.thebrokenrail.energonrelics.block.util.energy.EnergyProviderBlock;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import java.util.function.Function;
public class CreativeEnergySourceBlock extends EnergyProviderBlock {
public CreativeEnergySourceBlock() {
super(FabricBlockSettings.copy(Blocks.BEDROCK).dropsNothing());
}
@Override
protected Function<BlockEntityType<BlockEntity>, BlockEntity> getFactory() {
return CreativeEnergySourceBlockEntity::new;
}
}

View File

@ -0,0 +1,28 @@
package com.thebrokenrail.energonrelics.block.entity;
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
import com.thebrokenrail.energonrelics.energy.core.EnergyProviderBlockEntity;
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) {
super(type);
}
@Override
public long getDisplayEnergy() {
return Long.MAX_VALUE;
}
@Override
public List<EnergyProviderBlockEntity> startTick() {
setEnergy(getDisplayEnergy());
return super.startTick();
}
}

View File

@ -97,7 +97,7 @@ public class StructureGeneratorBlock extends SimpleBlockWithEntity {
} }
public void schedule(World world, BlockPos pos) { public void schedule(World world, BlockPos pos) {
world.getBlockTickScheduler().schedule(pos, this, 4); world.getBlockTickScheduler().schedule(pos, this, 0);
} }
@Override @Override

View File

@ -1,10 +1,12 @@
package com.thebrokenrail.energonrelics.energy.core.util; package com.thebrokenrail.energonrelics.energy.core.util;
import com.thebrokenrail.energonrelics.energy.core.EnergyProviderBlockEntity; import com.thebrokenrail.energonrelics.energy.core.EnergyProviderBlockEntity;
import net.minecraft.world.World;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
public class EnergyTicker { public class EnergyTicker {
private static final List<EnergyProviderBlockEntity> scheduled = new ArrayList<>(); private static final List<EnergyProviderBlockEntity> scheduled = new ArrayList<>();
@ -13,26 +15,30 @@ public class EnergyTicker {
scheduled.add(provider); scheduled.add(provider);
} }
public static void tick() { public static void tick(World world) {
List<EnergyProviderBlockEntity> started = new ArrayList<>(); if (Objects.requireNonNull(world.getServer()).getThread() != Thread.currentThread()) {
scheduled.clear();
} else {
List<EnergyProviderBlockEntity> started = new ArrayList<>();
List<EnergyProviderBlockEntity> temp = new ArrayList<>(scheduled); List<EnergyProviderBlockEntity> temp = new ArrayList<>(scheduled);
List<EnergyProviderBlockEntity> temp2 = new ArrayList<>(); List<EnergyProviderBlockEntity> temp2 = new ArrayList<>();
while (!temp.isEmpty()) { while (!temp.isEmpty()) {
for (EnergyProviderBlockEntity provider : temp) { for (EnergyProviderBlockEntity provider : temp) {
if (!started.contains(provider)) { if (!started.contains(provider)) {
temp2.addAll(provider.startTick()); temp2.addAll(provider.startTick());
started.add(provider); started.add(provider);
}
} }
temp.clear();
temp.addAll(temp2);
temp2.clear();
} }
temp.clear();
temp.addAll(temp2);
temp2.clear();
}
Collections.shuffle(started); Collections.shuffle(started);
for (EnergyProviderBlockEntity provider : started) { for (EnergyProviderBlockEntity provider : started) {
provider.logicTick(); provider.logicTick();
}
} }
} }
} }

View File

@ -16,7 +16,7 @@ public abstract class MixinWorld {
@Inject(at = @At("TAIL"), method = "tickBlockEntities") @Inject(at = @At("TAIL"), method = "tickBlockEntities")
public void tickBlockEntities(CallbackInfo info) { public void tickBlockEntities(CallbackInfo info) {
if (!isClient()) { if (!isClient()) {
EnergyTicker.tick(); EnergyTicker.tick((World) (Object) this);
} }
} }
} }

View File

@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "energonrelics:block/creative_energy_source"
}
}
}

View File

@ -36,5 +36,6 @@
"item.minecraft.tipped_arrow.effect.energonrelics.veridium_poison": "Arrow of Degradation", "item.minecraft.tipped_arrow.effect.energonrelics.veridium_poison": "Arrow of Degradation",
"block.energonrelics.lightning_rod": "Lightning Rod", "block.energonrelics.lightning_rod": "Lightning Rod",
"block.energonrelics.forcefield": "Forcefield", "block.energonrelics.forcefield": "Forcefield",
"block.energonrelics.forcefield_projector": "Forcefield Projector" "block.energonrelics.forcefield_projector": "Forcefield Projector",
"block.energonrelics.creative_energy_source": "Creative Energy Source"
} }

View File

@ -0,0 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "energonrelics:block/creative_energy_source"
}
}

View File

@ -0,0 +1,3 @@
{
"parent": "energonrelics:block/creative_energy_source"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 713 B