Skip to content

Commit

Permalink
Merge pull request #32 from falkreon/1.19
Browse files Browse the repository at this point in the history
Lit, Hangable Lanterns
  • Loading branch information
maximumpower55 authored Apr 23, 2023
2 parents 6b81c2b + 31a22c5 commit 21ea65a
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
import io.github.debuggyteam.architecture_extensions.staticdata.BlockGroupSchema;
import io.github.debuggyteam.architecture_extensions.staticdata.StaticData;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Block;
import net.minecraft.item.ItemGroup;
import net.minecraft.registry.Registries;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;

Expand All @@ -27,7 +22,6 @@
import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.loader.api.entrypoint.EntrypointContainer;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings;
import org.quiltmc.qsl.resource.loader.api.InMemoryResourcePack;
import org.quiltmc.qsl.resource.loader.api.ResourceLoader;
import org.quiltmc.qsl.resource.loader.api.ResourcePackRegistrationContext;
Expand Down Expand Up @@ -70,7 +64,7 @@ public void onInitialize(ModContainer mod) {
.builder(id("building_blocks"))
.icon(() -> PeculiarBlocks.DEBUGGY_BLOCK.asItem().getDefaultStack()) // TODO: Better icon?
.build();

PeculiarBlocks.register();

VanillaIntegration.INSTANCE.integrate(new ArchExIntegrationContextImpl(VanillaIntegration.INSTANCE, mod.metadata().id()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum BlockType {
JOIST((baseBlock, settings) -> new JoistBlock(settings), 1.5f, noVariants(), SafeRenderLayer.SOLID),
CROWN_MOLDING((baseBlock, settings) -> new CrownMoldingBlock(baseBlock.getDefaultState(), settings), 1.5f, variantsOf("", "inner", "outer"), SafeRenderLayer.SOLID),
POST_CAP((baseBlock, settings) -> new PostCapBlock(settings), 1.5f, noVariants(), SafeRenderLayer.SOLID),
POST_LANTERN((baseBlock, settings) -> new PostLanternBlock(settings), 1.5f, noVariants(), SafeRenderLayer.SOLID),
POST_LANTERN((baseBlock, settings) -> new PostLanternBlock(settings), 1.5f, variantsOf("", "hanging"), SafeRenderLayer.SOLID),
ROD((baseBlock, settings) -> new ArchExRodBlock(settings), 1f, noVariants(), SafeRenderLayer.SOLID),
ROOF((baseBlock, settings) -> new RoofBlock(baseBlock.getDefaultState(), settings), 2.5f, variantsOf("", "inner", "outer"), SafeRenderLayer.SOLID),
WALL_POST((baseBlock, settings) -> new WallPostBlock(settings), 2.5f, noVariants(), SafeRenderLayer.SOLID),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.debuggyteam.architecture_extensions.blocks;

import io.github.debuggyteam.architecture_extensions.util.VoxelHelper;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
Expand All @@ -9,31 +10,56 @@
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.function.BooleanBiFunction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldAccess;

public class PostLanternBlock extends Block {
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;

protected static final VoxelShape POST_CAP_SHAPE = Block.createCuboidShape(5.0, 0.0, 5.0, 11.0, 6.0, 11.0);
public static final BooleanProperty HANGING = Properties.HANGING;

private static final VoxelShape LANTERN_BODY = Block.createCuboidShape(5, 0, 5, 11, 6, 11);
private static final VoxelShape LANTERN_CAP = Block.createCuboidShape(4, 5, 4, 12, 6, 12);
private static final VoxelShape LANTERN_FINIAL = Block.createCuboidShape(6, 6, 6, 10, 7, 10);

private static final VoxelShape POST_LANTERN_SHAPE = VoxelShapes.combine(
VoxelShapes.combine(LANTERN_BODY, LANTERN_CAP, BooleanBiFunction.OR),
LANTERN_FINIAL, BooleanBiFunction.OR);

private static final VoxelShape HANGING_LANTERN_BODY = Block.createCuboidShape(5, 9, 5, 11, 15, 11);
private static final VoxelShape HANGING_LANTERN_CAP = Block.createCuboidShape(4, 14, 4, 12, 15, 12);
private static final VoxelShape HANGING_LANTERN_FINIAL = Block.createCuboidShape(6, 15, 6, 10, 16, 10);

private static final VoxelShape HANGING_POST_LANTERN_SHAPE = VoxelShapes.combine(
VoxelShapes.combine(HANGING_LANTERN_BODY, HANGING_LANTERN_CAP, BooleanBiFunction.OR),
HANGING_LANTERN_FINIAL, BooleanBiFunction.OR);

public PostLanternBlock(Settings settings) {
super(settings);
super(settings.luminance(state -> 15));
this.setDefaultState(this.getDefaultState().with(WATERLOGGED, false)); // Thanks LambdAurora!
}

@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
return POST_CAP_SHAPE;
return state.get(HANGING) ? HANGING_POST_LANTERN_SHAPE : POST_LANTERN_SHAPE;
}

// Deals with waterlogging. Thanks acikek!

@Override
public BlockState getPlacementState(ItemPlacementContext context) {
return this.getDefaultState().with(WATERLOGGED, context.getWorld().getFluidState(context.getBlockPos()).getFluid() == Fluids.WATER);
BlockState placementState = this.getDefaultState();

if (context.getSide().equals(Direction.DOWN)) {
placementState = placementState.with(HANGING, canHang(context.getWorld(), context.getBlockPos()));
} else {
placementState = placementState.with(HANGING, false);
}

// Deals with waterlogging. Thanks acikek!
return placementState.with(WATERLOGGED, context.getWorld().getFluidState(context.getBlockPos()).getFluid() == Fluids.WATER);
}

@Override
Expand All @@ -44,12 +70,41 @@ public FluidState getFluidState(BlockState state) {
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (state.get(WATERLOGGED)) world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));


if (state.get(HANGING)) {
//Make sure we can still hang from the block above us, and if not, do not hang
if (!canHang(world, pos)) {
return state.with(HANGING, false);
}
} else {
/*
* This is more complicated because we kind of favor the non-hanging status. If we're not ahnging, but the
* block below us is completely air, and we discover that there's something to hang from, go ahead and hang.
*/
if (world.getBlockState(pos.down()).isAir()) {
if (canHang(world, pos)) {
return state.with(HANGING, true);
}
}
}

return state;
}

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

public static boolean canHang(BlockView world, BlockPos pos) {
BlockPos above = pos.up();
VoxelShape shape = world.getBlockState(above).getCollisionShape(world, above);

if (!VoxelHelper.testVoxel(shape, 7, 0, 7)) return false;
if (!VoxelHelper.testVoxel(shape, 7, 0, 8)) return false;
if (!VoxelHelper.testVoxel(shape, 8, 0, 7)) return false;
if (!VoxelHelper.testVoxel(shape, 8, 0, 8)) return false;

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.debuggyteam.architecture_extensions.util;

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

import net.minecraft.util.shape.VoxelShape;

public class VoxelHelper {
public static boolean testVoxel(VoxelShape shape, int x, int y, int z) {

List<Boolean> hits = new ArrayList<>();
shape.forEachBox((x1, y1, z1, x2, y2, z2) -> {
int x1i = (int) (x1 * 16);
int y1i = (int) (y1 * 16);
int z1i = (int) (z1 * 16);
int x2i = (int) (x2 * 16);
int y2i = (int) (y2 * 16);
int z2i = (int) (z2 * 16);

if (x >= x1i && y >= y1i && z >= z1i && x < x2i && y < y2i && z < z2i) {
hits.add(Boolean.valueOf(true));
}
});

return !hits.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"variants": {
"": {
"model": "{model}"
}
"hanging=false,waterlogged=false": {
"model": "{model}"
},
"hanging=false,waterlogged=true": {
"model": "{model}"
},
"hanging=true,waterlogged=false": {
"model": "{model}_hanging"
},
"hanging=true,waterlogged=true": {
"model": "{model}_hanging"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"credit": "Made with Blockbench by Cart3r.",
"credit": "Made with Blockbench by Cart3r, edited by Falkreon.",
"textures": {
"lantern_texture": "minecraft:block/lantern",
"lantern_texture": "block/lantern",
"particle": "#texture"
},
"elements": [
Expand Down Expand Up @@ -66,8 +66,6 @@
"rotation": {"angle": 0, "axis": "y", "origin": [8, 17, 8]},
"faces": {
"north": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"east": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"south": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"west": {"uv": [1, 1, 2, 5], "texture": "#texture"}
}
},
Expand All @@ -76,8 +74,6 @@
"to": [6, 5, 11],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 17, 8]},
"faces": {
"north": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"east": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"south": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"west": {"uv": [1, 1, 2, 5], "texture": "#texture"}
}
Expand All @@ -87,10 +83,8 @@
"to": [11, 5, 11],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 17, 8]},
"faces": {
"north": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"east": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"south": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"west": {"uv": [1, 1, 2, 5], "texture": "#texture"}
"south": {"uv": [1, 1, 2, 5], "texture": "#texture"}
}
},
{
Expand All @@ -99,9 +93,7 @@
"rotation": {"angle": 0, "axis": "y", "origin": [8, 17, 8]},
"faces": {
"north": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"east": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"south": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"west": {"uv": [1, 1, 2, 5], "texture": "#texture"}
"east": {"uv": [1, 1, 2, 5], "texture": "#texture"}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"credit": "Made with Blockbench by Cart3r, edited by Falkreon.",
"textures": {
"lantern_texture": "block/lantern",
"particle": "#texture"
},
"elements": [
{
"from": [5, 9, 5],
"to": [11, 10, 11],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 17, 8]},
"faces": {
"north": {"uv": [5, 14, 11, 15], "texture": "#texture"},
"east": {"uv": [5, 14, 11, 15], "texture": "#texture"},
"south": {"uv": [5, 14, 11, 15], "texture": "#texture"},
"west": {"uv": [5, 14, 11, 15], "texture": "#texture"},
"down": {"uv": [0, 10, 6, 16], "texture": "#texture"}
}
},
{
"from": [4, 14, 4],
"to": [12, 15, 12],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 17, 8]},
"faces": {
"north": {"uv": [4, 10, 12, 11], "texture": "#texture"},
"east": {"uv": [4, 10, 12, 11], "texture": "#texture"},
"south": {"uv": [4, 10, 12, 11], "texture": "#texture"},
"west": {"uv": [4, 10, 12, 11], "texture": "#texture"},
"up": {"uv": [4, 4, 12, 12], "rotation": 90, "texture": "#texture"},
"down": {"uv": [4, 4, 12, 12], "rotation": 270, "texture": "#texture"}
}
},
{
"from": [6, 15, 6],
"to": [10, 16, 10],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 17, 8]},
"faces": {
"north": {"uv": [6, 9, 10, 10], "texture": "#texture"},
"east": {"uv": [6, 9, 10, 10], "texture": "#texture"},
"south": {"uv": [6, 9, 10, 10], "texture": "#texture"},
"west": {"uv": [6, 9, 10, 10], "texture": "#texture"},
"up": {"uv": [6, 6, 10, 10], "rotation": 90, "texture": "#texture"}
}
},
{
"from": [5, 10, 6],
"to": [11, 14, 10],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 17, 8]},
"faces": {
"east": {"uv": [1, 4, 5, 8], "texture": "#lantern_texture"},
"west": {"uv": [1, 4, 5, 8], "texture": "#lantern_texture"}
}
},
{
"from": [6, 10, 5],
"to": [10, 14, 11],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 17, 8]},
"faces": {
"north": {"uv": [1, 4, 5, 8], "texture": "#lantern_texture"},
"south": {"uv": [1, 4, 5, 8], "texture": "#lantern_texture"}
}
},
{
"from": [5, 10, 5],
"to": [6, 14, 6],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 17, 8]},
"faces": {
"north": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"west": {"uv": [1, 1, 2, 5], "texture": "#texture"}
}
},
{
"from": [5, 10, 10],
"to": [6, 14, 11],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 17, 8]},
"faces": {
"south": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"west": {"uv": [1, 1, 2, 5], "texture": "#texture"}
}
},
{
"from": [10, 10, 10],
"to": [11, 14, 11],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 17, 8]},
"faces": {
"east": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"south": {"uv": [1, 1, 2, 5], "texture": "#texture"}
}
},
{
"from": [10, 10, 5],
"to": [11, 14, 6],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 17, 8]},
"faces": {
"north": {"uv": [1, 1, 2, 5], "texture": "#texture"},
"east": {"uv": [1, 1, 2, 5], "texture": "#texture"}
}
}
],
"display": {
"thirdperson_righthand": {
"rotation": [75, 45, 0],
"translation": [0, 2.5, 1.25],
"scale": [0.375, 0.375, 0.375]
},
"thirdperson_lefthand": {
"rotation": [75, 45, 0],
"translation": [0, 2.5, 0],
"scale": [0.375, 0.375, 0.375]
},
"firstperson_righthand": {
"rotation": [0, 45, 0],
"translation": [1.5, 4.25, 0],
"scale": [0.4, 0.4, 0.4]
},
"firstperson_lefthand": {
"rotation": [0, 45, 0],
"translation": [1.5, 4.25, 0],
"scale": [0.4, 0.4, 0.4]
},
"ground": {
"translation": [0, 3, 0],
"scale": [0.38672, 0.38672, 0.38672]
},
"gui": {
"rotation": [30, 225, 0],
"translation": [0, 2.25, 0],
"scale": [0.79102, 0.79102, 0.79102]
},
"head": {
"translation": [0, 14.25, 0],
"scale": [2.60547, 2.60547, 2.60547]
},
"fixed": {
"translation": [0, 2.5, 0],
"scale": [0.5, 0.5, 0.5]
}
}
}

0 comments on commit 21ea65a

Please sign in to comment.