split conjured lights and conjured blocks

also, properly waterlog conjured lights
This commit is contained in:
yrsegal@gmail.com 2022-04-09 15:16:48 -04:00
parent 5d4c09186d
commit 1e55a57884
10 changed files with 146 additions and 85 deletions

View file

@ -467,7 +467,7 @@ f3c6b6917e504e1c3d5d8875f7cce6f311e791d2 data/hexcasting/tags/blocks/akashic_log
b596d96eebb4f7bad5930f4eebc589f292b59c98 data/hexcasting/tags/blocks/akashic_planks.json
74700d556ca80c7a1db5fd4efb09c3ddb26cad66 data/hexcasting/tags/items/akashic_logs.json
74700d556ca80c7a1db5fd4efb09c3ddb26cad66 data/hexcasting/tags/items/akashic_planks.json
f930dbc5b41d42150d388e39b29b940229658809 data/minecraft/tags/blocks/crystal_sound_blocks.json
1dc89dff5d4fadb95d9b5a2a5a910f63ea4b02bf data/minecraft/tags/blocks/crystal_sound_blocks.json
556d2e6068965e90c307a435b372ae761cd1c606 data/minecraft/tags/blocks/doors.json
c25784941d6416744fb2ca2d43a3203e5c3e7c8a data/minecraft/tags/blocks/leaves.json
f3c6b6917e504e1c3d5d8875f7cce6f311e791d2 data/minecraft/tags/blocks/logs.json

View file

@ -2,6 +2,7 @@
"replace": false,
"values": [
"hexcasting:conjured",
"hexcasting:conjured_block",
"hexcasting:amethyst_tiles",
"hexcasting:amethyst_sconce"
]

View file

