Skip to content

Commit

Permalink
Add large energy storage, add energy storage UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Rearth committed Apr 2, 2024
1 parent c8c37bd commit d2d92fe
Show file tree
Hide file tree
Showing 24 changed files with 683 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 1.20.4 2024-04-01T19:45:11.2977587 Oritech/Model Definitions
0ea8315aed10abcf90ec950fee0062aed26075cb assets\oritech\models\item\energy_pipe.json
// 1.20.4 2024-04-01T23:00:46.7476488 Oritech/Model Definitions
8ede0997449fd1c3f65a07df184768a843b473ed assets\oritech\models\item\centrifuge_block.json
0ea8315aed10abcf90ec950fee0062aed26075cb assets\oritech\models\item\energy_pipe.json
90e28b721796ff7ee21c8eefe4525f03a251d2fb assets\oritech\models\block\machine_extender.json
3fcaea2f05319816f7904137763182c4106c91a9 assets\oritech\blockstates\destroyer_block.json
e6f197ee5ac22cd68bc502a86d40b65bfe40884a assets\oritech\models\item\target_designator.json
7eb395cd65df72caf43bedc54067cbf53940fd6c assets\oritech\blockstates\centrifuge_block.json
8ef5ff056a3d2fa26393ec9ccb4b6f3b410f8be8 assets\oritech\models\item\item_pipe.json
b91305cbccecb97f9d74e2b92787ae9fa6387786 assets\oritech\blockstates\fluid_pipe.json
7eb395cd65df72caf43bedc54067cbf53940fd6c assets\oritech\blockstates\fragment_forge_block.json
b91305cbccecb97f9d74e2b92787ae9fa6387786 assets\oritech\blockstates\fluid_pipe.json
98d62a615b70fca694eb00c6b8aa9297c4a92b62 assets\oritech\blockstates\energy_pipe_connection.json
7eb395cd65df72caf43bedc54067cbf53940fd6c assets\oritech\blockstates\big_solar_panel_block.json
3ceff0ef4325bb269831205626285bc857c60de8 assets\oritech\models\item\destroyer_block.json
Expand All @@ -24,17 +24,18 @@ ee822d455f99c8c53c789fdb744979f678ca2729 assets\oritech\blockstates\fertilizer_b
46af77abe62b29d232feadccde429fd59d5603fc assets\oritech\blockstates\placer_block.json
3d37038977380bd685f913e722cc3b1c3a25c35d assets\oritech\models\item\atomic_forge_block.json
7eb395cd65df72caf43bedc54067cbf53940fd6c assets\oritech\blockstates\test_generator_block.json
b5ee97616ae0d2da17dfaecf45aa42f2cf19f691 assets\oritech\blockstates\machine_extender.json
eafe84c787830ab2a866e0878e9ed718d58659f5 assets\oritech\blockstates\banana_block.json
b5ee97616ae0d2da17dfaecf45aa42f2cf19f691 assets\oritech\blockstates\machine_extender.json
25864df3cd7786f2bf4fe6fa9855b3cf366c28ca assets\oritech\models\item\banana.json
1fdbeb99862a58436d745edb768b503539ecb295 assets\oritech\models\item\placer_block.json
58b38bcc6c404953490330d4cc797464b6874d88 assets\oritech\models\item\test_generator_block.json
b8bc03092cb1eb686ede01daffc7421253af860c assets\oritech\models\item\machine_extender.json
9cd64a2fe3b9a0ee479646d36cc0302bcd7cab4f assets\oritech\models\block\destroyer_block.json
45fbece69084d6df6eaa4ba344d25eef914c63c3 assets\oritech\models\item\small_storage_block.json
9cd64a2fe3b9a0ee479646d36cc0302bcd7cab4f assets\oritech\models\block\destroyer_block.json
63f14855c688ce7ec236097ce232dd381cbc1538 assets\oritech\blockstates\addon_indicator_block.json
7ee14de0149c70d1145dbf338518690b536cc02e assets\oritech\models\item\powered_furnace_block.json
746b98d721e5ae0d96dd769e71b786afa8c2d142 assets\oritech\models\item\banana_block.json
c0a08ce14172e22abd9f55d82686f7e96e74834a assets\oritech\blockstates\large_storage_block.json
230eb8fa77942cdf46509bea8df75b48f82e9e8e assets\oritech\blockstates\machine_frame_block.json
9caec2452545622571a137712307b8e0e669af9e assets\oritech\models\block\block_fertilizer_head.json
7eb395cd65df72caf43bedc54067cbf53940fd6c assets\oritech\blockstates\atomic_forge_block.json
Expand All @@ -48,16 +49,17 @@ a5afa0ba8780ec08bd0a9284bc08e0c681fe7158 assets\oritech\blockstates\block_placer
5054284e6d5fe0785ac93bdda5101c47337953cf assets\oritech\models\item\machine_frame_block.json
7b3ae67ec28f9b36b96539cd48b92096861d0853 assets\oritech\models\item\oil_bucket.json
56c7ceb5cc86d67913ad95cb4ae5ec192aed926f assets\oritech\models\block\pump_block.json
7eb395cd65df72caf43bedc54067cbf53940fd6c assets\oritech\blockstates\powered_furnace_block.json
1b9cd3719105dc1e03398de41f2cab37337816fe assets\oritech\blockstates\machine_core_good.json
ccd7e87c2ba5a5062bb88aa6e103d49d47cd56ff assets\oritech\blockstates\energy_pipe.json
7eb395cd65df72caf43bedc54067cbf53940fd6c assets\oritech\blockstates\powered_furnace_block.json
5462a2453fcdd2f8b99129894aec60f282d29ca9 assets\oritech\models\item\pulverizer_block.json
ae8496aa356910304cb7036f1290ca3f7d76437e assets\oritech\models\item\item_filter_block.json
a3f9b72f6f36d42af4e5c3a87d7e180b2e36a2ed assets\oritech\models\item\machine_core_good.json
97794db126be871e2cb68297abbe8917c343e705 assets\oritech\models\item\fluid_pipe.json
469ea8a66c529fe26bc029c21092e7f062ed0e40 assets\oritech\models\block\banana_block.json
d35ecef5df9198b12dc04267780c727c144b1959 assets\oritech\models\item\assembler_block.json
f337c5c80895d0c133e8218a41a0915b307cce18 assets\oritech\blockstates\small_storage_block.json
b6ebdae5692a337d52fe49ec327da5cff08540da assets\oritech\models\item\large_storage_block.json
d39d7a8eaa54d12c155fb1acd1722e322c0aeac3 assets\oritech\models\block\block_destroyer_head.json
7eb395cd65df72caf43bedc54067cbf53940fd6c assets\oritech\blockstates\foundry_block.json
30525b49546801c90bc77faa6eab332ba288eca5 assets\oritech\models\item\fertilizer_block.json
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "oritech:block/large_storage_block"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "oritech:block/large_storage_block"
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
package rearth.oritech.block.base.entity;

import net.fabricmc.fabric.api.lookup.v1.block.BlockApiCache;
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
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.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.property.Property;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import rearth.oritech.block.blocks.machines.storage.SmallStorageBlock;
import rearth.oritech.client.init.ParticleContent;
import rearth.oritech.client.init.ModScreens;
import rearth.oritech.client.ui.UpgradableMachineScreenHandler;
import rearth.oritech.network.NetworkContent;
import rearth.oritech.util.*;
import team.reborn.energy.api.EnergyStorage;
import team.reborn.energy.api.base.DelegatingEnergyStorage;
Expand All @@ -25,7 +37,7 @@
import java.util.List;
import java.util.Objects;

public abstract class ExpandableEnergyStorageBlockEntity extends BlockEntity implements EnergyProvider, MachineAddonController, BlockEntityTicker<ExpandableEnergyStorageBlockEntity> {
public abstract class ExpandableEnergyStorageBlockEntity extends BlockEntity implements EnergyProvider, MachineAddonController, ScreenProvider, ExtendedScreenHandlerFactory, BlockEntityTicker<ExpandableEnergyStorageBlockEntity> {

private final List<BlockPos> connectedAddons = new ArrayList<>();
private final List<BlockPos> openSlots = new ArrayList<>();
Expand Down Expand Up @@ -98,9 +110,6 @@ protected HashMap<Direction, BlockApiCache<EnergyStorage, Direction>> getNeighbo
var facing = getFacing();
var blockInFront = (BlockPos) Geometry.offsetToWorldPosition(facing, new Vec3i(-1, 0, 0), pos);

System.out.println(blockInFront.toCenterPos());
ParticleContent.HIGHLIGHT_BLOCK.spawn(world, Vec3d.of(blockInFront));

var frontCache = BlockApiCache.create(EnergyStorage.SIDED, (ServerWorld) world, blockInFront);
res.put(Direction.DOWN, frontCache);

Expand Down Expand Up @@ -186,4 +195,73 @@ public void setBaseAddonData(BaseAddonData data) {
}

public abstract long getDefaultExtractionRate();

@Override
public void writeScreenOpeningData(ServerPlayerEntity player, PacketByteBuf buf) {
buf.writeBlockPos(this.getPos());
buf.write(ADDON_UI_ENDEC, getUiData());
buf.writeFloat(getCoreQuality());
NetworkContent.MACHINE_CHANNEL.serverHandle(this).send(new NetworkContent.GenericEnergySyncPacket(pos, energyStorage.amount, energyStorage.capacity));
}

@Override
public Text getDisplayName() {
return Text.literal("invalid");
}

@Nullable
@Override
public ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player) {
return new UpgradableMachineScreenHandler(syncId, playerInventory, this, getUiData(), getCoreQuality());
}

@Override
public List<GuiSlot> getGuiSlots() {
return List.of();
}

@Override
public float getDisplayedEnergyUsage() {
return 0;
}

@Override
public float getProgress() {
return 0;
}

@Override
public InventoryInputMode getInventoryInputMode() {
return InventoryInputMode.FILL_LEFT_TO_RIGHT;
}

@Override
public boolean inputOptionsEnabled() {
return false;
}

@Override
public Inventory getDisplayedInventory() {
return new SimpleInventory();
}

@Override
public ScreenHandlerType<?> getScreenHandlerType() {
return ModScreens.STORAGE_SCREEN;
}

@Override
public BarConfiguration getEnergyConfiguration() {
return new BarConfiguration(80, 26, 15, 54);
}

@Override
public boolean showProgress() {
return false;
}

@Override
public Property<Direction> getBlockFacingProperty() {
return SmallStorageBlock.TARGET_DIR;
}
}
10 changes: 3 additions & 7 deletions src/main/java/rearth/oritech/block/blocks/MachineCoreBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import rearth.oritech.block.base.block.MachineBlock;
import rearth.oritech.block.base.block.MultiblockFrameInteractionBlock;
import rearth.oritech.block.entity.machines.MachineCoreEntity;
import rearth.oritech.util.MultiblockMachineController;
import rearth.oritech.util.ScreenProvider;

