aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/features/puzzlesolvers/ArrowTerminalSolver.java
blob: 14870f2158fa9275cebcf33adf894f8814de1a02 (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
package me.Danker.features.puzzlesolvers;

import me.Danker.commands.ToggleCommand;
import me.Danker.events.PacketWriteEvent;
import me.Danker.utils.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.C02PacketUseEntity;
import net.minecraft.util.BlockPos;
import net.minecraftforge.event.entity.player.EntityInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class ArrowTerminalSolver {

    @SubscribeEvent
    public void onEntityInteract(EntityInteractEvent event) {
        Minecraft mc = Minecraft.getMinecraft();
        if (mc.thePlayer != event.entityPlayer) return;

        if (ToggleCommand.itemFrameOnSeaLanternsToggled && Utils.inDungeons && event.target instanceof EntityItemFrame) {
            EntityItemFrame itemFrame = (EntityItemFrame) event.target;
            ItemStack item = itemFrame.getDisplayedItem();
            if (item == null || item.getItem() != Items.arrow) return;
            BlockPos blockPos = Utils.getBlockUnderItemFrame(itemFrame);
            if (mc.theWorld.getBlockState(blockPos).getBlock() == Blocks.sea_lantern) {
                event.setCanceled(true);
            }
        }
    }

    @SubscribeEvent
    public void onPacket(PacketWriteEvent event) {
        if (ToggleCommand.itemFrameOnSeaLanternsToggled && Utils.inDungeons && event.packet instanceof C02PacketUseEntity) {
            Minecraft mc = Minecraft.getMinecraft();
            C02PacketUseEntity packet = (C02PacketUseEntity) event.packet;
            Entity entityHit = packet.getEntityFromWorld(mc.theWorld);
            if (entityHit instanceof EntityItemFrame) {
                EntityItemFrame itemFrame = (EntityItemFrame) entityHit;
                ItemStack item = itemFrame.getDisplayedItem();
                if (item != null && item.getItem() == Items.arrow) {
                    BlockPos blockPos = Utils.getBlockUnderItemFrame(itemFrame);
                    if (mc.theWorld.getBlockState(blockPos).getBlock() == Blocks.sea_lantern) {
                        event.setCanceled(true);
                    }
                }
            }
        }

    }

}