Skip to content

Commit bde3c77

Browse files
committed
1.21.5 port complete
1 parent 9a643a0 commit bde3c77

File tree

8 files changed

+245
-160
lines changed

8 files changed

+245
-160
lines changed

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ cursegradle_version=1.4.0
1212

1313
# Fabric Properties
1414
# check these on https://fabricmc.net/develop
15-
minecraft_version=1.21.4
16-
yarn_mappings=1.21.4+build.8
15+
minecraft_version=1.21.5
16+
yarn_mappings=1.21.5+build.1
1717
loader_version=0.17.2
1818

1919
# Mod Properties
@@ -26,5 +26,5 @@ modrinth_id=gnSVsvlY
2626
curseforge_id=974793
2727

2828
# Dependencies
29-
fabric_version=0.119.4+1.21.4
29+
fabric_version=0.128.2+1.21.5
3030
fabric_kotlin_version=1.13.4+kotlin.2.2.0

src/main/kotlin/net/johnpgr/craftingtableiifabric/block/CraftingTableIIBlock.kt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,35 @@ import net.minecraft.util.shape.VoxelShape
3737
import net.minecraft.world.BlockView
3838
import net.minecraft.world.World
3939

40-
class CraftingTableIIBlock : BlockWithEntity(Settings.copy(Blocks.CRAFTING_TABLE).registryKey(REGISTRY_KEY)) {
40+
class CraftingTableIIBlock : BlockWithEntity(
41+
Settings.copy(Blocks.CRAFTING_TABLE).registryKey(REGISTRY_KEY)
42+
) {
4143
companion object {
4244
val ID = CraftingTableIIMod.id("crafting_table_ii")
43-
val REGISTRY_KEY: RegistryKey<Block> = RegistryKey.of(RegistryKeys.BLOCK, ID)
44-
val ITEM_REGISTRY_KEY: RegistryKey<Item> = RegistryKey.of(RegistryKeys.ITEM, ID)
45-
val CODEC: MapCodec<CraftingTableIIBlock> = createCodec { CraftingTableIIBlock() }
45+
val REGISTRY_KEY: RegistryKey<Block> =
46+
RegistryKey.of(RegistryKeys.BLOCK, ID)
47+
val ITEM_REGISTRY_KEY: RegistryKey<Item> =
48+
RegistryKey.of(RegistryKeys.ITEM, ID)
49+
val CODEC: MapCodec<CraftingTableIIBlock> =
50+
createCodec { CraftingTableIIBlock() }
4651

4752
fun register() {
4853
Registry.register(Registries.BLOCK, ID, CraftingTableIIMod.BLOCK)
4954

5055
Registry.register(
5156
Registries.ITEM, ITEM_REGISTRY_KEY, BlockItem(
5257
CraftingTableIIMod.BLOCK,
53-
Item.Settings().useBlockPrefixedTranslationKey().registryKey(ITEM_REGISTRY_KEY)
58+
Item.Settings().useBlockPrefixedTranslationKey()
59+
.registryKey(ITEM_REGISTRY_KEY)
5460
)
5561
)
5662

57-
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register { content ->
58-
content.addAfter(
59-
Items.CRAFTING_TABLE, CraftingTableIIMod.BLOCK
60-
)
61-
}
63+
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL)
64+
.register { content ->
65+
content.addAfter(
66+
Items.CRAFTING_TABLE, CraftingTableIIMod.BLOCK
67+
)
68+
}
6269
}
6370
}
6471

@@ -156,11 +163,7 @@ class CraftingTableIIBlock : BlockWithEntity(Settings.copy(Blocks.CRAFTING_TABLE
156163
return validateTicker(
157164
type,
158165
CraftingTableIIMod.ENTITY_TYPE
159-
) { world1, pos, state1, entity ->
160-
CraftingTableIIBlockEntity.tick(
161-
world1, pos, state1, entity as CraftingTableIIBlockEntity
162-
)
163-
}!!
166+
) { world1, pos, state1, entity -> entity.tick() }!!
164167
}
165168

166169
override fun hasComparatorOutput(state: BlockState): Boolean {

src/main/kotlin/net/johnpgr/craftingtableiifabric/block/entity/CraftingTableIIBlockEntity.kt

Lines changed: 81 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -23,92 +23,41 @@ class CraftingTableIIBlockEntity(
2323
pos: BlockPos,
2424
state: BlockState,
2525
) : BlockEntity(CraftingTableIIMod.ENTITY_TYPE, pos, state), Inventory {
26-
private var inventory =
27-
DefaultedList.ofSize(CraftingTableIIInventory.SIZE, ItemStack.EMPTY)
28-
private var doorState = DoorState.CLOSED
29-
var doorAngle = 0.0f
30-
3126
companion object {
27+
private const val OPEN_SPEED = 0.2f
28+
3229
fun register() {
3330
Registry.register(
3431
Registries.BLOCK_ENTITY_TYPE,
3532
CraftingTableIIBlock.ID,
3633
CraftingTableIIMod.ENTITY_TYPE,
3734
)
3835
}
36+
}
3937

40-
private const val OPEN_SPEED = 0.2f
41-
42-
fun tick(
43-
world: World,
44-
pos: BlockPos,
45-
state: BlockState,
46-
entity: CraftingTableIIBlockEntity
47-
) {
48-
val player = world.getClosestPlayer(
49-
pos.x.toDouble(),
50-
pos.y.toDouble(),
51-
pos.z.toDouble(),
52-
10.0,
53-
false
54-
) ?: return
55-
56-
val playerDistance = player.squaredDistanceTo(
57-
pos.x.toDouble(),
58-
pos.y.toDouble(),
59-
pos.z.toDouble()
60-
)
61-
62-
if (playerDistance < 7.0) {
63-
entity.doorAngle += OPEN_SPEED
64-
if (entity.doorAngle > 1.8f) entity.doorAngle = 1.8f
65-
66-
if (entity.doorState != DoorState.OPEN) {
67-
entity.doorState = DoorState.OPEN
68-
world.playSound(
69-
pos.x.toDouble(),
70-
pos.y.toDouble(),
71-
pos.z.toDouble(),
72-
SoundEvents.BLOCK_CHEST_OPEN,
73-
SoundCategory.BLOCKS,
74-
0.2f,
75-
world.random.nextFloat() * 0.1f + 0.2f,
76-
false
77-
)
78-
}
79-
} else if (playerDistance > 7.0) {
80-
entity.doorAngle -= OPEN_SPEED
81-
if (entity.doorAngle < 0f) entity.doorAngle = 0f
82-
83-
if (entity.doorState != DoorState.CLOSED) {
84-
entity.doorState = DoorState.CLOSED
85-
world.playSound(
86-
pos.x.toDouble(),
87-
pos.y.toDouble(),
88-
pos.z.toDouble(),
89-
SoundEvents.BLOCK_CHEST_CLOSE,
90-
SoundCategory.BLOCKS,
91-
0.2f,
92-
world.random.nextFloat() * 0.1f + 0.2f,
93-
false
94-
)
95-
}
96-
}
97-
}
98-
38+
enum class DoorState {
39+
OPEN,
40+
CLOSED
9941
}
10042

43+
private var inventory: DefaultedList<ItemStack> = DefaultedList.ofSize(
44+
CraftingTableIIInventory.SIZE,
45+
ItemStack.EMPTY
46+
)
47+
private var doorState: DoorState = DoorState.CLOSED
48+
var doorAngle: Float = 0.0f
49+
10150
override fun readNbt(
102-
nbt: NbtCompound?,
103-
registryLookup: RegistryWrapper.WrapperLookup?
51+
nbt: NbtCompound,
52+
registryLookup: RegistryWrapper.WrapperLookup
10453
) {
10554
super.readNbt(nbt, registryLookup)
10655
Inventories.readNbt(nbt, inventory, registryLookup)
10756
}
10857

10958
override fun writeNbt(
110-
nbt: NbtCompound?,
111-
registryLookup: RegistryWrapper.WrapperLookup?
59+
nbt: NbtCompound,
60+
registryLookup: RegistryWrapper.WrapperLookup
11261
) {
11362
super.writeNbt(nbt, registryLookup)
11463
Inventories.writeNbt(nbt, inventory, registryLookup)
@@ -162,8 +111,69 @@ class CraftingTableIIBlockEntity(
162111
return true
163112
}
164113

165-
enum class DoorState {
166-
OPEN,
167-
CLOSED
114+
fun tick() {
115+
val world: World = world ?: return
116+
val x = pos.x.toDouble()
117+
val y = pos.y.toDouble()
118+
val z = pos.z.toDouble()
119+
120+
val player = world.getClosestPlayer(
121+
x, y, z,
122+
10.0,
123+
false
124+
) ?: return
125+
126+
val playerDistance = player.squaredDistanceTo(x, y, z)
127+
128+
if (playerDistance < 7.0) {
129+
onPlayerApproach(player)
130+
} else if (playerDistance > 7.0) {
131+
onPlayerLeave(player)
132+
}
133+
}
134+
135+
@Suppress("UNUSED_PARAMETER")
136+
fun onPlayerApproach(player: PlayerEntity) {
137+
val world: World = world ?: return
138+
139+
doorAngle += OPEN_SPEED
140+
if (doorAngle > 1.8f) doorAngle = 1.8f
141+
142+
if (doorState != DoorState.OPEN) {
143+
doorState = DoorState.OPEN
144+
145+
world.playSound(
146+
null,
147+
pos.x.toDouble(),
148+
pos.y.toDouble(),
149+
pos.z.toDouble(),
150+
SoundEvents.BLOCK_CHEST_OPEN,
151+
SoundCategory.BLOCKS,
152+
0.2f,
153+
world.random.nextFloat() * 0.1f + 0.2f,
154+
)
155+
}
156+
}
157+
158+
@Suppress("UNUSED_PARAMETER")
159+
fun onPlayerLeave(player: PlayerEntity) {
160+
val world: World = world ?: return
161+
162+
doorAngle -= OPEN_SPEED
163+
if (doorAngle < 0f) doorAngle = 0f
164+
165+
if (doorState != DoorState.CLOSED) {
166+
doorState = DoorState.CLOSED
167+
world.playSound(
168+
null,
169+
pos.x.toDouble(),
170+
pos.y.toDouble(),
171+
pos.z.toDouble(),
172+
SoundEvents.BLOCK_CHEST_CLOSE,
173+
SoundCategory.BLOCKS,
174+
0.2f,
175+
world.random.nextFloat() * 0.1f + 0.2f,
176+
)
177+
}
168178
}
169179
}

src/main/kotlin/net/johnpgr/craftingtableiifabric/block/entity/CraftingTableIIBlockEntityRenderer.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import net.minecraft.client.util.math.MatrixStack
1616
import net.minecraft.state.property.Properties
1717
import net.minecraft.util.math.Direction
1818
import net.minecraft.util.math.RotationAxis
19+
import net.minecraft.util.math.Vec3d
1920

2021
@Environment(EnvType.CLIENT)
2122
class CraftingTableIIBlockEntityRenderer(context: BlockEntityRendererFactory.Context) :
@@ -54,7 +55,8 @@ class CraftingTableIIBlockEntityRenderer(context: BlockEntityRendererFactory.Con
5455
matrices: MatrixStack,
5556
vertexConsumers: VertexConsumerProvider,
5657
light: Int,
57-
overlay: Int
58+
overlay: Int,
59+
cameraPos: Vec3d
5860
) {
5961
val consumer = texture.getVertexConsumer(
6062
vertexConsumers,
@@ -67,6 +69,7 @@ class CraftingTableIIBlockEntityRenderer(context: BlockEntityRendererFactory.Con
6769
))
6870
val lightAbove =
6971
if (entity.hasWorld()) WorldRenderer.getLightmapCoordinates(
72+
WorldRenderer.BrightnessGetter.DEFAULT,
7073
entity.world,
7174
entity.cachedState,
7275
entity.pos.up()

src/main/kotlin/net/johnpgr/craftingtableiifabric/recipe/CraftingTableIIRecipeManager.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,24 @@ class CraftingTableIIRecipeManager(
4040
* Refreshes the list of craftable items based on the current state of the player's inventory and recipe book.
4141
* This method updates the `recipeItemStacks` property with the new list of craftable item stacks.
4242
*/
43-
4443
private fun refreshResults() {
45-
val collections = recipeBook.getResultsForCategory(RecipeBookType.CRAFTING).onEach { collection ->
46-
collection.populateRecipes(recipeFinder) { screenHandler.canDisplay(it) }
47-
}
44+
val collections =
45+
recipeBook.getResultsForCategory(RecipeBookType.CRAFTING)
46+
.onEach { collection ->
47+
collection.populateRecipes(recipeFinder) {
48+
screenHandler.canDisplay(
49+
it
50+
)
51+
}
52+
}
4853

4954
this.results = collections.flatMap { collection ->
5055
collection.filter(RecipeFilterMode.CRAFTABLE).map { entry ->
51-
Result(entry.id(), entry.getStacks(ctx), entry.craftingRequirements.getOrDefault(emptyList()))
56+
Result(
57+
entry.id(),
58+
entry.getStacks(ctx),
59+
entry.craftingRequirements.getOrDefault(emptyList())
60+
)
5261
}
5362
}
5463
}

0 commit comments

Comments
 (0)