Skip to content

Commit

Permalink
even more work
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Jul 18, 2024
1 parent b5f7507 commit ec3407e
Show file tree
Hide file tree
Showing 25 changed files with 4,741 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public static PacketConstructor<?> getPacket(@NotNull ResourceLocation resourceL
*/
@Nullable
public static BlueberryPacket<?> handle(@NotNull CustomPacketPayload packet) {
PacketConstructor<?> blueberryPacketConstructor = getPacket(packet.id(), BlueberryPacketFlow.TO_CLIENT);
if (!(packet instanceof BlueberryCustomPayload customPayload)) return null;
PacketConstructor<?> blueberryPacketConstructor = getPacket(customPayload.id(), BlueberryPacketFlow.TO_CLIENT);
return createBlueberryPacket(blueberryPacketConstructor, new FriendlyByteBuf(Unpooled.wrappedBuffer(customPayload.payload())));
}

Expand All @@ -87,8 +87,8 @@ public static BlueberryPacket<?> handle(@NotNull CustomPacketPayload packet) {
*/
@Nullable
public static BlueberryPacket<?> handle(@NotNull ServerboundCustomPayloadPacket packet) {
PacketConstructor<?> blueberryPacketConstructor = getPacket(packet.payload().id(), BlueberryPacketFlow.TO_SERVER);
if (!(packet.payload() instanceof BlueberryCustomPayload customPayload)) return null;
PacketConstructor<?> blueberryPacketConstructor = getPacket(customPayload.id(), BlueberryPacketFlow.TO_SERVER);
return createBlueberryPacket(blueberryPacketConstructor, new FriendlyByteBuf(Unpooled.wrappedBuffer(customPayload.payload())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.ArrayList;
import java.util.List;

public class ClientboundBlueberryHandshakePacket implements Packet<ClientStatusPacketListener> {
public class ClientboundBlueberryHandshakePacket /*implements Packet<ClientStatusPacketListener>*/ {
private final List<ModInfo> modInfos;

public ClientboundBlueberryHandshakePacket(@NotNull List<ModInfo> modInfos) {
Expand All @@ -26,15 +26,15 @@ public ClientboundBlueberryHandshakePacket(@NotNull FriendlyByteBuf friendlyByte
}
}

@Override
// @Override
public void write(@NotNull FriendlyByteBuf friendlyByteBuf) {
friendlyByteBuf.writeCollection(modInfos, (buf, modInfo) -> {
buf.writeUtf(modInfo.modId());
buf.writeUtf(modInfo.version());
});
}

@Override
// @Override
public void handle(@NotNull ClientStatusPacketListener clientBlueberryPacketListener) {
((ClientBlueberryHandshakePacketListener) clientBlueberryPacketListener).handleBlueberryHandshakeResponse(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.blueberrymc.world.item;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
Expand All @@ -17,10 +16,7 @@ public class ItemStackBuilder {
public final Item item;
public int amount;
public int damageValue = 0;
@Nullable public CompoundTag tag;
@Nullable public Component hoverName;
@NotNull public final Map<Enchantment, Integer> enchantments = new ConcurrentHashMap<>();
public int repairCost = 0;

protected ItemStackBuilder(@NotNull Item item, int amount) {
this.item = item;
Expand All @@ -30,7 +26,7 @@ protected ItemStackBuilder(@NotNull Item item, int amount) {
@Contract(pure = true)
@NotNull
public static ItemStackBuilder builder(@NotNull ItemLike itemLike, int amount, @Nullable CompoundTag tag) {
return builder(itemLike.asItem(), amount).tag(tag);
return builder(itemLike.asItem(), amount);
}

@Contract(pure = true)
Expand All @@ -45,19 +41,6 @@ public static ItemStackBuilder builder(@NotNull ItemLike itemLike) {
return builder(itemLike.asItem(), 1);
}

@Contract(pure = true)
@NotNull
public CompoundTag getOrCreateTag() {
return this.tag != null ? this.tag : (this.tag = new CompoundTag());
}

@Contract(pure = true)
@NotNull
public ItemStackBuilder tag(@Nullable CompoundTag tag) {
this.tag = tag;
return this;
}

@Contract(pure = true)
@NotNull
public ItemStackBuilder amount(int amount) {
Expand Down Expand Up @@ -94,17 +77,6 @@ public ItemStackBuilder damageValue(int damageValue) {
return this;
}

/**
* Sets the name that is shown when a player hovers the item. also known as display name.
* @param hoverName the hover name
*/
@Contract(pure = true)
@NotNull
public ItemStackBuilder hoverName(@Nullable Component hoverName) {
this.hoverName = hoverName;
return this;
}

/**
* Enchants an item.
* @param enchantment the enchantment to add
Expand Down Expand Up @@ -140,22 +112,12 @@ public ItemStackBuilder removeEnchant(@NotNull Enchantment enchantment, int leve
return this;
}

@Contract(pure = true)
@NotNull
public ItemStackBuilder repairCost(int repairCost) {
this.repairCost = repairCost;
return this;
}

@Contract(pure = true)
@NotNull
public ItemStack build() {
ItemStack stack = new ItemStack(item, amount);
if (damageValue != 0) stack.setDamageValue(damageValue);
if (tag != null) stack.setTag(tag);
if (hoverName != null) stack.setHoverName(hoverName);
if (!enchantments.isEmpty()) enchantments.forEach(stack::enchant);
if (repairCost != 0) stack.setRepairCost(repairCost);
return stack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,13 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.CraftingBookCategory;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.item.crafting.ShapelessRecipe;
import net.minecraft.world.item.crafting.*;
import net.minecraft.world.level.ItemLike;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

public abstract class RecipeBuilder {
Expand Down Expand Up @@ -188,7 +179,8 @@ public RecipeHolder<ShapedRecipe> build() {
index.getAndIncrement();
}
});
return new RecipeHolder<>(id, new ShapedRecipe(group, category, getWidth(), getHeight(), list, result));
ShapedRecipePattern pattern = new ShapedRecipePattern(getWidth(), getHeight(), list, Optional.of(new ShapedRecipePattern.Data(key, rows)));
return new RecipeHolder<>(id, new ShapedRecipe(group, category, pattern, result));
}

// --- getters
Expand Down
6 changes: 6 additions & 0 deletions Blueberry-API/src/main/java/net/fabricmc/api/EnvType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.fabricmc.api;

public enum EnvType {
CLIENT,
SERVER,
}
10 changes: 10 additions & 0 deletions Blueberry-API/src/main/java/net/fabricmc/api/Environment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.fabricmc.api;

import java.lang.annotation.*;

@Retention(RetentionPolicy.CLASS)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.PACKAGE})
@Documented
public @interface Environment {
EnvType value();
}
Loading

0 comments on commit ec3407e

Please sign in to comment.