Skip to content

Commit

Permalink
Update to 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Dec 15, 2023
1 parent 467986e commit cf7f77c
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 122 deletions.
8 changes: 4 additions & 4 deletions common/src/main/kotlin/juuxel/adorn/block/AdornBlocks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ object AdornBlocks : RegistryHelper() {

val STONE_TORCH_GROUND: Block by registerBlockWithoutItem("stone_torch") {
TorchBlock(
ParticleTypes.FLAME,
AbstractBlock.Settings.copy(Blocks.TORCH)
.sounds(BlockSoundGroup.STONE)
.luminance { 15 },
ParticleTypes.FLAME
.luminance { 15 }
)
}
val STONE_TORCH_WALL: Block by registerBlockWithoutItem("wall_stone_torch") {
WallTorchBlock(
AbstractBlock.Settings.copy(STONE_TORCH_GROUND).dropsLike(STONE_TORCH_GROUND),
ParticleTypes.FLAME
ParticleTypes.FLAME,
AbstractBlock.Settings.copy(STONE_TORCH_GROUND).dropsLike(STONE_TORCH_GROUND)
)
}

Expand Down
17 changes: 6 additions & 11 deletions common/src/main/kotlin/juuxel/adorn/block/BrewerBlock.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package juuxel.adorn.block

import com.mojang.serialization.MapCodec
import juuxel.adorn.block.entity.BrewerBlockEntity
import juuxel.adorn.lib.AdornStats
import juuxel.adorn.util.buildShapeRotationsFromNorth
import juuxel.adorn.util.mergeShapeMaps
import net.minecraft.block.Block
import net.minecraft.block.BlockState
import net.minecraft.block.BlockWithEntity
import net.minecraft.block.ShapeContext
import net.minecraft.block.entity.BlockEntity
import net.minecraft.block.entity.BlockEntityTicker
import net.minecraft.block.entity.BlockEntityType
import net.minecraft.block.entity.LootableContainerBlockEntity
import net.minecraft.entity.LivingEntity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.inventory.Inventory
import net.minecraft.item.ItemPlacementContext
import net.minecraft.item.ItemStack
import net.minecraft.particle.ParticleTypes
Expand Down Expand Up @@ -63,16 +64,8 @@ class BrewerBlock(settings: Settings) : VisibleBlockWithEntity(settings), BlockW
}

override fun onStateReplaced(state: BlockState, world: World, pos: BlockPos, newState: BlockState, moved: Boolean) {
if (!state.isOf(newState.block)) {
val entity = world.getBlockEntity(pos)

if (entity is Inventory) {
ItemScatterer.spawn(world, pos, entity)
world.updateComparators(pos, this)
}

super.onStateReplaced(state, world, pos, newState, moved)
}
ItemScatterer.onStateReplaced(state, newState, world, pos)
super.onStateReplaced(state, world, pos, newState, moved)
}

override fun createBlockEntity(pos: BlockPos, state: BlockState): BlockEntity? =
Expand Down Expand Up @@ -106,6 +99,8 @@ class BrewerBlock(settings: Settings) : VisibleBlockWithEntity(settings), BlockW
}
}

override fun getCodec(): MapCodec<out BlockWithEntity> = throw UnsupportedOperationException()

companion object {
val FACING: DirectionProperty = Properties.HORIZONTAL_FACING
val HAS_MUG: BooleanProperty = BooleanProperty.of("has_mug")
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/kotlin/juuxel/adorn/block/ChairBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ class ChairBlock(variant: BlockVariant) : CarpetedBlock(variant.createSettings()
}
}

override fun onBreak(world: World, pos: BlockPos, state: BlockState, player: PlayerEntity) {
override fun onBreak(world: World, pos: BlockPos, state: BlockState, player: PlayerEntity): BlockState {
if (!world.isClient && player.isCreative) {
TallPlantBlock.onBreakInCreative(world, pos, state, player)
}

super.onBreak(world, pos, state, player)
return super.onBreak(world, pos, state, player)
}

override fun onPlaced(world: World, pos: BlockPos, state: BlockState, entity: LivingEntity?, stack: ItemStack) {
Expand Down
17 changes: 6 additions & 11 deletions common/src/main/kotlin/juuxel/adorn/block/DrawerBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package juuxel.adorn.block

import com.mojang.serialization.MapCodec
import juuxel.adorn.block.entity.DrawerBlockEntity
import juuxel.adorn.block.entity.SimpleContainerBlockEntity
import juuxel.adorn.block.variant.BlockVariant
Expand All @@ -11,12 +12,12 @@ import juuxel.adorn.util.buildShapeRotationsFromNorth
import juuxel.adorn.util.mergeShapeMaps
import net.minecraft.block.Block
import net.minecraft.block.BlockState
import net.minecraft.block.BlockWithEntity
import net.minecraft.block.ShapeContext
import net.minecraft.block.entity.BlockEntity
import net.minecraft.block.entity.LootableContainerBlockEntity
import net.minecraft.entity.LivingEntity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.inventory.Inventory
import net.minecraft.item.ItemPlacementContext
import net.minecraft.item.ItemStack
import net.minecraft.menu.Menu
Expand Down Expand Up @@ -62,16 +63,8 @@ class DrawerBlock(variant: BlockVariant) : VisibleBlockWithEntity(variant.create
}

override fun onStateReplaced(state: BlockState, world: World, pos: BlockPos, newState: BlockState, moved: Boolean) {
if (!state.isOf(newState.block)) {
val entity = world.getBlockEntity(pos)

if (entity is Inventory) {
ItemScatterer.spawn(world, pos, entity)
world.updateComparators(pos, this)
}

super.onStateReplaced(state, world, pos, newState, moved)
}
ItemScatterer.onStateReplaced(state, newState, world, pos)
super.onStateReplaced(state, world, pos, newState, moved)
}

override fun getOutlineShape(state: BlockState, world: BlockView, pos: BlockPos, context: ShapeContext): VoxelShape =
Expand Down Expand Up @@ -104,6 +97,8 @@ class DrawerBlock(variant: BlockVariant) : VisibleBlockWithEntity(variant.create
}
}

override fun getCodec(): MapCodec<out BlockWithEntity> = throw UnsupportedOperationException()

companion object {
val FACING = Properties.HORIZONTAL_FACING

Expand Down
13 changes: 2 additions & 11 deletions common/src/main/kotlin/juuxel/adorn/block/KitchenCupboardBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import net.minecraft.block.entity.BlockEntity
import net.minecraft.block.entity.LootableContainerBlockEntity
import net.minecraft.entity.LivingEntity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.inventory.Inventory
import net.minecraft.item.ItemStack
import net.minecraft.menu.Menu
import net.minecraft.server.world.ServerWorld
Expand Down Expand Up @@ -43,16 +42,8 @@ class KitchenCupboardBlock(variant: BlockVariant) : AbstractKitchenCounterBlock(
}

override fun onStateReplaced(state: BlockState, world: World, pos: BlockPos, newState: BlockState, moved: Boolean) {
if (!state.isOf(newState.block)) {
val entity = world.getBlockEntity(pos)

if (entity is Inventory) {
ItemScatterer.spawn(world, pos, entity)
world.updateComparators(pos, this)
}

super.onStateReplaced(state, world, pos, newState, moved)
}
ItemScatterer.onStateReplaced(state, newState, world, pos)
super.onStateReplaced(state, world, pos, newState, moved)
}

override fun onPlaced(world: World, pos: BlockPos, state: BlockState, entity: LivingEntity?, stack: ItemStack) {
Expand Down
16 changes: 6 additions & 10 deletions common/src/main/kotlin/juuxel/adorn/block/ShelfBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

package juuxel.adorn.block

import com.mojang.serialization.MapCodec
import juuxel.adorn.block.variant.BlockVariant
import juuxel.adorn.lib.AdornStats
import juuxel.adorn.platform.PlatformBridges
import juuxel.adorn.util.buildShapeRotations
import net.minecraft.block.Block
import net.minecraft.block.BlockState
import net.minecraft.block.BlockWithEntity
import net.minecraft.block.Blocks
import net.minecraft.block.ShapeContext
import net.minecraft.block.Waterloggable
Expand Down Expand Up @@ -170,16 +172,8 @@ class ShelfBlock(variant: BlockVariant) : VisibleBlockWithEntity(variant.createS
}

override fun onStateReplaced(state: BlockState, world: World, pos: BlockPos, newState: BlockState, moved: Boolean) {
if (!state.isOf(newState.block)) {
val entity = world.getBlockEntity(pos)

if (entity is Inventory) {
ItemScatterer.spawn(world, pos, entity)
world.updateComparators(pos, this)
}

super.onStateReplaced(state, world, pos, newState, moved)
}
ItemScatterer.onStateReplaced(state, newState, world, pos)
super.onStateReplaced(state, world, pos, newState, moved)
}

override fun mirror(state: BlockState, mirror: BlockMirror) =
Expand All @@ -198,6 +192,8 @@ class ShelfBlock(variant: BlockVariant) : VisibleBlockWithEntity(variant.createS
override fun createBlockEntity(pos: BlockPos, state: BlockState): BlockEntity? =
AdornBlockEntities.SHELF.instantiate(pos, state)

override fun getCodec(): MapCodec<out BlockWithEntity> = throw UnsupportedOperationException()

companion object {
val FACING = Properties.HORIZONTAL_FACING
val WATERLOGGED = Properties.WATERLOGGED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

package juuxel.adorn.block

import com.mojang.serialization.MapCodec
import juuxel.adorn.block.entity.TradingStationBlockEntity
import juuxel.adorn.criterion.AdornCriteria
import juuxel.adorn.lib.AdornGameRules
import juuxel.adorn.lib.AdornStats
import juuxel.adorn.util.getText
import net.minecraft.block.Block
import net.minecraft.block.BlockState
import net.minecraft.block.BlockWithEntity
import net.minecraft.block.ShapeContext
import net.minecraft.block.entity.BlockEntity
import net.minecraft.client.item.TooltipContext
Expand Down Expand Up @@ -116,9 +118,9 @@ class TradingStationBlock(settings: Settings) : VisibleBlockWithEntity(settings)

world.updateComparators(pos, this)
}

super.onStateReplaced(state, world, pos, newState, moved)
}

super.onStateReplaced(state, world, pos, newState, moved)
}

override fun getOutlineShape(state: BlockState, world: BlockView, pos: BlockPos, context: ShapeContext) =
Expand All @@ -143,6 +145,8 @@ class TradingStationBlock(settings: Settings) : VisibleBlockWithEntity(settings)
}
}

