aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/MiningStuff.java
blob: 8b130d242470816d491dd5ba49fc06a1c37d99e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package io.github.moulberry.notenoughupdates.miscfeatures;

import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils;
import io.github.moulberry.notenoughupdates.overlays.CommissionOverlay;
import io.github.moulberry.notenoughupdates.util.SBInfo;
import io.github.moulberry.notenoughupdates.util.SpecialColour;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.block.BlockStone;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.init.Blocks;
import net.minecraft.network.play.server.S23PacketBlockChange;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class MiningStuff {

    private static BlockPos overlayLoc = null;
    private static long titaniumNotifMillis = 0;

    public static void processBlockChangePacket(S23PacketBlockChange packetIn) {
        if(!NotEnoughUpdates.INSTANCE.config.mining.titaniumAlert) {
            return;
        }

        IBlockState state = packetIn.getBlockState();
        if(SBInfo.getInstance().getLocation() != null &&
                SBInfo.getInstance().getLocation().startsWith("mining_") &&
                state.getBlock() == Blocks.stone && state.getValue(BlockStone.VARIANT) == BlockStone.EnumType.DIORITE_SMOOTH) {

            for(String s : CommissionOverlay.commissionProgress.keySet()) {
                if(s.contains("Titanium")) {
                    BlockPos pos = packetIn.getBlockPosition();

                    IBlockState existingBlock = Minecraft.getMinecraft().theWorld.getBlockState(pos);
                    if(existingBlock == null) return;
                    if(existingBlock.getBlock() == Blocks.stone && existingBlock.getValue(BlockStone.VARIANT) == BlockStone.EnumType.DIORITE_SMOOTH) return;

                    BlockPos player = Minecraft.getMinecraft().thePlayer.getPosition();

                    double distSq = pos.distanceSq(player);

                    if(distSq < 12*12) {
                        titaniumNotifMillis = System.currentTimeMillis();
                    }
                    return;
                }
            }
        }
    }

    @SubscribeEvent
    public void onRenderOverlay(RenderGameOverlayEvent.Post event) {
        if(!NotEnoughUpdates.INSTANCE.config.mining.titaniumAlert) {
            return;
        }

        int delta = (int)(System.currentTimeMillis() - titaniumNotifMillis);
        int notifLen = 5000;
        int fadeLen = 500;
        if(delta < notifLen && event.type == RenderGameOverlayEvent.ElementType.ALL) {
            ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
            int width = scaledResolution.getScaledWidth();
            int height = scaledResolution.getScaledHeight();

            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);

            GlStateManager.pushMatrix();
            GlStateManager.translate((float)(width / 2), (float)(height / 2), 0.0F);
            GlStateManager.scale(4.0F, 4.0F, 4.0F);

            int colour1 = 0xcc;
            int colour2 = 0xff;

            double factor = (Math.sin(delta*2*Math.PI/1000)+1)/2;
            int colour = (int)(colour1*factor + colour2*(1-factor));

            int alpha = 255;
            if(delta < fadeLen) {
                alpha = delta*255/fadeLen;
            } else if(delta > notifLen-fadeLen) {
                alpha = (notifLen-delta)*255/fadeLen;
            }

            if(alpha > 10) {
                TextRenderUtils.drawStringCenteredScaledMaxWidth("Titanium has spawned nearby!", Minecraft.getMinecraft().fontRendererObj,
                        0, 0, true, width/4-20, colour | (colour << 8) | (colour << 16) | (alpha << 24));
            }


            GlStateManager.popMatrix();
        }
    }

    public static void tick() {
        if(SBInfo.getInstance().getLocation() == null) return;
        if(!SBInfo.getInstance().getLocation().equals("mining_3")) return;
        if(Minecraft.getMinecraft().theWorld == null) return;

        for(Entity entity : Minecraft.getMinecraft().theWorld.loadedEntityList) {
            if(entity instanceof EntityCreeper) {
                EntityCreeper creeper = (EntityCreeper) entity;
                if(creeper.isInvisible() && creeper.getPowered()) {

                    BlockPos below = creeper.getPosition().down();
                    IBlockState state = Minecraft.getMinecraft().theWorld.getBlockState(below);
                    if(state != null && state.getBlock() == Blocks.stained_glass) {
                        creeper.setInvisible(!NotEnoughUpdates.INSTANCE.config.mining.revealMistCreepers);
                    }
                }
            }
        }
    }

    @SubscribeEvent
    public void renderWorldLast(RenderWorldLastEvent event) {
        if(overlayLoc == null) return;

        Entity viewer = Minecraft.getMinecraft().getRenderViewEntity();
        double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * event.partialTicks;
        double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * event.partialTicks;
        double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * event.partialTicks;

        AxisAlignedBB bb = new AxisAlignedBB(
                overlayLoc.getX()-viewerX,
                overlayLoc.getY()-viewerY,
                overlayLoc.getZ()-viewerZ,
                overlayLoc.getX()+1-viewerX,
                overlayLoc.getY()+1-viewerY,
                overlayLoc.getZ()+1-viewerZ).expand(0.01f, 0.01f, 0.01f);

        GlStateManager.disableCull();
        CustomItemEffects.drawFilledBoundingBox(bb, 1f, SpecialColour.special(0, 100, 0xff0000));
        GlStateManager.enableCull();
        GlStateManager.enableTexture2D();
    }

    @SubscribeEvent
    public void onLoadWorld(WorldEvent.Load event) {
        overlayLoc = null;
    }

    @SubscribeEvent
    public void onChatRecevied(ClientChatReceivedEvent event) {
        if(!NotEnoughUpdates.INSTANCE.config.mining.puzzlerSolver) {
            overlayLoc = null;
            return;
        }

        if(event.message.getFormattedText().startsWith("\u00A7e[NPC] \u00A7dPuzzler") &&
                event.message.getUnformattedText().contains(":")) {
            String clean = Utils.cleanColour(event.message.getUnformattedText());
            clean = clean.split(":")[1].trim();

            BlockPos pos = new BlockPos(181, 195, 135);

            for(int i=0; i<clean.length(); i++) {
                char c = clean.charAt(i);

                if(c == '\u25C0') { //Left
                    pos = pos.add(1, 0, 0);
                } else if(c == '\u25B2') { //Up
                    pos = pos.add(0, 0, 1);
                } else if(c == '\u25BC') { //Down
                    pos = pos.add(0, 0, -1);
                } else if(c == '\u25B6') { //Right
                    pos = pos.add(-1, 0, 0);
                } else {
                    return;
                }
            }

            overlayLoc = pos;
        }
    }

    public static boolean blockClicked(BlockPos loc) {
        if(loc.equals(overlayLoc)) {
            overlayLoc = null;
        }
        IBlockState state = Minecraft.getMinecraft().theWorld.getBlockState(loc);
        if(NotEnoughUpdates.INSTANCE.config.mining.dontMineStone &&
                state != null && SBInfo.getInstance().getLocation() != null &&
                SBInfo.getInstance().getLocation().startsWith("mining_") &&
                state.getBlock() == Blocks.stone && state.getValue(BlockStone.VARIANT) == BlockStone.EnumType.STONE) {
            return true;
        }