block destruction work

This commit is contained in:
austin 2025-04-26 17:36:12 -04:00
parent df72d51ea2
commit d0fcded76d
4 changed files with 58 additions and 9 deletions

View File

@ -1552,6 +1552,7 @@ Fix bug where inventory items aren't destroying physics on server
Align voxel lookups for movement audio and interaction targeting Align voxel lookups for movement audio and interaction targeting
Align block lookups for interaction targeting Align block lookups for interaction targeting
Cursor logic around blocks Cursor logic around blocks
Block destruction work

View File

@ -57,15 +57,11 @@ public class ItemActions {
if(cursorPos == null){ if(cursorPos == null){
cursorPos = new Vector3d(centerPos).add(new Vector3d(eyePos).normalize().mul(-CollisionEngine.DEFAULT_INTERACT_DISTANCE)); cursorPos = new Vector3d(centerPos).add(new Vector3d(eyePos).normalize().mul(-CollisionEngine.DEFAULT_INTERACT_DISTANCE));
} }
//tell the server we want the secondary hand item to START doing something
Globals.clientConnection.queueOutgoingMessage(InventoryMessage.constructclientRequestPerformItemActionMessage( //send server message if we're not doing a block edit
"handRight", //client sends custom packets for block editing
ITEM_ACTION_CODE_PRIMARY, boolean sendServerMessage = true;
ITEM_ACTION_CODE_STATE_ON,
cursorPos.x,
cursorPos.y,
cursorPos.z
));
//TODO: do any immediate client side calculations here (ie start playing an animation until we get response from server) //TODO: do any immediate client side calculations here (ie start playing an animation until we get response from server)
if(Globals.playerEntity != null){ if(Globals.playerEntity != null){
ClientAttackTree attackTree = CreatureUtils.clientGetAttackTree(Globals.playerEntity); ClientAttackTree attackTree = CreatureUtils.clientGetAttackTree(Globals.playerEntity);
@ -83,8 +79,27 @@ public class ItemActions {
if(data.getClientSidePrimary() != null){ if(data.getClientSidePrimary() != null){
ClientScriptUtils.fireSignal(data.getClientSidePrimary()); ClientScriptUtils.fireSignal(data.getClientSidePrimary());
} }
if(data.getPrimaryUsage() != null){
if(data.getPrimaryUsage().getBlockId() != null){
sendServerMessage = false;
BlockEditing.destroyBlock();
Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.INTERACT_SFX_BLOCK_PLACE, VirtualAudioSourceType.CREATURE, false);
}
}
} }
} }
if(sendServerMessage){
//tell the server we want the secondary hand item to START doing something
Globals.clientConnection.queueOutgoingMessage(InventoryMessage.constructclientRequestPerformItemActionMessage(
"handRight",
ITEM_ACTION_CODE_PRIMARY,
ITEM_ACTION_CODE_STATE_ON,
cursorPos.x,
cursorPos.y,
cursorPos.z
));
}
} }
/** /**

View File

@ -23,4 +23,14 @@ public class BlockEditing {
ScriptClientVoxelUtils.clientRequestEditBlock(chunkPos, cornerVoxel, type, metadata, blockSize); ScriptClientVoxelUtils.clientRequestEditBlock(chunkPos, cornerVoxel, type, metadata, blockSize);
} }
/**
* Destroy blocks
*/
public static void destroyBlock(){
Vector3i cornerVoxel = Globals.cursorState.getBlockCornerVoxelPos();
int blockSize = Globals.cursorState.getBlockSize();
Vector3i chunkPos = Globals.clientWorldData.convertRealToWorldSpace(EntityUtils.getPosition(Globals.playerBlockCursor));
ScriptClientVoxelUtils.clientRequestEditBlock(chunkPos, cornerVoxel, (short)0, (short)0, blockSize);
}
} }

View File

@ -69,6 +69,11 @@ public class Item extends CommonEntityType {
*/ */
String clientSideSecondary; String clientSideSecondary;
/**
* The usage logic for a primary usage of this item
*/
ItemUsage primaryUsage;
/** /**
* The usage logic for a secondary usage of this item * The usage logic for a secondary usage of this item
*/ */
@ -151,6 +156,7 @@ public class Item extends CommonEntityType {
usage.setBlockId(blockType.getId()); usage.setBlockId(blockType.getId());
usage.setOnlyOnMouseDown(true); usage.setOnlyOnMouseDown(true);
rVal.setSecondaryUsage(usage); rVal.setSecondaryUsage(usage);
rVal.setPrimaryUsage(usage);
//attach common tokens //attach common tokens
@ -216,6 +222,7 @@ public class Item extends CommonEntityType {
public String getClientSideSecondary(){ public String getClientSideSecondary(){
return clientSideSecondary; return clientSideSecondary;
} }
/** /**
* Gets the secondary usage logic of this item * Gets the secondary usage logic of this item
* @return The secondary usage logic * @return The secondary usage logic
@ -232,4 +239,20 @@ public class Item extends CommonEntityType {
this.secondaryUsage = secondaryUsage; this.secondaryUsage = secondaryUsage;
} }
/**
* Gets the primary usage logic of this item
* @return The primary usage logic
*/
public ItemUsage getPrimaryUsage(){
return primaryUsage;
}
/**
* Sets the primary usage logic of this item
* @param primaryUsage The primary usage logic
*/
public void setPrimaryUsage(ItemUsage primaryUsage){
this.primaryUsage = primaryUsage;
}
} }