a bit of patchouli-based reorganization

This commit is contained in:
Ellpeck 2019-03-01 18:27:24 +01:00
parent 59d037a6e5
commit 62ccda3025
6 changed files with 82 additions and 17 deletions

View file

@ -3,13 +3,12 @@ package de.ellpeck.naturesaura.blocks.multi;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.multiblock.IMultiblock; import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
import de.ellpeck.naturesaura.api.multiblock.Matcher; import de.ellpeck.naturesaura.api.multiblock.Matcher;
import de.ellpeck.naturesaura.api.multiblock.Matcher.ICheck; import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import vazkii.patchouli.api.PatchouliAPI;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -103,19 +102,7 @@ public class Multiblock implements IMultiblock {
this.matchers.put(new BlockPos(x, y, z), matcher); this.matchers.put(new BlockPos(x, y, z), matcher);
} }
for (int i = 1; i < rawMatchers.length; i += 2) { PatchouliCompat.addPatchouliMultiblock(name, pattern, rawMatchers);
if (rawMatchers[i] instanceof Matcher) {
Matcher matcher = (Matcher) rawMatchers[i];
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));
}
}
PatchouliAPI.instance.registerMultiblock(name, PatchouliAPI.instance.makeMultiblock(pattern, rawMatchers));
NaturesAuraAPI.MULTIBLOCKS.put(this.name, this); NaturesAuraAPI.MULTIBLOCKS.put(this.name, this);
} }

View file

@ -3,9 +3,9 @@ package de.ellpeck.naturesaura.compat;
import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.compat.crafttweaker.CraftTweakerCompat; import de.ellpeck.naturesaura.compat.crafttweaker.CraftTweakerCompat;
import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.Loader;
import vazkii.patchouli.api.PatchouliAPI;
public final class Compat { public final class Compat {
@ -21,7 +21,11 @@ public final class Compat {
if (baubles) if (baubles)
MinecraftForge.EVENT_BUS.register(new BaublesCompat()); MinecraftForge.EVENT_BUS.register(new BaublesCompat());
PatchouliAPI.instance.setConfigFlag(NaturesAura.MOD_ID + ":rf_converter", ModConfig.enabledFeatures.rfConverter); PatchouliCompat.preInit();
}
public static void preInitClient(){
PatchouliCompat.preInitClient();
} }
public static void postInit() { public static void postInit() {

View file

@ -0,0 +1,39 @@
package de.ellpeck.naturesaura.compat.patchouli;
import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.multiblock.Matcher;
import net.minecraft.util.ResourceLocation;
import vazkii.patchouli.api.PatchouliAPI;
public final class PatchouliCompat {
public static Class bookGuiClass;
public static void preInit() {
PatchouliAPI.instance.setConfigFlag(NaturesAura.MOD_ID + ":rf_converter", ModConfig.enabledFeatures.rfConverter);
}
public static void preInitClient() {
try {
bookGuiClass = Class.forName("vazkii.patchouli.client.book.gui.GuiBook");
} catch (ClassNotFoundException e) {
NaturesAura.LOGGER.warn("Couldn't find Patchouli book class, not loading special visuals :(");
}
}
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));
}
}
PatchouliAPI.instance.registerMultiblock(name, PatchouliAPI.instance.makeMultiblock(pattern, rawMatchers));
}
}

View file

