Skip to content

Commit

Permalink
Add ME Source Jar
Browse files Browse the repository at this point in the history
(model and texture courtesy of Ridanisaurus)
  • Loading branch information
62832 committed Jun 15, 2024
1 parent e12dee9 commit a5022e6
Show file tree
Hide file tree
Showing 37 changed files with 765 additions and 42 deletions.
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencyResolutionManagement {
library("ae2", "appeng", "appliedenergistics2-forge").versionRef("ae2")
library("aecapfix", "curse.maven", "aecapfix-914685").version("5017517")

version("ars", "4.6.0.99")
version("ars", "4.9.0.165")
library("ars", "com.hollingsworth.ars_nouveau", "ars_nouveau-$minecraftVersion").versionRef("ars")

library("geckolib", "software.bernie.geckolib", "geckolib-forge-$minecraftVersion").version("4.2.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ class BlockStateModelProvider extends BlockStateProvider {

@Override
protected void registerStatesAndModels() {
simpleBlock(ArsEngBlocks.SOURCE_ACCEPTOR.block());
simpleBlockItem(ArsEngBlocks.SOURCE_ACCEPTOR.block(), cubeAll(ArsEngBlocks.SOURCE_ACCEPTOR.block()));
simpleBlockWithItem(ArsEngBlocks.SOURCE_ACCEPTOR.block(), cubeAll(ArsEngBlocks.SOURCE_ACCEPTOR.block()));

var sourceJarModel = models().getExistingFile(ArsEngBlocks.ME_SOURCE_JAR.id());
horizontalBlock(ArsEngBlocks.ME_SOURCE_JAR.block(), sourceJarModel);
simpleBlockItem(ArsEngBlocks.ME_SOURCE_JAR.block(), sourceJarModel);

var sourceCell = "block/source_drive_cell";
models().getBuilder(sourceCell)
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/gripe/_90/arseng/ArsEnergistique.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gripe._90.arseng;

import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.api.distmarker.Dist;
Expand All @@ -21,6 +22,8 @@
import appeng.core.localization.GuiText;
import appeng.parts.automation.StackWorldBehaviors;

import gripe._90.arseng.client.MESourceJarBlockEntityRenderer;
import gripe._90.arseng.client.SourceRenderer;
import gripe._90.arseng.definition.ArsEngBlocks;
import gripe._90.arseng.definition.ArsEngCapabilities;
import gripe._90.arseng.definition.ArsEngConfig;
Expand All @@ -30,7 +33,6 @@
import gripe._90.arseng.item.SourceCellItem;
import gripe._90.arseng.me.cell.CreativeSourceCellHandler;
import gripe._90.arseng.me.cell.SourceCellHandler;
import gripe._90.arseng.me.client.SourceRenderer;
import gripe._90.arseng.me.key.SourceKey;
import gripe._90.arseng.me.key.SourceKeyType;
import gripe._90.arseng.me.strategy.SourceContainerItemStrategy;
Expand Down Expand Up @@ -97,6 +99,8 @@ private static void init() {
ArsEngItems.getCells().forEach(cell -> StorageCellModels.registerModel(cell, driveCell));
ArsEngItems.getPortables().forEach(portable -> StorageCellModels.registerModel(portable, driveCell));
StorageCellModels.registerModel(ArsEngItems.CREATIVE_SOURCE_CELL, driveCell);

BlockEntityRenderers.register(ArsEngBlocks.ME_SOURCE_JAR_ENTITY, MESourceJarBlockEntityRenderer::new);
}
}
}
152 changes: 152 additions & 0 deletions src/main/java/gripe/_90/arseng/block/MESourceJarBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package gripe._90.arseng.block;

import java.util.stream.Stream;
import javax.annotation.ParametersAreNonnullByDefault;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
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.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

import appeng.api.orientation.IOrientableBlock;
import appeng.api.orientation.IOrientationStrategy;
import appeng.api.orientation.OrientationStrategies;
import appeng.hooks.WrenchHook;

import gripe._90.arseng.block.entity.MESourceJarBlockEntity;

@ParametersAreNonnullByDefault
public class MESourceJarBlock extends Block implements EntityBlock, SimpleWaterloggedBlock, IOrientableBlock {
private static final VoxelShape SHAPE = Stream.of(
Block.box(4, 13, 4, 12, 14, 12),
Block.box(0, 0, 0, 16, 1, 16),
Block.box(2, 1, 2, 14, 2, 14),
Block.box(3, 2, 3, 13, 13, 13),
Block.box(3, 14, 3, 13, 16, 13),
Block.box(6, 1, 14, 10, 16, 16),
Block.box(6, 14, 13, 10, 16, 16),
Block.box(5, 5, 13, 11, 11, 16))
.reduce((v1, v2) -> Shapes.join(v1, v2, BooleanOp.OR))
.get();

public MESourceJarBlock() {
super(Properties.of()
.strength(2.2f, 11.f)
.mapColor(MapColor.METAL)
.sound(SoundType.GLASS)
.noOcclusion());
registerDefaultState(defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, false));
}

@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new MESourceJarBlockEntity(pos, state);
}

@Override
public void setPlacedBy(
Level level, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) {
if (entity instanceof Player player && level.getBlockEntity(pos) instanceof MESourceJarBlockEntity jar) {
jar.getMainNode().setOwningPlayer(player);
}
}

@SuppressWarnings("deprecation")
@Override
public boolean hasAnalogOutputSignal(BlockState pState) {
return true;
}

@SuppressWarnings("deprecation")
@Override
public int getAnalogOutputSignal(BlockState state, Level level, BlockPos pos) {
var jar = (MESourceJarBlockEntity) level.getBlockEntity(pos);
return jar != null ? jar.calculateComparatorLevel() : 0;
}

@SuppressWarnings("deprecation")
@NotNull
@Override
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return SHAPE;
}

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

@SuppressWarnings("deprecation")
@NotNull
@Override
public FluidState getFluidState(BlockState state) {
return state.getValue(BlockStateProperties.WATERLOGGED)
? Fluids.WATER.getSource(false)
: Fluids.EMPTY.defaultFluidState();
}

@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
var fluidState = context.getLevel().getFluidState(context.getClickedPos());
return defaultBlockState()
.setValue(BlockStateProperties.WATERLOGGED, fluidState.getType() == Fluids.WATER)
.setValue(
BlockStateProperties.HORIZONTAL_FACING,
context.getHorizontalDirection().getOpposite());
}

@SuppressWarnings("deprecation")
@NotNull
@Override
public BlockState updateShape(
BlockState state,
Direction dir,
BlockState neighbourState,
LevelAccessor level,
BlockPos pos,
BlockPos neighbourPos) {
if (state.getValue(BlockStateProperties.WATERLOGGED)) {
level.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
}

return super.updateShape(state, dir, neighbourState, level, pos, neighbourPos);
}

@Override
public IOrientationStrategy getOrientationStrategy() {
return OrientationStrategies.horizontalFacing();
}

@Override
protected void spawnDestroyParticles(Level level, Player player, BlockPos pos, BlockState state) {
// Suppress break particles & sound when being disassembled by a wrench
if (!WrenchHook.isDisassembling()) {
super.spawnDestroyParticles(level, player, pos, state);
}
}
}
Loading

0 comments on commit a5022e6

Please sign in to comment.