Skip to content

Commit

Permalink
Minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Jul 4, 2024
1 parent c291dd4 commit 6b294e7
Show file tree
Hide file tree
Showing 27 changed files with 340 additions and 5 deletions.
Binary file added amethyst.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions src/main/java/miyucomics/hexical/blocks/HexCandleBlock.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package miyucomics.hexical.blocks

import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.common.particles.ConjureParticleOptions
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.block.*
import net.minecraft.block.entity.BlockEntity
import net.minecraft.block.entity.BlockEntityTicker
import net.minecraft.block.entity.BlockEntityType
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.sound.BlockSoundGroup
import net.minecraft.sound.SoundCategory
import net.minecraft.sound.SoundEvents
import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import net.minecraft.util.hit.BlockHitResult
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Vec3d
import net.minecraft.util.math.random.Random
import net.minecraft.world.World
import net.minecraft.world.event.GameEvent

class HexCandleBlock : CandleBlock(Settings.of(Material.DECORATION).nonOpaque().strength(0.1f).sounds(BlockSoundGroup.CANDLE).luminance(STATE_TO_LUMINANCE)), BlockEntityProvider {
override fun onUse(state: BlockState, world: World, pos: BlockPos, player: PlayerEntity, hand: Hand, hit: BlockHitResult?): ActionResult {
if (player.isSneaking)
return super.onUse(state, world, pos, player, hand, hit)
if (!state.get(AbstractCandleBlock.LIT))
return super.onUse(state, world, pos, player, hand, hit)
val stack = player.getStackInHand(hand)
val be = world.getBlockEntity(pos)!! as HexCandleBlockEntity
var givenColor = IXplatAbstractions.INSTANCE.getColorizer(player)
if (IXplatAbstractions.INSTANCE.isColorizer(stack))
givenColor = FrozenColorizer(stack.copy(), player.uuid)
be.setPigment(givenColor)
world.emitGameEvent(player, GameEvent.BLOCK_CHANGE, pos)
return ActionResult.SUCCESS
}

override fun randomDisplayTick(state: BlockState, world: World, pos: BlockPos, random: Random) {
if (!state.get(AbstractCandleBlock.LIT))
return
getParticleOffsets(state).forEach { offset: Vec3d ->
val position = offset.add(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble())
if (random.nextFloat() < 0.25f)
world.playSound(position.x + 0.5, position.y + 0.5, position.z + 0.5, SoundEvents.BLOCK_CANDLE_AMBIENT, SoundCategory.BLOCKS, 1.0f + random.nextFloat(), random.nextFloat() * 0.7f + 0.3f, false)
}
}

fun getPositions(state: BlockState): Iterable<Vec3d> {
return getParticleOffsets(state)
}

override fun createBlockEntity(pos: BlockPos?, state: BlockState?): BlockEntity = HexCandleBlockEntity(pos, state)
override fun <T : BlockEntity> getTicker(world: World, state: BlockState, type: BlockEntityType<T>): BlockEntityTicker<T> = BlockEntityTicker { world1, pos, state1, blockEntity -> tick(world1, pos, state1, blockEntity as HexCandleBlockEntity) }

companion object {
fun tick(world: World, pos: BlockPos, state: BlockState, blockEntity: HexCandleBlockEntity) {
if (!world.isClient)
return
if (!state.get(AbstractCandleBlock.LIT))
return
val pigment = blockEntity.getPigment()
(state.block as HexCandleBlock).getPositions(state).forEach { offset: Vec3d ->
if (world.random.nextFloat() > 0.5)
return@forEach
val position = offset.add(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble())
world.addParticle(
ConjureParticleOptions(pigment.getColor(world.time.toFloat(), position), true),
position.x, position.y, position.z,
0.0, world.random.nextFloat() * 0.02, 0.0
)
}
}
}
}
30 changes: 30 additions & 0 deletions src/main/java/miyucomics/hexical/blocks/HexCandleBlockEntity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package miyucomics.hexical.blocks

import at.petrak.hexcasting.api.misc.FrozenColorizer
import miyucomics.hexical.registry.HexicalBlocks
import net.minecraft.block.BlockState
import net.minecraft.block.entity.BlockEntity
import net.minecraft.nbt.NbtCompound
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket
import net.minecraft.util.math.BlockPos

class HexCandleBlockEntity(pos: BlockPos?, state: BlockState?) : BlockEntity(HexicalBlocks.HEX_CANDLE_BLOCK_ENTITY, pos, state) {
private var pigment: FrozenColorizer = FrozenColorizer.DEFAULT.get()

fun getPigment() = this.pigment
fun setPigment(pigment: FrozenColorizer) {
this.pigment = pigment
markDirty()
}

override fun writeNbt(nbt: NbtCompound) {
nbt.put("pigment", pigment.serializeToNBT())
}

override fun readNbt(nbt: NbtCompound) {
pigment = FrozenColorizer.fromNBT(nbt.getCompound("pigment"))
}

override fun toUpdatePacket(): BlockEntityUpdateS2CPacket = BlockEntityUpdateS2CPacket.create(this)
override fun toInitialChunkDataNbt(): NbtCompound = createNbt()
}
4 changes: 2 additions & 2 deletions src/main/java/miyucomics/hexical/blocks/MageBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ class MageBlock : BlockConjured(

override fun spawnBreakParticles(pLevel: World?, pPlayer: PlayerEntity?, pPos: BlockPos?, pState: BlockState?) {}
override fun createBlockEntity(pos: BlockPos, state: BlockState) = MageBlockEntity(pos, state)
override fun <T : BlockEntity?> getTicker(pworld: World, pstate: BlockState, type: BlockEntityType<T>) = BlockEntityTicker { world, position, state, blockEntity: T -> tick(world, position, state, blockEntity) }
override fun <T : BlockEntity> getTicker(pworld: World, pstate: BlockState, type: BlockEntityType<T>): BlockEntityTicker<T> = BlockEntityTicker { world, position, state, blockEntity -> tick(world, position, state, blockEntity) }

companion object {
fun <T> tick(world: World, position: BlockPos, state: BlockState, blockEntity: T) {
fun tick(world: World, position: BlockPos, state: BlockState, blockEntity: BlockEntity) {
if (blockEntity !is MageBlockEntity)
return
if (!blockEntity.properties["invisible"]!!)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package miyucomics.hexical.mixin;

import at.petrak.hexcasting.api.spell.casting.CastingHarness;
import at.petrak.hexcasting.api.spell.iota.Iota;
import at.petrak.hexcasting.common.blocks.akashic.BlockAkashicBookshelf;
import at.petrak.hexcasting.common.blocks.akashic.BlockEntityAkashicBookshelf;
import at.petrak.hexcasting.common.lib.HexSounds;
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(BlockAkashicBookshelf.class)
public class BlockAkashicBookshelfMixin {
@Inject(method = "onUse", at = @At(value = "TAIL"))
private void copyIota(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable<ActionResult> cir) {
if (world.isClient)
return;
if (player.isSneaking() || hand == Hand.OFF_HAND)
return;
BlockEntity shelf = world.getBlockEntity(pos);
if (shelf instanceof BlockEntityAkashicBookshelf) {
NbtCompound nbt = ((BlockEntityAkashicBookshelf) shelf).getIotaTag();
if (nbt == null)
return;
CastingHarness harness = IXplatAbstractions.INSTANCE.getHarness((ServerPlayerEntity) player, hand);
harness.getStack().add(HexIotaTypes.deserialize(nbt, (ServerWorld) world));
IXplatAbstractions.INSTANCE.setHarness((ServerPlayerEntity) player, harness);
world.playSound(null, pos, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.BLOCKS, 1f, 1f);
player.swingHand(hand, true);
}
}
}
6 changes: 6 additions & 0 deletions src/main/java/miyucomics/hexical/registry/HexicalBlocks.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package miyucomics.hexical.registry

import miyucomics.hexical.HexicalMain
import miyucomics.hexical.blocks.HexCandleBlock
import miyucomics.hexical.blocks.HexCandleBlockEntity
import miyucomics.hexical.blocks.MageBlock
import miyucomics.hexical.blocks.MageBlockEntity
import net.minecraft.block.entity.BlockEntityType
import net.minecraft.util.registry.Registry

object HexicalBlocks {
val HEX_CANDLE_BLOCK: HexCandleBlock = HexCandleBlock()
val HEX_CANDLE_BLOCK_ENTITY: BlockEntityType<HexCandleBlockEntity> = BlockEntityType.Builder.create(::HexCandleBlockEntity, HEX_CANDLE_BLOCK).build(null)
val MAGE_BLOCK: MageBlock = MageBlock()
val MAGE_BLOCK_ENTITY: BlockEntityType<MageBlockEntity> = BlockEntityType.Builder.create(::MageBlockEntity, MAGE_BLOCK).build(null)

@JvmStatic
fun init() {
Registry.register(Registry.BLOCK, HexicalMain.id("hex_candle"), HEX_CANDLE_BLOCK)
Registry.register(Registry.BLOCK_ENTITY_TYPE, HexicalMain.id("hex_candle"), HEX_CANDLE_BLOCK_ENTITY)
Registry.register(Registry.BLOCK, HexicalMain.id("mage_block"), MAGE_BLOCK)
Registry.register(Registry.BLOCK_ENTITY_TYPE, HexicalMain.id("mage_block"), MAGE_BLOCK_ENTITY)
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/miyucomics/hexical/registry/HexicalItems.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ object HexicalItems {
Registry.register(Registry.ITEM, HexicalMain.id("hextito"), HEXTITO_ITEM)
Registry.register(Registry.ITEM, HexicalMain.id("null_media"), NULL_MEDIA_ITEM)
Registry.register(Registry.ITEM, HexicalMain.id("mage_block"), BlockItem(HexicalBlocks.MAGE_BLOCK, Settings()))
Registry.register(Registry.ITEM, HexicalMain.id("hex_candle"), BlockItem(HexicalBlocks.HEX_CANDLE_BLOCK, Settings().group(HEXICAL_GROUP)))
}

@JvmStatic
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/miyucomics/hexical/registry/HexicalPatterns.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ object HexicalPatterns {
register("soroban_increment", "wdeaqq", HexDir.NORTH_EAST, OpSorobanIncrement())
register("soroban_reset", "qdeeaae", HexDir.NORTH_EAST, OpSorobanReset())

register("prestidigitation", "wedewedew", HexDir.NORTH_EAST, OpPrestidigitation())
register("can_prestidigitate", "wqaqwqaqw", HexDir.NORTH_WEST, OpCanPrestidigitation())
register("prestidigitation", "wqaqwqaqw", HexDir.NORTH_WEST, OpPrestidigitation())
register("can_prestidigitate", "wedewedew", HexDir.NORTH_EAST, OpCanPrestidigitation())

register("magic_missile", "qaqww", HexDir.WEST, OpMagicMissile())

Expand Down
28 changes: 28 additions & 0 deletions src/main/resources/assets/hexical/blockstates/hex_candle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"variants": {
"candles=1,lit=false": {
"model": "hexical:block/hex_candle_one_candle"
},
"candles=1,lit=true": {
"model": "hexical:block/hex_candle_one_candle_lit"
},
"candles=2,lit=false": {
"model": "hexical:block/hex_candle_two_candles"
},
"candles=2,lit=true": {
"model": "hexical:block/hex_candle_two_candles_lit"
},
"candles=3,lit=false": {
"model": "hexical:block/hex_candle_three_candles"
},
"candles=3,lit=true": {
"model": "hexical:block/hex_candle_three_candles_lit"
},
"candles=4,lit=false": {
"model": "hexical:block/hex_candle_four_candles"
},
"candles=4,lit=true": {
"model": "hexical:block/hex_candle_four_candles_lit"
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/hexical/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"advancements.hexical.reload_lamp.title": "In with the New!",
"advancements.hexical.reload_lamp.description": "Reload the lamp.",

"block.hexical.hex_candle": "Hex Candle",
"block.hexical.mage_block": "Mage Block",
"entity.hexical.living_scroll": "Living Scroll",
"entity.hexical.magic_missile": "Magic Missile",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/template_four_candles",
"textures": {
"all": "hexical:block/hex_candle",
"particle": "hexical:block/hex_candle"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/template_four_candles",
"textures": {
"all": "hexical:block/hex_candle_lit",
"particle": "hexical:block/hex_candle_lit"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/template_candle",
"textures": {
"all": "hexical:block/hex_candle",
"particle": "hexical:block/hex_candle"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/template_candle",
"textures": {
"all": "hexical:block/hex_candle_lit",
"particle": "hexical:block/hex_candle_lit"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/template_three_candles",
"textures": {
"all": "hexical:block/hex_candle",
"particle": "hexical:block/hex_candle"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/template_three_candles",
"textures": {
"all": "hexical:block/hex_candle_lit",
"particle": "hexical:block/hex_candle_lit"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/template_two_candles",
"textures": {
"all": "hexical:block/hex_candle",
"particle": "hexical:block/hex_candle"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/template_two_candles",
"textures": {
"all": "hexical:block/hex_candle_lit",
"particle": "hexical:block/hex_candle_lit"
}
}
6 changes: 6 additions & 0 deletions src/main/resources/assets/hexical/models/item/hex_candle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "hexical:item/hex_candle"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions src/main/resources/data/hexical/loot_tables/blocks/hex_candle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"add": false,
"conditions": [
{
"block": "hexical:hex_candle",
"condition": "minecraft:block_state_property",
"properties": {
"candles": "2"
}
}
],
"count": 2.0,
"function": "minecraft:set_count"
},
{
"add": false,
"conditions": [
{
"block": "hexical:hex_candle",
"condition": "minecraft:block_state_property",
"properties": {
"candles": "3"
}
}
],
"count": 3.0,
"function": "minecraft:set_count"
},
{
"add": false,
"conditions": [
{
"block": "hexical:hex_candle",
"condition": "minecraft:block_state_property",
"properties": {
"candles": "4"
}
}
],
"count": 4.0,
"function": "minecraft:set_count"
},
{
"function": "minecraft:explosion_decay"
}
],
"name": "hexical:hex_candle"
}
],
"rolls": 1.0
}
]
}
Loading

0 comments on commit 6b294e7

Please sign in to comment.