forked from Moulberry/AxiomPaperPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Moulberry:master' into master
- Loading branch information
Showing
16 changed files
with
834 additions
and
30 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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/moulberry/axiom/blueprint/BlockEntityMap.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,25 @@ | ||
package com.moulberry.axiom.blueprint; | ||
|
||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class BlockEntityMap { | ||
|
||
private static final Map<Block, BlockEntityType<?>> blockBlockEntityTypeMap = new HashMap<>(); | ||
static { | ||
for (BlockEntityType<?> blockEntityType : BuiltInRegistries.BLOCK_ENTITY_TYPE) { | ||
for (Block validBlock : blockEntityType.validBlocks) { | ||
blockBlockEntityTypeMap.put(validBlock, blockEntityType); | ||
} | ||
} | ||
} | ||
|
||
public static BlockEntityType<?> get(Block block) { | ||
return blockBlockEntityTypeMap.get(block); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/com/moulberry/axiom/blueprint/BlueprintHeader.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 com.moulberry.axiom.blueprint; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.ListTag; | ||
import net.minecraft.nbt.StringTag; | ||
import net.minecraft.nbt.Tag; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public record BlueprintHeader(String name, String author, List<String> tags, float thumbnailYaw, float thumbnailPitch, boolean lockedThumbnail, int blockCount) { | ||
|
||
private static final int CURRENT_VERSION = 0; | ||
|
||
public void write(FriendlyByteBuf friendlyByteBuf) { | ||
friendlyByteBuf.writeUtf(this.name); | ||
friendlyByteBuf.writeUtf(this.author); | ||
friendlyByteBuf.writeCollection(this.tags, FriendlyByteBuf::writeUtf); | ||
friendlyByteBuf.writeInt(this.blockCount); | ||
} | ||
|
||
public static BlueprintHeader read(FriendlyByteBuf friendlyByteBuf) { | ||
String name = friendlyByteBuf.readUtf(); | ||
String author = friendlyByteBuf.readUtf(); | ||
List<String> tags = friendlyByteBuf.readList(FriendlyByteBuf::readUtf); | ||
int blockCount = friendlyByteBuf.readInt(); | ||
return new BlueprintHeader(name, author, tags, 0, 0, true, blockCount); | ||
} | ||
|
||
public static BlueprintHeader load(CompoundTag tag) { | ||
long version = tag.getLong("Version"); | ||
String name = tag.getString("Name"); | ||
String author = tag.getString("Author"); | ||
float thumbnailYaw = tag.contains("ThumbnailYaw", Tag.TAG_FLOAT) ? tag.getFloat("ThumbnailYaw") : 135; | ||
float thumbnailPitch = tag.contains("ThumbnailPitch", Tag.TAG_FLOAT) ? tag.getFloat("ThumbnailPitch") : 30; | ||
boolean lockedThumbnail = tag.getBoolean("LockedThumbnail"); | ||
int blockCount = tag.getInt("BlockCount"); | ||
|
||
List<String> tags = new ArrayList<>(); | ||
for (Tag string : tag.getList("Tags", Tag.TAG_STRING)) { | ||
tags.add(string.getAsString()); | ||
} | ||
|
||
return new BlueprintHeader(name, author, tags, thumbnailYaw, thumbnailPitch, lockedThumbnail, blockCount); | ||
} | ||
|
||
public CompoundTag save(CompoundTag tag) { | ||
ListTag listTag = new ListTag(); | ||
for (String string : this.tags) { | ||
listTag.add(StringTag.valueOf(string)); | ||
} | ||
|
||
tag.putLong("Version", CURRENT_VERSION); | ||
tag.putString("Name", this.name); | ||
tag.putString("Author", this.author); | ||
tag.put("Tags", listTag); | ||
tag.putFloat("ThumbnailYaw", this.thumbnailYaw); | ||
tag.putFloat("ThumbnailPitch", this.thumbnailPitch); | ||
tag.putBoolean("LockedThumbnail", this.lockedThumbnail); | ||
tag.putInt("BlockCount", this.blockCount); | ||
return tag; | ||
} | ||
|
||
} |
Oops, something went wrong.