@ -124,7 +124,8 @@ public class RegisterClientStuff {
});
for (var cutout : new Block[]{
HexBlocks.CONJURED.get(),
HexBlocks.CONJURED_LIGHT.get(),
HexBlocks.CONJURED_BLOCK.get(),
HexBlocks.AKASHIC_DOOR.get(),
HexBlocks.AKASHIC_TRAPDOOR.get(),
HexBlocks.SCONCE.get(),

View file

@ -2,13 +2,10 @@ package at.petrak.hexcasting.common.blocks;
import at.petrak.hexcasting.common.casting.colors.FrozenColorizer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
@ -16,37 +13,27 @@ 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.RenderShape;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
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.BooleanProperty;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class BlockConjured extends Block implements SimpleWaterloggedBlock, EntityBlock {
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final BooleanProperty LIGHT = BooleanProperty.create("light");
private static final VoxelShape LIGHT_SHAPE = Block.box(5.0D, 5.0D, 5.0D, 11.0D, 11.0D, 11.0D);
public class BlockConjured extends Block implements EntityBlock {
public BlockConjured(BlockBehaviour.Properties properties) {
public BlockConjured(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(LIGHT, false).setValue(WATERLOGGED, false));
}
@Override
public void playerWillDestroy(Level pLevel, BlockPos pPos, BlockState pState, Player pPlayer) {
super.playerWillDestroy(pLevel, pPos, pState, pPlayer);
// For some reason the block doesn't play breaking noises. So we fix that!
pPlayer.playSound(SoundEvents.GLASS_BREAK, 1f, 1f);
pPlayer.playSound(SoundEvents.AMETHYST_BLOCK_BREAK, 1f, 1f);
}
@Nullable
@ -69,16 +56,9 @@ public class BlockConjured extends Block implements SimpleWaterloggedBlock, Enti
@Override
public void stepOn(Level pLevel, @NotNull BlockPos pPos, @NotNull BlockState pState, @NotNull Entity pEntity) {
BlockEntity tile = pLevel.getBlockEntity(pPos);
if (tile instanceof BlockEntityConjured bec && !bec.getBlockState().getValue(LIGHT)) {
if (tile instanceof BlockEntityConjured bec) {
bec.walkParticle(pEntity);
}
super.stepOn(pLevel, pPos, pState, pEntity);
}
@Override
protected void createBlockStateDefinition(StateDefinition.@NotNull Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(LIGHT, WATERLOGGED);
}
@Nullable
@ -101,17 +81,6 @@ public class BlockConjured extends Block implements SimpleWaterloggedBlock, Enti
super.onPlace(pState, pLevel, pPos, pOldState, pIsMoving);
}
@Override
public @NotNull VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos,
@NotNull CollisionContext context) {
return state.getValue(LIGHT) ? LIGHT_SHAPE : super.getShape(state, level, pos, context);
}
@Override
public @NotNull PushReaction getPistonPushReaction(@NotNull BlockState state) {
return state.getValue(LIGHT) ? PushReaction.DESTROY : super.getPistonPushReaction(state);
}
@Override
public boolean propagatesSkylightDown(@NotNull BlockState pState, @NotNull BlockGetter pLevel,
@NotNull BlockPos pPos) {
@ -119,25 +88,7 @@ public class BlockConjured extends Block implements SimpleWaterloggedBlock, Enti
}
@Override
public int getLightEmission(BlockState state, BlockGetter world, BlockPos pos) {
return state.getValue(LIGHT) ? 15 : 2;
}
@Override
public boolean canConnectRedstone(BlockState state, BlockGetter world, BlockPos pos,
@Nullable Direction direction) {
return false;
}
@Override
public boolean isValidSpawn(BlockState state, BlockGetter world, BlockPos pos, SpawnPlacements.Type type,
EntityType<?> entityType) {
return false;
}
@Override
public @NotNull VoxelShape getVisualShape(@NotNull BlockState pState, @NotNull BlockGetter pLevel,
@NotNull BlockPos pPos, @NotNull CollisionContext pContext) {
public @NotNull VoxelShape getVisualShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
return Shapes.empty();
}
@ -151,14 +102,9 @@ public class BlockConjured extends Block implements SimpleWaterloggedBlock, Enti
return RenderShape.INVISIBLE;
}
@Override
public @NotNull VoxelShape getCollisionShape(@NotNull BlockState state, @NotNull BlockGetter pLevel,
@NotNull BlockPos pPos, @NotNull CollisionContext pContext) {
return state.getValue(LIGHT) ? Shapes.empty() : super.getCollisionShape(state, pLevel, pPos, pContext);
}
@Override
protected void spawnDestroyParticles(Level pLevel, Player pPlayer, BlockPos pPos, BlockState pState) {
// NO-OP
}
@Override

View file

@ -0,0 +1,87 @@
package at.petrak.hexcasting.common.blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.entity.LivingEntity;
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.BlockBehaviour;
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.BooleanProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nonnull;
public class BlockConjuredLight extends BlockConjured implements SimpleWaterloggedBlock {
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
private static final VoxelShape SHAPE = Block.box(5.0D, 5.0D, 5.0D, 11.0D, 11.0D, 11.0D);
public BlockConjuredLight(BlockBehaviour.Properties properties) {
super(properties);
this.registerDefaultState(defaultBlockState().setValue(WATERLOGGED, false));
}
@Override
protected void createBlockStateDefinition(StateDefinition.@NotNull Builder<Block, BlockState> builder) {
builder.add(WATERLOGGED);
}
@Override
public boolean propagatesSkylightDown(BlockState state, @Nonnull BlockGetter reader, @Nonnull BlockPos pos) {
return !state.getValue(WATERLOGGED);
}
@Nonnull
@Override
public FluidState getFluidState(BlockState state) {
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
}
@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
FluidState fluidState = pContext.getLevel().getFluidState(pContext.getClickedPos());
return defaultBlockState().setValue(WATERLOGGED, fluidState.is(FluidTags.WATER) && fluidState.getAmount() == 8);
}
@Nonnull
@Override
public BlockState updateShape(BlockState state, @Nonnull Direction facing, @Nonnull BlockState facingState, @Nonnull LevelAccessor level, @Nonnull BlockPos pos, @Nonnull BlockPos facingPos) {
if (state.getValue(WATERLOGGED)) {
level.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
}
return super.updateShape(state, facing, facingState, level, pos, facingPos);
}
@Override
public @NotNull VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos,
@NotNull CollisionContext context) {
return SHAPE;
}
@Override
public @NotNull PushReaction getPistonPushReaction(@NotNull BlockState state) {
return PushReaction.DESTROY;
}
@Override
public boolean addLandingEffects(BlockState state1, ServerLevel worldserver, BlockPos pos, BlockState state2,
LivingEntity entity, int numberOfParticles) {
return true;
}
}

