PlaceBlockInteraction class
Пакет: com.hypixel.hytale.server.core.modules.interaction.interaction.config.client
Файл: com/hypixel/hytale/server/core/modules/interaction/interaction/config/client/PlaceBlockInteraction.java
extends: SimpleInteraction
Поля (39)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
HytaleLogger |
LOGGER |
|
|
return |
|
|
return |
|
|
return |
|
|
return |
|
|
return |
|
|
return |
|
|
return |
|
BlockRotation |
var10 |
|
World |
var11 |
|
Store |
var12 |
|
Ref |
var13 |
|
Player |
var14 |
|
boolean |
var15 |
|
boolean |
var16 |
|
boolean |
var17 |
|
boolean |
var18 |
|
|
var18 |
|
PlayerSettings |
var19 |
|
com.hypixel.hytale.protocol.PlaceBlockInteraction |
var2 |
|
ItemContainer |
var20 |
|
Vector3i |
var21 |
|
String |
var22 |
|
BlockType |
var23 |
|
int |
var24 |
|
BlockType |
var25 |
|
String |
var26 |
|
|
var26 |
|
PlacementGestureTracker |
var27 |
|
String |
var28 |
|
BlockSection |
var29 |
|
RotationTuple |
var30 |
|
ItemStack |
var31 |
|
boolean |
var32 |
|
InteractionSyncData |
var6 |
|
InteractionSyncData |
var6 |
|
Ref |
var7 |
|
CommandBuffer |
var8 |
|
BlockPosition |
var9 |
Методы (8)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
|
if if(!var1) |
|
|
if if(var9 != null && var10 != null) |
|
|
if if(var15 && !var18) |
|
|
if if(var20 == null) |
|
|
if if(var22 == null) |
|
|
if if(var24 != -1 && var25 == null) |
|
|
if if(var27 != null) |
|
|
if if(!var1) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.modules.interaction.interaction.config.client;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.protocol.BlockPosition;
class="kw">import com.hypixel.hytale.protocol.BlockRotation;
class="kw">import com.hypixel.hytale.protocol.GameMode;
class="kw">import com.hypixel.hytale.protocol.InteractionState;
class="kw">import com.hypixel.hytale.protocol.InteractionSyncData;
class="kw">import com.hypixel.hytale.protocol.InteractionType;
class="kw">import com.hypixel.hytale.protocol.Rotation;
class="kw">import com.hypixel.hytale.protocol.WaitForDataFrom;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockFace;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.RotationTuple;
class="kw">import com.hypixel.hytale.server.core.entity.EntityUtils;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionContext;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
class="kw">import com.hypixel.hytale.server.core.modules.entity.player.PlayerSettings;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.BlockPlaceUtils;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.Interaction;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.SimpleInteraction;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.util.InteractionValidation;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3i;
class="kw">public class PlaceBlockInteraction class="kw">extends SimpleInteraction {
class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
@Nonnull
class="kw">public class="kw">static class="kw">final BuilderCodec<PlaceBlockInteraction> CODEC = BuilderCodec.builder(
PlaceBlockInteraction.class, PlaceBlockInteraction::new, SimpleInteraction.CODEC
)
.documentation("Places the current or given block.")
.<String>append(new KeyedCodec<>("BlockTypeToPlace", Codec.STRING), (var0, var1) -> var0.blockTypeKey = var1, var0 -> var0.blockTypeKey)
.addValidatorLate(() -> BlockType.VALIDATOR_CACHE.getValidator().late())
.documentation("Overrides the placed block type of the held item with the provided block type.")
.add()
.<Boolean>append(new KeyedCodec<>("RemoveItemInHand", Codec.BOOLEAN), (var0, var1) -> var0.removeItemInHand = var1, var0 -> var0.removeItemInHand)
.documentation("Determines whether to remove the item that is in the instigating entities hand.")
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("QuickReplace", Codec.BOOLEAN),
(var0, var1) -> var0.quickReplace = var1,
var0 -> var0.quickReplace,
(var0, var1) -> var0.quickReplace = var1.quickReplace
)
.documentation("Replaces the targeted block without requiring it to be broken first. Only honored for players in Creative.")
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("QuickRetype", Codec.BOOLEAN),
(var0, var1) -> var0.quickRetype = var1,
var0 -> var0.quickRetype,
(var0, var1) -> var0.quickRetype = var1.quickRetype
)
.documentation("Swaps the targeted block to the held block type while keeping its shape and rotation. Only honored for players in Creative.")
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("NoPhysics", Codec.BOOLEAN),
(var0, var1) -> var0.noPhysics = var1,
var0 -> var0.noPhysics,
(var0, var1) -> var0.noPhysics = var1.noPhysics
)
.documentation("Suppresses block physics updates for the placement. Only honored for players in Creative.")
.add()
.build();
@Nullable
class="kw">protected String blockTypeKey;
class="kw">protected boolean removeItemInHand = true;
class="kw">protected boolean quickReplace;
class="kw">protected boolean quickRetype;
class="kw">protected boolean noPhysics;
class="kw">public PlaceBlockInteraction() {
}
@Nonnull
@Override
class="kw">public WaitForDataFrom getWaitForDataFrom() {
class="kw">return WaitForDataFrom.Client;
}
@Override
class="kw">protected class="kw">final void tick0(boolean var1, float var2, @Nonnull InteractionType var3, @Nonnull InteractionContext var4, @Nonnull CooldownHandler var5) {
InteractionSyncData var6 = var4.getClientState();
assert var6 != null;
if (!var1) {
var4.getState().state = var6.state;
} else {
Ref var7 = var4.getEntity();
CommandBuffer var8 = var4.getCommandBuffer();
assert var8 != null;
BlockPosition var9 = var6.blockPosition;
BlockRotation var10 = var6.blockRotation;
if (var9 != null && var10 != null) {
World var11 = var8.getExternalData().getWorld();
Store var12 = var11.getChunkStore().getStore();
Ref var13 = var12.getExternalData().getChunkSectionReferenceAtBlock(var9.x, var9.y, var9.z);
if (var13 == null || !var13.isValid()) {
var4.getState().state = InteractionState.Failed;
class="kw">return;
}
Player var14 = var8.getComponent(var7, Player.getComponentType());
boolean var15 = var14 != null && var14.getGameMode() == GameMode.Creative;
boolean var16 = var15 && this.quickReplace;
boolean var17 = var15 && this.quickRetype;
boolean var18 = var15 && this.noPhysics;
if (var15 && !var18) {
PlayerSettings var19 = var8.getComponent(var7, PlayerSettings.getComponentType());
var18 = var19 != null && var19.creativeSettings().noPhysics();
}
ItemStack var31 = var4.getHeldItem();
if (var31 == null && (!var16 || this.blockTypeKey == null)) {
var4.getState().state = InteractionState.Failed;
class="kw">return;
}
ItemContainer var20 = var4.getHeldItemContainer();
if (var20 == null) {
var4.getState().state = InteractionState.Failed;
class="kw">return;
}
Vector3i var21 = new Vector3i(var9.x, var9.y, var9.z);
if (!InteractionValidation.canPlayerInteractWithBlock(var7, var8, var4.getHeldItem(), var21)) {
LOGGER.at(Level.WARNING)
.log("%s failed place block interaction distance check at [%d, %d, %d]", EntityUtils.getEntityName(var7, var8), var21.x, var21.y, var21.z);
var4.getState().state = InteractionState.Failed;
class="kw">return;
}
String var22 = this.blockTypeKey != null ? this.blockTypeKey : var31.getBlockKey();
if (var22 == null) {
class="kw">return;
}
BlockType var23 = BlockType.getAssetMap().getAsset(var22);
int var24 = var6.placedBlockId;
BlockType var25 = var24 == -1 ? null : BlockType.getAssetMap().getAsset(var24);
if (var24 != -1 && var25 == null) {
LOGGER.at(Level.WARNING).log("%s sent an unknown placed block id %d in a place block interaction", EntityUtils.getEntityName(var7, var8), var24);
var4.getState().state = InteractionState.Failed;
class="kw">return;
}
String var26 = var25 == null ? null : var25.getId();
if (var26 != null
&& !var16
&& !var17
&& !var18
&& !var26.equals(this.blockTypeKey)
&& (var23 == null || !BlockPlaceUtils.canPlaceBlock(var23, var26))) {
var26 = null;
}
PlacementGestureTracker var27 = var4.getMetaStore().getIfPresentMetaObject(DragPlaceBlockInteraction.FORK_GESTURE_TRACKER);
if (var27 != null) {
String var28 = var26 != null ? var26 : this.blockTypeKey;
if (!var27.validatePlacement(var21, "Empty".equals(var28), var15)) {
LOGGER.at(Level.WARNING)
.log("%s failed place block gesture position check at [%d, %d, %d]", EntityUtils.getEntityName(var7, var8), var21.x, var21.y, var21.z);
var4.getState().state = InteractionState.Failed;
class="kw">return;
}
}
BlockPlaceUtils.placeBlock(
var7,
var31,
var26 != null ? var26 : this.blockTypeKey,
var20,
new Vector3i(BlockFace.fromProtocolFace(var4.getClientState().blockFace).getDirection()),
var21,
var10,
var4.getHeldItemSlot(),
this.removeItemInHand,
var13,
var12,
var8,
var16,
var17,
var18
);
boolean var32 = var14 == null || var14.getGameMode() == GameMode.Adventure;
if (var32 && var31 != null && var31.getQuantity() == 1 && this.removeItemInHand) {
var4.setHeldItem(null);
}
BlockSection var29 = var12.getComponent(var13, BlockSection.getComponentType());
RotationTuple var30 = var29.getRotation(var9.x, var9.y, var9.z);
var4.getState().blockPosition = var9;
var4.getState().placedBlockId = var29.get(var9.x, var9.y, var9.z);
var4.getState().blockRotation = new BlockRotation(var30.yaw().toPacket(), var30.pitch().toPacket(), var30.roll().toPacket());
}
super.tick0(var1, var2, var3, var4, var5);
}
}
@Override
class="kw">protected void simulateTick0(boolean var1, float var2, @Nonnull InteractionType var3, @Nonnull InteractionContext var4, @Nonnull CooldownHandler var5) {
super.simulateTick0(var1, var2, var3, var4, var5);
if (!Interaction.failed(var4.getState().state)) {
InteractionSyncData var6 = var4.getClientState();
assert var6 != null;
if (!var1) {
var4.getState().state = var4.getClientState().state;
} else {
var6.blockRotation = new BlockRotation(Rotation.None, Rotation.None, Rotation.None);
}
}
}
@Nonnull
@Override
class="kw">protected com.hypixel.hytale.protocol.Interaction generatePacket() {
class="kw">return new com.hypixel.hytale.protocol.PlaceBlockInteraction();
}
@Override
class="kw">protected void configurePacket(com.hypixel.hytale.protocol.Interaction var1) {
super.configurePacket(var1);
com.hypixel.hytale.protocol.PlaceBlockInteraction var2 = (com.hypixel.hytale.protocol.PlaceBlockInteraction)var1;
var2.blockId = this.blockTypeKey == null ? -1 : BlockType.getAssetMap().getIndex(this.blockTypeKey);
var2.removeItemInHand = this.removeItemInHand;
var2.quickReplace = this.quickReplace;
var2.quickRetype = this.quickRetype;
var2.noPhysics = this.noPhysics;
}
@Override
class="kw">public boolean needsRemoteSync() {
class="kw">return true;
}
@Override
class="kw">public String toString() {
class="kw">return "PlaceBlockInteraction{blockTypeKey='"
+ this.blockTypeKey
+ "', removeItemInHand="
+ this.removeItemInHand
+ ", quickReplace="
+ this.quickReplace
+ ", quickRetype="
+ this.quickRetype
+ ", noPhysics="
+ this.noPhysics
+ "}";
}
}