Skip to content

Commit

Permalink
Changed the Soul Laser Base to have a soul capability and the pipe ne…
Browse files Browse the repository at this point in the history
…twork will now store the souls extracted from the pipes
  • Loading branch information
Buuz135 committed Nov 28, 2024
1 parent ece68e5 commit a70ac26
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 94 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Version 1.10.2
* Changed the Soul Laser Base to have a soul capability and the pipe network will now store the souls extracted from the pipes

# Version 1.10.1
* Added comparator support for the Soul Laser Base closes #11

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ repositories {
dependencies {
compileOnly("mezz.jei:jei-1.21.1-neoforge-api:${jei_version}")
runtimeOnly("mezz.jei:jei-1.21.1-neoforge:${jei_version}")
implementation project.dependencies.create('com.hrznstudio:titanium:1.21-4.0.21')
implementation project.dependencies.create('com.hrznstudio:titanium:1.21-4.0.30')
implementation project.dependencies.create('com.buuz135:industrialforegoing:1.21-3.6.13')
implementation "vazkii.patchouli:Patchouli:${patchouli_version}"
compileOnly "dev.emi:emi-neoforge:${emi_version}:api"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod_name=Industrial Foregoing Souls
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT
# The mod version. See https://semver.org/
mod_version=1.10.1
mod_version=1.10.2
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import com.buuz135.industrialforegoingsouls.block.SoulLaserBaseBlock;
import com.buuz135.industrialforegoingsouls.block.SoulPipeBlock;
import com.buuz135.industrialforegoingsouls.block.SoulSurgeBlock;
import com.buuz135.industrialforegoingsouls.block.tile.SoulLaserBaseBlockEntity;
import com.buuz135.industrialforegoingsouls.block_network.DefaultSoulNetworkElement;
import com.buuz135.industrialforegoingsouls.block_network.SoulNetwork;
import com.buuz135.industrialforegoingsouls.capabilities.SLBSoulCap;
import com.buuz135.industrialforegoingsouls.capabilities.SoulCapabilities;
import com.buuz135.industrialforegoingsouls.data.IFSoulsBiomeTagProvider;
import com.buuz135.industrialforegoingsouls.data.IFSoulsLangProvider;
import com.buuz135.industrialforegoingsouls.data.IFSoulsRecipeProvider;
Expand All @@ -13,26 +16,29 @@
import com.hrznstudio.titanium.block_network.element.NetworkElementRegistry;
import com.hrznstudio.titanium.datagenerator.loot.TitaniumLootTableProvider;
import com.hrznstudio.titanium.datagenerator.model.BlockItemModelGeneratorProvider;
import com.hrznstudio.titanium.event.handler.EventManager;
import com.hrznstudio.titanium.module.BlockWithTile;
import com.hrznstudio.titanium.module.ModuleController;
import com.hrznstudio.titanium.network.NetworkHandler;
import com.hrznstudio.titanium.tab.TitaniumTab;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.Event;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.data.event.GatherDataEvent;

import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;

// The value here should match an entry in the META-INF/neoforge.mods.toml file
@Mod(IndustrialForegoingSouls.MOD_ID)
public class IndustrialForegoingSouls extends ModuleController {

Expand All @@ -51,6 +57,14 @@ public IndustrialForegoingSouls(Dist dist, IEventBus modBus, ModContainer contai
}
NetworkRegistry.INSTANCE.addFactory(SoulNetwork.SOUL_NETWORK, new SoulNetwork.Factory());
NetworkElementRegistry.INSTANCE.addFactory(DefaultSoulNetworkElement.ID, new DefaultSoulNetworkElement.Factory());
EventManager.mod(RegisterCapabilitiesEvent.class).process(event -> {
event.registerBlock(SoulCapabilities.BLOCK, (level, blockPos, blockState, blockEntity, direction) -> {
if (direction == Direction.UP && blockEntity instanceof SoulLaserBaseBlockEntity soulLaserBaseBlockEntity){
return new SLBSoulCap(soulLaserBaseBlockEntity);
}
return null;
}, SOUL_LASER_BLOCK.block().get());
}).subscribe();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;

public class SoulLaserBaseBlock extends IndustrialBlock<SoulLaserBaseBlockEntity> implements INetworkDirectionalConnection {
public class SoulLaserBaseBlock extends IndustrialBlock<SoulLaserBaseBlockEntity>{

public SoulLaserBaseBlock() {
super("soul_laser_base", BlockBehaviour.Properties.ofFullCopy(Blocks.IRON_BLOCK), SoulLaserBaseBlockEntity.class, ModuleResourceProduction.TAB_RESOURCE);
Expand All @@ -30,11 +30,6 @@ public void registerRecipe(RecipeOutput consumer) {
//TODO
}

@Override
public boolean canConnect(BlockState state, Direction direction) {
return direction == Direction.UP;
}

@Override
protected boolean hasAnalogOutputSignal(BlockState state) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.buuz135.industrialforegoingsouls.IndustrialForegoingSouls;
import com.buuz135.industrialforegoingsouls.block.tile.SoulPipeBlockEntity;
import com.buuz135.industrialforegoingsouls.capabilities.SoulCapabilities;
import com.buuz135.industrialforegoingsouls.config.IFSoulsClient;
import com.google.common.collect.ImmutableMap;
import com.hrznstudio.titanium.block.BasicTileBlock;
Expand Down Expand Up @@ -93,12 +94,15 @@ private BlockState createState(Level world, BlockPos pos, BlockState curr) {

protected PipeState getConnectionType(Level world, BlockPos pos, Direction direction, BlockState state) {
var relativeState = world.getBlockState(pos.relative(direction));
if (relativeState.getBlock() instanceof SoulPipeBlock || relativeState.getBlock() instanceof SoulSurgeBlock || relativeState.getBlock().equals(Blocks.STONE_BRICKS)) {
if (relativeState.getBlock() instanceof SoulPipeBlock || relativeState.getBlock() instanceof SoulSurgeBlock) {
return PipeState.PIPE;
}
if (relativeState.getBlock() instanceof INetworkDirectionalConnection networkDirectionalConnection && networkDirectionalConnection.canConnect(relativeState, direction.getOpposite())) {
return PipeState.BLOCK;
}
if (world.getCapability(SoulCapabilities.BLOCK, pos.relative(direction), direction.getOpposite()) != null){
return PipeState.BLOCK;
}
return PipeState.NO;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.buuz135.industrialforegoingsouls.IndustrialForegoingSouls;
import com.buuz135.industrialforegoingsouls.block_network.DefaultSoulNetworkElement;
import com.buuz135.industrialforegoingsouls.block_network.SoulNetwork;
import com.buuz135.industrialforegoingsouls.capabilities.ISoulHandler;
import com.buuz135.industrialforegoingsouls.client.SculkSoulTankScreenAddon;
import com.buuz135.industrialforegoingsouls.config.ConfigSoulLaserBase;
import com.hrznstudio.titanium.annotation.Save;
Expand Down Expand Up @@ -138,9 +139,11 @@ public int getSoulAmount() {
return soulAmount;
}

public void useSoul() {
--this.soulAmount;
public int useSoul(int soulAmount) {
var oldAmount = this.soulAmount;
this.soulAmount = Math.max(0, this.soulAmount - soulAmount);
syncObject(this.soulAmount);
return oldAmount - this.soulAmount;
}

@Override
Expand All @@ -166,47 +169,4 @@ public boolean canAcceptAugment(ItemStack augment) {
return super.canAcceptAugment(augment);
}

@Override
public void clearRemoved() {
super.clearRemoved();
if (level instanceof ServerLevel serverLevel) {
serverLevel.getServer().submitAsync(() -> {
NetworkManager networkManager = NetworkManager.get(level);

if (networkManager.getElement(worldPosition) == null) {
networkManager.addElement(createElement(level, worldPosition));
}
});
}
}

@Override
public void onChunkUnloaded() {
super.onChunkUnloaded();
unloaded = true;
}

@Override
public void setRemoved() {
super.setRemoved();

if (!level.isClientSide && !unloaded) {
NetworkManager networkManager = NetworkManager.get(level);

NetworkElement pipe = networkManager.getElement(worldPosition);
if (pipe != null) {
//spawnDrops(pipe);
}

networkManager.removeElement(worldPosition);
}
}

protected NetworkElement createElement(Level level, BlockPos pos) {
return new DefaultSoulNetworkElement(level, pos);
}

public SoulNetwork getNetwork() {
return (SoulNetwork) NetworkManager.get(this.level).getElement(worldPosition).getNetwork();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.buuz135.industrialforegoingsouls.block.tile;

import com.buuz135.industrialforegoingsouls.capabilities.ISoulHandler;
import com.buuz135.industrialforegoingsouls.capabilities.SoulCapabilities;
import com.hrznstudio.titanium.annotation.Save;
import com.hrznstudio.titanium.block.BasicTileBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -21,6 +24,16 @@ public SoulPipeBlockEntity(BasicTileBlock<SoulPipeBlockEntity> base, BlockEntity
@Override
public void serverTick(Level level, BlockPos pos, BlockState state, SoulPipeBlockEntity blockEntity) {
super.serverTick(level, pos, state, blockEntity);
for (Direction value : Direction.values()) {
var capability = level.getCapability(SoulCapabilities.BLOCK, pos.relative(value), value.getOpposite());
if (capability != null) {
var network = getNetwork();
if (network != null) {
var simulated = capability.drain(4, ISoulHandler.Action.SIMULATE);
capability.drain(network.addSouls(this.level, simulated), ISoulHandler.Action.EXECUTE);
}
}
}
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ public void serverTick(Level level, BlockPos pos, BlockState state, SoulSurgeBlo
if (state.getValue(SoulSurgeBlock.ENABLED)) {
if (tickingTime <= 0) {
var network = getNetwork();
for (NetworkElement soulLaserDrill : network.getSoulLaserDrills()) {
var soulTile = soulLaserDrill.getLevel().getBlockEntity(soulLaserDrill.getPos());
if (soulTile instanceof SoulLaserBaseBlockEntity soulLaserBaseBlockEntity && soulLaserBaseBlockEntity.getSoulAmount() > 0) {
soulLaserBaseBlockEntity.useSoul();
if (network != null) {
if (network.getSoulAmount() > 0) {
network.useSoul(this.level);
tickingTime = ConfigSoulSurge.SOUL_TIME;
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@ public DefaultSoulNetworkElement(Level level, BlockPos pos) {
@Override
public void joinNetwork(Network network) {
super.joinNetwork(network);
if (network instanceof SoulNetwork matterNetwork) {
matterNetwork.addElement(this);
}
}

@Override
public void leaveNetwork() {
if (this.network instanceof SoulNetwork matterNetwork) {
matterNetwork.removeElement(this);
}
super.leaveNetwork();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.buuz135.industrialforegoingsouls.IndustrialForegoingSouls;
import com.buuz135.industrialforegoingsouls.block.tile.SoulLaserBaseBlockEntity;
import com.buuz135.industrialforegoingsouls.config.IFSoulsMachines;
import com.hrznstudio.titanium.block_network.Network;
import com.hrznstudio.titanium.block_network.NetworkFactory;
import com.hrznstudio.titanium.block_network.NetworkManager;
import com.hrznstudio.titanium.block_network.element.NetworkElement;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -20,47 +22,53 @@ public class SoulNetwork extends Network {

public static ResourceLocation SOUL_NETWORK = ResourceLocation.fromNamespaceAndPath(IndustrialForegoingSouls.MOD_ID, "soul");

private List<NetworkElement> queueNetworkElements;
private List<NetworkElement> soulLaserDrills;
private int soulAmount;

public SoulNetwork(BlockPos originPos, String id) {
public SoulNetwork(BlockPos originPos, String id, int soulAmount) {
super(originPos, id);
this.queueNetworkElements = new ArrayList<>();
this.soulLaserDrills = new ArrayList<>();
}

public void addElement(NetworkElement element) {
this.queueNetworkElements.add(element);
}

public void removeElement(NetworkElement element) {
var tile = element.getLevel().getBlockEntity(element.getPos());
if (tile instanceof SoulLaserBaseBlockEntity) this.soulLaserDrills.remove(element);
this.soulAmount = soulAmount;
}

@Override
public void update(Level level) {
super.update(level);
for (NetworkElement element : this.queueNetworkElements) {
var tile = element.getLevel().getBlockEntity(element.getPos());
if (tile instanceof SoulLaserBaseBlockEntity) {
this.soulLaserDrills.add(element);
}
}
this.queueNetworkElements.clear();

}

@Override
public void onMergedWith(Network mainNetwork) {
if (mainNetwork instanceof SoulNetwork matterNetwork) {
this.addSouls(null, matterNetwork.soulAmount);
}
}

public int addSouls(Level level, int soulAmount){
var oldAmount = this.soulAmount;
this.soulAmount = Math.min(getMaxSouls(), soulAmount + oldAmount);
if (level != null) NetworkManager.get(level).setDirty(true);
return this.soulAmount - oldAmount;
}

public boolean useSoul(Level level){
if (this.soulAmount > 0) {
--this.soulAmount;
if (level != null) NetworkManager.get(level).setDirty(true);
return true;
}
return false;
}

public int getMaxSouls(){
return this.graph.getElements().size() * IFSoulsMachines.SOUL_AMOUNT_PER_PIPE;
}

public int getSoulAmount() {
return soulAmount;
}

@Override
public CompoundTag writeToNbt(CompoundTag tag) {
var nbt = super.writeToNbt(tag);
nbt.putInt("soulAmount", soulAmount);
return nbt;
}

Expand All @@ -69,22 +77,19 @@ public ResourceLocation getType() {
return SOUL_NETWORK;
}

public List<NetworkElement> getSoulLaserDrills() {
return soulLaserDrills;
}

public static class Factory implements NetworkFactory {

private static final Logger LOGGER = LogManager.getLogger(Factory.class);

@Override
public Network create(BlockPos pos) {
return new SoulNetwork(pos, NetworkFactory.randomString(new Random(), 8));
return new SoulNetwork(pos, NetworkFactory.randomString(new Random(), 8), 0);
}

@Override
public Network create(CompoundTag tag) {
SoulNetwork network = new SoulNetwork(BlockPos.of(tag.getLong("origin")), tag.getString("id"));
SoulNetwork network = new SoulNetwork(BlockPos.of(tag.getLong("origin")), tag.getString("id"), tag.getInt("soulAmount"));

LOGGER.debug("Deserialized matter network {} of type {}", network.getId(), network.getType().toString());

Expand Down
Loading

0 comments on commit a70ac26

Please sign in to comment.