Commit graph

89 commits

Author SHA1 Message Date
modmuss50
9ff28f4026
Split client only code into its own sourceset. (#2179)
A common source of crashes on modded Minecraft servers comes from modders accidently calling client only code from the client, this PR is another large step towards elimitating that.

This PR has been months in the making and years in the planning, requiring major changes to Loom & Loader. In recent Minecraft versions Mojang has made it easier than ever to cleanly split the jar, going against the status-quo of merging the client and server into one jar.

From the start we have designed Fabric to have a very clear split between client and common (client & server) code. Fabric has always encoraged keeping client only code seprate from the server, this can be seen at a fundamental level with the entrypoints in Loader. Fabric API's have all been designed with this mind.

This PR provides a compile safety net around Fabric API using client only code on the server. Even though there are almost 400 changed files, minimal changes beyond moving the files were required to achieve this in Fabric API, thanks to the effort of all contributors in the past.

These changes should not affect modders or players in anyway, a single "universal" jar is still produced. Im happy to awnswer any questions.
2022-05-21 16:26:46 +01:00
Technici4n
3572ae8d5f Fix #2164: Transfer API performance issues (#2189)
* Fix #2164: Transfer API performance issue

* Cache ItemStack in ItemVariantImpl

* Fix checkstyle

* Fix #2201

* Update comment in getCachedStack()

(cherry picked from commit f4563ac81e)
2022-05-20 18:21:50 +01:00
modmuss50
56447d9b95 22w17a 2022-04-27 20:48:57 +01:00
Technici4n
50e8465e2e
Transfer API improvements and breaking changes for 1.19 (#2139)
* Remove deprecated APIs

* Remove the transaction requirement for storage iteration

* Remove useless TransactionContext parameters in StorageUtil

* Improve SnapshotParticipant javadoc

* Fix tests

* Allow client-side SIDED item/fluid storage queries with a few caveats

* Add SidedStorageBlockEntity for easier block entity hierarchy registration
2022-04-27 18:38:29 +01:00
modmuss50
ec94c6f636
22w16b
Co-authored-by: Player <player@player.to>
2022-04-20 22:22:10 +01:00
modmuss50
0c7c3953f9 Merge remote-tracking branch 'origin/1.18.2' into 1.19 2022-04-10 17:20:49 +01:00
Technici4n
2373a54507 Transfer API improvements 3
- **(Slightly source-breaking change)** Change the return type of `Storage#iterator` and `Storage#iterable` from `Iterator<StorageView<T>>` to `Iterator<? extends StorageView<T>>` to allow returning a list directly. Most modders shouldn't be affected by this (this only broke one call site in the whole module).
- Precise that using the iterator or a view after the transaction is closed is "undefined behavior". Also specify that calling remove on the iterator is not allowed.
- Add `StorageView#getUnderlyingView` to be able to tell if some views are equal. This is useful to **compute the contents of multiple storage views without duplicates** (see testmod).
- Expose the lifecycle of the transaction manager cleanly with an enum.
- Definalize some methods in `SingleStackStorage` to allow custom implementations of some of them if needed.
- Add a note to `BlockApiLookup` to fix #1998.
- Play the composter empty sound when it is emptied through the transfer API, as a comment in the source code suggests.

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>
2022-04-10 16:42:38 +01:00
Technici4n
dbb7b03f94
Add common (client/server) FluidVariant attributes (#2095)
* Add common (client/server) FluidVariant properties

* Remove density, move constants to FluidConstants, javadoc

* Javadoc, downgrade exception to LOGGER.warn

* attributes -> properties

* Property -> attribute

* Apply reviews

* Use optional sounds, mix into BucketItem

* Automatically implement Fluid#getBucketFillSound from the attribute

* Update fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/fluid/FluidConstants.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Tests, a few fixes

* Add gametest for viscosity, isLighterThanAir -> flowsUpwards

* flowsUpwards -> isLighterThanAir

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>
2022-04-10 16:27:13 +01:00
deirn
82a21997c3
Change PlayerInventoryStorage#drop to use PlayerEntity#dropItem (#2098)
* change `PlayerInventoryStorage#drop` to use `PlayerEntity#dropItem`

* at -> from

* remainder
2022-04-10 16:27:07 +01:00
modmuss50
717abbc48a 22w14a 2022-04-06 21:49:45 +01:00
modmuss50
a67d2aa505 22w12a 2022-03-24 20:18:23 +00:00
Technici4n
cca23f938e Fix #1912 and #1972: inventory updates in transactions (#1979) 2022-03-03 18:15:40 +00:00
modmuss50
d882b91555
Port to 22w06a (#1989)
This snapshot is possibly one of the most impactful for API we have ever had. This PR is an inital port to support 22w06a, stuff will be missing and broken. 

# Removed modules:
- fabric-mining-levels-v0 - Previously deprecated
- fabric-object-builders-v0 - Previously deprecated
- fabric-tag-extensions-v0
- fabric-tool-attribute-api-v1

# Modules with API breaking changes:
- fabric-biome-api-v1
- fabric-content-registries-v0
- fabric-data-generation-api-v1
- fabric-mining-level-api-v1
- fabric-object-builder-api-v1
- fabric-resource-conditions-api-v1
- fabric-structure-api-v1

# Impactful API changes:
### fabric-object-builder-api-v1
- Removed - FabricBlockSettings.breakByHand
- Removed - FabricBlockSettings.breakByTool  - Previously deprecated

# Notable changes

- fabric-registry-sync-v0 moves vanilla's new registry freezing to a later point in time, allowing mods to add to the registry during init.

# Known issues:
- ServerBugfixMixin used to fix https://bugs.mojang.com/browse/MC-195468 has not yet been ported.
2022-02-11 17:02:44 +00:00
modmuss50
d7c144a830
Migrate to SLF4j and update loom (#1960)
* Migrate to SLF4j and update loom

* Update loom

* Update to latest loom
2022-01-30 21:37:23 +00:00
modmuss50
b4f4f6cda4 Update Loom and Loader. Cleanup/improve buildscript. 2021-11-12 15:02:54 +00:00
modmuss50
c3150579ea Bump version 2021-11-06 20:31:21 +00:00
modmuss50
65d505fc8a Bump versions
All of the version need to be bumped due to fabric-api-base being updated, this highlights the need for a better solution.
2021-11-05 17:09:48 +00:00
Technici4n
d4df60101d Another wave of transfer API improvements (#1801)
* Another wave of transfer API improvements

* Cleaner implementation of FilteringStorage#...Of

* Undo colored name for water and lava variants
2021-11-05 15:53:07 +00:00
modmuss50
e14f9c8f05 21w44a 2021-11-03 18:57:29 +00:00
modmuss50
168f4a3be2 Bump version 2021-10-31 11:13:10 +00:00
modmuss50
edf35c6176 Make dimension API stable. Remove usage of @Deprecated for experimental modules. 2021-10-31 10:59:59 +00:00
modmuss50
0b944752fc 21w43a 2021-10-27 20:48:33 +01:00
modmuss50
c683a6555f Bump version 2021-10-07 13:02:52 +01:00
Technici4n
396dbf1cf1 Transfer API: bugfixes and improvements (#1762)
* Fix SingleVariantItemStorage extraction bug

* Inventory wrappers: reuse the original stack more aggressively

* Add some filtered overloads to StorageUtil methods

* Override PlayerInventoryStorage#insert to call #offer

* Add small comment regarding predicates
2021-10-07 12:29:07 +01:00
modmuss50
46582230fb Bump version 2021-09-09 19:28:18 +01:00
Technici4n
86bae2c0e9
Work around vanilla capturing ItemStack references (#1700) 2021-09-09 18:47:06 +01:00
modmuss50
fc40aa9d88 Bump version 2021-09-01 18:57:12 +01:00
Technici4n
9f7c50187c
Transfer API: continuous fluid-containing items and other base implementations. (#1665)
* Transfer API: continuous fluid-containing items and other base implementations

* Update player inventory storage TODO

* Add PlayerInventoryStorage test

* getHandSlot() and small fixes

* Use simulateExtract in findExtractableContent

* Apply review

* Post-rebase fixes

* Add tentative InventoryProvider support

Co-authored-by: Player <player@player.to>
2021-09-01 12:23:34 +01:00
modmuss50
cbda9318cd
Update Gradle/Loom and mappings. (#1692)
* Update Gradle/Loom and mappings.

* Fix deprecations and enforce

* Review feedback

* More cleanup and deprecation fixes.
2021-08-31 14:00:20 +01:00
Technici4n
49e84ad51a
Add Transaction#getCurrentUnsafe and fix mixin fields (#1685)
* Add Transaction#getCurrentUnsafe and fix mixin fields

* Update fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/impl/transfer/transaction/TransactionManagerImpl.java

Co-authored-by: BasiqueEvangelist <basiqueevangelist@yandex.ru>

Co-authored-by: BasiqueEvangelist <basiqueevangelist@yandex.ru>
2021-08-31 13:59:58 +01:00
Technici4n
96bf6a7e71
Allow fluid variant colors to depend on the position (#1620)
* Allow fluid variant colors to depend on the position

Also add a smarter FluidVariantRendering#getTooltip.

* Add fluid variant rendering testmod

* 255/256 is not 1

* Actually it's in the top left
2021-08-24 17:43:59 +01:00
modmuss50
8195aec1e2 Bump version 2021-08-21 20:29:23 +01:00
Technici4n
a9bcdbef6a
Reorganize transfer API testmod and rework item api injections (#1652)
* Reorganize the transer API testmod

* Rework mixins. Closes #1649.
2021-08-21 18:33:23 +01:00
modmuss50
0b4433eeba Bump version 2021-08-20 12:14:05 +01:00
Technici4n
a6db925daf
Fix droppers deleting items when they fail to insert (#1646) (#1647) 2021-08-20 12:01:43 +01:00
modmuss50
3fe74aa162 Bump version 2021-08-18 18:39:11 +01:00
Technici4n
0d7a4ee070
Fabric Transfer API: item transfer and fluid-containing items. (#1553)
* Add item and "fluid item" APIs

* Rework ContainerItemContext javadoc

* Rework the Inventory wrapper API

* Cleanup inventory wrapper implementation, add < 64 max stack count test, separate tests better

* Fix Inventory wrapper not limiting the stack count correctly (thanks @lilybeevee!)

* Rewrite inventory wrapper, add SingleStackStorage base implementation

* Composters

* SingleStackStorage adjustements

* Bump version

* Move icon to correct location. Closes #1565

* Bump version

* Remove composter implementation (it's broken), slight renames

* Fix SidedInventory extract

* Bump version

* Don't use MAVEN_USERNAME if it's not specified

* Add comparator output, add missing markDirty calls, fix tests

* Bump version

* Add SingleVariantStorage, deprecate SingleFluidStorage, definalize a few things, make sure markDirty() is only called once per successful outer transaction in inventory wrappers

* Add composter support

* Move EmptyFluidView to BlankVariantView, update README and package-info

* Bump version

* Key -> variant

* Add Transaction#openNested(@Nullable TransactionContext)

* Add SingleSlotContainerItemContext

* Bump prerelease version

* Remove useless comment

* Remove ContainerItemContext#getWorld

* Bump prerelease version

* Add StorageUtil#findExtractableContent and ContainerItemContext#withInitial

* Bump prerelease version
2021-08-17 19:08:09 +01:00
modmuss50
3fe3c3f50c Bump version 2021-07-12 19:25:45 +01:00
Technici4n
c09be4c48a
Fabric Transfer API: "fluid only" edition (#1356)
* Original fluid API design

* Rework the transaction system

* First javadoc pass

* Add a testmod, a base implementation for fluid storages and fix some little bugs

* Fix checkstyle

* Make Movement#move extract from the view and not the whole Storage

* Document and update FluidPreconditions

* Use for-each in CombinedStorage and document a little

* Remove useless overrides in Insertion/ExtractionOnlyStorage

* Move SnapshotParticipant#snapshots to the top of the class, and make updateSnapshots public

* Fix garbage collection of unused CauldronWrappers

* Use ArrayList directly

* Remove locking, reorganize transaction implementation, and add outer close callback

* Add more javadoc

* Rework Storage#forEach into Storage#iterator

* Add a few missing `transaction.addCloseCallback(iterator)`

* Add anyView(), exactView(), capacity() and isEmpty()

* Add Storage#iterable to make iteration friendlier to for loops

* Storages may now have multiple open iterators

Co-authored-by: Devan-Kerman <dev.sel20@gmail.com>

* Make CombinedStorage#supportsInsertion/Extraction iterate through the parts

* Block updates should be used when the supportsInsertion/Extraction status changes

* Fluid -> FluidKey

* Remove all references to ItemKey inside FluidKey, and other minor tweaks

* Cache FluidKeys with a null tag inside Fluid directly

* Fluid unit convention

* Add FluidKeyRendering and RenderHandler

* Bump version for more testing (also published to my maven)

* Add SingleViewIterator, massively reduce code duplication!

* Make API experimental, and add README

* Bump version

* Apparently Fluids.EMPTY is flowing

* Add package info

* Minor adjustements

* 1.17 port, cauldron support, add ResourceKey

* Checkstyle, gas rendering, use record for ResourceAmount

* Add a few helpers, rename some stuff

* Remove anyView, allow nullable in StorageUtil#find*, fix missing try block

* Slight findStoredResource cleanup

* Slightly improve implementation

* Bump version

* Fix wrong transaction

* I wrote in a comment that this could happen...

* Fix SingleFluidStorage bugs, add tests in the testmod, add testmod assets

* Add extract stick

* Rename a few things

* `ResourceKey<T>` -> `TransferKey<O>`
* `ResourceKey#getResource()` -> `TransferKey#getObject()` as resource is already widely used through the API for the keys themselves.
* `tag` -> `nbt`
* Add `get` prefixes to `StorageView` functions

* Bump version

* FluidKey -> FluidVariant

* Bump version

* Expand getVersion() documentation, make it thread-safe and use long.

Co-authored-by: Player <player@player.to>

* empty resource -> blank resource, and update SingleFluidStorage

Co-authored-by: Player <player@player.to>

* Make CauldronFluidContent a final class instead of a record.

Co-authored-by: Player <player@player.to>

* Get rid of CauldronFluidContent#minLevel (was always 1)

* Fix nested commits. (Thanks @warjort!)

* Separate Transaction and TransactionContext

Co-authored-by: Devan-Kerman <dev.sel20@gmail.com>
Co-authored-by: Player <player@player.to>

* Change WorldLocation into a private record

* Bump version

* Guard against exceptions thrown in close callbacks

* Make sure blank fluid variants don't have a tag

* Add documentation, make CauldronStorage clearer

Co-authored-by: frqnny <45723631+frqnny@users.noreply.github.com>

* Allow null storages in StorageUtil#move, and clarify sidedness of FluidStorage

* Add explicit hashCode and equals for transfer variants

* Remove ugly equals and hashCode overrides, and add constant time hashcode spec

Co-authored-by: Devan-Kerman <dev.sel20@gmail.com>
Co-authored-by: liach <liach@users.noreply.github.com>
Co-authored-by: Player <player@player.to>
Co-authored-by: frqnny <45723631+frqnny@users.noreply.github.com>
2021-07-12 18:28:33 +01:00