override fun getCodec(): MapCodec<out BlockWithEntity> = throw UnsupportedOperationException()

companion object {
val WATERLOGGED = Properties.WATERLOGGED
private const val OWNER_DESCRIPTION = "block.adorn.trading_station.description.owner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ abstract class BaseContainerBlockEntity(type: BlockEntityType<*>, pos: BlockPos,
protected var items: DefaultedList<ItemStack> = DefaultedList.ofSize(size, ItemStack.EMPTY)

override fun writeNbt(nbt: NbtCompound) = super.writeNbt(nbt).apply {
if (!serializeLootTable(nbt)) {
if (!writeLootTable(nbt)) {
Inventories.writeNbt(nbt, items)
}
}

override fun readNbt(nbt: NbtCompound) {
super.readNbt(nbt)
if (!deserializeLootTable(nbt)) {
if (!readLootTable(nbt)) {
Inventories.readNbt(nbt, items)
}
}

override fun getInvStackList() = items
override fun method_11282() = items

override fun setInvStackList(items: DefaultedList<ItemStack>) {
this.items = items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class GuideBookScreen(private val book: Book) : Screen(NarratorManager.EMPTY) {

private class CloseButton(x: Int, y: Int, pressAction: PressAction) :
ButtonWidget(x, y, 8, 8, Text.empty(), pressAction, DEFAULT_NARRATION_SUPPLIER) {
override fun renderButton(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
override fun renderWidget(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
val texture = if (isHovered) CLOSE_BOOK_ACTIVE_TEXTURE else CLOSE_BOOK_INACTIVE_TEXTURE
context.drawTexture(texture, x, y, 0f, 0f, 8, 8, 8, 8)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
package juuxel.adorn.criterion

import com.google.gson.JsonNull
import com.google.gson.JsonObject
import com.mojang.serialization.Codec
import com.mojang.serialization.codecs.RecordCodecBuilder
import net.minecraft.advancement.criterion.AbstractCriterion
import net.minecraft.advancement.criterion.AbstractCriterionConditions
import net.minecraft.item.ItemStack
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer
import net.minecraft.predicate.entity.EntityPredicate
import net.minecraft.predicate.entity.LootContextPredicate
import net.minecraft.predicate.item.ItemPredicate
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.util.dynamic.Codecs
import java.util.Optional

class BoughtFromTradingStationCriterion : AbstractCriterion<BoughtFromTradingStationCriterion.Conditions>() {
override fun conditionsFromJson(
json: JsonObject,
playerPredicate: Optional<LootContextPredicate>,
predicateDeserializer: AdvancementEntityPredicateDeserializer
): Conditions = Conditions(
playerPredicate,
ItemPredicate.fromJson(json["item"]).orElse(null)
)
override fun getConditionsCodec(): Codec<Conditions> = Conditions.CODEC

fun trigger(player: ServerPlayerEntity, soldItem: ItemStack) {
trigger(player) { it.matches(soldItem) }
}

class Conditions(playerPredicate: Optional<LootContextPredicate>, private val soldItem: ItemPredicate?) :
AbstractCriterionConditions(playerPredicate) {
data class Conditions(val playerPredicate: Optional<LootContextPredicate>, val soldItem: Optional<ItemPredicate>) : AbstractCriterion.Conditions {
override fun player(): Optional<LootContextPredicate> = playerPredicate

fun matches(stack: ItemStack): Boolean =
soldItem == null || soldItem.test(stack)
soldItem.map { it.test(stack) }.orElse(true)

override fun toJson(): JsonObject {
val json = super.toJson()
json.add("sold_item", soldItem?.toJson() ?: JsonNull.INSTANCE)
return json
companion object {
val CODEC: Codec<Conditions> = RecordCodecBuilder.create { instance ->
instance.group(
Codecs.createStrictOptionalFieldCodec(EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC, "player")
.forGetter(Conditions::playerPredicate),
Codecs.createStrictOptionalFieldCodec(ItemPredicate.CODEC, "item")
.forGetter(Conditions::soldItem)
).apply(instance, ::Conditions)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,37 @@
package juuxel.adorn.criterion

import com.google.gson.JsonObject
import com.google.gson.JsonParseException
import com.mojang.serialization.JsonOps
import juuxel.adorn.util.logger
import com.mojang.serialization.Codec
import com.mojang.serialization.codecs.RecordCodecBuilder
import net.minecraft.advancement.criterion.AbstractCriterion
import net.minecraft.advancement.criterion.AbstractCriterionConditions
import net.minecraft.predicate.BlockPredicate
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer
import net.minecraft.predicate.entity.EntityPredicate
import net.minecraft.predicate.entity.LootContextPredicate
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.util.Util
import net.minecraft.util.dynamic.Codecs
import net.minecraft.util.math.BlockPos
import java.util.Optional

class SitOnBlockCriterion : AbstractCriterion<SitOnBlockCriterion.Conditions>() {
override fun conditionsFromJson(
json: JsonObject,
playerPredicate: Optional<LootContextPredicate>,
predicateDeserializer: AdvancementEntityPredicateDeserializer
): Conditions = Conditions(playerPredicate, Util.getResult(BlockPredicate.CODEC.parse(JsonOps.INSTANCE, json["block"]), ::JsonParseException))
override fun getConditionsCodec(): Codec<Conditions> = Conditions.CODEC

fun trigger(player: ServerPlayerEntity, pos: BlockPos) {
trigger(player) { it.matches(player, pos) }
}

companion object {
private val LOGGER = logger()
}
data class Conditions(val playerPredicate: Optional<LootContextPredicate>, val block: BlockPredicate) : AbstractCriterion.Conditions {
override fun player(): Optional<LootContextPredicate> = playerPredicate

class Conditions(playerPredicate: Optional<LootContextPredicate>, private val block: BlockPredicate) :
AbstractCriterionConditions(playerPredicate) {
fun matches(player: ServerPlayerEntity, pos: BlockPos): Boolean =
block.test(player.serverWorld, pos)

override fun toJson(): JsonObject {
val json = super.toJson()
json.add(
"block",
BlockPredicate.CODEC.encodeStart(JsonOps.INSTANCE, block).getOrThrow(false) {
LOGGER.error("Could not encode block predicate {}: {}", block, it)
}
)
return json
companion object {
val CODEC: Codec<Conditions> = RecordCodecBuilder.create { instance ->
instance.group(
Codecs.createStrictOptionalFieldCodec(EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC, "player")
.forGetter(Conditions::playerPredicate),
BlockPredicate.CODEC.fieldOf("block").forGetter(Conditions::block)
).apply(instance, ::Conditions)
}
}
}
}
Loading

0 comments on commit cf7f77c

Please sign in to comment.