Search in sources :

Example 66 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project Tropicraft by Tropicraft.

the class TropicraftTropicalFishEntity method saveToBucketTag.

/**
 * Add extra data to the bucket that just picked this fish up
 */
@Override
public void saveToBucketTag(final ItemStack bucket) {
    super.saveToBucketTag(bucket);
    CompoundTag compoundnbt = bucket.getOrCreateTag();
    compoundnbt.putInt("BucketVariantTag", getFishType().id);
}
Also used : CompoundTag(net.minecraft.nbt.CompoundTag)

Example 67 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project MC-Prefab by Brian-Wuest.

the class StructureEventHandler method setItemFrameFacingAndRotation.

private static Entity setItemFrameFacingAndRotation(ItemFrame frame, BuildEntity buildEntity, BlockPos entityPos, Structure structure) {
    float yaw = frame.getYRot();
    Rotation rotation = Rotation.NONE;
    double x_axis_offset = buildEntity.entityXAxisOffset;
    double z_axis_offset = buildEntity.entityZAxisOffset;
    Direction facing = frame.getDirection();
    double y_axis_offset = buildEntity.entityYAxisOffset;
    x_axis_offset = x_axis_offset * -1;
    z_axis_offset = z_axis_offset * -1;
    Direction structureDirection = structure.getClearSpace().getShape().getDirection();
    Direction configurationDirection = structure.configuration.houseFacing.getOpposite();
    if (facing != Direction.UP && facing != Direction.DOWN) {
        if (configurationDirection == structureDirection.getOpposite()) {
            rotation = Rotation.CLOCKWISE_180;
            facing = facing.getOpposite();
        } else if (configurationDirection == structureDirection.getClockWise()) {
            rotation = Rotation.CLOCKWISE_90;
            facing = facing.getClockWise();
        } else if (configurationDirection == structureDirection.getCounterClockWise()) {
            rotation = Rotation.COUNTERCLOCKWISE_90;
            facing = facing.getCounterClockWise();
        } else {
            x_axis_offset = 0;
            z_axis_offset = 0;
        }
    }
    yaw = frame.rotate(rotation);
    CompoundTag compound = new CompoundTag();
    ((HangingEntity) frame).addAdditionalSaveData(compound);
    compound.putByte("Facing", (byte) facing.get3DDataValue());
    ((HangingEntity) frame).readAdditionalSaveData(compound);
    StructureEventHandler.updateEntityHangingBoundingBox(frame);
    frame.moveTo(entityPos.getX() + x_axis_offset, entityPos.getY() + y_axis_offset, entityPos.getZ() + z_axis_offset, yaw, frame.getXRot());
    StructureEventHandler.updateEntityHangingBoundingBox(frame);
    ChunkAccess chunk = structure.world.getChunkAt(entityPos);
    chunk.setUnsaved(true);
    return frame;
}
Also used : HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) Direction(net.minecraft.core.Direction) NetworkDirection(net.minecraftforge.network.NetworkDirection) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 68 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project MC-Prefab by Brian-Wuest.

the class StructureEventHandler method onClone.

/**
 * This occurs when a player dies and is used to make sure that a player does not get a duplicate starting house.
 *
 * @param event The player clone event.
 */