View file

@ -22,7 +22,7 @@ public class BlockEntityConjured extends PaucalBlockEntity {
}
public void walkParticle(Entity pEntity) {
if (getBlockState().getBlock() instanceof BlockConjured) {
if (getBlockState().getBlock() instanceof BlockConjuredLight) {
for (int i = 0; i < 3; ++i) {
int color = this.colorizer.getColor(pEntity.tickCount, pEntity.position()
.add(new Vec3(RANDOM.nextFloat(), RANDOM.nextFloat(), RANDOM.nextFloat()).scale(
@ -40,12 +40,12 @@ public class BlockEntityConjured extends PaucalBlockEntity {
}
public void particleEffect() {
if (getBlockState().getBlock() instanceof BlockConjured) {
if (getBlockState().getBlock() instanceof BlockConjuredLight) {
int color = this.colorizer.getColor(RANDOM.nextFloat() * 16384,
new Vec3(RANDOM.nextFloat(), RANDOM.nextFloat(), RANDOM.nextFloat()).scale(
RANDOM.nextFloat() * 3));
assert level != null;
if (getBlockState().getValue(BlockConjured.LIGHT)) {
if (getBlockState().getBlock() == HexBlocks.CONJURED_LIGHT.get()) {
if (RANDOM.nextFloat() < 0.5) {
level.addParticle(new ConjureParticleOptions(color, true),
(double) getBlockPos().getX() + 0.45D + (RANDOM.nextFloat() * 0.1D),
@ -70,7 +70,7 @@ public class BlockEntityConjured extends PaucalBlockEntity {
}
public void landParticle(Entity entity, int number) {
if (getBlockState().getBlock() instanceof BlockConjured) {
if (getBlockState().getBlock() instanceof BlockConjuredLight) {
for (int i = 0; i < number * 2; i++) {
int color = this.colorizer.getColor(entity.tickCount, entity.position()
.add(new Vec3(RANDOM.nextFloat(), RANDOM.nextFloat(), RANDOM.nextFloat()).scale(

View file

@ -18,7 +18,7 @@ public class HexBlockEntities {
public static final RegistryObject<BlockEntityType<BlockEntityConjured>> CONJURED_TILE = BLOCK_ENTITIES.register(
"conjured_tile",
() -> BlockEntityType.Builder.of(BlockEntityConjured::new, HexBlocks.CONJURED.get()).build(null));
() -> BlockEntityType.Builder.of(BlockEntityConjured::new, HexBlocks.CONJURED_LIGHT.get(), HexBlocks.CONJURED_BLOCK.get()).build(null));
public static final RegistryObject<BlockEntityType<BlockEntityAkashicBookshelf>> AKASHIC_BOOKSHELF_TILE = BLOCK_ENTITIES.register(
"akashic_bookshelf_tile",

View file

@ -32,16 +32,29 @@ import java.util.function.Supplier;
public class HexBlocks {
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, HexMod.MOD_ID);
public static final RegistryObject<Block> CONJURED = blockItem("conjured",
public static final RegistryObject<Block> CONJURED_LIGHT = blockNoItem("conjured",
() -> new BlockConjuredLight(
BlockBehaviour.Properties.of(Material.AMETHYST, MaterialColor.DIAMOND)
.sound(SoundType.AMETHYST)
.lightLevel((state) -> 15)
.noDrops()
.isValidSpawn((state, world, pos, entityType) -> false)
.instabreak()
.noCollission()
.isSuffocating(HexBlocks::never)
.isViewBlocking(HexBlocks::never)));
public static final RegistryObject<Block> CONJURED_BLOCK = blockNoItem("conjured_block",
() -> new BlockConjured(
BlockBehaviour.Properties.of(Material.AMETHYST, MaterialColor.DIAMOND)
.sound(SoundType.AMETHYST)
.lightLevel((state) -> 15)
.noDrops()
.isValidSpawn((state, world, pos, entityType) -> false)
.instabreak()
.noOcclusion()
.isSuffocating(HexBlocks::never)
.isViewBlocking(HexBlocks::never)),
new Item.Properties());
.isViewBlocking(HexBlocks::never)));
private static BlockBehaviour.Properties slateish() {
return BlockBehaviour.Properties
@ -163,6 +176,10 @@ public class HexBlocks {
return false;
}
private static <T extends Block> RegistryObject<T> blockNoItem(String name, Supplier<T> block) {
return BLOCKS.register(name, block);
}
private static <T extends Block> RegistryObject<T> blockItem(String name, Supplier<T> block) {
return blockItem(name, block, HexItems.props());
}
@ -173,5 +190,6 @@ public class HexBlocks {
HexItems.ITEMS.register(name, () -> new BlockItem(out.get(), props));
return out;
}
}

View file

@ -6,10 +6,14 @@ import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellOperator
import at.petrak.hexcasting.common.blocks.BlockConjured
import at.petrak.hexcasting.common.blocks.BlockConjuredLight
import at.petrak.hexcasting.common.blocks.HexBlocks
import at.petrak.hexcasting.common.casting.CastingContext
import at.petrak.hexcasting.common.lib.HexCapabilities
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.context.DirectionalPlaceContext
import net.minecraft.world.phys.Vec3
class OpConjure(val light: Boolean) : SpellOperator {
@ -30,22 +34,26 @@ class OpConjure(val light: Boolean) : SpellOperator {
private data class Spell(val target: Vec3, val light: Boolean) : RenderedSpell {
override fun cast(ctx: CastingContext) {
if (ctx.world.getBlockState(BlockPos(target)).isAir) {
var state = HexBlocks.CONJURED.get().defaultBlockState()
if (this.light) {
state = state.setValue(BlockConjured.LIGHT, true)
}
ctx.world.setBlock(BlockPos(target), state, 2)
val pos = BlockPos(target)
val placeContext = DirectionalPlaceContext(ctx.world, pos, Direction.DOWN, ItemStack.EMPTY, Direction.UP)
val maybeCap = ctx.caster.getCapability(HexCapabilities.PREFERRED_COLORIZER).resolve()
if (!maybeCap.isPresent)
return
val cap = maybeCap.get()
val worldState = ctx.world.getBlockState(pos)
if (worldState.canBeReplaced(placeContext)) {
val block = if (this.light) HexBlocks.CONJURED_LIGHT else HexBlocks.CONJURED_BLOCK
val state = block.get().getStateForPlacement(placeContext)
if (state != null) {
ctx.world.setBlock(pos, state, 2)
if (ctx.world.getBlockState(BlockPos(target)).block is BlockConjured) {
BlockConjured.setColor(ctx.world, BlockPos(target), cap.colorizer)
val maybeCap = ctx.caster.getCapability(HexCapabilities.PREFERRED_COLORIZER).resolve()
if (!maybeCap.isPresent)
return
val cap = maybeCap.get()
if (ctx.world.getBlockState(pos).block is BlockConjuredLight) {
BlockConjured.setColor(ctx.world, pos, cap.colorizer)
}
}
}
}
}
}
}

View file

@ -38,7 +38,7 @@ public class HexBlockTagProvider extends BlockTagsProvider {
.add(HexBlocks.AKASHIC_LEAVES1.get(), HexBlocks.AKASHIC_LEAVES2.get(), HexBlocks.AKASHIC_LEAVES3.get());
tag(BlockTags.CRYSTAL_SOUND_BLOCKS)
.add(HexBlocks.CONJURED.get(), HexBlocks.AMETHYST_TILES.get(), HexBlocks.SCONCE.get());
.add(HexBlocks.CONJURED_LIGHT.get(), HexBlocks.CONJURED_BLOCK.get(), HexBlocks.AMETHYST_TILES.get(), HexBlocks.SCONCE.get());
tag(HexBlockTags.AKASHIC_LOGS)
.add(HexBlocks.AKASHIC_LOG.get(), HexBlocks.AKASHIC_LOG_STRIPPED.get(),