Skip to content

Commit

Permalink
big changes are coming (they're already here)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttttdoy committed Aug 14, 2024
1 parent ed618e0 commit 0bdaec8
Show file tree
Hide file tree
Showing 18 changed files with 973 additions and 590 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
- [X] items inputted into machines from their sides are voided out of existence
- [X] items not saving on world save/load
- [ ] Fluid texture on diesel machine needs to be normalized
- [ ] (major) tool gun stacking up/absorbing clicks when not equipped
- [X] (major) tool gun stacking up/absorbing clicks when not equipped
- [ ] Tool gun beam is scuffed
- [ ] Certain slots in block entity screens not showing any items on client
- [ ] happy block explosion not actually exploding an area
Expand Down
126 changes: 126 additions & 0 deletions src/main/kotlin/breadmod/ClientForgeEventBus.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
package breadmod

import breadmod.ClientModEventBus.createMappingsForControls
import breadmod.ClientModEventBus.toolGunBindList
import breadmod.datagen.tool_gun.BreadModToolGunModeProvider.Companion.TOOL_GUN_DEF
import breadmod.item.tool_gun.ToolGunItem
import breadmod.network.PacketHandler.NETWORK
import breadmod.network.tool_gun.ToolGunPacket
import breadmod.util.render.renderBuffer
import com.mojang.blaze3d.platform.InputConstants
import net.minecraft.client.KeyMapping
import net.minecraft.client.Minecraft
import net.minecraft.client.player.LocalPlayer
import net.minecraft.sounds.SoundEvents
import net.minecraftforge.api.distmarker.Dist
import net.minecraftforge.client.event.InputEvent
import net.minecraftforge.client.event.RenderLevelStageEvent
import net.minecraftforge.client.settings.KeyConflictContext
import net.minecraftforge.client.settings.KeyModifier
import net.minecraftforge.event.TickEvent
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent
import net.minecraftforge.eventbus.api.SubscribeEvent
import net.minecraftforge.fml.common.Mod
Expand Down Expand Up @@ -32,6 +45,119 @@ object ClientForgeEventBus {
options.keyMappings = ArrayUtils.removeElements(options.keyMappings, *createMappingsForControls().toTypedArray())
}

// val keyMap = KeyMapping("tool gun test", GLFW.GLFW_KEY_H, "breadmod")
val changeMode = KeyMapping(
"controls.${ModMain.ID}.$TOOL_GUN_DEF.change_mode",
KeyConflictContext.IN_GAME,
KeyModifier.SHIFT,
InputConstants.Type.MOUSE.getOrCreate(InputConstants.MOUSE_BUTTON_RIGHT),
"controls.${ModMain.ID}.category.$TOOL_GUN_DEF"
)

@SubscribeEvent
fun keyInput(event: InputEvent.Key) {
val instance = Minecraft.getInstance()
val player: LocalPlayer = instance.player ?: return
val level = instance.level ?: return
val stack = player.mainHandItem
val item = stack.item

if(item is ToolGunItem) {
val currentMode = item.getCurrentMode(stack)
if(player.isHolding(item) && changeMode.consumeClick() &&
event.action == InputConstants.PRESS) {
NETWORK.sendToServer(ToolGunPacket(true))
player.playSound(SoundEvents.DISPENSER_FAIL, 1.0f, 1.0f)
} else {
currentMode.keyBinds.forEach {
val bind = toolGunBindList[it] ?: return@forEach
if(player.isHolding(item) && event.key == bind.key.value && event.action == InputConstants.PRESS) {
NETWORK.sendToServer(ToolGunPacket(false, it))
println("firing action")
currentMode.mode.action(level, player, stack, it)
}
}
}
}
}

@SubscribeEvent
fun mouseInput(event: InputEvent.MouseButton.Post) {
val instance = Minecraft.getInstance()
val player: LocalPlayer = instance.player ?: return
val level = instance.level ?: return
val stack = player.mainHandItem
val item = stack.item

if(item is ToolGunItem) {
// println(event.modifiers)
val currentMode = item.getCurrentMode(stack)
currentMode.keyBinds.forEach {
val bind = toolGunBindList[it] ?: return@forEach
if(player.isHolding(item) && event.button == bind.key.value
&& event.action == InputConstants.PRESS) {
NETWORK.sendToServer(ToolGunPacket(false, it))
println("firing action")
currentMode.mode.action(level, player, stack, it)
}
}
}
}

@SubscribeEvent
fun playerTick(event: TickEvent.ClientTickEvent) {
val instance = Minecraft.getInstance()
val player = instance.player ?: return
val level = instance.level ?: return
val stack = player.mainHandItem
val item = stack.item

if(item is ToolGunItem) {
val currentMode = item.getCurrentMode(stack)
if(player.isHolding(item)) {
currentMode.mode.open(level, player, stack, null)
} else {
currentMode.mode.close(level, player, stack, null)
}
}
}

// @SubscribeEvent
// fun clientTick(event: TickEvent.ClientTickEvent) {
// if(event.phase != TickEvent.Phase.END) return
//
// val instance = Minecraft.getInstance()
// val level = instance.level ?: return
// val player = instance.player ?: return
// val stack = player.mainHandItem
// val item = stack.item
//
// if(item is ToolGunItem && player.isHolding(stack.item)) {
// val currentMode = item.getCurrentMode(stack)
// if(level.isClientSide) {
// if(!player.isHolding(item)) currentMode.mode.close(level, player, stack, null)
// else {
// if(ToolGunItem.changeMode.consumeClick()) {
// NETWORK.sendToServer(ToolGunPacket(true))
// player.playSound(SoundEvents.DISPENSER_FAIL, 1.0f, 1.0f)
// } else {
// currentMode.mode.open(level, player, stack, null)
// currentMode.keyBinds.forEach {
// val bind = toolGunBindList[it]
// if(bind != null && bind.consumeClick()) {
// NETWORK.sendToServer(ToolGunPacket(false, it))
// currentMode.mode.action(level, player, stack, it)
// }
// }
// }
// }
// } else {
// if(player.isHolding(item)) currentMode.mode.open(level, player, stack, null)
// else currentMode.mode.close(level, player, stack, null)
// }
// }
// }

// @Suppress("UNUSED_PARAMETER")
// @SubscribeEvent
// fun onTick(event: TickEvent.ClientTickEvent) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/breadmod/ClientModEventBus.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package breadmod

import breadmod.ClientForgeEventBus.changeMode
import breadmod.ModMain.ID
import breadmod.ModMain.modLocation
import breadmod.client.render.SidedScreenRenderer
Expand All @@ -12,13 +13,12 @@ import breadmod.datagen.tool_gun.BreadModToolGunModeProvider.Companion.TOOL_GUN_
import breadmod.datagen.tool_gun.BreadModToolGunModeProvider.Control
import breadmod.client.render.entity.BreadBulletEntityRenderer
import breadmod.client.render.entity.PrimedHappyBlockRenderer
import breadmod.client.hud.ToolGunOverlay
import breadmod.client.gui.ToolGunOverlay
import breadmod.client.render.ToasterRenderer
import breadmod.item.armor.BreadArmorItem
import breadmod.item.armor.ArmorColor
import breadmod.client.screen.CertificateItemScreen
import breadmod.client.screen.tool_gun.ToolGunCreatorScreen
import breadmod.item.tool_gun.ToolGunItem.Companion.changeMode
import breadmod.registry.block.ModBlockEntityTypes
import breadmod.registry.entity.ModEntityTypes.BREAD_BULLET_ENTITY
import breadmod.registry.entity.ModEntityTypes.HAPPY_BLOCK_ENTITY
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package breadmod.client.hud
package breadmod.client.gui

import breadmod.util.render.scaleFlat
import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiGraphics
Expand Down Expand Up @@ -46,8 +47,6 @@ abstract class AbstractModGuiOverlay: IGuiOverlay {
pPlayer: LocalPlayer
)

fun PoseStack.scaleFlat(scale: Float) = this.scale(scale, scale, scale)

fun drawScaledText(
pText: Component,
pPose: PoseStack,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package breadmod.client.hud
package breadmod.client.gui

import breadmod.ClientModEventBus.toolGunBindList
import breadmod.ModMain.modLocation
Expand All @@ -7,6 +7,7 @@ import breadmod.datagen.tool_gun.BreadModToolGunModeProvider.Companion.TOOL_GUN_
import breadmod.datagen.tool_gun.ModToolGunModeDataLoader
import breadmod.item.tool_gun.ToolGunItem
import breadmod.item.tool_gun.ToolGunItem.Companion.MODE_NAMESPACE_TAG
import breadmod.util.render.scaleFlat
import com.mojang.blaze3d.platform.InputConstants
import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.ChatFormatting
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package breadmod.client.gui.components

import breadmod.util.render.scaleFlat
import com.mojang.blaze3d.systems.RenderSystem
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.Font
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.components.AbstractButton
import net.minecraft.client.gui.narration.NarrationElementOutput
import net.minecraft.network.chat.Component
import java.awt.Color

/** A scalable button widget.
* ### Note: text currently does not support scrolling */
abstract class ScaledAbstractButton(
private val pX: Int,
private val pY: Int,
private val pWidth: Int,
private val pHeight: Int,
private val pScale: Double,
private val pMessage: Component
) : AbstractButton(pX, pY, pWidth, pHeight, pMessage) {
val font: Font = Minecraft.getInstance().font

// todo look into converting clicked, isMouseOver, and renderWidget into using doubles for their positioning instead of using the superclass positioning
// todo look into implementing OnPress from Button.java (might not be possible)

override fun updateWidgetNarration(pNarrationElementOutput: NarrationElementOutput) {}

override fun renderWidget(pGuiGraphics: GuiGraphics, pMouseX: Int, pMouseY: Int, pPartialTick: Float) {
val poseStack = pGuiGraphics.pose()
pGuiGraphics.setColor(1.0f, 1.0f, 1.0f, alpha)
RenderSystem.enableBlend()
RenderSystem.enableDepthTest()
poseStack.pushPose()
poseStack.translate(pX.toDouble(), pY.toDouble(), 0.0)
poseStack.scaleFlat(pScale.toFloat())
pGuiGraphics.blitNineSliced(WIDGETS_LOCATION, 0, 0, pWidth, pHeight,
20, 4, 200, 20, 0, textureY
)
// renderString(pGuiGraphics, font, fgColor or (Mth.ceil(this.alpha * 255.0f) shl 24))
// todo re-implementation of scrolling string that supports scaling.
// AbstractWidget.renderScrollingString(pGuiGraphics, font, pMessage, 0, 0, pWidth, pHeight, Color.WHITE.rgb)
pGuiGraphics.drawString(font, pMessage, 2, 1, Color.WHITE.rgb, true)
poseStack.popPose()
}

override fun renderScrollingString(pGuiGraphics: GuiGraphics, pFont: Font, pWidth: Int, pColor: Int) {
super.renderScrollingString(pGuiGraphics, pFont, pWidth, pColor)
}

override fun render(pGuiGraphics: GuiGraphics, pMouseX: Int, pMouseY: Int, pPartialTick: Float) {
if(visible) {
isHovered = pMouseX >= x && pMouseY >= y && pMouseX < x + (width * pScale) && pMouseY < y + (height * pScale)
renderWidget(pGuiGraphics, pMouseX, pMouseY, pPartialTick)
updateTooltip()
}
}

// the hitbox for the widget
override fun clicked(pMouseX: Double, pMouseY: Double): Boolean =
active && visible && pMouseX >= x && pMouseY >= y &&
pMouseX < x + (width * pScale) && pMouseY < y + (height * pScale)

// controls the "hover" graphic when mouse is over widget
override fun isMouseOver(pMouseX: Double, pMouseY: Double): Boolean =
active && visible && pMouseX >= x && pMouseY >= y &&
pMouseX < x + (width * pScale) && pMouseY < y + (height * pScale)

override fun isFocused(): Boolean = isHovered
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package breadmod.client.gui.components

import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.components.AbstractWidget
import net.minecraft.client.gui.narration.NarrationElementOutput
import net.minecraft.network.chat.Component

abstract class ScaledAbstractWidget(
pX: Int,
pY: Int,
pWidth: Int,
pHeight: Int,
private val pScale: Double,
pMessage: Component
) : AbstractWidget(pX, pY, pWidth, pHeight, pMessage) {
override fun updateWidgetNarration(pNarrationElementOutput: NarrationElementOutput) {}

// todo look into converting clicked, isMouseOver, and renderWidget into using doubles for their positioning instead of using the superclass positioning

override fun render(pGuiGraphics: GuiGraphics, pMouseX: Int, pMouseY: Int, pPartialTick: Float) {
if(visible) {
isHovered = pMouseX >= x && pMouseY >= y && pMouseX < x + (width * pScale) && pMouseY < y + (height * pScale)
renderWidget(pGuiGraphics, pMouseX, pMouseY, pPartialTick)
updateTooltip()
}
}

// the hitbox for the widget
override fun clicked(pMouseX: Double, pMouseY: Double): Boolean =
active && visible && pMouseX >= x && pMouseY >= y &&
pMouseX < x + (width * pScale) && pMouseY < y + (height * pScale)

// controls the "hover" graphic when mouse is over widget
override fun isMouseOver(pMouseX: Double, pMouseY: Double): Boolean =
active && visible && pMouseX >= x && pMouseY >= y &&
pMouseX < x + (width * pScale) && pMouseY < y + (height * pScale)

override fun isFocused(): Boolean = isHovered
}
Loading

0 comments on commit 0bdaec8

Please sign in to comment.