2019-03-01 18:27:24 +01:00
|
|
|
package de.ellpeck.naturesaura.compat.patchouli;
|
|
|
|
|
2020-01-21 23:02:39 +01:00
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
2020-01-28 18:08:56 +01:00
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
2019-03-01 18:27:24 +01:00
|
|
|
import de.ellpeck.naturesaura.ModConfig;
|
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
|
|
|
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;
|
2020-02-07 15:22:30 +01:00
|
|
|
import de.ellpeck.naturesaura.events.ClientEvents;
|
2020-04-29 16:38:50 +02:00
|
|
|
import de.ellpeck.naturesaura.recipes.ModRecipe;
|
|
|
|
import de.ellpeck.naturesaura.recipes.ModRecipes;
|
2019-03-01 23:54:38 +01:00
|
|
|
import de.ellpeck.naturesaura.renderers.SupporterFancyHandler;
|
|
|
|
import de.ellpeck.naturesaura.renderers.SupporterFancyHandler.FancyInfo;
|
2020-04-29 16:38:50 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.client.gui.AbstractGui;
|
2019-03-01 20:51:43 +01:00
|
|
|
import net.minecraft.client.renderer.RenderHelper;
|
2020-04-29 16:38:50 +02:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.crafting.IRecipe;
|
|
|
|
import net.minecraft.item.crafting.IRecipeType;
|
|
|
|
import net.minecraft.item.crafting.RecipeManager;
|
2019-03-01 18:27:24 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2020-09-22 03:17:02 +02:00
|
|
|
import net.minecraft.util.text.StringTextComponent;
|
|
|
|
import net.minecraft.util.text.Style;
|
2019-03-01 20:51:43 +01:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2020-04-29 16:38:50 +02:00
|
|
|
import net.minecraft.world.World;
|
2019-10-20 22:30:49 +02: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;
|
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2020-04-01 00:43:27 +02:00
|
|
|
import net.minecraftforge.fml.DeferredWorkQueue;
|
2020-01-28 18:08:56 +01:00
|
|
|
import net.minecraftforge.fml.client.gui.GuiUtils;
|
2019-03-03 23:33:38 +01:00
|
|
|
import vazkii.patchouli.api.BookDrawScreenEvent;
|
2019-03-01 18:27:24 +01:00
|
|
|
import vazkii.patchouli.api.PatchouliAPI;
|
|
|
|
|
2019-03-01 20:51:43 +01:00
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.Month;
|
|
|
|
import java.util.Collections;
|
2020-04-29 16:38:50 +02:00
|
|
|
import java.util.List;
|
2019-03-31 10:21:59 +02:00
|
|
|
import java.util.Map;
|
2020-04-29 16:38:50 +02:00
|
|
|
import java.util.Optional;
|
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");
|
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) {
|
|
|
|
for (int i = 1; i < rawMatchers.length; i += 2) {
|
|
|
|
if (rawMatchers[i] instanceof Matcher) {
|
|
|
|
Matcher matcher = (Matcher) rawMatchers[i];
|
|
|
|
Matcher.ICheck check = matcher.getCheck();
|
|
|
|
if (check == null)
|
|
|
|
rawMatchers[i] = PatchouliAPI.instance.anyMatcher();
|
|
|
|
else
|
|
|
|
rawMatchers[i] = PatchouliAPI.instance.predicateMatcher(matcher.getDefaultState(),
|
|
|
|
state -> check.matches(null, null, null, null, state, (char) 0));
|
|
|
|
}
|
|
|
|
}
|
2020-04-01 00:43:27 +02:00
|
|
|
DeferredWorkQueue.runLater(() -> PatchouliAPI.instance.registerMultiblock(name, PatchouliAPI.instance.makeMultiblock(pattern, rawMatchers)));
|
2020-02-07 15:22:30 +01:00
|
|
|
}
|
|
|
|
|
2020-04-29 16:38:50 +02:00
|
|
|
public static <T extends IRecipe<?>> T getRecipe(String type, String name) {
|
|
|
|
RecipeManager manager = Minecraft.getInstance().world.getRecipeManager();
|
2020-02-07 15:22:30 +01:00
|
|
|
ResourceLocation res = new ResourceLocation(name);
|
2020-04-29 16:38:50 +02:00
|
|
|
ResourceLocation pre = new ResourceLocation(res.getNamespace(), type + "/" + res.getPath());
|
|
|
|
return (T) manager.getRecipe(pre).orElse(null);
|
2020-02-07 15:22:30 +01:00
|
|
|
}
|
|
|
|
|
2020-01-26 19:26:50 +01:00
|
|
|
@Override
|
2020-04-26 20:40:28 +02:00
|
|
|
public void setup() {
|
2020-04-01 01:46:33 +02:00
|
|
|
DeferredWorkQueue.runLater(() -> {
|
|
|
|
PatchouliAPI.instance.setConfigFlag(NaturesAura.MOD_ID + ":rf_converter", ModConfig.instance.rfConverter.get());
|
|
|
|
PatchouliAPI.instance.setConfigFlag(NaturesAura.MOD_ID + ":chunk_loader", ModConfig.instance.chunkLoader.get());
|
|
|
|
});
|
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) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-03 23:33:38 +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) {
|
|
|
|
if (event.book == null || !event.book.equals(BOOK))
|
|
|
|
return;
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
if (now.getMonth() == Month.MAY && now.getDayOfMonth() == 21) {
|
|
|
|
int x = event.gui.width / 2 + 272 / 2 - 16;
|
|
|
|
int y = event.gui.height / 2 - 180 / 2 - 26;
|
2019-03-01 20:51:43 +01:00
|
|
|
|
2019-03-03 23:33:38 +01:00
|
|
|
RenderHelper.disableStandardItemLighting();
|
2020-01-21 23:02:39 +01:00
|
|
|
GlStateManager.color4f(1, 1, 1, 1);
|
|
|
|
event.gui.getMinecraft().getTextureManager().bindTexture(ClientEvents.BOOK_GUI);
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(event.matrixStack, x, y, 469, 0, 43, 42, 512, 256);
|
2019-03-01 20:51:43 +01:00
|
|
|
|
2019-03-03 23:33:38 +01:00
|
|
|
if (event.mouseX >= x && event.mouseY >= y && event.mouseX < x + 43 && event.mouseY < y + 42)
|
2020-09-22 03:17:02 +02:00
|
|
|
GuiUtils.drawHoveringText(event.matrixStack,
|
|
|
|
Collections.singletonList(new StringTextComponent("It's the author Ellpeck's birthday!").setStyle(Style.EMPTY.setFormatting(TextFormatting.GOLD))),
|
2020-01-21 23:02:39 +01:00
|
|
|
event.mouseX, event.mouseY, event.gui.width, event.gui.height, 0, event.gui.getMinecraft().fontRenderer);
|
2020-02-27 12:27:34 +01:00
|
|
|
} else if (now.getMonth() == Month.JUNE) {
|
|
|
|
int x = event.gui.width / 2 + 272 / 2;
|
|
|
|
int y = event.gui.height / 2 - 180 / 2 + 16;
|
|
|
|
|
|
|
|
RenderHelper.disableStandardItemLighting();
|
|
|
|
GlStateManager.color4f(1, 1, 1, 1);
|
|
|
|
event.gui.getMinecraft().getTextureManager().bindTexture(ClientEvents.BOOK_GUI);
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(event.matrixStack, x, y, 424, 0, 45, 26, 512, 256);
|
2020-02-27 12:27:34 +01:00
|
|
|
|
|
|
|
if (event.mouseX >= x && event.mouseY >= y && event.mouseX < x + 45 && event.mouseY < y + 26)
|
2020-09-22 03:17:02 +02:00
|
|
|
GuiUtils.drawHoveringText(event.matrixStack,
|
|
|
|
Collections.singletonList(new StringTextComponent("§6Happy §4P§6r§ei§2d§9e§5!")),
|
2020-02-27 12:27:34 +01:00
|
|
|
event.mouseX, event.mouseY, event.gui.width, event.gui.height, 0, event.gui.getMinecraft().fontRenderer);
|
2019-03-03 23:33:38 +01:00
|
|
|
}
|
2019-03-01 23:54:38 +01:00
|
|
|
|
2020-09-22 03:17:02 +02:00
|
|
|
String name = event.gui.getMinecraft().player.getName().getString();
|
2019-03-03 23:33:38 +01:00
|
|
|
FancyInfo info = SupporterFancyHandler.FANCY_INFOS.get(name);
|
|
|
|
if (info != null) {
|
|
|
|
int x = event.gui.width / 2 - 272 / 2 + 20;
|
|
|
|
int y = event.gui.height / 2 + 180 / 2;
|
2019-03-01 23:54:38 +01:00
|
|
|
|
2019-03-03 23:33:38 +01:00
|
|
|
RenderHelper.disableStandardItemLighting();
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.color4f(1, 1, 1, 1);
|
2020-01-21 23:02:39 +01:00
|
|
|
event.gui.getMinecraft().getTextureManager().bindTexture(ClientEvents.BOOK_GUI);
|
2019-03-01 23:54:38 +01:00
|
|
|
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(event.matrixStack, x, y, 496, 44, 16, 18, 512, 256);
|
2019-03-03 23:33:38 +01:00
|
|
|
if (info.tier == 1) {
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(event.matrixStack, x, y, 496 - 16, 44, 16, 18, 512, 256);
|
2019-03-03 23:33:38 +01:00
|
|
|
} else {
|
|
|
|
float r = ((info.color >> 16) & 255) / 255F;
|
|
|
|
float g = ((info.color >> 8) & 255) / 255F;
|
|
|
|
float b = (info.color & 255) / 255F;
|
2020-01-28 18:08:56 +01:00
|
|
|
RenderSystem.color3f(r, g, b);
|
2020-09-22 03:17:02 +02:00
|
|
|
AbstractGui.blit(event.matrixStack, 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
|
|
|
|
2019-03-03 23:33:38 +01:00
|
|
|
if (event.mouseX >= x && event.mouseY >= y && event.mouseX < x + 16 && event.mouseY < y + 18)
|
2020-09-22 03:17:02 +02:00
|
|
|
GuiUtils.drawHoveringText(event.matrixStack,
|
|
|
|
Collections.singletonList(new StringTextComponent("Thanks for your support, " + name + "!").setStyle(Style.EMPTY.setFormatting(TextFormatting.YELLOW))),
|
2020-01-21 23:02:39 +01:00
|
|
|
event.mouseX, event.mouseY, event.gui.width, event.gui.height, 0, event.gui.getMinecraft().fontRenderer);
|
2019-03-01 23:54:38 +01:00
|
|
|
|
2019-03-01 18:27:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|