Skip to content

Commit

Permalink
Simplify factory-to-callback methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jun 20, 2020
1 parent b07adcc commit ce9e034
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ public interface ChunkComponentCallback extends ComponentCallback<Chunk, Copyabl

@ApiStatus.Experimental
static <C extends Component> void register(ComponentType<C> type, ChunkComponentFactory<? extends C> factory) {
EVENT.register((chunk, components) -> {
CopyableComponent<?> cc = factory.createForChunk(chunk);
if (cc != null) {
components.put(type, cc);
}
});
EVENT.register((chunk, components) -> components.put(type, factory.createForChunk(chunk)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,7 @@ static <E extends Entity> Event<EntityComponentCallback<E>> event(Class<E> clazz

@ApiStatus.Experimental
static <C extends Component, E extends Entity> void register(ComponentType<C> type, Class<E> targetClass, EntityComponentFactory<C, E> factory) {
event(targetClass).register((entity, components) -> {
C c = factory.createForEntity(entity);
if (c != null) {
components.put(type, c);
}
});
event(targetClass).register((entity, components) -> components.put(type, factory.createForEntity(entity)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ static Event<ItemComponentCallback> event(@Nullable Item item) {

@ApiStatus.Experimental
static <C extends Component> void register(ComponentType<C> type, @Nullable Item item, ItemComponentFactory<? extends C> factory) {
event(item).register((stack, components) -> {
CopyableComponent<?> cc = factory.createForStack(stack);
if (cc != null) {
components.put(type, cc);
}
});
event(item).register((stack, components) -> components.put(type, factory.createForStack(stack)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ static Event<ItemComponentCallbackV2> event(@Nullable Item item) {
@ApiStatus.Experimental
static <C extends Component> void register(ComponentType<C> type, @Nullable Item item, ItemComponentFactoryV2<? extends C> factory) {
event(item).register((it, stack, components) -> {
CopyableComponent<?> cc = factory.createForStack(it, stack);
if (cc != null) {
components.put(type, cc);
}
components.put(type, factory.createForStack(it, stack));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import net.minecraft.world.WorldProperties;
import org.jetbrains.annotations.ApiStatus;

import javax.annotation.Nullable;
import javax.annotation.Nonnull;

/**
* A component factory for {@linkplain WorldProperties world saves}.
Expand All @@ -45,6 +45,6 @@ public interface LevelComponentFactory<C extends Component> {
*
* @param properties the {@code WorldProperties} being constructed
*/
@Nullable
@Nonnull
C createForSave(WorldProperties properties);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ public interface LevelComponentCallback extends ComponentCallback<WorldPropertie

@ApiStatus.Experimental
static <C extends Component> void register(ComponentType<C> type, LevelComponentFactory<C> factory) {
EVENT.register((level, components) -> {
Component c = factory.createForSave(level);
if (c != null) {
components.put(type, c);
}
});
EVENT.register((level, components) -> components.put(type, factory.createForSave(level)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ public interface WorldComponentCallback extends ComponentCallback<World, Compone
});

static <C extends Component> void register(ComponentType<C> type, WorldComponentFactory<C> factory) {
EVENT.register((world, components) -> {
C c = factory.createForWorld(world);
if (c != null) {
components.put(type, c);
}
});
EVENT.register((world, components) -> components.put(type, factory.createForWorld(world)));
}

/**
Expand Down

0 comments on commit ce9e034

Please sign in to comment.