Skip to content

Commit 209b77e

Browse files
committed
Initial port to 1.17.1
1 parent 498fdb5 commit 209b77e

File tree

124 files changed

+1474
-1651
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1474
-1651
lines changed

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group=net.darkhax.bookshelf
2-
version=10.2
2+
version=11.0
33

44
mod_name=Bookshelf
55
mod_author=Darkhax
@@ -9,10 +9,10 @@ mod_source=https://github.com/Darkhax-Minecraft/Bookshelf
99
mod_issues=https://github.com/Darkhax-Minecraft/Bookshelf/issues
1010
mod_description=A library for building other mods.
1111

12-
minecraft_version=1.16.5
12+
minecraft_version=1.17.1
1313

1414
# ForgeGradle properties (gradle/forge.gradle)
15-
forge_version=36.2.2
15+
forge_version=37.0.22
1616
forge_at=src/main/resources/META-INF/accesstransformer.cfg
1717

1818
# CurseForge properties (gradle/curseforge.gradle)

gradle/forge.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ processResources {
160160

161161
def buildProps = project.properties.clone()
162162

163+
// When patreon data is available add credits and supporter info.
163164
if (project.ext.has('patreon') && project.ext.patreon.pledges && !project.ext.patreon.pledges.isEmpty()) {
164165

165166
def supporters = new ArrayList<String>()
@@ -177,6 +178,10 @@ processResources {
177178
buildProps.put('modCredits', "${project.ext.modCredits} and the supporters on Patreon: ${supporters.join(', ')}")
178179
}
179180

181+
// Replaces FML's magic file.jarVersion string with the correct version at
182+
// build time.
183+
buildProps.put('file', [jarVersion: project.version])
184+
180185
filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
181186

182187
expand buildProps

gradle/java.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ java {
1010
withJavadocJar()
1111

1212
// Set minimum language version.
13-
toolchain.languageVersion = JavaLanguageVersion.of(8)
13+
toolchain.languageVersion = JavaLanguageVersion.of(16)
1414
}
1515

1616
javadoc {

src/main/java/net/darkhax/bookshelf/Bookshelf.java

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@
5252
import net.darkhax.bookshelf.loot.modifier.ModifierRecipe;
5353
import net.darkhax.bookshelf.loot.modifier.ModifierSilkTouch;
5454
import net.darkhax.bookshelf.registry.RegistryHelper;
55-
import net.minecraft.advancements.criterion.ItemPredicate;
56-
import net.minecraft.command.arguments.ArgumentSerializer;
57-
import net.minecraft.enchantment.EnchantmentType;
58-
import net.minecraft.item.AxeItem;
59-
import net.minecraft.item.HoeItem;
60-
import net.minecraft.item.PickaxeItem;
61-
import net.minecraft.item.ShearsItem;
62-
import net.minecraft.item.ShovelItem;
63-
import net.minecraft.item.SwordItem;
64-
import net.minecraft.loot.LootConditionType;
65-
import net.minecraft.util.ResourceLocation;
55+
import net.minecraft.advancements.critereon.ItemPredicate;
56+
import net.minecraft.commands.synchronization.EmptyArgumentSerializer;
57+
import net.minecraft.world.item.enchantment.EnchantmentCategory;
58+
import net.minecraft.world.item.AxeItem;
59+
import net.minecraft.world.item.HoeItem;
60+
import net.minecraft.world.item.PickaxeItem;
61+
import net.minecraft.world.item.ShearsItem;
62+
import net.minecraft.world.item.ShovelItem;
63+
import net.minecraft.world.item.SwordItem;
64+
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
65+
import net.minecraft.resources.ResourceLocation;
6666
import net.minecraftforge.common.ToolType;
6767
import net.minecraftforge.fml.common.Mod;
6868
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@@ -86,19 +86,19 @@ public final class Bookshelf {
8686

8787
private final RegistryHelper registry = new RegistryHelper(MOD_ID, LOG);
8888

89-
public final LootConditionType conditionIsMob;
90-
public final LootConditionType conditionCheckVillage;
91-
public final LootConditionType conditionCheckStructure;
92-
public final LootConditionType conditionCheckSlimeChunk;
93-
public final LootConditionType conditionCheckRarity;
94-
public final LootConditionType conditionCheckRaid;
95-
public final LootConditionType conditionCheckPower;
96-
public final LootConditionType conditionCheckItem;
97-
public final LootConditionType conditionCheckHarvestLevel;
98-
public final LootConditionType conditionCheckEnergy;
99-
public final LootConditionType conditionCheckEnchantability;
100-
public final LootConditionType conditionCheckBiomeTag;
101-
public final LootConditionType conditionCheckDimension;
89+
public final LootItemConditionType conditionIsMob;
90+
public final LootItemConditionType conditionCheckVillage;
91+
public final LootItemConditionType conditionCheckStructure;
92+
public final LootItemConditionType conditionCheckSlimeChunk;
93+
public final LootItemConditionType conditionCheckRarity;
94+
public final LootItemConditionType conditionCheckRaid;
95+
public final LootItemConditionType conditionCheckPower;
96+
public final LootItemConditionType conditionCheckItem;
97+
public final LootItemConditionType conditionCheckHarvestLevel;
98+
public final LootItemConditionType conditionCheckEnergy;
99+
public final LootItemConditionType conditionCheckEnchantability;
100+
public final LootItemConditionType conditionCheckBiomeTag;
101+
public final LootItemConditionType conditionCheckDimension;
102102

103103
public Bookshelf () {
104104

@@ -107,8 +107,8 @@ public Bookshelf () {
107107

108108
// Command arguments
109109
this.registry.commands.registerCommandArgument("enum", ArgumentTypeHandOutput.class, new ArgumentTypeHandOutput.Serialzier());
110-
this.registry.commands.registerCommandArgument("mod", ArgumentTypeMod.class, new ArgumentSerializer<>( () -> ArgumentTypeMod.INSTACE));
111-
this.registry.commands.registerCommandArgument("loot", ArgumentTypeLootTable.class, new ArgumentSerializer<>( () -> ArgumentTypeLootTable.INSTACE));
110+
this.registry.commands.registerCommandArgument("mod", ArgumentTypeMod.class, new EmptyArgumentSerializer<>( () -> ArgumentTypeMod.INSTACE));
111+
this.registry.commands.registerCommandArgument("loot", ArgumentTypeLootTable.class, new EmptyArgumentSerializer<>( () -> ArgumentTypeLootTable.INSTACE));
112112

113113
// Loot Modifier
114114
this.registry.lootModifiers.register(ModifierClear.SERIALIZER, "clear");
@@ -159,20 +159,20 @@ public Bookshelf () {
159159
this.registry.ingredients.register("any_sword", IngredientToolType.create(i -> i instanceof SwordItem, null));
160160
this.registry.ingredients.register("any_shear", IngredientToolType.create(i -> i instanceof ShearsItem, null));
161161

162-
this.registry.ingredients.register("enchant_armor", IngredientEnchantmentType.create(EnchantmentType.ARMOR));
163-
this.registry.ingredients.register("enchant_armor_feet", IngredientEnchantmentType.create(EnchantmentType.ARMOR_FEET));
164-
this.registry.ingredients.register("enchant_armor_legs", IngredientEnchantmentType.create(EnchantmentType.ARMOR_LEGS));
165-
this.registry.ingredients.register("enchant_armor_chest", IngredientEnchantmentType.create(EnchantmentType.ARMOR_CHEST));
166-
this.registry.ingredients.register("enchant_armor_head", IngredientEnchantmentType.create(EnchantmentType.ARMOR_HEAD));
167-
this.registry.ingredients.register("enchant_weapon", IngredientEnchantmentType.create(EnchantmentType.WEAPON));
168-
this.registry.ingredients.register("enchant_digger", IngredientEnchantmentType.create(EnchantmentType.DIGGER));
169-
this.registry.ingredients.register("enchant_fishing_rod", IngredientEnchantmentType.create(EnchantmentType.FISHING_ROD));
170-
this.registry.ingredients.register("enchant_trident", IngredientEnchantmentType.create(EnchantmentType.TRIDENT));
171-
this.registry.ingredients.register("enchant_breakable", IngredientEnchantmentType.create(EnchantmentType.BREAKABLE));
172-
this.registry.ingredients.register("enchant_bow", IngredientEnchantmentType.create(EnchantmentType.BOW));
173-
this.registry.ingredients.register("enchant_wearable", IngredientEnchantmentType.create(EnchantmentType.WEARABLE));
174-
this.registry.ingredients.register("enchant_crossbow", IngredientEnchantmentType.create(EnchantmentType.CROSSBOW));
175-
this.registry.ingredients.register("enchant_vanishable", IngredientEnchantmentType.create(EnchantmentType.VANISHABLE));
162+
this.registry.ingredients.register("enchant_armor", IngredientEnchantmentType.create(EnchantmentCategory.ARMOR));
163+
this.registry.ingredients.register("enchant_armor_feet", IngredientEnchantmentType.create(EnchantmentCategory.ARMOR_FEET));
164+
this.registry.ingredients.register("enchant_armor_legs", IngredientEnchantmentType.create(EnchantmentCategory.ARMOR_LEGS));
165+
this.registry.ingredients.register("enchant_armor_chest", IngredientEnchantmentType.create(EnchantmentCategory.ARMOR_CHEST));
166+
this.registry.ingredients.register("enchant_armor_head", IngredientEnchantmentType.create(EnchantmentCategory.ARMOR_HEAD));
167+
this.registry.ingredients.register("enchant_weapon", IngredientEnchantmentType.create(EnchantmentCategory.WEAPON));
168+
this.registry.ingredients.register("enchant_digger", IngredientEnchantmentType.create(EnchantmentCategory.DIGGER));
169+
this.registry.ingredients.register("enchant_fishing_rod", IngredientEnchantmentType.create(EnchantmentCategory.FISHING_ROD));
170+
this.registry.ingredients.register("enchant_trident", IngredientEnchantmentType.create(EnchantmentCategory.TRIDENT));
171+
this.registry.ingredients.register("enchant_breakable", IngredientEnchantmentType.create(EnchantmentCategory.BREAKABLE));
172+
this.registry.ingredients.register("enchant_bow", IngredientEnchantmentType.create(EnchantmentCategory.BOW));
173+
this.registry.ingredients.register("enchant_wearable", IngredientEnchantmentType.create(EnchantmentCategory.WEARABLE));
174+
this.registry.ingredients.register("enchant_crossbow", IngredientEnchantmentType.create(EnchantmentCategory.CROSSBOW));
175+
this.registry.ingredients.register("enchant_vanishable", IngredientEnchantmentType.create(EnchantmentCategory.VANISHABLE));
176176

177177
// Block Ingredients
178178
BlockIngredient.register(BlockIngredientAny.SERIALIZER, BlockIngredientAny.ID);

src/main/java/net/darkhax/bookshelf/block/DisplayableBlockState.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
import com.google.gson.JsonElement;
66
import com.google.gson.JsonObject;
77
import com.google.gson.JsonParseException;
8-
import com.mojang.blaze3d.matrix.MatrixStack;
8+
import com.mojang.blaze3d.vertex.PoseStack;
99

1010
import net.darkhax.bookshelf.serialization.ISerializer;
1111
import net.darkhax.bookshelf.serialization.Serializers;
1212
import net.darkhax.bookshelf.util.RenderUtils;
13-
import net.minecraft.block.BlockState;
14-
import net.minecraft.client.renderer.IRenderTypeBuffer;
15-
import net.minecraft.network.PacketBuffer;
16-
import net.minecraft.util.Direction;
17-
import net.minecraft.util.JSONUtils;
18-
import net.minecraft.util.math.BlockPos;
19-
import net.minecraft.util.math.vector.Vector3f;
20-
import net.minecraft.world.World;
13+
import net.minecraft.world.level.block.state.BlockState;
14+
import net.minecraft.client.renderer.MultiBufferSource;
15+
import net.minecraft.network.FriendlyByteBuf;
16+
import net.minecraft.core.Direction;
17+
import net.minecraft.util.GsonHelper;
18+
import net.minecraft.core.BlockPos;
19+
import com.mojang.math.Vector3f;
20+
import net.minecraft.world.level.Level;
2121
import net.minecraftforge.api.distmarker.Dist;
2222
import net.minecraftforge.api.distmarker.OnlyIn;
2323

@@ -84,7 +84,7 @@ public void setRenderFluid (boolean renderFluid) {
8484
}
8585

8686
@OnlyIn(Dist.CLIENT)
87-
public void render (World world, BlockPos pos, MatrixStack matrix, IRenderTypeBuffer buffer, int light, int overlay, Direction... preferredSides) {
87+
public void render (Level world, BlockPos pos, PoseStack matrix, MultiBufferSource buffer, int light, int overlay, Direction... preferredSides) {
8888

8989
matrix.pushPose();
9090
this.getScale().ifPresent(vec -> matrix.scale(vec.x(), vec.y(), vec.z()));
@@ -108,7 +108,7 @@ public DisplayableBlockState read (JsonElement json) {
108108
return new DisplayableBlockState(state, scale, offset, renderFluid);
109109
}
110110

111-
throw new JsonParseException("Expected properties to be an object. Recieved " + JSONUtils.getType(json));
111+
throw new JsonParseException("Expected properties to be an object. Recieved " + GsonHelper.getType(json));
112112
}
113113

114114
@Override
@@ -123,7 +123,7 @@ public JsonElement write (DisplayableBlockState toWrite) {
123123
}
124124

125125
@Override
126-
public DisplayableBlockState read (PacketBuffer buffer) {
126+
public DisplayableBlockState read (FriendlyByteBuf buffer) {
127127

128128
final BlockState state = Serializers.BLOCK_STATE.read(buffer);
129129
final Optional<Vector3f> scale = Serializers.VEC3F.readOptional(buffer);
@@ -133,7 +133,7 @@ public DisplayableBlockState read (PacketBuffer buffer) {
133133
}
134134

135135
@Override
136-
public void write (PacketBuffer buffer, DisplayableBlockState toWrite) {
136+
public void write (FriendlyByteBuf buffer, DisplayableBlockState toWrite) {
137137

138138
Serializers.BLOCK_STATE.write(buffer, toWrite.getState());
139139
Serializers.VEC3F.writeOptional(buffer, toWrite.getScale());

src/main/java/net/darkhax/bookshelf/block/IBookshelfBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import javax.annotation.Nullable;
44

5-
import net.minecraft.item.Item;
5+
import net.minecraft.world.item.Item;
66

77
public interface IBookshelfBlock {
88

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* This class was created by <Darkhax>. It is distributed as part of Bookshelf. You can find
3+
* the original source here: https://github.com/Darkhax-Minecraft/Bookshelf
4+
*
5+
* Bookshelf is Open Source and distributed under the GNU Lesser General Public License version
6+
* 2.1.
7+
*/
8+
package net.darkhax.bookshelf.block.blockentity;
9+
10+
import net.minecraft.core.BlockPos;
11+
import net.minecraft.world.level.ChunkPos;
12+
import net.minecraft.world.level.block.entity.BlockEntity;
13+
import net.minecraft.world.level.block.entity.BlockEntityType;
14+
import net.minecraft.world.level.block.state.BlockState;
15+
import net.minecraftforge.common.util.Lazy;
16+
17+
public abstract class BlockEntityBase extends BlockEntity {
18+
19+
/**
20+
* Lazily gets the chunk position of the block entity. Used by {@link #getChunkPos()}.
21+
*/
22+
private final Lazy<ChunkPos> chunkPos = Lazy.of( () -> new ChunkPos(this.getBlockPos()));
23+
24+
public BlockEntityBase (BlockEntityType<?> type, BlockPos pos, BlockState state) {
25+
26+
super(type, pos, state);
27+
}
28+
29+
/**
30+
* Checks if the block entity has a valid world position.
31+
* @return Whether or not the block has a valid position.
32+
*/
33+
public boolean hasPosition () {
34+
35+
return this.worldPosition != null && this.worldPosition != BlockPos.ZERO;
36+
}
37+
38+
/**
39+
* Checks if the block entity is initialized and loaded. Makes sure it has a world, position, and is in a loaded chunk.
40+
* @return Whether or not the block entity is loaded.
41+
*/
42+
public boolean isLoaded () {
43+
44+
return this.hasLevel() && this.hasPosition() && this.getLevel().isLoaded(this.getBlockPos());
45+
}
46+
47+
/**
48+
* Gets the current block state at the position of the block entity. This will lookup the state rather than using the cached value.
49+
* @return The block state that is currently at the position of the block entity.
50+
*/
51+
public BlockState getCurrentState () {
52+
53+
return this.isLoaded() ? this.getLevel().getBlockState(this.worldPosition) : null;
54+
}
55+
56+
/**
57+
* Gets the chunk position of the block entity. This will get the cached chunk position and is not serialized.
58+
* @return The block entities chunk position.
59+
*/
60+
public ChunkPos getChunkPos () {
61+
62+
return this.chunkPos.get();
63+
}
64+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* This class was created by <Darkhax>. It is distributed as part of Bookshelf. You can find
3+
* the original source here: https://github.com/Darkhax-Minecraft/Bookshelf
4+
*
5+
* Bookshelf is Open Source and distributed under the GNU Lesser General Public License version
6+
* 2.1.
7+
*/
8+
package net.darkhax.bookshelf.block.blockentity;
9+
10+
import javax.annotation.Nullable;
11+
12+
import net.darkhax.bookshelf.util.WorldUtils;
13+
import net.minecraft.core.BlockPos;
14+
import net.minecraft.nbt.CompoundTag;
15+
import net.minecraft.network.Connection;
16+
import net.minecraft.network.protocol.Packet;
17+
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
18+
import net.minecraft.server.level.ServerLevel;
19+
import net.minecraft.world.level.block.entity.BlockEntityType;
20+
import net.minecraft.world.level.block.state.BlockState;
21+
import net.minecraftforge.common.util.Constants.BlockFlags;
22+
23+
public abstract class BlockEntityNetworked extends BlockEntityBase {
24+
25+
public BlockEntityNetworked (BlockEntityType<?> type, BlockPos pos, BlockState state) {
26+
27+
super(type, pos, state);
28+
}
29+
30+
@Override
31+
public ClientboundBlockEntityDataPacket getUpdatePacket () {
32+
33+
return new ClientboundBlockEntityDataPacket(this.worldPosition, 0, this.getUpdateTag());
34+
}
35+
36+
@Override
37+
public void onDataPacket (Connection net, ClientboundBlockEntityDataPacket packet) {
38+
39+
super.onDataPacket(net, packet);
40+
this.readSyncData(packet.getTag());
41+
}
42+
43+
@Override
44+
public CompoundTag getUpdateTag () {
45+
46+
return this.writeSyncData(super.getUpdateTag());
47+
}
48+
49+
/**
50+
* Forces a data sync from the server to the client.
51+
* @param renderUpdate Whether or not a render update should also happen. This should be used when you want to change the baked block model.
52+
*/
53+
public void sync (boolean renderUpdate) {
54+
55+
// Tells the game to re-render the chunk in addition to updating the block entity.
56+
if (renderUpdate) {
57+
58+
this.setChanged();
59+
final BlockState state = this.getCurrentState();
60+
this.level.sendBlockUpdated(this.worldPosition, state, state, BlockFlags.DEFAULT_AND_RERENDER);
61+
}
62+
63+
// Tells the game to send a tracking packet to all players tracking the block entity.
64+
else if (this.level instanceof ServerLevel) {
65+
66+
final Packet<?> packet = this.getUpdatePacket();
67+
WorldUtils.sendToTracking((ServerLevel) this.level, this.getChunkPos(), packet, false);
68+
}
69+
}
70+
71+
/**
72+
* Writes a data tag that will be sent to the client. This is used to keep the block entity in sync. This will be read by {@link #readSyncData(CompoundTag)} on the client.
73+
* @param data The data tag that will be sent to the client. This is initially populated using the super {@link #getUpdateTag()}.
74+
* @return The data tag to sync with the client.
75+
*/
76+
@Nullable
77+
public abstract CompoundTag writeSyncData(@Nullable CompoundTag data);
78+
79+
/**
80+
* Reads a data tag that was sent from the server. The tag should be assumed to have been written using {@link #writeSyncData(CompoundTag)}.
81+
* @param data The data that was sent from the server.
82+
*/
83+
public abstract void readSyncData(CompoundTag data);
84+
}

0 commit comments

Comments
 (0)