Skip to content

Commit

Permalink
Demat Circuit + Structure Backend (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
Duzos authored Nov 19, 2024
2 parents 9c23088 + ba09d45 commit 2cfd196
Show file tree
Hide file tree
Showing 22 changed files with 532 additions and 52 deletions.
3 changes: 3 additions & 0 deletions src/main/java/loqor/ait/core/AITBlockEntityTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import loqor.ait.core.blockentities.*;
import loqor.ait.core.blockentities.control.RedstoneControlBlockEntity;
import loqor.ait.core.blocks.PowerConverterBlock;
import loqor.ait.core.engine.block.generic.GenericStructureSystemBlockEntity;
import loqor.ait.core.engine.link.block.FluidLinkBlockEntity;

public class AITBlockEntityTypes implements BlockEntityRegistryContainer {
Expand Down Expand Up @@ -57,4 +58,6 @@ public class AITBlockEntityTypes implements BlockEntityRegistryContainer {
.create(ZeitonCageBlockEntity::new, AITBlocks.ZEITON_CAGE).build();
public static BlockEntityType<PowerConverterBlock.BlockEntity> POWER_CONVERTER_BLOCK_TYPE = FabricBlockEntityTypeBuilder
.create(PowerConverterBlock.BlockEntity::new, AITBlocks.POWER_CONVERTER).build();
public static BlockEntityType<GenericStructureSystemBlockEntity> GENERIC_SUBSYSTEM_BLOCK_TYPE = FabricBlockEntityTypeBuilder
.create(GenericStructureSystemBlockEntity::new, AITBlocks.GENERIC_SUBSYSTEM).build();
}
5 changes: 5 additions & 0 deletions src/main/java/loqor/ait/core/AITBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import loqor.ait.core.blocks.*;
import loqor.ait.core.blocks.DoorBlock;
import loqor.ait.core.blocks.control.RedstoneControlBlock;
import loqor.ait.core.engine.block.generic.GenericSubSystemBlock;
import loqor.ait.datagen.datagen_providers.util.AutomaticModel;
import loqor.ait.datagen.datagen_providers.util.NoBlockDrop;
import loqor.ait.datagen.datagen_providers.util.NoEnglish;
Expand Down Expand Up @@ -128,6 +129,10 @@ public class AITBlocks implements BlockRegistryContainer {
@PickaxeMineable(tool = PickaxeMineable.Tool.IRON)
public static final Block POWER_CONVERTER = new PowerConverterBlock(FabricBlockSettings.create().nonOpaque()
.requiresTool().instrument(Instrument.COW_BELL).strength(1.5F, 6.0F).pistonBehavior(PistonBehavior.DESTROY));
@PickaxeMineable(tool = PickaxeMineable.Tool.IRON)
@NoEnglish
public static final Block GENERIC_SUBSYSTEM = new GenericSubSystemBlock(FabricBlockSettings.create().nonOpaque()
.requiresTool().instrument(Instrument.COW_BELL).strength(1.5F, 6.0F).pistonBehavior(PistonBehavior.DESTROY));


@NoBlockItem
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/loqor/ait/core/AITItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
import net.minecraft.util.Rarity;

import loqor.ait.AITMod;
import loqor.ait.core.engine.SubSystem;
import loqor.ait.core.engine.item.SubSystemItem;
import loqor.ait.core.item.*;
import loqor.ait.core.item.blueprint.BlueprintItem;
import loqor.ait.core.item.control.GenericControlBlockItem;
import loqor.ait.core.item.link.AbstractLinkItem;
import loqor.ait.core.item.link.FluidLinkItem;
import loqor.ait.core.item.link.MercurialLinkItem;
import loqor.ait.core.item.part.MachineItem;
import loqor.ait.core.item.part.MachinePartItem;
import loqor.ait.datagen.datagen_providers.util.NoEnglish;

Expand Down Expand Up @@ -112,8 +113,8 @@ ArmorItem.Type.HELMET, new OwoItemSettings().group(AITMod.AIT_ITEM_GROUP).maxCou
new OwoItemSettings() /* .group(AITMod.AIT_ITEM_GROUP) */);

// Components
public static final Item DEMATERIALIZATION_CIRCUIT = new MachineItem(
new OwoItemSettings() /* .group(AITMod.AIT_ITEM_GROUP) */);
public static final Item DEMATERIALIZATION_CIRCUIT = new SubSystemItem(
new OwoItemSettings().group(AITMod.AIT_ITEM_GROUP), SubSystem.Id.DEMAT);

// Blueprint
public static final Item BLUEPRINT = new BlueprintItem(
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/loqor/ait/core/blockentities/EngineBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import loqor.ait.core.AITBlockEntityTypes;
import loqor.ait.core.AITSounds;
import loqor.ait.core.engine.SubSystem;
import loqor.ait.core.engine.block.SubSystemBlockEntity;
import loqor.ait.core.engine.impl.EngineSystem;
Expand All @@ -29,20 +28,19 @@ public EngineBlockEntity(BlockPos pos, BlockState state) {
if (!this.hasWorld()) return;
}

public void useOn(BlockState state, World world, boolean sneaking, PlayerEntity player, ItemStack hand) {
@Override
public ActionResult useOn(BlockState state, World world, boolean sneaking, PlayerEntity player, ItemStack hand) {
ActionResult result = super.useOn(state, world, sneaking, player, hand);
if (result != ActionResult.PASS)
return result;

if (world.isClient() || this.tardis().isEmpty())
return;
return ActionResult.FAIL;

EngineSystem engine = this.tardis().get().subsystems().engine();

if (engine.isRepairItem(hand) && engine.durability() < 100) {
engine.addDurability(5);
hand.decrement(1);
world.playSound(null, this.getPos(), AITSounds.BWEEP, SoundCategory.BLOCKS, 0.5f, 1f);
return;
}

engine.setEnabled(!engine.isEnabled());
return ActionResult.SUCCESS;
}

@Override
Expand Down
24 changes: 8 additions & 16 deletions src/main/java/loqor/ait/core/blocks/EngineBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@

import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;

import loqor.ait.core.AITBlockEntityTypes;
import loqor.ait.core.blockentities.EngineBlockEntity;
import loqor.ait.core.engine.SubSystem;
import loqor.ait.core.engine.block.SubSystemBlock;
import loqor.ait.core.engine.block.SubSystemBlockEntity;

public class EngineBlock extends SubSystemBlock implements BlockEntityProvider {
protected static final VoxelShape Y_SHAPE = Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 48.0, 16.0);
Expand All @@ -27,17 +25,6 @@ public EngineBlock(Settings settings) {
super(settings, SubSystem.Id.ENGINE);
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand,
BlockHitResult hit) {
BlockEntity blockEntity = world.getBlockEntity(pos);
ItemStack stack = player.getStackInHand(hand);
if (blockEntity instanceof EngineBlockEntity engineBlockEntity)
engineBlockEntity.useOn(state, world, player.isSneaking(), player, stack);

return ActionResult.SUCCESS;
}

@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return Y_SHAPE;
Expand Down Expand Up @@ -86,4 +73,9 @@ public void randomDisplayTick(BlockState state, World world, BlockPos pos, Rando
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.ENTITYBLOCK_ANIMATED;
}

@Override
protected BlockEntityType<? extends SubSystemBlockEntity> getType() {
return AITBlockEntityTypes.ENGINE_BLOCK_ENTITY_TYPE;
}
}
3 changes: 3 additions & 0 deletions src/main/java/loqor/ait/core/engine/DurableSubSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ protected void onDurabilityChange(float before, float after) {
this.sync();
}
protected void onBreak() {
this.setEnabled(false);
}

protected void onRepair() {
this.setEnabled(true);
}
protected int changeFrequency() {
return 20;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/loqor/ait/core/engine/StructureHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package loqor.ait.core.engine;

import loqor.ait.core.engine.block.multi.MultiBlockStructure;

public interface StructureHolder {
MultiBlockStructure getStructure();
}
4 changes: 3 additions & 1 deletion src/main/java/loqor/ait/core/engine/SubSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import loqor.ait.api.Initializable;
import loqor.ait.api.TardisComponent;
import loqor.ait.client.tardis.ClientTardis;
import loqor.ait.core.engine.impl.DematCircuit;
import loqor.ait.core.engine.impl.EngineSystem;
import loqor.ait.core.tardis.ServerTardis;
import loqor.ait.core.tardis.Tardis;
Expand Down Expand Up @@ -84,7 +85,8 @@ public static void init(SubSystem system, Tardis tardis, TardisComponent.InitCon
}

public enum Id implements SubSystem.IdLike {
ENGINE(EngineSystem.class, EngineSystem::new),;
ENGINE(EngineSystem.class, EngineSystem::new),
DEMAT(DematCircuit.class, DematCircuit::new);
private final Supplier<SubSystem> creator;

private final Class<? extends SubSystem> clazz;
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/loqor/ait/core/engine/block/SubSystemBlock.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package loqor.ait.core.engine.block;

import org.jetbrains.annotations.Nullable;

import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

Expand Down Expand Up @@ -33,4 +42,26 @@ public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockSt

super.onStateReplaced(state, world, pos, newState, moved);
}

@Override
public @Nullable <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return (world1, pos, state1, blockEntity) -> {
if (blockEntity instanceof SubSystemBlockEntity be) {
be.tick(world1, pos, state1);
}
};
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand,
BlockHitResult hit) {
BlockEntity blockEntity = world.getBlockEntity(pos);
ItemStack stack = player.getStackInHand(hand);
if (blockEntity instanceof SubSystemBlockEntity be)
return be.useOn(state, world, player.isSneaking(), player, stack);

return ActionResult.SUCCESS;
}

protected abstract BlockEntityType<? extends SubSystemBlockEntity> getType();
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
package loqor.ait.core.engine.block;


import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import loqor.ait.core.AITSounds;
import loqor.ait.core.engine.DurableSubSystem;
import loqor.ait.core.engine.SubSystem;
import loqor.ait.core.engine.link.block.FluidLinkBlockEntity;
import loqor.ait.core.engine.registry.SubSystemRegistry;
import loqor.ait.core.util.SoundData;

public class SubSystemBlockEntity extends FluidLinkBlockEntity {
private SubSystem.IdLike id;
protected SubSystem.IdLike id;

public SubSystemBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state, SubSystem.IdLike id) {
super(type, pos, state);
this.id = id;
}

public SubSystem system() {
if (this.tardis() == null || this.tardis().isEmpty()) return null;
if (this.tardis() == null || this.tardis().isEmpty() || this.id() == null) return null;

return this.tardis().get().subsystems().get(this.id);
return this.tardis().get().subsystems().get(this.id());
}
protected SubSystem.IdLike id() {
if (this.id == null) {
Expand All @@ -35,6 +43,9 @@ protected SubSystem.IdLike id() {
public void onGainFluid() {
super.onGainFluid();

if (this.system() instanceof DurableSubSystem durable) {
if (durable.isBroken()) return;
}
this.system().setEnabled(true);
}

Expand All @@ -54,4 +65,35 @@ protected SoundData getGainPowerSound() {
protected SoundData getLosePowerSound() {
return new SoundData(AITSounds.SIEGE_ENABLE, SoundCategory.BLOCKS, 0.25f, 1.0f);
}

public void tick(World world, BlockPos pos, BlockState state) {}
public ActionResult useOn(BlockState state, World world, boolean sneaking, PlayerEntity player, ItemStack hand) {
if (this.system() instanceof DurableSubSystem durable) {
if (durable.isRepairItem(hand) && durable.durability() < 100) {
durable.addDurability(5);
hand.decrement(1);
world.playSound(null, this.getPos(), AITSounds.BWEEP, SoundCategory.BLOCKS, 0.5f, 1f);
return ActionResult.SUCCESS;
}
}
return ActionResult.PASS;
}

@Override
public void writeNbt(NbtCompound nbt) {
super.writeNbt(nbt);

if (this.id != null) {
nbt.putString("id", this.id.toString());
}
}

@Override
public void readNbt(NbtCompound nbt) {
super.readNbt(nbt);

if (nbt.contains("id")) {
this.id = SubSystemRegistry.getInstance().get(nbt.getString("id"));
}
}
}
Loading

0 comments on commit 2cfd196

Please sign in to comment.