@SubscribeEvent
public static void onClone(PlayerEvent.Clone event) {
    if (event.getPlayer() instanceof ServerPlayer) {
        // Don't add the tag unless the house item was added. This way it can be added if the feature is turned on.
        // When the player is cloned, make sure to copy the tag. If this is not done the item can be given to the
        // player again if they die before the log out and log back in.
        CompoundTag originalTag = event.getOriginal().getPersistentData();
        // Use the server configuration to determine if the house should be added for this player.
        String startingItem = CommonProxy.proxyConfiguration.serverConfiguration.startingItem;
        if (startingItem != null && !startingItem.equalsIgnoreCase("Nothing")) {
            if (originalTag.contains(EntityPlayerConfiguration.PLAYER_ENTITY_TAG)) {
                CompoundTag newPlayerTag = event.getPlayer().getPersistentData();
                newPlayerTag.put(EntityPlayerConfiguration.PLAYER_ENTITY_TAG, originalTag.get(EntityPlayerConfiguration.PLAYER_ENTITY_TAG));
                // Send the persist tag to the client.
                Prefab.network.sendTo(new PlayerEntityTagMessage(originalTag.getCompound(EntityPlayerConfiguration.PLAYER_ENTITY_TAG)), ((ServerPlayer) event.getPlayer()).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
            }
        }
    }
}
Also used : PlayerEntityTagMessage(com.wuest.prefab.proxy.messages.PlayerEntityTagMessage) ServerPlayer(net.minecraft.server.level.ServerPlayer) CompoundTag(net.minecraft.nbt.CompoundTag) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 69 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project MC-Prefab by Brian-Wuest.

the class StructureEventHandler method setPaintingFacingAndRotation.

private static Entity setPaintingFacingAndRotation(Painting entity, BuildEntity buildEntity, BlockPos entityPos, Structure structure) {
    float yaw = entity.getYRot();
    Rotation rotation = Rotation.NONE;
    double x_axis_offset = 0;
    double z_axis_offset = 0;
    Direction facing = entity.getDirection();
    double y_axis_offset = buildEntity.entityYAxisOffset * -1;
    Direction structureDirection = structure.getClearSpace().getShape().getDirection();
    Direction configurationDirection = structure.configuration.houseFacing.getOpposite();
    if (configurationDirection == structureDirection.getOpposite()) {
        rotation = Rotation.CLOCKWISE_180;
        facing = facing.getOpposite();
    } else if (configurationDirection == structureDirection.getClockWise()) {
        rotation = Rotation.CLOCKWISE_90;
        facing = facing.getClockWise();
    } else if (configurationDirection == structureDirection.getCounterClockWise()) {
        rotation = Rotation.COUNTERCLOCKWISE_90;
        facing = facing.getCounterClockWise();
    }
    int paintingBlockWidth = entity.motive.getWidth() / 16;
    int paintingBlockHeight = entity.motive.getHeight() / 16;
    if ((paintingBlockHeight > paintingBlockWidth || paintingBlockHeight > 1) && !(paintingBlockWidth == 4 && paintingBlockHeight == 3)) {
        y_axis_offset--;
    }
    yaw = entity.rotate(rotation);
    CompoundTag compound = new CompoundTag();
    ((HangingEntity) entity).addAdditionalSaveData(compound);
    compound.putByte("Facing", (byte) facing.get2DDataValue());
    ((HangingEntity) entity).readAdditionalSaveData(compound);
    StructureEventHandler.updateEntityHangingBoundingBox(entity);
    entity.moveTo(entityPos.getX() + x_axis_offset, entityPos.getY() + y_axis_offset, entityPos.getZ() + z_axis_offset, yaw, entity.getXRot());
    StructureEventHandler.updateEntityHangingBoundingBox(entity);
    ChunkAccess chunk = structure.world.getChunkAt(entityPos);
    chunk.setUnsaved(true);
    return entity;
}
Also used : HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) Direction(net.minecraft.core.Direction) NetworkDirection(net.minecraftforge.network.NetworkDirection) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 70 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project MC-Prefab by Brian-Wuest.

the class StructureTagMessage method decode.

public static StructureTagMessage decode(FriendlyByteBuf buf) {
    // This class is very useful in general for writing more complex objects.
    CompoundTag tag = buf.readNbt();
    StructureTagMessage returnValue = new StructureTagMessage();
    returnValue.structureConfig = EnumStructureConfiguration.getFromIdentifier(tag.getInt("config"));
    returnValue.tagMessage = tag.getCompound("dataTag");
    return returnValue;
}
Also used : CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

CompoundTag (net.minecraft.nbt.CompoundTag)146 ListTag (net.minecraft.nbt.ListTag)41 ItemStack (net.minecraft.world.item.ItemStack)22 TagCompound (de.keyle.knbt.TagCompound)12 ResourceLocation (net.minecraft.resources.ResourceLocation)12 Nullable (org.checkerframework.checker.nullness.qual.Nullable)10 Keys (org.spongepowered.api.data.Keys)9 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)9 Constants (org.spongepowered.common.util.Constants)9 TagList (de.keyle.knbt.TagList)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 IntArrayTag (net.minecraft.nbt.IntArrayTag)8 Tag (net.minecraft.nbt.Tag)8 ResourceKey (org.spongepowered.api.ResourceKey)8 DataContainer (org.spongepowered.api.data.persistence.DataContainer)8 DataView (org.spongepowered.api.data.persistence.DataView)8 ByteArrayTag (net.minecraft.nbt.ByteArrayTag)7 TagString (de.keyle.knbt.TagString)6 Block (net.minecraft.world.level.block.Block)6