Networking fix

This commit is contained in:
Aleksey 2020-10-01 21:51:52 +03:00
parent 0f82dbc35f
commit adc7849c10
5 changed files with 21 additions and 21 deletions

View file

@ -37,4 +37,8 @@ public class BetterEnd implements ModInitializer {
public static Identifier getResId(String path) {
return new Identifier(MOD_ID, path);
}
public static String getStringId(String id) {
return String.format("%s:%s", MOD_ID, id);
}
}

View file

@ -19,7 +19,7 @@ import net.minecraft.util.thread.ThreadExecutor;
import ru.betterend.blocks.entities.ESignBlockEntity;
import ru.betterend.client.gui.BlockSignEditScreen;
@Mixin(value = ClientPlayNetworkHandler.class, priority = 1000)
@Mixin(ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin
{
@Shadow

View file

@ -113,7 +113,7 @@ public class AlloyingRecipe implements Recipe<Inventory> {
public static Builder create(String id) {
INSTANCE.id = BetterEnd.getResId(id);
INSTANCE.group = String.format("%s:%s", GROUP, id);
INSTANCE.group = String.format("%s_%s", GROUP, id);
INSTANCE.primaryInput = null;
INSTANCE.secondaryInput = null;
INSTANCE.output = null;

View file

@ -32,24 +32,12 @@ public class AlloyingRecipeSerializer implements RecipeSerializer<AlloyingRecipe
@Override
public AlloyingRecipe read(Identifier id, PacketByteBuf packetBuffer) {
String group = packetBuffer.readString();
Ingredient primaryInput = Ingredient.fromPacket(packetBuffer);
Ingredient secondaryInput = Ingredient.fromPacket(packetBuffer);
ItemStack output = packetBuffer.readItemStack();
float experience = packetBuffer.readFloat();
int smeltTime = packetBuffer.readVarInt();
return new AlloyingRecipe(id, group, primaryInput, secondaryInput, output, experience, smeltTime);
Identifier recipeId = packetBuffer.readIdentifier();
return (AlloyingRecipe) EndRecipeManager.getRecipe(AlloyingRecipe.TYPE, recipeId);
}
@Override
public void write(PacketByteBuf packetBuffer, AlloyingRecipe recipe) {
packetBuffer.writeString(recipe.group);
recipe.primaryInput.write(packetBuffer);
recipe.secondaryInput.write(packetBuffer);
packetBuffer.writeItemStack(recipe.output);
packetBuffer.writeFloat(recipe.experience);
packetBuffer.writeInt(recipe.smeltTime);
packetBuffer.writeIdentifier(recipe.id);
}
}

View file

@ -24,6 +24,13 @@ public class EndRecipeManager {
list.put(recipe.getId(), recipe);
}
public static Recipe<?> getRecipe(RecipeType<?> type, Identifier id) {
if (RECIPES.containsKey(type)) {
return RECIPES.get(type).get(id);
}
return null;
}
public static Map<RecipeType<?>, Map<Identifier, Recipe<?>>> getMap(Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes) {
Map<RecipeType<?>, Map<Identifier, Recipe<?>>> result = Maps.newHashMap();
@ -53,13 +60,14 @@ public class EndRecipeManager {
}
static <S extends RecipeSerializer<T>, T extends Recipe<?>> S registerSerializer(String id, S serializer) {
return Registry.register(Registry.RECIPE_SERIALIZER, BetterEnd.getResId(id), serializer);
return Registry.register(Registry.RECIPE_SERIALIZER, BetterEnd.getStringId(id), serializer);
}
static <T extends Recipe<?>> RecipeType<T> registerType(String name) {
return Registry.register(Registry.RECIPE_TYPE, BetterEnd.getResId(name), new RecipeType<T>() {
static <T extends Recipe<?>> RecipeType<T> registerType(String type) {
Identifier recipeTypeId = BetterEnd.getResId(type);
return Registry.register(Registry.RECIPE_TYPE, recipeTypeId, new RecipeType<T>() {
public String toString() {
return name;
return type;
}
});
}