Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
CreatureChat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Public
CreatureChat
Commits
c9df1a56
Commit
c9df1a56
authored
Jan 27, 2025
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Experimental work on a new Tag editor screen and screen handler.
parent
a9c7b69f
Pipeline
#13315
passed with stages
in 2 minutes 18 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
187 additions
and
1 deletion
+187
-1
ClientInit.java
src/client/java/com/owlmaddie/ClientInit.java
+4
-0
ClickHandler.java
src/client/java/com/owlmaddie/ui/ClickHandler.java
+3
-1
CreatureTagEditorScreen.java
...client/java/com/owlmaddie/ui/CreatureTagEditorScreen.java
+40
-0
ModScreenHandlers.java
src/client/java/com/owlmaddie/ui/ModScreenHandlers.java
+28
-0
TagEditorScreenHandler.java
src/client/java/com/owlmaddie/ui/TagEditorScreenHandler.java
+112
-0
No files found.
src/client/java/com/owlmaddie/ClientInit.java
View file @
c9df1a56
...
@@ -6,6 +6,7 @@ import com.owlmaddie.particle.CreatureParticleFactory;
...
@@ -6,6 +6,7 @@ import com.owlmaddie.particle.CreatureParticleFactory;
import
com.owlmaddie.particle.LeadParticleFactory
;
import
com.owlmaddie.particle.LeadParticleFactory
;
import
com.owlmaddie.ui.BubbleRenderer
;
import
com.owlmaddie.ui.BubbleRenderer
;
import
com.owlmaddie.ui.ClickHandler
;
import
com.owlmaddie.ui.ClickHandler
;
import
com.owlmaddie.ui.ModScreenHandlers
;
import
com.owlmaddie.ui.PlayerMessageManager
;
import
com.owlmaddie.ui.PlayerMessageManager
;
import
net.fabricmc.api.ClientModInitializer
;
import
net.fabricmc.api.ClientModInitializer
;
import
net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
;
import
net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
;
...
@@ -38,6 +39,9 @@ public class ClientInit implements ClientModInitializer {
...
@@ -38,6 +39,9 @@ public class ClientInit implements ClientModInitializer {
ParticleFactoryRegistry
.
getInstance
().
register
(
LEAD_ENEMY_PARTICLE
,
CreatureParticleFactory:
:
new
);
ParticleFactoryRegistry
.
getInstance
().
register
(
LEAD_ENEMY_PARTICLE
,
CreatureParticleFactory:
:
new
);
ParticleFactoryRegistry
.
getInstance
().
register
(
LEAD_PARTICLE
,
LeadParticleFactory:
:
new
);
ParticleFactoryRegistry
.
getInstance
().
register
(
LEAD_PARTICLE
,
LeadParticleFactory:
:
new
);
// Register Creature Tag Editor
ModScreenHandlers
.
register
();
ClientTickEvents
.
END_CLIENT_TICK
.
register
(
client
->
{
ClientTickEvents
.
END_CLIENT_TICK
.
register
(
client
->
{
tickCounter
++;
tickCounter
++;
PlayerMessageManager
.
tickUpdate
();
PlayerMessageManager
.
tickUpdate
();
...
...
src/client/java/com/owlmaddie/ui/ClickHandler.java
View file @
c9df1a56
...
@@ -139,7 +139,9 @@ public class ClickHandler {
...
@@ -139,7 +139,9 @@ public class ClickHandler {
ClientPackets
.
sendUpdateLineNumber
(
closestEntity
,
chatData
.
currentLineNumber
-
ChatDataManager
.
DISPLAY_NUM_LINES
);
ClientPackets
.
sendUpdateLineNumber
(
closestEntity
,
chatData
.
currentLineNumber
-
ChatDataManager
.
DISPLAY_NUM_LINES
);
}
else
if
(
hitRegion
.
equals
(
"RIGHT"
)
&&
chatData
.
isEndOfMessage
())
{
}
else
if
(
hitRegion
.
equals
(
"RIGHT"
)
&&
chatData
.
isEndOfMessage
())
{
// End of chat (open player chat screen)
// End of chat (open player chat screen)
client
.
setScreen
(
new
ChatScreen
(
closestEntity
,
client
.
player
));
//client.setScreen(new ChatScreen(closestEntity, client.player));
TagEditorScreenHandler
handler
=
new
TagEditorScreenHandler
(
0
,
player
.
getInventory
());
client
.
setScreen
(
new
CreatureTagEditorScreen
(
handler
,
player
));
}
else
if
(
hitRegion
.
equals
(
"TOP"
))
{
}
else
if
(
hitRegion
.
equals
(
"TOP"
))
{
// Hide chat
// Hide chat
ClientPackets
.
setChatStatus
(
closestEntity
,
ChatDataManager
.
ChatStatus
.
HIDDEN
);
ClientPackets
.
setChatStatus
(
closestEntity
,
ChatDataManager
.
ChatStatus
.
HIDDEN
);
...
...
src/client/java/com/owlmaddie/ui/CreatureTagEditorScreen.java
0 → 100644
View file @
c9df1a56
package
com
.
owlmaddie
.
ui
;
import
net.minecraft.client.gui.screen.ingame.HandledScreen
;
import
net.minecraft.client.gui.widget.TextFieldWidget
;
import
net.minecraft.entity.player.PlayerEntity
;
import
net.minecraft.text.Text
;
import
net.minecraft.client.gui.DrawContext
;
public
class
CreatureTagEditorScreen
extends
HandledScreen
<
TagEditorScreenHandler
>
{
private
TextFieldWidget
nameField
;
public
CreatureTagEditorScreen
(
TagEditorScreenHandler
handler
,
PlayerEntity
player
)
{
super
(
handler
,
player
.
getInventory
(),
Text
.
literal
(
"Creature Tag Editor"
));
}
@Override
protected
void
init
()
{
super
.
init
();
this
.
nameField
=
new
TextFieldWidget
(
this
.
textRenderer
,
this
.
x
+
10
,
this
.
y
+
10
,
150
,
20
,
Text
.
literal
(
"Enter name"
));
this
.
addDrawableChild
(
this
.
nameField
);
}
@Override
protected
void
drawForeground
(
DrawContext
context
,
int
mouseX
,
int
mouseY
)
{
context
.
drawTextWithShadow
(
this
.
textRenderer
,
this
.
title
,
8
,
6
,
0xFFFFFF
);
}
@Override
protected
void
drawBackground
(
DrawContext
context
,
float
delta
,
int
mouseX
,
int
mouseY
)
{
context
.
fillGradient
(
this
.
x
,
this
.
y
,
this
.
x
+
this
.
backgroundWidth
,
this
.
y
+
this
.
backgroundHeight
,
0xFFCCCCCC
,
0xFF888888
);
}
@Override
public
boolean
mouseClicked
(
double
mouseX
,
double
mouseY
,
int
button
)
{
if
(
this
.
nameField
.
isMouseOver
(
mouseX
,
mouseY
))
{
this
.
nameField
.
setFocused
(
true
);
}
return
super
.
mouseClicked
(
mouseX
,
mouseY
,
button
);
}
}
src/client/java/com/owlmaddie/ui/ModScreenHandlers.java
0 → 100644
View file @
c9df1a56
package
com
.
owlmaddie
.
ui
;
import
net.minecraft.registry.Registries
;
import
net.minecraft.registry.Registry
;
import
net.minecraft.screen.ScreenHandlerType
;
import
net.minecraft.util.Identifier
;
import
net.minecraft.resource.featuretoggle.FeatureFlags
;
public
class
ModScreenHandlers
{
public
static
final
ScreenHandlerType
<
TagEditorScreenHandler
>
TAG_EDITOR_SCREEN_HANDLER
;
static
{
TAG_EDITOR_SCREEN_HANDLER
=
new
ScreenHandlerType
<>(
(
syncId
,
playerInventory
)
->
new
TagEditorScreenHandler
(
syncId
,
playerInventory
),
FeatureFlags
.
VANILLA_FEATURES
);
Registry
.
register
(
Registries
.
SCREEN_HANDLER
,
new
Identifier
(
"mymod"
,
"tag_editor"
),
// Replace "mymod" with your mod ID
TAG_EDITOR_SCREEN_HANDLER
);
}
public
static
void
register
()
{
// Ensure this is called during mod initialization to register the handler
}
}
src/client/java/com/owlmaddie/ui/TagEditorScreenHandler.java
0 → 100644
View file @
c9df1a56
package
com
.
owlmaddie
.
ui
;
import
net.minecraft.entity.player.PlayerEntity
;
import
net.minecraft.entity.player.PlayerInventory
;
import
net.minecraft.inventory.Inventory
;
import
net.minecraft.inventory.SimpleInventory
;
import
net.minecraft.item.ItemStack
;
import
net.minecraft.screen.ScreenHandler
;
import
net.minecraft.screen.slot.Slot
;
public
class
TagEditorScreenHandler
extends
ScreenHandler
{
private
final
Inventory
inventory
;
public
TagEditorScreenHandler
(
int
syncId
,
PlayerInventory
playerInventory
)
{
super
(
ModScreenHandlers
.
TAG_EDITOR_SCREEN_HANDLER
,
syncId
);
this
.
inventory
=
new
SimpleInventory
(
2
);
// 2 custom slots: input and output
// Input slot
this
.
addSlot
(
new
Slot
(
this
.
inventory
,
0
,
80
,
20
));
// Output slot
this
.
addSlot
(
new
Slot
(
this
.
inventory
,
1
,
120
,
20
)
{
@Override
public
boolean
canInsert
(
ItemStack
stack
)
{
return
false
;
// Prevent inserting items into the output slot
}
});
// Player inventory slots
int
playerInventoryStartY
=
84
;
int
hotbarStartY
=
142
;
// Main inventory slots (3 rows of 9)
for
(
int
row
=
0
;
row
<
3
;
row
++)
{
for
(
int
col
=
0
;
col
<
9
;
col
++)
{
this
.
addSlot
(
new
Slot
(
playerInventory
,
col
+
row
*
9
+
9
,
8
+
col
*
18
,
playerInventoryStartY
+
row
*
18
));
}
}
// Hotbar slots (1 row of 9)
for
(
int
col
=
0
;
col
<
9
;
col
++)
{
this
.
addSlot
(
new
Slot
(
playerInventory
,
col
,
8
+
col
*
18
,
hotbarStartY
));
}
}
@Override
public
boolean
canUse
(
PlayerEntity
player
)
{
return
true
;
// Allow the player to use the screen
}
@Override
public
ItemStack
quickMove
(
PlayerEntity
player
,
int
index
)
{
ItemStack
itemStack
=
ItemStack
.
EMPTY
;
Slot
slot
=
this
.
slots
.
get
(
index
);
if
(
slot
!=
null
&&
slot
.
hasStack
())
{
ItemStack
originalStack
=
slot
.
getStack
();
itemStack
=
originalStack
.
copy
();
if
(
index
<
this
.
inventory
.
size
())
{
// If the clicked slot is in the custom inventory (input/output), move to the player's inventory
if
(!
this
.
moveItemStackTo
(
originalStack
,
this
.
inventory
.
size
(),
this
.
slots
.
size
(),
true
))
{
return
ItemStack
.
EMPTY
;
}
}
else
{
// If the clicked slot is in the player's inventory, move to the input slot
if
(!
this
.
moveItemStackTo
(
originalStack
,
0
,
1
,
false
))
{
// 0 to 1 = input slot range
return
ItemStack
.
EMPTY
;
}
}
if
(
originalStack
.
isEmpty
())
{
slot
.
setStack
(
ItemStack
.
EMPTY
);
}
else
{
slot
.
markDirty
();
}
}
return
itemStack
;
}
private
boolean
moveItemStackTo
(
ItemStack
stack
,
int
startIndex
,
int
endIndex
,
boolean
reverseDirection
)
{
boolean
moved
=
false
;
int
i
=
reverseDirection
?
endIndex
-
1
:
startIndex
;
while
(
stack
.
getCount
()
>
0
&&
(!
reverseDirection
&&
i
<
endIndex
||
reverseDirection
&&
i
>=
startIndex
))
{
Slot
slot
=
this
.
slots
.
get
(
i
);
ItemStack
currentStack
=
slot
.
getStack
();
if
(
slot
.
canInsert
(
stack
))
{
int
maxInsert
=
Math
.
min
(
slot
.
getMaxItemCount
(
stack
),
stack
.
getMaxCount
());
int
amountToMove
=
Math
.
min
(
maxInsert
-
currentStack
.
getCount
(),
stack
.
getCount
());
if
(
amountToMove
>
0
)
{
if
(
currentStack
.
isEmpty
())
{
slot
.
setStack
(
stack
.
split
(
amountToMove
));
}
else
if
(
ItemStack
.
canCombine
(
currentStack
,
stack
))
{
currentStack
.
increment
(
amountToMove
);
stack
.
decrement
(
amountToMove
);
}
slot
.
markDirty
();
moved
=
true
;
}
}
i
+=
reverseDirection
?
-
1
:
1
;
}
return
moved
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment