-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed how conjured blocks work fundamentally
- Loading branch information
1 parent
8d0db26
commit 06f8782
Showing
19 changed files
with
223 additions
and
285 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
common/src/main/java/miyucomics/hexical/blocks/AdvancedConjuredBlock.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package miyucomics.hexical.blocks | ||
|
||
import at.petrak.hexcasting.api.misc.FrozenColorizer | ||
import at.petrak.hexcasting.common.blocks.BlockConjured | ||
import miyucomics.hexical.registry.HexicalBlocks | ||
import net.minecraft.block.BlockState | ||
import net.minecraft.block.Blocks | ||
import net.minecraft.block.MapColor | ||
import net.minecraft.block.Material | ||
import net.minecraft.block.entity.BlockEntity | ||
import net.minecraft.block.entity.BlockEntityTicker | ||
import net.minecraft.block.entity.BlockEntityType | ||
import net.minecraft.entity.Entity | ||
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.math.BlockPos | ||
import net.minecraft.util.math.Vec3i | ||
import net.minecraft.world.BlockView | ||
import net.minecraft.world.World | ||
import net.minecraft.world.WorldAccess | ||
|
||
class AdvancedConjuredBlock : BlockConjured(Settings.of(Material.ORGANIC_PRODUCT).nonOpaque().dropsNothing().breakInstantly().luminance { _ -> 2 }.mapColor(MapColor.CLEAR).suffocates { _, _, _ -> false }.blockVision { _, _, _ -> false }.allowsSpawning { _, _, _, _ -> false }.sounds(BlockSoundGroup.AMETHYST_CLUSTER)) { | ||
private val offsets: List<Vec3i> = listOf( | ||
Vec3i(-1, 0, 0), Vec3i(1, 0, 0), | ||
Vec3i(0, -1, 0), Vec3i(0, 1, 0), | ||
Vec3i(0, 0, -1), Vec3i(0, 0, 1), | ||
) | ||
|
||
override fun onBreak(world: World, position: BlockPos, state: BlockState, player: PlayerEntity) { | ||
world.playSound(position.x.toDouble(), position.y.toDouble(), position.z.toDouble(), SoundEvents.BLOCK_AMETHYST_BLOCK_BREAK, SoundCategory.BLOCKS, 1f, 1f, true) | ||
val tile = world.getBlockEntity(position) | ||
if (tile !is AdvancedConjuredBlockEntity) | ||
return | ||
if (!tile.volatile) | ||
return | ||
world.setBlockState(position, Blocks.AIR.defaultState) | ||
for (offset in offsets) { | ||
val positionToTest = position.add(offset); | ||
val otherState = world.getBlockState(positionToTest) | ||
val block = otherState.block | ||
if (block == HexicalBlocks.ADVANCED_CONJURED_BLOCK) | ||
block.onBreak(world, positionToTest, otherState, player) | ||
} | ||
} | ||
|
||
override fun onEntityLand(world: BlockView, entity: Entity) { | ||
val velocity = entity.velocity | ||
if (velocity.y < 0) | ||
entity.setVelocity(velocity.x, -velocity.y, velocity.z) | ||
} | ||
|
||
override fun createBlockEntity(pos: BlockPos, state: BlockState): BlockEntity { | ||
return AdvancedConjuredBlockEntity(pos, state) | ||
} | ||
|
||
override fun <T : BlockEntity?> getTicker(world: World, state: BlockState?, type: BlockEntityType<T>?): BlockEntityTicker<T>? { | ||
return if (world.isClient) BlockEntityTicker { _, _, _, blockEntity: T -> tick(blockEntity) } else null | ||
} | ||
|
||
override fun onSteppedOn(world: World, pos: BlockPos, state: BlockState, entity: Entity) { | ||
val tile = world.getBlockEntity(pos) | ||
if (tile is AdvancedConjuredBlockEntity) | ||
tile.walkParticle(entity) | ||
} | ||
|
||
companion object { | ||
fun <T> tick(blockEntity: T) { | ||
if (blockEntity is AdvancedConjuredBlockEntity) | ||
blockEntity.particleEffect() | ||
} | ||
|
||
fun setProperty(world: WorldAccess, pos: BlockPos, property: String) { | ||
val blockEntity = world.getBlockEntity(pos) | ||
if (blockEntity is AdvancedConjuredBlockEntity) | ||
blockEntity.setProperty(property) | ||
} | ||
|
||
fun setColor(world: WorldAccess, pos: BlockPos, colorizer: FrozenColorizer) { | ||
val blockEntity = world.getBlockEntity(pos) | ||
if (blockEntity is AdvancedConjuredBlockEntity) | ||
blockEntity.setColorizer(colorizer) | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
common/src/main/java/miyucomics/hexical/blocks/AdvancedConjuredBlockEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package miyucomics.hexical.blocks | ||
|
||
import at.petrak.hexcasting.api.block.HexBlockEntity | ||
import at.petrak.hexcasting.api.misc.FrozenColorizer | ||
import at.petrak.hexcasting.api.spell.iota.DoubleIota | ||
import at.petrak.hexcasting.api.spell.iota.Vec3Iota | ||
import at.petrak.hexcasting.api.utils.vecFromNBT | ||
import at.petrak.hexcasting.common.particles.ConjureParticleOptions | ||
import miyucomics.hexical.registry.HexicalBlocks | ||
import net.minecraft.block.BlockState | ||
import net.minecraft.entity.Entity | ||
import net.minecraft.nbt.NbtCompound | ||
import net.minecraft.util.math.BlockPos | ||
import net.minecraft.util.math.Vec3d | ||
import java.util.* | ||
|
||
class AdvancedConjuredBlockEntity(pos: BlockPos?, state: BlockState?) : HexBlockEntity(HexicalBlocks.ADVANCED_CONJURED_BLOCK_ENTITY, pos, state) { | ||
private val random = Random() | ||
private val colorizerTag: String = "colorizer" | ||
private val bouncyTag: String = "bouncy" | ||
private val slipperyTag: String = "slippery" | ||
private val volatileTag: String = "volatile" | ||
private var colorizer: FrozenColorizer = FrozenColorizer.DEFAULT.get() | ||
var bouncy: Boolean = false | ||
var slippery: Boolean = false | ||
var volatile: Boolean = false | ||
|
||
fun walkParticle(entity: Entity) { | ||
for (i in 0..2) { | ||
val color = colorizer.getColor(entity.age.toFloat(), entity.pos.add( | ||
Vec3d(random.nextDouble(), random.nextDouble(), random.nextDouble()).multiply( | ||
random.nextDouble() * 3))) | ||
assert(world != null) | ||
world!!.addParticle( | ||
ConjureParticleOptions(color, false), | ||
entity.x + (random.nextFloat() * 0.6) - 0.3, | ||
getPos().y + (random.nextFloat() * 0.05) + 0.95, | ||
entity.z + (random.nextFloat() * 0.6) - 0.3, | ||
random.nextFloat(-0.02f, 0.02f).toDouble(), | ||
random.nextFloat(0.02f).toDouble(), | ||
random.nextFloat(-0.02f, 0.02f).toDouble() | ||
) | ||
} | ||
} | ||
|
||
fun particleEffect() { | ||
val color = colorizer.getColor( | ||
random.nextFloat() * 16384, Vec3d(random.nextDouble(), random.nextDouble(), random.nextDouble()).multiply( | ||
random.nextDouble() * 3)) | ||
assert(world != null) | ||
if (random.nextFloat() < 0.2) { | ||
world!!.addParticle( | ||
ConjureParticleOptions(color, false), | ||
getPos().x.toDouble() + random.nextFloat(), | ||
getPos().y.toDouble() + random.nextFloat(), | ||
getPos().z.toDouble() + random.nextFloat(), | ||
random.nextFloat(-0.02f, 0.02f).toDouble(), | ||
random.nextFloat(-0.02f, 0.02f).toDouble(), | ||
random.nextFloat(-0.02f, 0.02f).toDouble() | ||
) | ||
} | ||
} | ||
|
||
override fun saveModData(tag: NbtCompound) { | ||
tag.put(colorizerTag, colorizer.serializeToNBT()) | ||
tag.putBoolean(bouncyTag, this.bouncy) | ||
tag.putBoolean(slipperyTag, this.slippery) | ||
tag.putBoolean(volatileTag, this.volatile) | ||
} | ||
|
||
override fun loadModData(tag: NbtCompound) { | ||
this.colorizer = FrozenColorizer.fromNBT(tag.getCompound(colorizerTag)) | ||
this.bouncy = tag.getBoolean(bouncyTag) | ||
this.slippery = tag.getBoolean(slipperyTag) | ||
this.volatile = tag.getBoolean(volatileTag) | ||
} | ||
|
||
fun setProperty(property: String) { | ||
when (property) { | ||
"bouncy" -> this.bouncy = true | ||
"slippery" -> this.slippery = true | ||
"volatile" -> this.volatile = true | ||
} | ||
this.sync() | ||
} | ||
|
||
fun setColorizer(colorizer: FrozenColorizer) { | ||
this.colorizer = colorizer | ||
this.sync() | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
common/src/main/java/miyucomics/hexical/blocks/ConjuredBouncyBlock.kt
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
common/src/main/java/miyucomics/hexical/blocks/ConjuredBouncyBlockEntity.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
common/src/main/java/miyucomics/hexical/blocks/ConjuredSlipperyBlock.kt
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
common/src/main/java/miyucomics/hexical/blocks/ConjuredSlipperyBlockEntity.kt
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
common/src/main/java/miyucomics/hexical/blocks/ConjuredVolatileBlock.kt
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
common/src/main/java/miyucomics/hexical/blocks/ConjuredVolatileBlockEntity.kt
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
common/src/main/java/miyucomics/hexical/casting/patterns/spells/OpConfigureBlock.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package miyucomics.hexical.casting.patterns.spells | ||
|
||
import at.petrak.hexcasting.api.misc.MediaConstants | ||
import at.petrak.hexcasting.api.spell.ParticleSpray | ||
import at.petrak.hexcasting.api.spell.RenderedSpell | ||
import at.petrak.hexcasting.api.spell.SpellAction | ||
import at.petrak.hexcasting.api.spell.casting.CastingContext | ||
import at.petrak.hexcasting.api.spell.getBlockPos | ||
import at.petrak.hexcasting.api.spell.iota.Iota | ||
import miyucomics.hexical.blocks.AdvancedConjuredBlock | ||
import net.minecraft.util.math.BlockPos | ||
import net.minecraft.util.math.Vec3d | ||
|
||
class OpConfigureBlock(private val property: String) : SpellAction { | ||
override val argc = 1 | ||
|
||
override fun execute(args: List<Iota>, ctx: CastingContext): Triple<RenderedSpell, Int, List<ParticleSpray>>? { | ||
val pos = args.getBlockPos(0, argc) | ||
ctx.assertVecInRange(pos) | ||
return Triple(Spell(pos, property), MediaConstants.DUST_UNIT, listOf(ParticleSpray.cloud(Vec3d.ofCenter(pos), 1.0))) | ||
} | ||
|
||
private data class Spell(val pos: BlockPos, val property: String) : RenderedSpell { | ||
override fun cast(ctx: CastingContext) { | ||
AdvancedConjuredBlock.setProperty(ctx.world, pos, property) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.