Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
235 commits
Select commit Hold shift + click to select a range
43ed60d
Offer more control over LightingChunk invalidations (#2156)
Minikloon May 30, 2024
5035c2b
fix light invalidation issue
iam4722202468 May 30, 2024
5ac26b1
Fix Entity::getEffectLevel having two meanings when returning 0 (#2163)
Minikloon May 30, 2024
406c686
add more command conditions
mudkipdev May 29, 2024
d46c626
Add signum operator to Vec
Minikloon May 29, 2024
1c7fc6c
Refactor lighting code, fix loaded chunks (#2164)
iam4722202468 May 30, 2024
4a07089
Switch to the new adventure domain (#2165)
ItsFelix5 May 30, 2024
9822331
fix: do not test block collision on entities without collision
mworzala May 31, 2024
19bb74e
Make PlayerProjectile extend Entity instead of LivingEntity
FluxCapacitor2 Jun 2, 2024
e61dc81
feat: initial conversion to adventure nbt. no tests, no anvil
mworzala Mar 17, 2024
18b6354
chore: basic nbt reader/writer for protocol while waiting for adventure
mworzala Apr 10, 2024
d2be7e1
feat: joinable server
mworzala Apr 10, 2024
0a6c821
fix: oops, health is before potion still
mworzala Apr 10, 2024
e857a29
chore: rebase on adventure-nbt
mworzala Apr 10, 2024
6300d76
feat: first version of a bunch of components
mworzala Apr 11, 2024
65e04d0
chore: delete all old metadata classes for now, may return compatibil…
mworzala Apr 11, 2024
af85459
chore: more components
mworzala Apr 12, 2024
4f12d65
chore: more components
mworzala Apr 12, 2024
b8a600b
chore: trying to fix nightmare loop
mworzala Apr 13, 2024
7ba6a6d
feat: functional components, but at what cost
mworzala Apr 13, 2024
444e74e
chore: cleanup itemcomponenttype, update to datagen changes
mworzala Apr 17, 2024
eccfaac
feat: more components
mworzala Apr 18, 2024
35f122b
feat: even more components (only 2 missing ones)
mworzala Apr 18, 2024
100661b
feat: first draft of cookies
mworzala Apr 18, 2024
5096c7a
feat: simplify sound events, fix update explosion packet
mworzala Apr 19, 2024
c4af024
feat: generate RecipeType (for ids)
mworzala Apr 19, 2024
2920cee
fix: do not send close inventory packet when opening a new inventory …
mworzala Apr 21, 2024
101211c
feat: anvil reading, other minor fixes
mworzala Apr 23, 2024
bf92944
feat: partial anvil writing, update tests (still many broken)
mworzala Apr 23, 2024
df3a540
chore: 1.20.5, disable some failing tests to get a functional build
mworzala Apr 23, 2024
1a2e817
chore: cicd trigger
mworzala Apr 23, 2024
88ab249
chore: update datagenerator
mworzala Apr 23, 2024
60d6324
fix: anvil not loading locations properly
mworzala Apr 23, 2024
92ce3e6
fix: particle packet reorder
mworzala Apr 23, 2024
1a4fbef
fix: do not allow writing air in declare recipes packet (added ItemSt…
mworzala Apr 23, 2024
bccd944
feat: initial ArgumentItemStack reader, other minor fixes
mworzala Apr 24, 2024
ea59ddb
fix: light test and update eye height in view direction test
mworzala Apr 24, 2024
0ed5a2a
chore: cleanup anvil test
mworzala Apr 24, 2024
67fe007
fix: dont oom reading item component, stub banner pattern component
mworzala Apr 25, 2024
f14ac37
fix: circular init :|
mworzala Apr 25, 2024
580438c
fix: correctly handle eating potions, time eating using ticks, defaul…
mworzala Apr 27, 2024
0650caa
fix: do not convert optchat metadata to chat
mworzala Apr 28, 2024
97618d7
chore: rebase, add stack size 99 test case
mworzala Apr 29, 2024
9043b6d
chore: another stack size test
mworzala Apr 29, 2024
cdc036c
feat: block predicate impl & some more tests
mworzala Apr 29, 2024
31fb33e
feat: initial anvilloader writer implementation
mworzala Apr 29, 2024
6f33d66
fix: correctly read declared recipes
mworzala Apr 29, 2024
bcffaef
chore: generalize ItemComponent to DataComponent (item component defs…
mworzala Apr 29, 2024
e1a4ea1
fix: update from lighting fix 35 rebase
mworzala Apr 30, 2024
3073a6d
chore: add PlayerAnvilInputEvent, other minor tweaks from self review
mworzala May 4, 2024
57ba1a5
fix: sync position after sending first chunk
mworzala May 4, 2024
3d84d94
chore: start testing components, fix valueless components
mworzala May 4, 2024
5fb5c82
chore: allow chunk subclasses to override heightmap generation
mworzala May 4, 2024
aa697a4
feat: first pass of standardizing dynamic registries
mworzala May 18, 2024
7f88699
feat: add DynamicRegistry.Key and reference it instead of the underly…
mworzala May 18, 2024
a6ab761
chore: cleanup & some component impl utility methods
mworzala May 18, 2024
4674a42
chore: depend on published version of data, not local
mworzala May 20, 2024
f2665be
chore: minor tweaks
mworzala May 23, 2024
abf80e5
chore: cleanup networkbuffer additions
mworzala May 23, 2024
c7fd6e2
chore: missing entity metas & extract shooter to abstractwindchargemeta
mworzala May 23, 2024
d4f1580
fix: correct handling of known packs exchange
mworzala May 23, 2024
aa7c03a
chore: merge datacomponentmap and datacomponentpatch to simplify api.…
mworzala May 27, 2024
0fd91b8
chore: more tests for components
mworzala May 27, 2024
fd19f12
chore: one more
mworzala May 27, 2024
1ce1766
fix: setTimeUpdate transition from duration to ticks, renamed to avoi…
DeidaraMC May 27, 2024
da09503
feat: LivingEntity fire overhaul (#2122)
DeidaraMC May 27, 2024
20e91c8
feat: world border overhaul, turned into a record and handled by the …
DeidaraMC May 27, 2024
c185337
Pathfinding 1.20.5 (#2153)
iam4722202468 May 28, 2024
5182f19
feat: cya later jitpack
mworzala May 28, 2024
e3c1c06
chore: remove some weird internal/experimental annotations
mworzala May 29, 2024
1d3feee
Item usage duration (#2128)
TogAr2 May 4, 2024
72ead66
fix: fixes from merging #2128
mworzala May 30, 2024
8b82651
feat: improve particle api
DeidaraMC Apr 25, 2024
7fef892
feat: generate particle data names automatically
mworzala May 30, 2024
943e763
chore: make all impls records + inner classes of Particle
mworzala May 30, 2024
5c2a41b
chore: minor cleanup, block display meta to use Block directly
mworzala May 30, 2024
533f033
fix: default zero use item time
mworzala Jun 2, 2024
37f466c
Move static Entity lookup maps to EntityTracker (#2167)
Minikloon Jun 3, 2024
b9616e6
chore: delete `Entity#setUuid` and `AsyncPlayerPreLoginEvent#setUuid`
mworzala Jun 3, 2024
b784cfc
chore: delete a deprecated Audience#sendMessage variant
mworzala Jun 3, 2024
75babcb
chore: javadocs and remove experimental pose update flag
mworzala Jun 3, 2024
83783e4
fix: fixes from rug pull
mworzala Jun 7, 2024
05546d8
fix: tag escape
mworzala Jun 7, 2024
ae7a80c
fix: inventory rebase fixes
mworzala Jun 8, 2024
d5a6392
Fix Attribute Read/Write due to initialization shenanagins (#2174)
GreatWyrm Jun 8, 2024
4a6641e
Only consider online players for unregisterInstance (#2171)
Minikloon Jun 8, 2024
d1624c2
Add new navigator generator & follower
iam4722202468 Jun 8, 2024
99f7667
Include ourself as a viewer when sending SWING_MAIN_ARM animation (#2…
kubbidev Jun 8, 2024
4d61d5b
fix: re-add deprecated Audience#sendMessage variant which was actuall…
mworzala Jun 8, 2024
e176899
Fix ITEM_NAME component translation in SetSlotPacket (#2176)
FluxCapacitor2 Jun 8, 2024
b3aa996
Fix the NBT representation of Unit (#2177)
Minikloon Jun 9, 2024
2fd79d0
Call UuidProvider in async (#2181)
MelonHell Jun 9, 2024
1c528d8
[RE] Update PlayerChangeHeldSlotEvent.java (#2179)
unjoinable Jun 9, 2024
aca4c3d
fix: correctly account for global biome palette
mworzala Jun 11, 2024
176d4bb
fix: incorrect region metatable offset when writing
mworzala Jun 12, 2024
914ddd8
Add Instance::getPlayerByUuid because for convenience (#2190)
Minikloon Jun 13, 2024
e4bec39
feat: hello, 1.21
mworzala May 30, 2024
141a251
feat: new packets, new registries except stubbed out enchantments, ot…
mworzala May 31, 2024
df14b50
chore: 1.21-pre2
mworzala Jun 2, 2024
af1f1c0
chore: start on enchantments
mworzala Jun 3, 2024
fc2ce0b
chore: start on enchant effect components
mworzala Jun 12, 2024
6345042
chore: protocol set
mworzala Jun 12, 2024
fadf30a
chore: start on effect types
mworzala Jun 12, 2024
f089708
feat: mostly functional enchants, needs cleanup
mworzala Jun 13, 2024
0e14214
feat: add some ItemStack convenience methods
mworzala Jun 13, 2024
2f5bb97
feat: minor improvements, 1.21 release
mworzala Jun 13, 2024
a909985
fix inventory packet for global translator
bea4dev Jun 11, 2024
0f81bc3
fix full light data is not sent (#2191)
bea4dev Jun 14, 2024
6766e3c
Add feature flags to AsyncPlayerConfigurationEvent
Flopgop Jun 14, 2024
461d0aa
fix player health update animation (#2183)
bea4dev Jun 15, 2024
8736fc4
fix projectile remove
bea4dev Jun 10, 2024
80377e3
Update Player.java (#2195)
unjoinable Jun 16, 2024
c864773
fix: deserialize `extra` correctly in component serializer
mworzala Jun 16, 2024
898032c
Fix add transaction
iam4722202468 Jun 16, 2024
f1d5940
Fix events not triggering for bows, crossbows, etc. (#2199)
iam4722202468 Jun 17, 2024
277dcea
fix: inverted vanilla exclusion
mworzala Jun 20, 2024
5eb1eea
fix: nbt byte for `sections[].Y` in anvil chunk data (fixes #2207)
mworzala Jun 25, 2024
2b661fd
Drop eventnode listener ref on invalidate (#2212)
Spliterash Jun 25, 2024
e513efb
Fixed bug in LargeFramebuffer#preparePacket(int,int,int) (#2213)
CrazySqueak Jun 25, 2024
d5c6126
Fix LivingEntity Damage Event Packet (#2209)
GreatWyrm Jun 25, 2024
9b4aba2
fix: correctly disconnect player if resource pack is not applied succ…
mworzala Jun 26, 2024
5cb1921
Ability to teleport player without teleport confirm (#2222)
MelonHell Jun 27, 2024
2c73b4b
fix: preserve handler in block placement rule neighbor updates
mworzala Jun 27, 2024
66dc936
fix: do not overwrite default movement speed attribute
mworzala Jun 27, 2024
4355343
Revert "fix: do not overwrite default movement speed attribute"
mworzala Jun 27, 2024
edb73f0
fix: update sprinting movement speed modifier serverside to keep sync…
mworzala Jun 27, 2024
8ea7760
fix: concurrent region file creation
mworzala Jun 29, 2024
77af815
fix: adding an existing viewer to a scoreboard kicks them (#2231)
DeidaraMC Jun 30, 2024
efeb222
fix: DustColorTransition packet reading/writing (#2236)
DeidaraMC Jul 1, 2024
4a03aec
Add Player#getCurrentItemUseTime (#2235)
TogAr2 Jul 1, 2024
73b3086
Fix infinite recursion. (#2230)
CrazySqueak Jul 1, 2024
435ee1f
chore: int flags potion constructor (#2238)
DeidaraMC Jul 2, 2024
3661ecb
chore: send keepalive packets immediately, simplify PacketProcessor#p…
DeidaraMC Jul 2, 2024
90fb708
Autogenerate Feature Flags (#2201)
Flopgop Jul 2, 2024
a49e167
feat: Improvements to AttributeInstance API (#2221)
VegetalDev Jul 4, 2024
0129aed
feat: Acquirable, ThreadDispatcher usage improvements (#2237)
VegetalDev Jul 4, 2024
d606051
fix: incorrect camel case in item component nbt (fixes #2233)
mworzala Jul 5, 2024
6877277
Add material setter in builder
TheMode Jul 7, 2024
8e1cb18
feat: ShapeImpl#collisionBoundingBoxes, ShapeImpl#occlusionBoundingBo…
VegetalDev Jul 8, 2024
5caa7ce
Automatically update an entity's attributes when changing equipment (…
GreatWyrm Jul 8, 2024
328b0e7
chore: add AlphaColor, convert Color to class, fix entity_effect part…
DeidaraMC Jul 8, 2024
d5c2f7d
fix: AttributeInstance#addModifier not refreshing cachedValue for new…
DeidaraMC Jul 8, 2024
afae77a
chore: add doc about kicking player during config
mworzala Jul 8, 2024
1903e8d
chore: enforce and document notnull chunk loader, add noop impl
mworzala Jul 8, 2024
fda23e4
Fix chunk lighting optimization (#2244)
Am-Gone Jul 9, 2024
c7efa82
Add a few useful methods to Direction (#2254)
Minikloon Jul 10, 2024
40517df
Add Block::original so it's easier to compare by block type (#2255)
Minikloon Jul 10, 2024
2be6f9c
fix: geyser keepalive incompatibility
mworzala Jul 10, 2024
79716ab
Fix NullPointer when changing equipment before checking attributes
GreatWyrm Jul 11, 2024
a68d13a
get back jmh/jcstress
TheMode Jul 12, 2024
591d161
Add getAndSetTag to TagWritable
TheMode Jul 12, 2024
345451f
Remove Instance/PlayerUtils
TheMode Jul 12, 2024
7d43da9
Move all flags to ServerFlag
TheMode Jul 12, 2024
e4267c7
MetadataHolder (#2263)
TheMode Jul 13, 2024
6932647
Move entity meta map to MetadataHolder
TheMode Jul 13, 2024
7dd1792
Fix biome sounds + particles (#2265)
iam4722202468 Jul 13, 2024
6fc64e3
Call ItemUpdateStateEvent before clearing item use (#2258)
TogAr2 Jul 15, 2024
60a83fd
feat: allow changing the number of threads used by the server process…
VegetalDev Jul 16, 2024
e5372fd
fix: optional world pos in lodestone tracker item component (fixes #2…
mworzala Jul 17, 2024
1f34e60
chore: add cursor position to `PlayerBlockPlaceEvent`
mworzala Jul 18, 2024
9c8593d
fix: node followers using the speed attribute base value instead of v…
Am-Gone Jul 23, 2024
99ca16e
feat: thread safety for AttributeInstance (#2297)
VegetalDev Jul 24, 2024
6406b36
Remove cursor items from individual inventories (#2294)
GoldenStack Jul 24, 2024
1ef0e26
feat: add ability to clear modifiers from an AttributeInstance (#2296)
VegetalDev Jul 24, 2024
247db8c
Make loyalty level a byte (#2300)
TogAr2 Jul 24, 2024
7c121ee
Remove static biome registry, simplify unit generation
TheMode Jul 25, 2024
f53625f
fix attribute packet (#2305)
TheMode Jul 25, 2024
35e395e
chore: bump data gen to fix light[level=0] emission value
mworzala Jul 26, 2024
12794d4
chore: Remove a bunch of Experimental annotations
mworzala Jul 26, 2024
3f60070
Direct writer for Adventure components (#2306)
mworzala Jul 28, 2024
a1e1dbd
fix: lower case click/hover action types
mworzala Jul 28, 2024
96dbad8
fix: Round up total sectors in region file
Aeltumn Aug 1, 2024
7b18017
fix: send attribute base value not computed.
mworzala Aug 1, 2024
d8896de
Apply microtus patches 1-20
TheMeinerLP May 22, 2024
f8ec1ab
Fix build grade
TheMeinerLP Aug 5, 2024
55afc5d
Add missing adventure nbt lib
TheMeinerLP Aug 5, 2024
ff46b91
Add missing dependencies
TheMeinerLP Aug 5, 2024
e238107
Remove old biome, banner, shield, particle, attribute system
TheMeinerLP Aug 5, 2024
f38712a
Fix forward data generator
TheMeinerLP Aug 5, 2024
ca79ddd
Disable stress tester for compile reasons
TheMeinerLP Aug 5, 2024
cee3516
Remove old network stack
TheMeinerLP Aug 5, 2024
d502d9c
Remove no longer exists api form player
TheMeinerLP Aug 5, 2024
bc76158
Fix forward bstats
TheMeinerLP Aug 5, 2024
d7fe1ef
Fix forward server flags
TheMeinerLP Aug 5, 2024
90833bb
Fix forward terminal color converter
TheMeinerLP Aug 5, 2024
a94ee76
Fix forward inventory tests
TheMeinerLP Aug 5, 2024
4613515
Fix forward frog meta test
TheMeinerLP Aug 5, 2024
80192ba
Update files like in microtus main
TheMeinerLP May 22, 2024
424febf
Apply better workflow
TheMeinerLP May 22, 2024
50461b0
Move miss landed classes after patching source
TheMeinerLP May 23, 2024
da85e47
Fix workflows for java 21
TheMeinerLP May 23, 2024
9bfc470
Fix workflows for java 21
TheMeinerLP May 23, 2024
6b0da35
[Chore] Update gradle to 8.7
TheMeinerLP May 24, 2024
9f46672
[Chore] Remove preview feature
TheMeinerLP May 24, 2024
695d85e
[Bugfix] Improve version string for bstats
TheMeinerLP May 24, 2024
19df70c
Update README.md
TheMeinerLP May 24, 2024
e5aa22a
Update snapshot and release version
OneLiteFeather May 24, 2024
368c7ca
[Chore] Replace e.printstacktrace with exception manager call or logger
TheMeinerLP May 25, 2024
3425222
Create CNAME
TheMeinerLP May 25, 2024
3d69a10
Bump snapshot version (#31)
TheMeinerLP May 25, 2024
0e1460d
Update build.gradle.kts
TheMeinerLP May 26, 2024
e7f951d
Improve license usage
TheMeinerLP May 26, 2024
281c5dc
Improve license usage
TheMeinerLP May 26, 2024
03f8014
[#30] Release 1.4.0
TheMeinerLP May 26, 2024
a70dbc2
[#30] Re-Release 1.4.1
TheMeinerLP May 26, 2024
188b008
Go back to snapshot
TheMeinerLP May 26, 2024
2027a55
Ignore bstats file
TheMeinerLP May 26, 2024
211e7ac
[#34] Better Notification System (#35)
TheMeinerLP May 27, 2024
121b70c
Add bom
TheMeinerLP May 28, 2024
aa53d00
Improve bom
TheMeinerLP May 28, 2024
d5658bb
Remove java version from bom
TheMeinerLP May 28, 2024
4ea40c0
Change bom deployment
TheMeinerLP May 28, 2024
7f51323
Change bom deployment
TheMeinerLP May 28, 2024
6ef2e93
[Feature] Improved Testing Lib (#42)
TheMeinerLP May 28, 2024
b1164b6
Add missing dependencies
TheMeinerLP May 28, 2024
24eb4f5
Add missing dependencies
TheMeinerLP May 28, 2024
a4f28ce
Improve release workflow
TheMeinerLP May 28, 2024
10f3ede
Improve release workflow
TheMeinerLP May 28, 2024
ebcc55b
Bump version
TheMeinerLP May 28, 2024
0b16478
Update dependency com.google.code.gson:gson to v2.11.0
renovate[bot] May 28, 2024
c9e1e74
Update dependency org.mockito:mockito-core to v5.12.0
renovate[bot] May 28, 2024
bcb639f
Update actions/cache action to v4
renovate[bot] May 28, 2024
7f5ba48
Update gradle/wrapper-validation-action action to v3
renovate[bot] May 28, 2024
8f4eecd
Update kotlin monorepo to v2
renovate[bot] May 28, 2024
85520fb
[Chore] Update gradle to version 8.8 (#58)
theEvilReaper Jun 1, 2024
c622ea4
Update CODEOWNERS
TheMeinerLP Jun 11, 2024
110e495
Update CODEOWNERS
TheMeinerLP Jun 11, 2024
b03c41d
Update README.md
TheMeinerLP Jun 16, 2024
47b675e
Bump version to 1.5.0
TheMeinerLP Aug 5, 2024
4dcf7ed
Add missing import
TheMeinerLP Aug 5, 2024
50c13ee
Add support for older as 1.21 minecraft worlds
TheMeinerLP Aug 5, 2024
af129a9
Update BOM dependencies
TheMeinerLP Aug 5, 2024
05e950f
Merge branch 'refs/heads/master' into feature/upstream
TheMeinerLP Aug 5, 2024
8e55835
Remove no longer needed classes
TheMeinerLP Aug 5, 2024
901f1aa
Fix forward compile issues
TheMeinerLP Aug 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 0 additions & 6 deletions bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ dependencies {
// Libraries
api(libs.gson)
api(libs.jcTools)
// Path finding
api(libs.hydrazine)

// Adventure, for user-interface
api(libs.bundles.adventure)
Expand All @@ -45,10 +43,6 @@ dependencies {
// Minestom Data (From MinestomDataGenerator)
api(libs.minestomData)

// NBT parsing/manipulation/saving
api("io.github.jglrxavpok.hephaistos:common:${libs.versions.hephaistos.get()}")
api("io.github.jglrxavpok.hephaistos:gson:${libs.versions.hephaistos.get()}")

// BStats
api(libs.bstats.base)
}
Expand Down
47 changes: 19 additions & 28 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {

group = "net.onelitefeather.microtus"

version = System.getenv("TAG_VERSION") ?: "1.4.3-SNAPSHOT"
version = System.getenv("TAG_VERSION") ?: "1.4.0-SNAPSHOT"

allprojects {
group = "net.onelitefeather.microtus"
Expand Down Expand Up @@ -58,7 +58,7 @@ tasks {
addStringOption("-release", "21")
// Links to external javadocs
links("https://docs.oracle.com/en/java/javase/21/docs/api/")
links("https://jd.advntr.dev/api/${libs.versions.adventure.get()}/")
links("https://jd.adventure.kyori.net/api/${libs.versions.adventure.get()}/")
}
}
withType<Zip> {
Expand All @@ -78,11 +78,11 @@ tasks {
}

dependencies {
// Testing Framework
testImplementation(project(mapOf("path" to ":testing")))
// Only here to ensure J9 module support for extensions and our classloaders
testCompileOnly(libs.mockito.core)

// Core dependencies
api(libs.slf4j)
api(libs.jetbrainsAnnotations)
api(libs.bundles.adventure)
implementation(libs.minestomData)

// Logging
implementation(libs.bundles.logging)
Expand All @@ -93,31 +93,22 @@ dependencies {
implementation(libs.caffeine)
api(libs.fastutil)
implementation(libs.bundles.flare)

// Libraries
api(libs.gson)
implementation(libs.jcTools)
// Path finding
api(libs.hydrazine)

// Adventure, for user-interface
api(libs.bundles.adventure)

// Kotlin Libraries
api(libs.bundles.kotlin)

// BStats
api(libs.bstats.base)
// Maven
api(libs.maven.resolver)
api(libs.maven.connector)
api(libs.maven.transport.http)

// Minestom Data (From MinestomDataGenerator)
implementation(libs.minestomData)

// NBT parsing/manipulation/saving
api("io.github.jglrxavpok.hephaistos:common:${libs.versions.hephaistos.get()}")
api("io.github.jglrxavpok.hephaistos:gson:${libs.versions.hephaistos.get()}")
// Libraries
api(libs.gson)
implementation(libs.jcTools)

// BStats
api(libs.bstats.base)
// Testing
testImplementation(libs.bundles.junit)
testImplementation(project(":testing"))
// Only here to ensure J9 module support for extensions and our classloaders
testCompileOnly(libs.mockito.core)
}


105 changes: 79 additions & 26 deletions code-generators/src/main/java/net/minestom/codegen/CodeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,128 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.TypeSpec;
import org.jetbrains.annotations.ApiStatus;
import com.squareup.javapoet.*;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.lang.model.SourceVersion;
import javax.lang.model.element.Modifier;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.Locale;

import static net.minestom.codegen.MinestomCodeGenerator.DEFAULT_INDENT;
import static net.minestom.codegen.MinestomCodeGenerator.extractNamespaces;

@ApiStatus.Internal
public class CodeGenerator implements CodeExporter {
public class CodeGenerator {
protected static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
private static final Logger LOGGER = LoggerFactory.getLogger(CodeGenerator.class);

private final File outputFolder;

public CodeGenerator(@NotNull File outputFolder) {
public CodeGenerator(File outputFolder) {
this.outputFolder = outputFolder;
}

public void generate(InputStream resourceFile, String packageName, String typeName, String loaderName, String generatedName) {
if (resourceFile == null) {
LOGGER.error("Failed to find resource file for {}", typeName);
LOGGER.error("Failed to find resource file for " + typeName);
return;
}
ClassName typeClass = ClassName.get(packageName, typeName);
ClassName loaderClass = ClassName.get(packageName, loaderName);

JsonObject json = GSON.fromJson(new InputStreamReader(resourceFile), JsonObject.class);
JsonObject json;
json = GSON.fromJson(new InputStreamReader(resourceFile), JsonObject.class);
ClassName materialsCN = ClassName.get(packageName, generatedName);
// BlockConstants class
TypeSpec.Builder blockConstantsClass = TypeSpec.interfaceBuilder(materialsCN)
// Add @SuppressWarnings("unused")
.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "unused").build())
.addJavadoc("Code autogenerated, do not edit!");

Map<String, String> replacementOptions = new HashMap<>();
replacementOptions.put("minecraft:", "");
replacementOptions.put(".", "_");
// Use data
json.keySet().forEach(namespace -> {
final String constantName = extractNamespaces(namespace, replacementOptions);
final String constantName = namespace
.replace("minecraft:", "")
.replace(".", "_")
.toUpperCase(Locale.ROOT);
blockConstantsClass.addField(
FieldSpec.builder(typeClass, constantName)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer(
// TypeClass.STONE = MaterialLoader.fromNamespaceId("minecraft:stone")
"$T.get($S)",
loaderClass,
namespace
)
.build()
);
});
writeFile(
JavaFile.builder(packageName, blockConstantsClass.build())
.indent(DEFAULT_INDENT)
writeFiles(
List.of(JavaFile.builder(packageName, blockConstantsClass.build())
.indent(" ")
.skipJavaLangImports(true)
.build()),
outputFolder);
}

public void generateKeys(InputStream resourceFile, String packageName, String typeName, String generatedName) {
if (resourceFile == null) {
LOGGER.error("Failed to find resource file for " + typeName);
return;
}

ClassName typeClass = ClassName.bestGuess(packageName + "." + typeName); // Use bestGuess to handle nested class
ClassName registryKeyClass = ClassName.get("net.minestom.server.registry", "DynamicRegistry", "Key");
ParameterizedTypeName typedRegistryKeyClass = ParameterizedTypeName.get(registryKeyClass, typeClass);

JsonObject json;
json = GSON.fromJson(new InputStreamReader(resourceFile), JsonObject.class);
ClassName materialsCN = ClassName.get(packageName, generatedName);
// BlockConstants class
TypeSpec.Builder blockConstantsClass = TypeSpec.interfaceBuilder(materialsCN)
// Add @SuppressWarnings("unused")
.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "unused").build())
.addJavadoc("Code autogenerated, do not edit!");

// Use data
json.keySet().forEach(namespace -> {
String constantName = namespace
.replace("minecraft:", "")
.replace(".", "_")
.toUpperCase(Locale.ROOT);
if (!SourceVersion.isName(constantName)) {
constantName = "_" + constantName;
}
blockConstantsClass.addField(
FieldSpec.builder(typedRegistryKeyClass, constantName)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer(
// TypeClass.STONE = NamespaceID.from("minecraft:stone")
"$T.of($S)",
registryKeyClass,
namespace
)
.build()
);
});
writeFiles(
List.of(JavaFile.builder(packageName, blockConstantsClass.build())
.indent(" ")
.skipJavaLangImports(true)
.build(),
outputFolder
);
.build()),
outputFolder);
}

private void writeFiles(@NotNull List<JavaFile> fileList, File outputFolder) {
for (JavaFile javaFile : fileList) {
try {
javaFile.writeTo(outputFolder);
} catch (IOException e) {
LOGGER.error("An error occured while writing source code to the file system.", e);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package net.minestom.codegen;

import com.google.gson.JsonObject;
import com.squareup.javapoet.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.lang.model.element.Modifier;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

public class ConstantsGenerator extends MinestomCodeGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(ConstantsGenerator.class);
private final InputStream constantsFile;
private final File outputFolder;

public ConstantsGenerator(@Nullable InputStream constantsFile, @NotNull File outputFolder) {
this.constantsFile = constantsFile;
this.outputFolder = outputFolder;
}

@Override
public void generate() {
if (constantsFile == null) {
LOGGER.error("Failed to find constants.json.");
LOGGER.error("Stopped code generation for recipe types.");
return;
}
if (!outputFolder.exists() && !outputFolder.mkdirs()) {
LOGGER.error("Output folder for code generation does not exist and could not be created.");
return;
}

// Important classes we use alot
JsonObject constants = GSON.fromJson(new InputStreamReader(constantsFile), JsonObject.class);
ClassName minecraftConstantsCN = ClassName.get("net.minestom.server", "MinecraftConstants");
TypeSpec.Builder constantsInterface = TypeSpec.interfaceBuilder(minecraftConstantsCN)
.addJavadoc("AUTOGENERATED by " + getClass().getSimpleName());

constantsInterface.addField(FieldSpec.builder(String.class, "VERSION_NAME")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer("$S", constants.get("name").getAsString())
.build()
);
constantsInterface.addField(FieldSpec.builder(TypeName.INT, "PROTOCOL_VERSION")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer("$L", constants.get("protocol").getAsInt())
.build()
);
constantsInterface.addField(FieldSpec.builder(TypeName.INT, "DATA_VERSION")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer("$L", constants.get("world").getAsInt())
.build()
);
constantsInterface.addField(FieldSpec.builder(TypeName.INT, "RESOURCE_PACK_VERSION")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer("$L", constants.get("resourcepack").getAsInt())
.build()
);
constantsInterface.addField(FieldSpec.builder(TypeName.INT, "DATA_PACK_VERSION")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer("$L", constants.get("datapack").getAsInt())
.build()
);

// Write files to outputFolder
writeFiles(
List.of(
JavaFile.builder("net.minestom.server", constantsInterface.build())
.indent(" ")
.skipJavaLangImports(true)
.build()
),
outputFolder
);
}

}
Loading