2019-03-01 18:27:24 +01:00
|
|
|
package de.ellpeck.naturesaura.compat.patchouli;
|
|
|
|
|
2021-12-16 21:56:27 +01:00
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
|
|
|
import de.ellpeck.naturesaura.ModConfig;
|
2019-03-01 18:27:24 +01:00
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2021-12-16 21:56:27 +01:00
|
|
|
import de.ellpeck.naturesaura.api.multiblock.Matcher;
|
2020-01-26 19:26:50 +01:00
|
|
|
import de.ellpeck.naturesaura.compat.ICompat;
|
2020-01-29 00:40:28 +01:00
|
|
|
import de.ellpeck.naturesaura.data.ItemTagProvider;
|
2021-12-16 21:56:27 +01:00
|
|
|
import de.ellpeck.naturesaura.events.ClientEvents;
|
|
|
|
import de.ellpeck.naturesaura.renderers.SupporterFancyHandler;
|
|
|
|
import net.minecraft.ChatFormatting;
|
2020-04-29 16:38:50 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2021-12-16 21:56:27 +01:00
|
|
|
import net.minecraft.client.gui.screens.Screen;
|
|
|
|
import net.minecraft.client.renderer.GameRenderer;
|
|
|
|
import net.minecraft.network.chat.Style;
|
|
|
|
import net.minecraft.network.chat.TextComponent;
|
2021-12-08 00:31:29 +01:00
|
|
|
import net.minecraft.resources.ResourceLocation;
|
2021-12-16 21:56:27 +01:00
|
|
|
import net.minecraft.world.item.crafting.Ingredient;
|
2021-12-08 00:31:29 +01:00
|
|
|
import net.minecraft.world.item.crafting.Recipe;
|
2021-12-16 21:56:27 +01:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2020-01-21 23:02:39 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2021-12-16 21:56:27 +01:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2021-03-30 16:22:40 +02:00
|
|
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
2021-12-16 21:56:27 +01:00
|
|
|
import vazkii.patchouli.api.BookDrawScreenEvent;
|
|
|
|
import vazkii.patchouli.api.IMultiblock;
|
|
|
|
import vazkii.patchouli.api.IVariable;
|
|
|
|
import vazkii.patchouli.api.PatchouliAPI;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.Month;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.stream.Collectors;
|
2019-03-01 20:51:43 +01:00
|
|
|
|
2020-01-26 19:26:50 +01:00
|
|
|
public class PatchouliCompat implements ICompat {
|
2019-03-01 18:27:24 +01:00
|
|
|
|
2019-03-01 20:51:43 +01:00
|
|
|
private static final ResourceLocation BOOK = new ResourceLocation(NaturesAura.MOD_ID, "book");
|
2021-03-30 16:22:40 +02:00
|
|
|
private static final Map<ResourceLocation, IMultiblock> MULTIBLOCKS = new HashMap<>();
|
2019-03-01 18:27:24 +01:00
|
|
|
|
2020-02-07 15:22:30 +01:00
|
|
|
public static void addPatchouliMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) {
|
2021-12-16 21:56:27 +01:00
|
|
|
for (var i = 1; i < rawMatchers.length; i += 2) {
|
|
|
|
if (rawMatchers[i] instanceof Matcher matcher) {
|
|
|
|
var check = matcher.check();
|
2020-02-07 15:22:30 +01:00
|
|
|
if (check == null)
|
2021-03-30 16:22:40 +02:00
|
|
|
rawMatchers[i] = PatchouliAPI.get().anyMatcher();
|
2020-02-07 15:22:30 +01:00
|
|
|
else
|
2021-12-16 21:56:27 +01:00
|
|
|
rawMatchers[i] = PatchouliAPI.get().predicateMatcher(matcher.defaultState(),
|
2020-02-07 15:22:30 +01:00
|
|
|
state -> check.matches(null, null, null, null, state, (char) 0));
|
|
|
|
}
|
|
|
|
}
|
2021-12-16 21:56:27 +01:00
|
|
|
MULTIBLOCKS.put(name, PatchouliAPI.get().makeMultiblock(pattern, rawMatchers));
|
2020-02-07 15:22:30 +01:00
|
|
|
}
|
|
|
|
|
2021-12-08 00:31:29 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public static <T extends Recipe<?>> T getRecipe(String type, String name) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var manager = Minecraft.getInstance().level.getRecipeManager();
|
|
|
|
var res = new ResourceLocation(name);
|
|
|
|
var pre = new ResourceLocation(res.getNamespace(), type + "/" + res.getPath());
|
2021-12-08 00:31:29 +01:00
|
|
|
return (T) manager.byKey(pre).orElse(null);
|
2020-02-07 15:22:30 +01:00
|
|
|
}
|
|
|
|
|
2021-12-16 21:56:27 +01:00
|
|
|
public static IVariable ingredientVariable(Ingredient ingredient) {
|
|
|
|
return IVariable.wrapList(Arrays.stream(ingredient.getItems())
|
2020-09-22 18:03:56 +02:00
|
|
|
.map(IVariable::from).collect(Collectors.toList()));
|
2021-12-16 21:56:27 +01:00
|
|
|
}
|
2020-09-22 18:03:56 +02:00
|
|
|
|
2020-01-26 19:26:50 +01:00
|
|
|
@Override
|
2021-03-30 16:22:40 +02:00
|
|
|
public void setup(FMLCommonSetupEvent event) {
|
2021-12-16 21:56:27 +01:00
|
|
|
event.enqueueWork(() -> {
|
|
|
|
for (var entry : MULTIBLOCKS.entrySet())
|
2021-03-30 16:22:40 +02:00
|
|
|
PatchouliAPI.get().registerMultiblock(entry.getKey(), entry.getValue());
|
|
|
|
|
|
|
|
PatchouliAPI.get().setConfigFlag(NaturesAura.MOD_ID + ":rf_converter", ModConfig.instance.rfConverter.get());
|
|
|
|
PatchouliAPI.get().setConfigFlag(NaturesAura.MOD_ID + ":chunk_loader", ModConfig.instance.chunkLoader.get());
|
2021-12-16 21:56:27 +01:00
|
|
|
});
|
2019-03-01 18:27:24 +01:00
|
|
|
}
|
|
|
|
|
2020-01-26 19:26:50 +01:00
|
|
|
@Override
|
2020-04-26 20:40:28 +02:00
|
|
|
public void setupClient() {
|
2020-01-26 19:26:50 +01:00
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addItemTags(ItemTagProvider provider) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-12-16 21:56:27 +01:00
|
|
|
@SubscribeEvent
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-03-03 23:33:38 +01:00
|
|
|
public void onBookDraw(BookDrawScreenEvent event) {
|
2021-12-16 21:56:27 +01:00
|
|
|
var book = event.getBook();
|
|
|
|
var gui = event.getScreen();
|
|
|
|
if (book == null || !book.equals(BOOK))
|
2019-03-03 23:33:38 +01:00
|
|
|
return;
|
2021-12-16 21:56:27 +01:00
|
|
|
var now = LocalDateTime.now();
|
2019-03-03 23:33:38 +01:00
|
|
|
if (now.getMonth() == Month.MAY && now.getDayOfMonth() == 21) {
|
2021-12-16 21:56:27 +01:00
|
|
|
var x = gui.width / 2 + 272 / 2 - 16;
|
|
|
|
var y = gui.height / 2 - 180 / 2 - 26;
|
|
|
|
|
|
|
|
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
|
|
|
RenderSystem.setShaderTexture(0, ClientEvents.BOOK_GUI);
|
|
|
|
Screen.blit(event.getPoseStack(), x, y, 469, 0, 43, 42, 512, 256);
|
|
|
|
|
|
|
|
if (event.getMouseX() >= x && event.getMouseY() >= y && event.getMouseX() < x + 43 && event.getMouseY() < y + 42)
|
|
|
|
gui.renderComponentTooltip(event.getPoseStack(),
|
|
|
|
Collections.singletonList(new TextComponent("It's the author Ellpeck's birthday!").setStyle(Style.EMPTY.applyFormat(ChatFormatting.GOLD))),
|
|
|
|
event.getMouseX(), event.getMouseY(), gui.getMinecraft().font);
|
2020-02-27 12:27:34 +01:00
|
|
|
} else if (now.getMonth() == Month.JUNE) {
|
2021-12-16 21:56:27 +01:00
|
|
|
var x = gui.width / 2 + 272 / 2;
|
|
|
|
var y = gui.height / 2 - 180 / 2 + 16;
|
|
|
|
|
|
|
|
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
|
|
|
RenderSystem.setShaderTexture(0, ClientEvents.BOOK_GUI);
|
|
|
|
Screen.blit(event.getPoseStack(), x, y, 424, 0, 45, 26, 512, 256);
|
|
|
|
|
|
|
|
if (event.getMouseX() >= x && event.getMouseY() >= y && event.getMouseX() < x + 45 && event.getMouseY() < y + 26)
|
|
|
|
gui.renderComponentTooltip(event.getPoseStack(),
|
|
|
|
Collections.singletonList(new TextComponent("§6Happy §4P§6r§ei§2d§9e§5!")),
|
|
|
|
event.getMouseX(), event.getMouseY(), gui.getMinecraft().font);
|
2019-03-03 23:33:38 +01:00
|
|
|
}
|
2019-03-01 23:54:38 +01:00
|
|
|
|
2021-12-16 21:56:27 +01:00
|
|
|
var name = gui.getMinecraft().player.getName().getString();
|
|
|
|
var info = SupporterFancyHandler.FANCY_INFOS.get(name);
|
2019-03-03 23:33:38 +01:00
|
|
|
if (info != null) {
|
2021-12-16 21:56:27 +01:00
|
|
|
var x = gui.width / 2 - 272 / 2 + 20;
|
|
|
|
var y = gui.height / 2 + 180 / 2;
|
2019-03-01 23:54:38 +01:00
|
|
|
|
2021-12-16 21:56:27 +01:00
|
|
|
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
|
|
|
RenderSystem.setShaderTexture(0, ClientEvents.BOOK_GUI);
|
2019-03-01 23:54:38 +01:00
|
|
|
|
2021-12-16 21:56:27 +01:00
|
|
|
Screen.blit(event.getPoseStack(), x, y, 496, 44, 16, 18, 512, 256);
|
|
|
|
if (info.tier() == 1) {
|
|
|
|
Screen.blit(event.getPoseStack(), x, y, 496 - 16, 44, 16, 18, 512, 256);
|
2019-03-03 23:33:38 +01:00
|
|
|
} else {
|
2021-12-16 21:56:27 +01:00
|
|
|
var r = ((info.color() >> 16) & 255) / 255F;
|
|
|
|
var g = ((info.color() >> 8) & 255) / 255F;
|
|
|
|
var b = (info.color() & 255) / 255F;
|
2021-12-19 18:24:54 +01:00
|
|
|
RenderSystem.setShaderColor(r, g, b, 1);
|
2021-12-16 21:56:27 +01:00
|
|
|
Screen.blit(event.getPoseStack(), x, y, 496 - 32, 44, 16, 18, 512, 256);
|
2019-03-03 23:33:38 +01:00
|
|
|
}
|
2019-03-01 23:54:38 +01:00
|
|
|
|
2021-12-16 21:56:27 +01:00
|
|
|
if (event.getMouseX() >= x && event.getMouseY() >= y && event.getMouseX() < x + 16 && event.getMouseY() < y + 18)
|
|
|
|
gui.renderComponentTooltip(event.getPoseStack(),
|
|
|
|
Collections.singletonList(new TextComponent("Thanks for your support, " + name + "!").setStyle(Style.EMPTY.applyFormat(ChatFormatting.YELLOW))),
|
|
|
|
event.getMouseX(), event.getMouseY(), gui.getMinecraft().font);
|
2019-03-01 23:54:38 +01:00
|
|
|
|
2019-03-01 18:27:24 +01:00
|
|
|
}
|
2021-12-16 21:56:27 +01:00
|
|
|
}
|
2019-03-01 18:27:24 +01:00
|
|
|
}
|