Skip to content

Commit

Permalink
Begin implementing item pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rearth committed Mar 14, 2024
1 parent d734db2 commit cd45baf
Show file tree
Hide file tree
Showing 17 changed files with 557 additions and 257 deletions.
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

<h3 align="center">Oritech</h3>

<p align="center">
A minecraft fabric tech mod, currently still WIP. Just like this readme.
<br/>
<br/>
<a href="https://github.com/rearth/Oritech"><strong>Explore the docs »</strong></a>
<br/>
<br/>
<a href="https://github.com/rearth/Oritech/issues">Report Bug</a>
.
<a href="https://github.com/rearth/Oritech/issues">Request Feature</a>
</p>
<p align="center">
A minecraft fabric tech mod, currently still WIP. Just like this readme.
<br/>
<br/>
<a href="https://github.com/rearth/Oritech"><strong>Explore the docs »</strong></a>
<br/>
<br/>
<a href="https://github.com/rearth/Oritech/issues">Report Bug</a>
.
<a href="https://github.com/rearth/Oritech/issues">Request Feature</a>
</p>

![Downloads](https://img.shields.io/github/downloads/rearth/Oritech/total) ![Stargazers](https://img.shields.io/github/stars/rearth/Oritech?style=social) ![Issues](https://img.shields.io/github/issues/rearth/Oritech) ![License](https://img.shields.io/github/license/rearth/Oritech)
Expand Down Expand Up @@ -73,7 +72,8 @@ const API_KEY = 'ENTER YOUR API';

## Usage

Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.
Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos
work well in this space. You may also link to more resources.

_For more examples, please refer to the [Documentation](https://example.com)_

Expand All @@ -83,11 +83,16 @@ See the [open issues](https://github.com/rearth/Oritech/issues) for a list of pr

## Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.
* If you have suggestions for adding or removing projects, feel free to [open an issue](https://github.com/rearth/Oritech/issues/new) to discuss it, or directly create a pull request after you edit the *README.md* file with necessary changes.
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any
contributions you make are **greatly appreciated**.

* If you have suggestions for adding or removing projects, feel free
to [open an issue](https://github.com/rearth/Oritech/issues/new) to discuss it, or directly create a pull request
after you edit the *README.md* file with necessary changes.
* Please make sure you check your spelling and grammar.
* Create individual PR for each suggestion.
* Please also read through the [Code Of Conduct](https://github.com/rearth/Oritech/blob/main/CODE_OF_CONDUCT.md) before posting your first idea as well.
* Please also read through the [Code Of Conduct](https://github.com/rearth/Oritech/blob/main/CODE_OF_CONDUCT.md) before
posting your first idea as well.

### Creating A Pull Request

Expand All @@ -100,7 +105,8 @@ Contributions are what make the open source community such an amazing place to b
## License

TODO
Distributed under the CC BY-NC 4.0 DEED License. See [LICENSE](https://github.com/rearth/Oritech/blob/main/LICENSE.md) for more information.
Distributed under the CC BY-NC 4.0 DEED License. See [LICENSE](https://creativecommons.org/licenses/by-nc/4.0/) for more
information.

## Acknowledgements

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// 1.20.4 2024-03-12T16:50:56.2758117 Oritech/Model Definitions
// 1.20.4 2024-03-14T00:31:03.2228696 Oritech/Model Definitions
3d6f377b938592ac22aca17bd64561a6579ad217 assets\oritech\blockstates\grinder_block.json
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
53f76976c5fe0593fa89a4b835dde07c96b07067 assets\oritech\blockstates\centrifuge_block.json
8ef5ff056a3d2fa26393ec9ccb4b6f3b410f8be8 assets\oritech\models\item\item_pipe.json
b91305cbccecb97f9d74e2b92787ae9fa6387786 assets\oritech\blockstates\fluid_pipe.json
98d62a615b70fca694eb00c6b8aa9297c4a92b62 assets\oritech\blockstates\energy_pipe_connection.json
95eae9b13fb2835f15057d2fd4d9550192064ca4 assets\oritech\models\item\grinder_block.json
Expand Down Expand Up @@ -44,8 +45,8 @@ a5afa0ba8780ec08bd0a9284bc08e0c681fe7158 assets\oritech\blockstates\block_placer
f29468ff950a191567ab35557334666099ccd7cc assets\oritech\blockstates\assembler_block.json
5054284e6d5fe0785ac93bdda5101c47337953cf assets\oritech\models\item\machine_frame_block.json
56c7ceb5cc86d67913ad95cb4ae5ec192aed926f assets\oritech\models\block\pump_block.json
3810f72943d88c81d3ab6b4329d437911c859621 assets\oritech\blockstates\powered_furnace_block.json
1b9cd3719105dc1e03398de41f2cab37337816fe assets\oritech\blockstates\machine_core_good.json
3810f72943d88c81d3ab6b4329d437911c859621 assets\oritech\blockstates\powered_furnace_block.json
ccd7e87c2ba5a5062bb88aa6e103d49d47cd56ff assets\oritech\blockstates\energy_pipe.json
5462a2453fcdd2f8b99129894aec60f282d29ca9 assets\oritech\models\item\pulverizer_block.json
a3f9b72f6f36d42af4e5c3a87d7e180b2e36a2ed assets\oritech\models\item\machine_core_good.json
Expand All @@ -55,8 +56,10 @@ d35ecef5df9198b12dc04267780c727c144b1959 assets\oritech\models\item\assembler_bl
d39d7a8eaa54d12c155fb1acd1722e322c0aeac3 assets\oritech\models\block\block_destroyer_head.json
b909a1e7a747bcbfaba3d33391ed75c361dff0c6 assets\oritech\blockstates\foundry_block.json
30525b49546801c90bc77faa6eab332ba288eca5 assets\oritech\models\item\fertilizer_block.json
5d80e89ede99144cb0f94a543c2b86239fc5cbdd assets\oritech\blockstates\item_pipe_connection.json
f53b229ded70f8ae0bff50e829d62326601b0fe8 assets\oritech\models\block\block_placer_head.json
b7e73ae6ffd983038af7540301bf488242562790 assets\oritech\models\block\fertilizer_block.json
83b81f38fd21e58e98aab409d36368b3a78b675e assets\oritech\blockstates\item_pipe.json
66c23bb916995ef1664b6119475d183a66f32624 assets\oritech\blockstates\block_fertilizer_head.json
3d6d17333aeaef12a7bd95f18b169ee69a0bab5f assets\oritech\blockstates\fluid_pipe_connection.json
42580a93e058faa5381bfac746ed2a200ec5f323 assets\oritech\models\item\laser_arm_block.json
Expand Down
7 changes: 7 additions & 0 deletions src/main/generated/assets/oritech/blockstates/item_pipe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "oritech:block/item_pipe"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "oritech:block/item_pipe_connection"
}
}
}
3 changes: 3 additions & 0 deletions src/main/generated/assets/oritech/models/item/item_pipe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "oritech:block/item_pipe"
}
8 changes: 7 additions & 1 deletion src/main/java/rearth/oritech/Oritech.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.slf4j.LoggerFactory;
import rearth.oritech.block.blocks.pipes.EnergyPipeBlock;
import rearth.oritech.block.blocks.pipes.FluidPipeBlock;
import rearth.oritech.block.blocks.pipes.ItemPipeBlock;
import rearth.oritech.block.entity.pipes.GenericPipeInterfaceEntity;
import rearth.oritech.client.init.ParticleContent;
import rearth.oritech.init.BlockContent;
Expand Down Expand Up @@ -50,12 +51,17 @@ private void onServerStarted(MinecraftServer minecraftServer) {
EnergyPipeBlock.ENERGY_PIPE_DATA = result;
}


var fluidDataId = "fluid_" + regKey.getNamespace() + "_" + regKey.getPath();
var fluidResult = world.getPersistentStateManager().getOrCreate(GenericPipeInterfaceEntity.PipeNetworkData.TYPE, fluidDataId);
if (fluidResult.hashCode() != 0) {
FluidPipeBlock.FLUID_PIPE_DATA = fluidResult;
}

var itemDataId = "item_" + regKey.getNamespace() + "_" + regKey.getPath();
var itemResult = world.getPersistentStateManager().getOrCreate(GenericPipeInterfaceEntity.PipeNetworkData.TYPE, itemDataId);
if (itemResult.hashCode() != 0) {
ItemPipeBlock.ITEM_PIPE_DATA = itemResult;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,6 @@ public boolean canInsert(int slot, ItemStack stack, @Nullable Direction side) {

var inv = getInputView();

System.out.println(inv);

// fill equally
// check all slots, find the one with the lowest (or empty) type
return switch (mode) {
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/rearth/oritech/block/blocks/pipes/ItemPipeBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package rearth.oritech.block.blocks.pipes;

import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup;
import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.Direction;
import rearth.oritech.block.entity.pipes.GenericPipeInterfaceEntity;
import rearth.oritech.init.BlockContent;

public class ItemPipeBlock extends GenericPipeBlock {

public static GenericPipeInterfaceEntity.PipeNetworkData ITEM_PIPE_DATA = new GenericPipeInterfaceEntity.PipeNetworkData();

public ItemPipeBlock(Settings settings) {
super(settings);
}

@Override
public BlockApiLookup<?, Direction> getSidesLookup() {
return ItemStorage.SIDED;
}

@Override
public BlockState getConnectionBlock() {
return BlockContent.ITEM_PIPE_CONNECTION.getDefaultState();
}

@Override
public BlockState getNormalBlock() {
return BlockContent.ITEM_PIPE.getDefaultState();
}

@Override
public String getPipeTypeName() {
return "item";
}

@Override
public boolean connectToBlockType(Block block) {
return block instanceof ItemPipeBlock || block instanceof ItemPipeConnectionBlock;
}

@Override
public GenericPipeInterfaceEntity.PipeNetworkData getNetworkData() {
return ITEM_PIPE_DATA;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package rearth.oritech.block.blocks.pipes;

import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup;
import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage;
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.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
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.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import rearth.oritech.block.entity.pipes.GenericPipeInterfaceEntity;
import rearth.oritech.block.entity.pipes.ItemPipeInterfaceEntity;
import rearth.oritech.init.BlockContent;

import static rearth.oritech.block.blocks.pipes.ItemPipeBlock.ITEM_PIPE_DATA;

public class ItemPipeConnectionBlock extends GenericPipeConnectionBlock {

public static final BooleanProperty EXTRACT = BooleanProperty.of("extract");

public ItemPipeConnectionBlock(Settings settings) {
super(settings);
this.setDefaultState(this.getDefaultState().with(EXTRACT, false));
}

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

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

if (world.isClient) return ActionResult.SUCCESS;

var oldExtract = state.get(EXTRACT);
world.setBlockState(pos, state.with(EXTRACT, !oldExtract));
System.out.println("changed extract to: " + !oldExtract);

return ActionResult.SUCCESS;
}

@Override
public BlockApiLookup<?, Direction> getSidesLookup() {
return ItemStorage.SIDED;
}

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

@Override
public BlockState getConnectionBlock() {
return BlockContent.ITEM_PIPE_CONNECTION.getDefaultState();
}

@Override
public BlockState getNormalBlock() {
return BlockContent.ITEM_PIPE.getDefaultState();
}

@Override
public String getPipeTypeName() {
return "item";
}

@Override
public boolean connectToBlockType(Block block) {
return block instanceof ItemPipeBlock || block instanceof ItemPipeConnectionBlock;
}

@Override
public GenericPipeInterfaceEntity.PipeNetworkData getNetworkData() {
return ITEM_PIPE_DATA;
}
}
Loading

0 comments on commit cd45baf

Please sign in to comment.