Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.specialeffect.eyemine.submod.movement.Swim;
import com.specialeffect.eyemine.submod.utils.DebugAverageFps;
import me.shedaniel.architectury.event.events.GuiEvent;
import com.specialeffect.eyemine.submod.survival.AutoAim;
import me.shedaniel.architectury.event.events.client.ClientLifecycleEvent;
import me.shedaniel.architectury.event.events.client.ClientRawInputEvent;
import me.shedaniel.architectury.registry.KeyBindings;
Expand All @@ -49,7 +50,7 @@ public class EyeMineClient {
public static boolean disableCustomNewWorld = false;

public static void init() {
//Initialize the first StateOverlay
// Initialize the first StateOverlay
MainClientHandler.initialize();

// Setup all other sub mods
Expand All @@ -60,8 +61,8 @@ public static void init() {
ClientRawInputEvent.KEY_PRESSED.register(CreativeClientHelper::onKeyInput);

ClientLifecycleEvent.CLIENT_SETUP.register((state) -> {
if(!Keybindings.keybindings.isEmpty()) {
for(KeyMapping keyBinding : Keybindings.keybindings) {
if (!Keybindings.keybindings.isEmpty()) {
for (KeyMapping keyBinding : Keybindings.keybindings) {
KeyBindings.registerKeyBinding(keyBinding);
}
}
Expand Down Expand Up @@ -102,6 +103,7 @@ private static void instantiateSubMods() {
setupSubMod(new IronSights());
setupSubMod(new NightVisionHelper());
setupSubMod(new CountBlocks());
setupSubMod(new AutoAim());
}

private static void setupSubMod(SubMod mod) {
Expand All @@ -113,7 +115,7 @@ public static void refresh() {
if (setupComplete) {
for (SubMod child : subModList) {
if (child instanceof IConfigListener) {
IConfigListener configListener = (IConfigListener)child;
IConfigListener configListener = (IConfigListener) child;
configListener.syncConfig();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,68 +1,150 @@
/**
* Copyright (C) 2016-2020 Kirsty McNaught
*
* Developed for SpecialEffect, www.specialeffect.org.uk
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This class control counting blocks
*
* @author Kirsty McNaught and Becky Tyler
* @version 1.0
*/
package com.specialeffect.eyemine.submod.building;

import com.specialeffect.eyemine.client.Keybindings;
import com.specialeffect.eyemine.submod.SubMod;
import com.specialeffect.utils.ModUtils;
import com.specialeffect.eyemine.mixin.KeyMappingAccessor;

import java.rmi.server.Skeleton;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.function.Predicate;

import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.platform.InputConstants.Type;

import org.lwjgl.glfw.GLFW;

import me.shedaniel.architectury.event.events.client.ClientRawInputEvent;
import me.shedaniel.architectury.event.events.client.ClientTickEvent;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import me.shedaniel.architectury.event.events.GuiEvent;
import me.shedaniel.architectury.event.events.EntityEvent.LivingAttack;
import me.shedaniel.architectury.event.events.BlockEvent;

import me.shedaniel.architectury.event.events.EntityEvent;

public class CountBlocks extends SubMod {
public final String MODID = "countblocks"; // this needs to be a unique ID
public final String MODID = "countblocks"; // this needs to be a unique ID

// Member variables we need
// - a static KeyMapping for the shortcut key
public static KeyMapping mNumberBlockKB;

// - a list of BlockPos positions for all the blocks we are tracking
public ArrayList<BlockPos> blockPosList;

// - a boolean indicating whether we are currently counting blocks
public boolean countingBlocks;

public void onInitializeClient() {

public void onInitializeClient() {
// Create the list of BlockPos positions
blockPosList = new ArrayList<BlockPos>();

// TODO: Register the key binding here
// by adding to Keybindings.keybindings and
// Initialise the countingBlocks flag
countingBlocks = false;

// Register the key binding here
Keybindings.keybindings.add(mNumberBlockKB = new KeyMapping(
"Number_Block", // this needs to be a unique name
Type.KEYSYM, // this is always KEYSYM
GLFW.GLFW_KEY_K, // this selects the default key. try autocompleting GLFW.GLFW_KEY... to see more
// options
"category.eyemine.category.eyegaze_common" // this sets the translation key for the name of the category
// in the controls list
// (we use eyegaze_common, eyegaze_extra and eyegaze_settings
// depending on the mod)
));

// by adding to Keybindings.keybindings and
// registering function with ClientRawInputEvent.Key_PRESSED
// (look at PickBlock class for reference)
ClientRawInputEvent.KEY_PRESSED.register(this::onKeyInput);

// Register the "place block" event
BlockEvent.PLACE.register(this::onPlaceBlock);

}

private InteractionResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) {
private InteractionResult onKeyInput(Minecraft minecraft, int keyCode, int scanCode, int action, int modifiers) {
// This method gets called when *any* key is pressed

// Skip if there is a GUI visible
if (ModUtils.hasActiveGui()) { return InteractionResult.PASS; }
if (ModUtils.hasActiveGui()) {
return InteractionResult.PASS;
}

// Skip if F3 is held down (this is used for debugging)
if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) { return InteractionResult.PASS; }

ModUtils.sendPlayerMessage("Key pressed: " + keyCode);

// TODO: add if statement for if the key pressed is the one we are using.
// Inside the if statement we will need to
// - turn counting on or off
// - empty the list of blocks

return InteractionResult.PASS;
if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), 292)) {
return InteractionResult.PASS;
}

// If statement for when the key pressed is the one we are using.
// Inside the if statement we will need to
// - turn counting on or off
// - empty the list of blocks
if (mNumberBlockKB.matches(keyCode, scanCode) && mNumberBlockKB.consumeClick()) {
ModUtils.sendPlayerMessage("Key pressed: " + keyCode);

// Toggle the value of countingBlocks
countingBlocks = !countingBlocks;

// Clear the list of BlockPos positions
blockPosList.clear();

}
return InteractionResult.PASS;
}


/**
* Whenever a block is placed, send a chat message with the position of the
* block
*
* @param l The level the block is being placed in
* @param position The position of the block that was placed
* @param state The block state of the block being placed
* @param entity The entity that placed the block.
* @return The return value is an InteractionResult. This is a value that tells
* the game what to do
* with the block.
*/
public InteractionResult onPlaceBlock(Level l, BlockPos position, BlockState state, Entity entity) {
// Add block's position to list of block positions
blockPosList.add(position);

// Send a chat message showing position and number of blocks placed
ModUtils.sendPlayerMessage("Block " + blockPosList.size() + " placed at " + position); // for debugging

// This method is called whenever a block is placed
return InteractionResult.PASS;
}
Expand Down
Loading