Skip to content

Commit

Permalink
Implement a crystal resonance generator (passive power generation for…
Browse files Browse the repository at this point in the history
… AE)
  • Loading branch information
shartte committed Mar 7, 2024
1 parent 15f039e commit 92d82cb
Show file tree
Hide file tree
Showing 29 changed files with 898 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"variants": {
"facing=down": {
"model": "ae2:block/crystal_resonance_generator",
"x": 180
},
"facing=east": {
"model": "ae2:block/crystal_resonance_generator",
"x": 90,
"y": 90
},
"facing=north": {
"model": "ae2:block/crystal_resonance_generator",
"x": 90
},
"facing=south": {
"model": "ae2:block/crystal_resonance_generator",
"x": 90,
"y": 180
},
"facing=up": {
"model": "ae2:block/crystal_resonance_generator",
"x": 360
},
"facing=west": {
"model": "ae2:block/crystal_resonance_generator",
"x": 90,
"y": 270
}
}
}
2 changes: 2 additions & 0 deletions src/generated/resources/assets/ae2/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"block.ae2.crafting_unit": "Crafting Unit",
"block.ae2.crank": "Wooden Crank",
"block.ae2.creative_energy_cell": "Creative Energy Cell",
"block.ae2.crystal_resonance_generator": "Crystal Resonance Generator",
"block.ae2.cut_quartz_block": "Cut Certus Quartz Block",
"block.ae2.cut_quartz_slab": "Cut Certus Quartz Slab",
"block.ae2.cut_quartz_stairs": "Cut Certus Quartz Stairs",
Expand Down Expand Up @@ -1003,5 +1004,6 @@
"waila.ae2.P2PUnlinked": "Unlinked",
"waila.ae2.Showing": "Showing",
"waila.ae2.Stored": "Stored: %s / %s",
"waila.ae2.Suppressed": "Suppressed",
"waila.ae2.Unlocked": "Unlocked"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "ae2:block/crystal_resonance_generator"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_fluix_block": {
"conditions": {
"items": [
{
"items": [
"ae2:fluix_block"
]
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "ae2:network/crystal_resonance_generator"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_fluix_block"
]
],
"rewards": {
"recipes": [
"ae2:network/crystal_resonance_generator"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "ae2:crystal_resonance_generator"
}
],
"rolls": 1.0
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"key": {
"c": {
"tag": "forge:ingots/copper"
},
"f": {
"item": "ae2:fluix_block"
},
"i": {
"tag": "forge:ingots/iron"
},
"q": {
"item": "ae2:charged_certus_quartz_crystal"
}
},
"pattern": [
"cfc",
"cqc",
"iii"
],
"result": {
"item": "ae2:crystal_resonance_generator"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"ae2:io_port",
"ae2:condenser",
"ae2:energy_acceptor",
"ae2:crystal_resonance_generator",
"ae2:vibration_chamber",
"ae2:growth_accelerator",
"ae2:energy_cell",
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/appeng/api/ids/AEBlockIds.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public final class AEBlockIds {
public static final ResourceLocation IO_PORT = id("io_port");
public static final ResourceLocation CONDENSER = id("condenser");
public static final ResourceLocation ENERGY_ACCEPTOR = id("energy_acceptor");
public static final ResourceLocation CRYSTAL_RESONANCE_GENERATOR = id("crystal_resonance_generator");

public static final ResourceLocation VIBRATION_CHAMBER = id("vibration_chamber");
public static final ResourceLocation GROWTH_ACCELERATOR = id("growth_accelerator");
public static final ResourceLocation ENERGY_CELL = id("energy_cell");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 AlgorithmX2
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package appeng.api.networking.energy;

import appeng.api.networking.IGridNodeService;

/**
* Passively provide power to the system. This happens at a constant rate, and is usually restricted to one generator
* per energy grid (which reaches past the normal grid due to quartz fiber).
*/
public interface IPassiveEnergyGenerator extends IGridNodeService {

/**
* AE per tick that is generated by this passive generator.
*/
double getRate();

/**
* Set to true to indicate this generator is supressed by another on the same energy grid.
*/
void setSuppressed(boolean suppressed);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/

package appeng.block.networking;

import java.util.Locale;

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

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition.Builder;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.AABB;
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.IOrientationStrategy;
import appeng.api.orientation.OrientationStrategies;
import appeng.api.orientation.RelativeSide;
import appeng.block.AEBaseEntityBlock;
import appeng.blockentity.networking.CrystalResonanceGeneratorBlockEntity;

public class CrystalResonanceGeneratorBlock extends AEBaseEntityBlock<CrystalResonanceGeneratorBlockEntity>
implements SimpleWaterloggedBlock {

public enum State implements StringRepresentable {
OFF, ON, HAS_CHANNEL;

@Override
public String getSerializedName() {
return this.name().toLowerCase(Locale.ROOT);
}
}

private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;

public CrystalResonanceGeneratorBlock() {
super(glassProps().noOcclusion().forceSolidOn());
this.registerDefaultState(this.defaultBlockState().setValue(WATERLOGGED, false));
}

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

@Override
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return getVoxelShape(state);
}

@Override
public VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return getVoxelShape(state);
}

@NotNull
private VoxelShape getVoxelShape(BlockState state) {
var orientation = getOrientation(state);
var forward = orientation.getSide(RelativeSide.FRONT);

double minX = 0;
double minY = 0;
double minZ = 0;
double maxX = 1;
double maxY = 1;
double maxZ = 1;

switch (forward) {
case DOWN -> {
minZ = minX = 3.0 / 16.0;
maxZ = maxX = 13.0 / 16.0;
maxY = 1.0;
minY = 5.0 / 16.0;
}
case EAST -> {
minZ = minY = 3.0 / 16.0;
maxZ = maxY = 13.0 / 16.0;
maxX = 11.0 / 16.0;
minX = 0.0;
}
case NORTH -> {
minY = minX = 3.0 / 16.0;
maxY = maxX = 13.0 / 16.0;
maxZ = 1.0;
minZ = 5.0 / 16.0;
}
case SOUTH -> {
minY = minX = 3.0 / 16.0;
maxY = maxX = 13.0 / 16.0;
maxZ = 11.0 / 16.0;
minZ = 0.0;
}
case UP -> {
minZ = minX = 3.0 / 16.0;
maxZ = maxX = 13.0 / 16.0;
maxY = 11.0 / 16.0;
minY = 0.0;
}
case WEST -> {
minZ = minY = 3.0 / 16.0;
maxZ = maxY = 13.0 / 16.0;
maxX = 1.0;
minX = 5.0 / 16.0;
}
default -> {
}
}

return Shapes.create(new AABB(minX, minY, minZ, maxX, maxY, maxZ));
}

@Override
public boolean propagatesSkylightDown(BlockState state, BlockGetter reader, BlockPos pos) {
return true;
}

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

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

@Override
public FluidState getFluidState(BlockState blockState) {
return blockState.getValue(WATERLOGGED).booleanValue()
? Fluids.WATER.getSource(false)
: super.getFluidState(blockState);
}

@Override
public BlockState updateShape(BlockState blockState, Direction facing, BlockState facingState, LevelAccessor level,
BlockPos currentPos, BlockPos facingPos) {
if (blockState.getValue(WATERLOGGED).booleanValue()) {
level.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
}

return super.updateShape(blockState, facing, facingState, level, currentPos, facingPos);
}

}
Loading

0 comments on commit 92d82cb

Please sign in to comment.