mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
More fixes, implement inventory mapper
This commit is contained in:
@@ -11,6 +11,7 @@ import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.geysermc.packgenerator.PackManager;
|
||||
import org.geysermc.packgenerator.mapper.InventoryMapper;
|
||||
import org.geysermc.packgenerator.mapper.ItemSuggestionProvider;
|
||||
import org.geysermc.packgenerator.mapper.PackMapper;
|
||||
|
||||
@@ -68,6 +69,7 @@ public class PackGeneratorCommand {
|
||||
})
|
||||
)
|
||||
.then(ClientCommandManager.literal("auto")
|
||||
.then(ClientCommandManager.literal("command")
|
||||
.then(ClientCommandManager.argument("suggestions", CommandSuggestionsArgumentType.TYPE)
|
||||
.executes(context -> {
|
||||
Pair<String, CompletableFuture<Suggestions>> suggestions = CommandSuggestionsArgumentType.getSuggestions(context, "suggestions");
|
||||
@@ -83,6 +85,21 @@ public class PackGeneratorCommand {
|
||||
})
|
||||
)
|
||||
)
|
||||
.then(ClientCommandManager.literal("inventory")
|
||||
.executes(context -> {
|
||||
packMapper.setItemProvider(InventoryMapper.INSTANCE);
|
||||
context.getSource().sendFeedback(Component.literal("Now watching inventories for custom items to map"));
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
.then(ClientCommandManager.literal("stop")
|
||||
.executes(context -> {
|
||||
packMapper.setItemProvider(null);
|
||||
context.getSource().sendFeedback(Component.literal("Stopped automatic mapping of custom items"));
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,13 @@ import net.minecraft.world.item.ItemStack;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class InventoryMapper implements CustomItemProvider {
|
||||
public static final InventoryMapper INSTANCE = new InventoryMapper();
|
||||
|
||||
public InventoryMapper() {
|
||||
}
|
||||
private InventoryMapper() {}
|
||||
|
||||
@Override
|
||||
public Stream<ItemStack> nextItems(LocalPlayer player, ClientPacketListener connection) {
|
||||
return Stream.empty();
|
||||
return player.containerMenu.getItems().stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,8 +13,8 @@ public class PackMapper {
|
||||
private final PackManager packManager;
|
||||
private CustomItemProvider itemProvider;
|
||||
|
||||
public PackMapper(PackManager manager) {
|
||||
this.manager = manager;
|
||||
public PackMapper(PackManager packManager) {
|
||||
this.packManager = packManager;
|
||||
}
|
||||
|
||||
public void setItemProvider(CustomItemProvider itemProvider) {
|
||||
|
||||
@@ -74,14 +74,7 @@ public class GeyserMappings {
|
||||
return mappings.size();
|
||||
}
|
||||
|
||||
public void map(ItemStack stack, ProblemReporter reporter, Consumer<GeyserSingleDefinition> mappingConsumer) {
|
||||
Optional<? extends ResourceLocation> patchedModel = stack.getComponentsPatch().get(DataComponents.ITEM_MODEL);
|
||||
//noinspection OptionalAssignedToNull - annoying Mojang
|
||||
if (patchedModel == null || patchedModel.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceLocation model = patchedModel.get();
|
||||
public void map(ItemStack stack, ResourceLocation model, ProblemReporter reporter, Consumer<GeyserSingleDefinition> mappingConsumer) {
|
||||
String displayName = stack.getHoverName().getString();
|
||||
int protectionValue = 0; // TODO check the attributes
|
||||
|
||||
|
||||
@@ -72,9 +72,20 @@ public class BedrockPack {
|
||||
}
|
||||
|
||||
public Optional<Boolean> map(ItemStack stack) {
|
||||
if (stack.isEmpty() || !modelsMapped.add(stack.get(DataComponents.ITEM_MODEL))) {
|
||||
if (stack.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
Optional<? extends ResourceLocation> patchedModel = stack.getComponentsPatch().get(DataComponents.ITEM_MODEL);
|
||||
//noinspection OptionalAssignedToNull - annoying Mojang
|
||||
if (patchedModel == null || patchedModel.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
ResourceLocation model = patchedModel.get();
|
||||
if (!modelsMapped.add(model)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
AtomicBoolean problems = new AtomicBoolean();
|
||||
ProblemReporter mapReporter = new ProblemReporter() {
|
||||
|
||||
@@ -90,7 +101,7 @@ public class BedrockPack {
|
||||
}
|
||||
};
|
||||
|
||||
mappings.map(stack, mapReporter, mapping -> {
|
||||
mappings.map(stack, model, mapReporter, mapping -> {
|
||||
// TODO a proper way to get texture from item model
|
||||
itemTextures.withItemTexture(mapping, mapping.bedrockIdentifier().getPath());
|
||||
ResourceLocation texture = mapping.bedrockIdentifier();
|
||||
|
||||
Reference in New Issue
Block a user