ChangeBlockInteraction class
Пакет: com.hypixel.hytale.server.core.modules.interaction.interaction.config.client
Файл: com/hypixel/hytale/server/core/modules/interaction/interaction/config/client/ChangeBlockInteraction.java
extends: SimpleBlockInteraction
Поля (22)
| Модификаторы | Тип | Имя |
|---|---|---|
|
Int2IntOpenHashMap |
var1 |
|
int |
var10 |
|
int |
var10 |
|
ChunkStore |
var11 |
|
Ref |
var12 |
|
BlockSection |
var13 |
|
int |
var14 |
|
int |
var15 |
|
int |
var16 |
|
BlockType |
var17 |
|
RotationTuple |
var18 |
|
Vector3d |
var19 |
|
com.hypixel.hytale.protocol.ChangeBlockInteraction |
var2 |
|
Ref |
var20 |
|
int |
var4 |
|
int |
var5 |
|
ChunkStore |
var6 |
|
Ref |
var7 |
|
int |
var8 |
|
BlockSection |
var8 |
|
int |
var9 |
|
int |
var9 |
Методы (9)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
|
if if(this.soundEventId != null) |
|
|
if if(var13 != null) |
|
|
if if(var15 == Integer.MIN_VALUE) |
|
|
if if(var17 == null) |
|
|
if if(this.soundEventIndex != 0) |
|
|
if if(this.changeMapIds == null) |
|
|
if if(var4 == Integer.MIN_VALUE) |
|
|
if if(var10 == Integer.MIN_VALUE) |
protected |
void |
processConfigvoid processConfig() |
Исходный код
Показать/скрыть
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.codec.codecs.map.MapCodec;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Ref;
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.Interaction;
class="kw">import com.hypixel.hytale.protocol.InteractionState;
class="kw">import com.hypixel.hytale.protocol.InteractionType;
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.asset.type.soundevent.config.SoundEvent;
class="kw">import com.hypixel.hytale.server.core.asset.type.soundevent.validator.SoundEventValidators;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionContext;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
class="kw">import com.hypixel.hytale.server.core.universe.world.SoundUtil;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.BlockOperations;
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 it.unimi.dsi.fastutil.ints.Int2IntMap;
class="kw">import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
class="kw">import java.util.HashMap;
class="kw">import java.util.Map;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">import org.joml.Vector3i;
class="kw">public class ChangeBlockInteraction class="kw">extends SimpleBlockInteraction {
@Nonnull
class="kw">public class="kw">static class="kw">final BuilderCodec<ChangeBlockInteraction> CODEC = BuilderCodec.builder(
ChangeBlockInteraction.class, ChangeBlockInteraction::new, SimpleBlockInteraction.CODEC
)
.documentation("Changes the target block to another block based on the block types provided.")
.<Map>appendInherited(
new KeyedCodec<>("Changes", new MapCodec<>(Codec.STRING, HashMap::new)),
(var0, var1) -> var0.blockTypeKeys = var1,
var0 -> var0.blockTypeKeys,
(var0, var1) -> var0.blockTypeKeys = var1.blockTypeKeys
)
.documentation(
"A map of the target block to the new block.\n\nWhen the interaction runs it will look for the block that was interacted with in this map and if found it will replace it with specified block"
)
.addValidator(BlockType.VALIDATOR_CACHE.getMapKeyValidator().late())
.addValidator(BlockType.VALIDATOR_CACHE.getMapValueValidator().late())
.add()
.<String>appendInherited(
new KeyedCodec<>("WorldSoundEventId", Codec.STRING),
(var0, var1) -> var0.soundEventId = var1,
var0 -> var0.soundEventId,
(var0, var1) -> var0.soundEventId = var1.soundEventId
)
.documentation("Sound event to play at the block location on block change.")
.addValidator(SoundEvent.VALIDATOR_CACHE.getValidator())
.addValidator(SoundEventValidators.MONO)
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("RequireNotBroken", Codec.BOOLEAN),
(var0, var1) -> var0.requireNotBroken = var1,
var0 -> var0.requireNotBroken,
(var0, var1) -> var0.requireNotBroken = var1.requireNotBroken
)
.documentation("If true, the interaction will fail if the held item is broken (durability = 0).")
.add()
.afterDecode(ChangeBlockInteraction::processConfig)
.build();
class="kw">private class="kw">static class="kw">final int SET_BLOCK_SETTINGS = 256;
class="kw">protected Map<String, String> blockTypeKeys;
class="kw">protected Int2IntMap changeMapIds;
@Nullable
class="kw">protected String soundEventId;
class="kw">protected class="kw">transient int soundEventIndex = 0;
class="kw">protected boolean requireNotBroken;
class="kw">public ChangeBlockInteraction() {
}
class="kw">protected void processConfig() {
if (this.soundEventId != null) {
this.soundEventIndex = SoundEvent.getAssetMap().getIndex(this.soundEventId);
}
}
@Override
class="kw">protected void interactWithBlock(
@Nonnull World var1,
@Nonnull CommandBuffer<EntityStore> var2,
@Nonnull InteractionType var3,
@Nonnull InteractionContext var4,
@Nullable ItemStack var5,
@Nonnull Vector3i var6,
@Nonnull CooldownHandler var7
) {
if (this.requireNotBroken && var5 != null && var5.isBroken()) {
var4.getState().state = InteractionState.Failed;
} else {
int var8 = var6.x();
int var9 = var6.y();
int var10 = var6.z();
ChunkStore var11 = var1.getChunkStore();
Ref var12 = var11.getChunkSectionReferenceAtBlock(var8, var9, var10);
if (var12 != null && var12.isValid()) {
BlockSection var13 = var11.getStore().getComponent(var12, BlockSection.getComponentType());
if (var13 != null) {
int var14 = var13.get(var8, var9, var10);
int var15 = this.getChangeMapIds().get(var14);
if (var15 == Integer.MIN_VALUE) {
var4.getState().state = InteractionState.Failed;
} else {
int var16 = var13.getRotationIndex(var8, var9, var10);
BlockType var17 = BlockType.getAssetMap().getAsset(var15);
if (var17 == null) {
var4.getState().state = InteractionState.Failed;
} else {
BlockOperations.setBlock(var11, var12, var8, var9, var10, var15, var17, var16, 0, 256);
RotationTuple var18 = RotationTuple.get(var16);
var4.getState().blockPosition = new BlockPosition(var8, var9, var10);
var4.getState().placedBlockId = var15;
var4.getState().blockRotation = new BlockRotation(var18.yaw().toPacket(), var18.pitch().toPacket(), var18.roll().toPacket());
if (this.soundEventIndex != 0) {
Vector3d var19 = new Vector3d();
var17.getBlockCenter(var16, var19);
var19.add(var8, var9, var10);
Ref var20 = var4.getEntity();
SoundUtil.playSoundEvent3d(var20, this.soundEventIndex, var19, true, var2);
}
}
}
}
}
}
}
@Nonnull
class="kw">private Int2IntMap getChangeMapIds() {
if (this.changeMapIds == null) {
Int2IntOpenHashMap var1 = new Int2IntOpenHashMap(this.blockTypeKeys.size());
var1.defaultReturnValue(Integer.MIN_VALUE);
this.blockTypeKeys.forEach((var2, var3) -> {
int var4 = BlockType.getAssetMap().getIndex(var2);
int var5 = BlockType.getAssetMap().getIndex(var3);
if (var4 == Integer.MIN_VALUE) {
HytaleLogger.getLogger().at(Level.SEVERE).log("Invalid BlockType: Interaction: %s, BlockType: %s", this.id, var2);
} else if (var5 == Integer.MIN_VALUE) {
HytaleLogger.getLogger().at(Level.SEVERE).log("Invalid BlockType: Interaction: %s, BlockType: %s", this.id, var3);
} else {
var1.put(var4, var5);
}
});
this.changeMapIds = var1;
}
class="kw">return this.changeMapIds;
}
@Override
class="kw">protected void simulateInteractWithBlock(
@Nonnull InteractionType var1, @Nonnull InteractionContext var2, @Nullable ItemStack var3, @Nonnull World var4, @Nonnull Vector3i var5
) {
if (this.requireNotBroken && var3 != null && var3.isBroken()) {
var2.getState().state = InteractionState.Failed;
} else {
ChunkStore var6 = var4.getChunkStore();
Ref var7 = var6.getChunkSectionReferenceAtBlock(var5.x(), var5.y(), var5.z());
BlockSection var8 = var7 != null && var7.isValid() ? var6.getStore().getComponent(var7, BlockSection.getComponentType()) : null;
int var9 = var8 != null ? var8.get(var5.x(), var5.y(), var5.z()) : 0;
int var10 = this.getChangeMapIds().get(var9);
if (var10 == Integer.MIN_VALUE) {
var2.getState().state = InteractionState.Failed;
}
}
}
@Nonnull
@Override
class="kw">protected Interaction generatePacket() {
class="kw">return new com.hypixel.hytale.protocol.ChangeBlockInteraction();
}
@Override
class="kw">protected void configurePacket(Interaction var1) {
super.configurePacket(var1);
com.hypixel.hytale.protocol.ChangeBlockInteraction var2 = (com.hypixel.hytale.protocol.ChangeBlockInteraction)var1;
var2.blockChanges = this.getChangeMapIds();
var2.worldSoundEventIndex = this.soundEventIndex;
var2.requireNotBroken = this.requireNotBroken;
}
@Nonnull
@Override
class="kw">public String toString() {
class="kw">return "ChangeBlockInteraction{blockTypeKeys="
+ this.blockTypeKeys
+ ", changeMapIds="
+ this.changeMapIds
+ ", soundEventId='"
+ this.soundEventId
+ "', soundEventIndex="
+ this.soundEventIndex
+ ", requireNotBroken="
+ this.requireNotBroken
+ "} "
+ super.toString();
}
}