-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07cf685
commit 1c33dd3
Showing
11 changed files
with
91 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
winterly-fabric/src/main/java/ru/pinkgoosik/winterly/fabric/data/WinterlyAttachedData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package ru.pinkgoosik.winterly.fabric.data; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Maps; | ||
import com.mojang.serialization.Codec; | ||
import net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry; | ||
import net.fabricmc.fabric.api.attachment.v1.AttachmentType; | ||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import org.jetbrains.annotations.Nullable; | ||
import ru.pinkgoosik.winterly.Winterly; | ||
import ru.pinkgoosik.winterly.data.CachedFlowers; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class WinterlyAttachedData { | ||
public static final AttachmentType<Map<String, String>> CACHED_FLOWERS = AttachmentRegistry.createPersistent(Winterly.id("cached_flowers"), Codec.unboundedMap(Codec.STRING, Codec.STRING)); | ||
|
||
public static void init() { | ||
ServerChunkEvents.CHUNK_LOAD.register((world, chunk) -> { | ||
var map = chunk.getAttached(CACHED_FLOWERS); | ||
|
||
if(map != null) { | ||
if(map instanceof ImmutableMap<String, String>) { | ||
chunk.setAttached(CACHED_FLOWERS, Maps.newLinkedHashMap(map)); | ||
} | ||
} | ||
}); | ||
|
||
CachedFlowers.instance = new CachedFlowers() { | ||
@Override | ||
public @Nullable Block getFlowerImpl(Level world, BlockPos pos) { | ||
var map = world.getChunkAt(pos).getAttached(CACHED_FLOWERS); | ||
if(map != null) { | ||
var block = map.get(pos.toShortString()); | ||
if(block != null) return BuiltInRegistries.BLOCK.get(ResourceLocation.parse(block)); | ||
} | ||
else { | ||
world.getChunkAt(pos).setAttached(CACHED_FLOWERS, new LinkedHashMap<String, String>()); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void cacheFlowerImpl(Level world, BlockPos pos, Block flower) { | ||
Map<String, String> map = world.getChunkAt(pos).getAttached(CACHED_FLOWERS); | ||
|
||
if(map != null) { | ||
map.put(pos.toShortString(), BuiltInRegistries.BLOCK.getKey(flower).toString()); | ||
} | ||
else { | ||
map = new LinkedHashMap<>(); | ||
map.put(pos.toShortString(), BuiltInRegistries.BLOCK.getKey(flower).toString()); | ||
world.getChunkAt(pos).setAttached(CACHED_FLOWERS, map); | ||
} | ||
|
||
} | ||
}; | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
winterly-fabric/src/main/java/ru/pinkgoosik/winterly/fabric/data/WinterlyComponents.java
This file was deleted.
Oops, something went wrong.
60 changes: 0 additions & 60 deletions
60
winterly-fabric/src/main/java/ru/pinkgoosik/winterly/fabric/data/WorldData.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 5 additions & 10 deletions
15
...rly-neoforge/src/main/java/ru/pinkgoosik/winterly/neoforge/registry/WinterlyFeatures.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,15 @@ | ||
package ru.pinkgoosik.winterly.neoforge.registry; | ||
|
||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.world.level.levelgen.feature.Feature; | ||
import net.neoforged.bus.api.IEventBus; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
import net.neoforged.neoforge.registries.RegisterEvent; | ||
import ru.pinkgoosik.winterly.Winterly; | ||
import ru.pinkgoosik.winterly.worldgen.CryomarbleFeature; | ||
import ru.pinkgoosik.winterly.worldgen.UndergroundIcicleFeature; | ||
|
||
public class WinterlyFeatures { | ||
|
||
public static final DeferredRegister<Feature<?>> REGISTERER = DeferredRegister.create(BuiltInRegistries.FEATURE, "winterly"); | ||
|
||
public static void init(IEventBus eventBus) { | ||
REGISTERER.register("underground_icicle", UndergroundIcicleFeature::new); | ||
REGISTERER.register("cryomarble", CryomarbleFeature::new); | ||
|
||
REGISTERER.register(eventBus); | ||
public static void init(RegisterEvent.RegisterHelper<Feature<?>> registry) { | ||
registry.register(Winterly.id("underground_icicle"), new UndergroundIcicleFeature()); | ||
registry.register(Winterly.id("cryomarble"), new CryomarbleFeature()); | ||
} | ||
} |