forked from VazkiiMods/Quark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
# | ||
#Tue Dec 22 14:17:37 GMT 2020 | ||
mod_name=Quark | ||
forge_version=34.1.32 | ||
forge_version=35.1.28 | ||
mapping_version=20200916-1.16.2 | ||
mapping_channel=snapshot | ||
mod_id=quark | ||
jei_version=7.6.0.49 | ||
jei_version=7.6.0.62 | ||
arl_version=1.6-46.85 | ||
version=r2.4 | ||
dir_output=../Build Output/Quark/ | ||
build_number=284 | ||
mc_version=1.16.3 | ||
mc_version=1.16.4 |
Empty file.
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/main/java/vazkii/quark/content/experimental/module/NarratorReadoutModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package vazkii.quark.content.experimental.module; | ||
|
||
import com.mojang.text2speech.Narrator; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.settings.KeyBinding; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.BlockRayTraceResult; | ||
import net.minecraft.util.math.RayTraceResult; | ||
import net.minecraft.util.text.StringTextComponent; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
import net.minecraftforge.client.event.InputEvent; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import vazkii.quark.base.client.ModKeybindHandler; | ||
import vazkii.quark.base.module.LoadModule; | ||
import vazkii.quark.base.module.ModuleCategory; | ||
import vazkii.quark.base.module.QuarkModule; | ||
|
||
@LoadModule(category = ModuleCategory.EXPERIMENTAL, enabledByDefault = false, hasSubscriptions = true, subscribeOn = Dist.CLIENT) | ||
public class NarratorReadoutModule extends QuarkModule { | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
private KeyBinding keybind; | ||
|
||
@Override | ||
@OnlyIn(Dist.CLIENT) | ||
public void clientSetup() { | ||
if(enabled) | ||
keybind = ModKeybindHandler.init("narrator_readout", "m", ModKeybindHandler.ACCESSIBILITY_GROUP); | ||
} | ||
|
||
@SubscribeEvent | ||
@OnlyIn(Dist.CLIENT) | ||
public void onMouseInput(InputEvent.MouseInputEvent event) { | ||
acceptInput(); | ||
} | ||
|
||
@SubscribeEvent | ||
@OnlyIn(Dist.CLIENT) | ||
public void onKeyInput(InputEvent.KeyInputEvent event) { | ||
acceptInput(); | ||
} | ||
|
||
private void acceptInput() { | ||
Minecraft mc = Minecraft.getInstance(); | ||
boolean down = keybind != null && keybind.isKeyDown(); | ||
if(mc.isGameFocused() && down) { | ||
Narrator narrator = Narrator.getNarrator(); | ||
String readout = getReadout(mc); | ||
if(readout != null) { | ||
narrator.say(readout, true); | ||
if(mc.player != null) | ||
mc.player.sendStatusMessage(new StringTextComponent(readout), true); | ||
} | ||
} | ||
} | ||
|
||
private String getReadout(Minecraft mc) { | ||
PlayerEntity player = mc.player; | ||
if(player == null) | ||
return "Not ingame."; | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
|
||
RayTraceResult ray = mc.objectMouseOver; | ||
if(ray != null && ray instanceof BlockRayTraceResult) { | ||
BlockPos pos = ((BlockRayTraceResult) ray).getPos(); | ||
BlockState state = mc.world.getBlockState(pos); | ||
|
||
Item item = state.getBlock().asItem(); | ||
if(item != null) { | ||
sb.append("Looking at "); | ||
sb.append(item.getDisplayName(new ItemStack(item)).getString().trim()); | ||
sb.append(", "); | ||
} | ||
} | ||
|
||
ItemStack stack = player.getHeldItemMainhand(); | ||
if(!stack.isEmpty()) { | ||
sb.append("Holding "); | ||
sb.append(stack.getDisplayName().getString().trim()); | ||
sb.append(", "); | ||
} | ||
|
||
sb.append("Health "); | ||
sb.append((int) mc.player.getHealth()); | ||
sb.append(", Food "); | ||
sb.append(mc.player.getFoodStats().getFoodLevel()); | ||
|
||
return sb.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters