Skip to content

Commit

Permalink
[ci skip] Port to NeoForge 24w14a
Browse files Browse the repository at this point in the history
Signed-off-by: shedaniel <[email protected]>
  • Loading branch information
shedaniel committed Apr 9, 2024
1 parent d19cb9a commit 4e15fa3
Show file tree
Hide file tree
Showing 88 changed files with 5,190 additions and 568 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ subprojects {

repositories {
maven { url "https://maven.neoforged.net/releases/" }
if (rootProject.neoforge_pr != "") {
maven {
url "https://prmaven.neoforged.net/NeoForge/pr$rootProject.neoforge_pr"
content {
includeModule("net.neoforged", "neoforge")
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public interface LootEvent {
*
* <h2>Example: adding diamonds as a drop for dirt</h2>
* <pre>{@code
* LootEvent.MODIFY_LOOT_TABLE.register((lootTables, id, context, builtin) -> {
* LootEvent.MODIFY_LOOT_TABLE.register((key, context, builtin) -> {
* // Check that the loot table is dirt and built-in
* if (builtin && Blocks.DIRT.getLootTable().equals(id)) {
* if (builtin && Blocks.DIRT.getLootTable().equals(key)) {
* // Create a loot pool with a single item entry of Items.DIAMOND
* LootPool.Builder pool = LootPool.lootPool().add(LootItem.lootTableItem(Items.DIAMOND));
* context.addPool(pool);
Expand All @@ -58,7 +58,7 @@ public interface LootEvent {
*
* @see ModifyLootTable#modifyLootTable(ResourceKey, LootTableModificationContext, boolean)
*/
// Event<ModifyLootTable> MODIFY_LOOT_TABLE = EventFactory.createLoop();
Event<ModifyLootTable> MODIFY_LOOT_TABLE = EventFactory.createLoop();

@FunctionalInterface
interface ModifyLootTable {
Expand Down
145 changes: 46 additions & 99 deletions common/src/main/java/dev/architectury/fluid/FluidStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package dev.architectury.fluid;

import com.google.common.collect.Iterators;
import com.mojang.serialization.Codec;
import dev.architectury.hooks.fluid.FluidStackHooks;
import dev.architectury.injectables.annotations.ExpectPlatform;
Expand All @@ -35,7 +34,8 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
Expand Down Expand Up @@ -66,100 +66,6 @@ private static FluidStackAdapter<Object> adapt(Function<FluidStack, Object> toVa
throw new AssertionError();
}

@Override
public DataComponentMap getComponents() {
return new DataComponentMap() {
@Nullable
@Override
public <T> T get(DataComponentType<? extends T> type) {
return getPatch().get(type).orElse(null);
}

@Override
public Set<DataComponentType<?>> keySet() {
return new AbstractSet<>() {
@Override
public Iterator<DataComponentType<?>> iterator() {
return Iterators.transform(getPatch().entrySet().iterator(), Map.Entry::getKey);
}

@Override
public int size() {
return getPatch().entrySet().size();
}

@Override
public boolean contains(Object o) {
if (!(o instanceof DataComponentType<?> type)) return false;
return getPatch().get(type).isPresent();
}
};
}
};
}

public <T> T set(DataComponentType<? super T> dataComponentType, @Nullable T object) {
T previous = (T) get(dataComponentType);
DataComponentPatch.Builder builder = DataComponentPatch.builder();
for (TypedDataComponent<?> component : getComponents()) {
if (component.type() != dataComponentType) {
builder.set(component);
}
}
if (object != null) {
builder.set(dataComponentType, object);
}
setPatch(builder.build());
return previous;
}

@Nullable
public <T, U> T update(DataComponentType<T> dataComponentType, T object, U object2, BiFunction<T, U, T> biFunction) {
return this.set(dataComponentType, biFunction.apply(this.getOrDefault(dataComponentType, object), object2));
}

@Nullable
public <T> T update(DataComponentType<T> dataComponentType, T object, UnaryOperator<T> unaryOperator) {
return this.set(dataComponentType, unaryOperator.apply(this.getOrDefault(dataComponentType, object)));
}

@Nullable
public <T> T remove(DataComponentType<? extends T> dataComponentType) {
return this.set(dataComponentType, null);
}

public void applyComponents(DataComponentPatch dataComponentPatch) {
DataComponentPatch.Builder builder = DataComponentPatch.builder();
for (TypedDataComponent<?> component : getComponents()) {
builder.set(component);
}
for (Map.Entry<DataComponentType<?>, Optional<?>> entry : dataComponentPatch.entrySet()) {
if (entry.getValue().isPresent()) {
//noinspection rawtypes
builder.set((DataComponentType) entry.getKey(), entry.getValue().get());
} else {
builder.remove(entry.getKey());
}
}
setPatch(builder.build());
}

public void applyComponents(DataComponentMap dataComponentMap) {
DataComponentPatch.Builder builder = DataComponentPatch.builder();
for (TypedDataComponent<?> component : getComponents()) {
builder.set(component);
}
for (TypedDataComponent<?> entry : dataComponentMap) {
if (entry.value() != null) {
//noinspection rawtypes
builder.set((DataComponentType) entry.type(), entry.value());
} else {
builder.remove(entry.type());
}
}
setPatch(builder.build());
}

@ApiStatus.Internal
public interface FluidStackAdapter<T> {
T create(Supplier<Fluid> fluid, long amount, @Nullable DataComponentPatch patch);
Expand All @@ -174,7 +80,19 @@ public interface FluidStackAdapter<T> {

DataComponentPatch getPatch(T value);

void setPatch(T value, DataComponentPatch patch);
PatchedDataComponentMap getComponents(T value);

void applyComponents(T value, DataComponentPatch patch);

void applyComponents(T value, DataComponentMap patch);

@Nullable <D> D set(T value, DataComponentType<? super D> type, @Nullable D component);

@Nullable <D> D remove(T value, DataComponentType<? extends D> type);

@Nullable <D> D update(T value, DataComponentType<D> type, D component, UnaryOperator<D> updater);

@Nullable <D, U> D update(T value, DataComponentType<D> type, D component, U updateContext, BiFunction<D, U, D> updater);

T copy(T value);

Expand Down Expand Up @@ -260,8 +178,37 @@ public DataComponentPatch getPatch() {
return ADAPTER.getPatch(value);
}

public void setPatch(DataComponentPatch patch) {
ADAPTER.setPatch(value, patch);
@Override
public PatchedDataComponentMap getComponents() {
return ADAPTER.getComponents(value);
}

public void applyComponents(DataComponentPatch patch) {
ADAPTER.applyComponents(value, patch);
}

public void applyComponents(DataComponentMap patch) {
ADAPTER.applyComponents(value, patch);
}

@Nullable
public <T> T set(DataComponentType<? super T> type, @Nullable T component) {
return ADAPTER.set(value, type, component);
}

@Nullable
public <T> T remove(DataComponentType<? extends T> type) {
return ADAPTER.remove(value, type);
}

@Nullable
public <T> T update(DataComponentType<T> type, T component, UnaryOperator<T> updater) {
return ADAPTER.update(value, type, component, updater);
}

@Nullable
public <T, U> T update(DataComponentType<T> type, T component, U updateContext, BiFunction<T, U, T> updater) {
return ADAPTER.update(value, type, component, updateContext, updater);
}

public Component getName() {
Expand Down
Loading

0 comments on commit 4e15fa3

Please sign in to comment.