import java.util.Objects;

Expand Down Expand Up @@ -81,11 +80,8 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
if (!world.isClient) {
var controllerPos = getControllerPos(world, pos);
var controllerBlock = world.getBlockState(controllerPos);
if (Objects.requireNonNull(controllerBlock).getBlock() instanceof MachineBlock) {
return controllerBlock.getBlock().onUse(controllerBlock, world, controllerPos, player, hand, hit);
}

if (Objects.requireNonNull(controllerBlock).getBlock() instanceof MultiblockFrameInteractionBlock) {
var controllerEntity = world.getBlockEntity(controllerPos);
if (controllerEntity instanceof ScreenProvider) {
return controllerBlock.getBlock().onUse(controllerBlock, world, controllerPos, player, hand, hit);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package rearth.oritech.block.blocks.machines.storage;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.text.Text;
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;
import org.jetbrains.annotations.Nullable;
import rearth.oritech.block.entity.machines.storage.LargeStorageBlockEntity;
import rearth.oritech.util.MultiblockMachineController;

import java.util.Objects;

import static rearth.oritech.block.base.block.MultiblockMachine.ASSEMBLED;

public class LargeStorageBlock extends SmallStorageBlock {

public LargeStorageBlock(Settings settings) {
super(settings);
setDefaultState(getDefaultState().with(ASSEMBLED, false));
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(ASSEMBLED);
}

@Override
public @Nullable BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new LargeStorageBlockEntity(pos, state);
}

@Override
public @Nullable BlockState getPlacementState(ItemPlacementContext ctx) {
return Objects.requireNonNull(super.getPlacementState(ctx)).with(SmallStorageBlock.TARGET_DIR, ctx.getHorizontalPlayerFacing().getOpposite());
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {

if (!world.isClient) {

var entity = world.getBlockEntity(pos);
if (!(entity instanceof MultiblockMachineController machineEntity)) {
return ActionResult.SUCCESS;
}

var wasAssembled = state.get(ASSEMBLED);

var isAssembled = machineEntity.initMultiblock(state);

// first time created
if (isAssembled && !wasAssembled) {
// NetworkContent.MACHINE_CHANNEL.serverHandle(machineEntity).send(new NetworkContent.MachineSetupEventPacket(pos));
return ActionResult.SUCCESS;
}

if (!isAssembled) {
player.sendMessage(Text.literal("Machine is not assembled. Please add missing core blocks"));
return ActionResult.SUCCESS;
}

}

return super.onUse(state, world, pos, player, hand, hit);
}

@Override
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {

if (!world.isClient() && state.get(ASSEMBLED)) {

var entity = world.getBlockEntity(pos);
if (entity instanceof MultiblockMachineController machineEntity) {
machineEntity.onControllerBroken();
}
}

return super.onBreak(world, pos, state, player);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rearth.oritech.block.blocks.machines.storage;

import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockRenderType;
Expand Down Expand Up @@ -66,9 +67,12 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt

machineEntity.initAddons();

var handler = (ExtendedScreenHandlerFactory) world.getBlockEntity(pos);
player.openHandledScreen(handler);

}

return super.onUse(state, world, pos, player, hand, hit);
return ActionResult.SUCCESS;
}

@Override
Expand Down
Loading

0 comments on commit d2d92fe

Please sign in to comment.