Skip to content

Commit

Permalink
bioreactor assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Thepigcat76 committed Dec 21, 2024
1 parent c66a85c commit 1b103d7
Show file tree
Hide file tree
Showing 35 changed files with 223 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.portingdeadmods.nautec.api.blockentities.multiblock.MultiblockEntity;
import com.portingdeadmods.nautec.api.utils.HorizontalDirection;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.IntIntPair;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
Expand All @@ -16,6 +15,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public interface Multiblock {
BooleanProperty FORMED = BooleanProperty.create("formed");
Expand Down Expand Up @@ -82,9 +82,10 @@ public interface Multiblock {
* <br>
* <br>
* Example: {@link com.indref.industrial_reforged.registries.multiblocks.BlastFurnaceMultiblock#getDefinition() BlastFurnaceMultiblock.getDefintion()}
*
* @return The integer to block map that provides the integer keys and their block values
*/
Int2ObjectMap<Block> getDefinition();
Map<Integer, Block> getDefinition();

/**
* This method provides the block entity resource for the controller of your multiblock.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.portingdeadmods.nautec.Nautec;
import com.portingdeadmods.nautec.api.client.screen.NTAbstractContainerScreen;
import com.portingdeadmods.nautec.api.menu.NTAbstractContainerMenu;
import com.portingdeadmods.nautec.content.blockentities.BioReactorBlockEntity;
import com.portingdeadmods.nautec.content.blockentities.multiblock.part.AugmentationStationExtensionBlockEntity;
import com.portingdeadmods.nautec.content.blockentities.multiblock.controller.BioReactorBlockEntity;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
package com.portingdeadmods.nautec.content.blockentities;
package com.portingdeadmods.nautec.content.blockentities.multiblock.controller;

import com.portingdeadmods.nautec.api.blockentities.LaserBlockEntity;
import com.portingdeadmods.nautec.api.blockentities.multiblock.MultiblockEntity;
import com.portingdeadmods.nautec.api.multiblocks.MultiblockData;
import com.portingdeadmods.nautec.capabilities.IOActions;
import com.portingdeadmods.nautec.content.menus.AugmentationStationExtensionMenu;
import com.portingdeadmods.nautec.content.menus.BioReactorMenu;
import com.portingdeadmods.nautec.registries.NTBlockEntityTypes;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.capabilities.BlockCapability;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

public class BioReactorBlockEntity extends LaserBlockEntity implements MenuProvider {

public class BioReactorBlockEntity extends LaserBlockEntity implements MenuProvider, MultiblockEntity {
private MultiblockData multiblockData;

public BioReactorBlockEntity(BlockPos blockPos, BlockState blockState) {
super(NTBlockEntityTypes.BIO_REACTOR.get(), blockPos, blockState);
Expand All @@ -44,12 +48,34 @@ public <T> Map<Direction, Pair<IOActions, int[]>> getSidedInteractions(BlockCapa
}

@Override
public Component getDisplayName() {
public @NotNull Component getDisplayName() {
return Component.literal("Bio Reactor");
}

@Override
public @Nullable AbstractContainerMenu createMenu(int containerId, Inventory playerInventory, Player player) {
return new BioReactorMenu(containerId, playerInventory, this);
}

@Override
public MultiblockData getMultiblockData() {
return this.multiblockData;
}

@Override
public void setMultiblockData(MultiblockData data) {
this.multiblockData = data;
}

@Override
protected void saveData(CompoundTag tag, HolderLookup.Provider provider) {
super.saveData(tag, provider);
tag.put("multiblockData", saveMBData());
}

@Override
protected void loadData(CompoundTag tag, HolderLookup.Provider provider) {
super.loadData(tag, provider);
this.multiblockData = loadMBData(tag.getCompound("multiblockData"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.portingdeadmods.nautec.content.blockentities.multiblock.part;

import com.portingdeadmods.nautec.api.blockentities.multiblock.MultiblockPartEntity;
import com.portingdeadmods.nautec.registries.NTBlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

public class BioReactorPartBlockEntity extends BlockEntity implements MultiblockPartEntity {
private BlockPos controllerPos;

public BioReactorPartBlockEntity(BlockPos pos, BlockState blockState) {
super(NTBlockEntityTypes, pos, blockState);
}

@Override
public BlockPos getControllerPos() {
return this.controllerPos;
}

@Override
public void setControllerPos(BlockPos blockPos) {
this.controllerPos = blockPos;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
import com.portingdeadmods.nautec.api.blockentities.ContainerBlockEntity;
import com.portingdeadmods.nautec.api.blocks.blockentities.LaserBlock;
import com.portingdeadmods.nautec.registries.NTBlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class BioReactorBlock extends LaserBlock {
Expand Down Expand Up @@ -43,4 +49,9 @@ protected MapCodec<? extends BaseEntityBlock> codec() {
BlockState state = super.getStateForPlacement(context);
return state != null ? state.setValue(FACING, context.getHorizontalDirection()) : null;
}

@Override
protected @NotNull InteractionResult useWithoutItem(BlockState p_60503_, Level p_60504_, BlockPos p_60505_, Player p_60506_, BlockHitResult p_60508_) {
return InteractionResult.FAIL;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.portingdeadmods.nautec.content.blocks;

import com.mojang.serialization.MapCodec;
import com.portingdeadmods.nautec.api.blockentities.ContainerBlockEntity;
import com.portingdeadmods.nautec.api.blocks.blockentities.LaserBlock;
import com.portingdeadmods.nautec.content.blockentities.multiblock.part.BioReactorPartBlockEntity;
import com.portingdeadmods.nautec.registries.NTBlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class BioReactorPartBlock extends BaseEntityBlock {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;

public BioReactorPartBlock(Properties properties) {
super(properties);
registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH));
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder.add(FACING));
}

@Override
protected MapCodec<? extends BaseEntityBlock> codec() {
return simpleCodec(BioReactorBlock::new);
}

@Override
public @Nullable BlockState getStateForPlacement(BlockPlaceContext context) {
BlockState state = super.getStateForPlacement(context);
return state != null ? state.setValue(FACING, context.getHorizontalDirection()) : null;
}

@Override
public @Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new BioReactorPartBlockEntity(pos, state);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.portingdeadmods.nautec.content.menus;

import com.portingdeadmods.nautec.api.menu.NTAbstractContainerMenu;
import com.portingdeadmods.nautec.content.blockentities.BioReactorBlockEntity;
import com.portingdeadmods.nautec.content.blockentities.IncubatorBlockEntity;
import com.portingdeadmods.nautec.content.blockentities.multiblock.controller.BioReactorBlockEntity;
import com.portingdeadmods.nautec.registries.NTMenuTypes;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Inventory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.portingdeadmods.nautec.content.multiblocks;

import com.portingdeadmods.nautec.Nautec;
import com.portingdeadmods.nautec.api.blockentities.multiblock.MultiblockEntity;
import com.portingdeadmods.nautec.api.multiblocks.Multiblock;
import com.portingdeadmods.nautec.api.multiblocks.MultiblockData;
Expand All @@ -15,13 +14,14 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

public class AugmentationStationMultiblock implements Multiblock {
public static final IntegerProperty AS_PART = IntegerProperty.create("as_part", 0, 8);

Expand Down Expand Up @@ -52,7 +52,7 @@ public MultiblockLayer[] getLayout() {
}

@Override
public Int2ObjectMap<Block> getDefinition() {
public Map<Integer, Block> getDefinition() {
Int2ObjectMap<Block> def = new Int2ObjectOpenHashMap<>();
def.put(0, null);
def.put(1, getUnformedController());
Expand All @@ -79,7 +79,7 @@ public void onStartUnforming(Level level, BlockPos firstPos, BlockPos controller

@Override
public void iterBlock(Level level, BlockPos blockPos, BlockPos controllerPos, int layerIndex, int layoutIndex, MultiblockData data, boolean forming) {
Int2ObjectMap<Block> def = getDefinition();
Map<Integer, Block> def = getDefinition();
int[] curLayer = getLayout()[0].layer();
Block block = def.get(curLayer[layerIndex]);
if (block == getUnformedController()
Expand All @@ -91,7 +91,7 @@ public void iterBlock(Level level, BlockPos blockPos, BlockPos controllerPos, in

@Override
public @Nullable BlockState formBlock(Level level, BlockPos blockPos, BlockPos controllerPos, int layerIndex, int layoutIndex, MultiblockData multiblockData, @Nullable Player player) {
Int2ObjectMap<Block> def = getDefinition();
Map<Integer, Block> def = getDefinition();
int[] curLayer = getLayout()[0].layer();
Block block = def.get(curLayer[layerIndex]);
if (block == getUnformedController()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.portingdeadmods.nautec.content.multiblocks;

import com.portingdeadmods.nautec.api.blockentities.multiblock.MultiblockEntity;
import com.portingdeadmods.nautec.api.multiblocks.Multiblock;
import com.portingdeadmods.nautec.api.multiblocks.MultiblockData;
import com.portingdeadmods.nautec.api.multiblocks.MultiblockLayer;
import com.portingdeadmods.nautec.registries.NTBlockEntityTypes;
import com.portingdeadmods.nautec.registries.NTBlocks;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

public class BioReactorMultiblock implements Multiblock {
@Override
public Block getUnformedController() {
return NTBlocks.BIO_REACTOR.get();
}

@Override
public Block getFormedController() {
return NTBlocks.BIO_REACTOR.get();
}

@Override
public MultiblockLayer[] getLayout() {
return new MultiblockLayer[]{
layer(
2, 1, 2,
1, 3, 1,
2, 1, 2
),
layer(
2, 1, 2,
1, 0, 1,
2, 1, 2
),
};
}

@Override
public Map<Integer, Block> getDefinition() {
return Map.of(
0, getUnformedController(),
1, NTBlocks.BACTERIAL_CONTAINMENT_SHIELD.get(),
2, NTBlocks.DARK_PRISMARINE_PILLAR.get(),
3, NTBlocks.POLISHED_PRISMARINE.get()
);
}

@Override
public BlockEntityType<? extends MultiblockEntity> getMultiBlockEntityType() {
return NTBlockEntityTypes.BIO_REACTOR.get();
}

@Override
public @Nullable BlockState formBlock(Level level, BlockPos blockPos, BlockPos controllerPos, int layerIndex, int layoutIndex, MultiblockData multiblockData, @Nullable Player player) {
return switch (layerIndex) {
case 4 -> Blocks.BARREL.defaultBlockState();
default -> Blocks.BAMBOO_PLANKS.defaultBlockState();
};
}

@Override
public boolean isFormed(Level level, BlockPos blockPos) {
BlockState block = level.getBlockState(blockPos);
return block.hasProperty(FORMED) && block.getValue(FORMED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

public class DrainMultiblock implements Multiblock {
public static final IntegerProperty DRAIN_PART = IntegerProperty.create("drain_part", 0, 8);

Expand All @@ -48,7 +50,7 @@ public MultiblockLayer[] getLayout() {
}

@Override
public Int2ObjectMap<Block> getDefinition() {
public Map<Integer, Block> getDefinition() {
Int2ObjectMap<Block> def = new Int2ObjectOpenHashMap<>();
def.put(0, NTBlocks.DRAIN_WALL.get());
def.put(1, getUnformedController());
Expand Down
Loading

0 comments on commit 1b103d7

Please sign in to comment.