@ -13,6 +13,7 @@ import de.ellpeck.naturesaura.blocks.tiles.TileEntityGratedChute;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar; import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityRFConverter; import de.ellpeck.naturesaura.blocks.tiles.TileEntityRFConverter;
import de.ellpeck.naturesaura.compat.Compat; import de.ellpeck.naturesaura.compat.Compat;
import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat;
import de.ellpeck.naturesaura.items.ItemRangeVisualizer; import de.ellpeck.naturesaura.items.ItemRangeVisualizer;
import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.particles.ParticleHandler; import de.ellpeck.naturesaura.particles.ParticleHandler;
@ -22,8 +23,11 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiChat; import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.init.Items; import net.minecraft.init.Items;
@ -37,11 +41,13 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeColorHelper; import net.minecraft.world.biome.BiomeColorHelper;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.IPlantable;
import net.minecraftforge.energy.EnergyStorage; import net.minecraftforge.energy.EnergyStorage;
import net.minecraftforge.fml.client.config.GuiUtils;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
@ -52,6 +58,9 @@ import org.apache.commons.lang3.mutable.MutableInt;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -60,6 +69,7 @@ import java.util.Map;
public class ClientEvents { public class ClientEvents {
public static final ResourceLocation OVERLAYS = new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/overlays.png"); public static final ResourceLocation OVERLAYS = new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/overlays.png");
private static final ResourceLocation BOOK_GUI = new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/book.png");
private static final ItemStack ITEM_FRAME = new ItemStack(Items.ITEM_FRAME); private static final ItemStack ITEM_FRAME = new ItemStack(Items.ITEM_FRAME);
private static final Map<ResourceLocation, Tuple<ItemStack, Boolean>> SHOWING_EFFECTS = new HashMap<>(); private static final Map<ResourceLocation, Tuple<ItemStack, Boolean>> SHOWING_EFFECTS = new HashMap<>();
private static ItemStack heldCache = ItemStack.EMPTY; private static ItemStack heldCache = ItemStack.EMPTY;
@ -95,6 +105,29 @@ public class ClientEvents {
mc.profiler.endSection(); mc.profiler.endSection();
} }
@SubscribeEvent
public void onGuiRender(GuiScreenEvent.DrawScreenEvent.Post event) {
GuiScreen gui = event.getGui();
if (PatchouliCompat.bookGuiClass != null && PatchouliCompat.bookGuiClass.isAssignableFrom(gui.getClass())) {
int mouseX = event.getMouseX();
int mouseY = event.getMouseY();
LocalDateTime now = LocalDateTime.now();
if (now.getMonth() == Month.MAY && now.getDayOfMonth() == 21) {
int x = gui.width / 2 + 272 / 2 - 16;
int y = gui.height / 2 - 180 / 2 - 26;
RenderHelper.disableStandardItemLighting();
GlStateManager.color(1, 1, 1, 1);
gui.mc.getTextureManager().bindTexture(BOOK_GUI);
Gui.drawModalRectWithCustomSizedTexture(x, y, 469, 0, 43, 42, 512, 256);
if (mouseX >= x && mouseY >= y && mouseX < x + 43 && mouseY < y + 42)
GuiUtils.drawHoveringText(Collections.singletonList(TextFormatting.GOLD + "It's the author Ellpeck's birthday!"),
mouseX, mouseY, gui.width, gui.height, 0, gui.mc.fontRenderer);
}
}
}
@SubscribeEvent @SubscribeEvent
public void onRenderLast(RenderWorldLastEvent event) { public void onRenderLast(RenderWorldLastEvent event) {
Minecraft mc = Minecraft.getMinecraft(); Minecraft mc = Minecraft.getMinecraft();

View file

@ -1,5 +1,6 @@
package de.ellpeck.naturesaura.proxy; package de.ellpeck.naturesaura.proxy;
import de.ellpeck.naturesaura.compat.Compat;
import de.ellpeck.naturesaura.events.ClientEvents; import de.ellpeck.naturesaura.events.ClientEvents;
import de.ellpeck.naturesaura.particles.ParticleHandler; import de.ellpeck.naturesaura.particles.ParticleHandler;
import de.ellpeck.naturesaura.particles.ParticleMagic; import de.ellpeck.naturesaura.particles.ParticleMagic;
@ -35,6 +36,7 @@ public class ClientProxy implements IProxy {
@Override @Override
public void preInit(FMLPreInitializationEvent event) { public void preInit(FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new ClientEvents()); MinecraftForge.EVENT_BUS.register(new ClientEvents());
Compat.preInitClient();
} }
@Override @Override

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB