Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement GuiMetaCodec #30

Merged
merged 7 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions api/src/main/java/team/unnamed/creative/metadata/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jetbrains.annotations.Unmodifiable;
import team.unnamed.creative.metadata.animation.AnimationMeta;
import team.unnamed.creative.metadata.filter.FilterMeta;
import team.unnamed.creative.metadata.gui.GuiMeta;
import team.unnamed.creative.metadata.language.LanguageMeta;
import team.unnamed.creative.metadata.overlays.OverlaysMeta;
import team.unnamed.creative.metadata.pack.PackMeta;
Expand Down Expand Up @@ -209,6 +210,20 @@ interface Builder {
return add(VillagerMeta.class, meta);
}

/**
* Adds a gui meta part.
*
* @param meta The added gui meta part
* @return This builder
* @sinceMinecraft 1.20.2
* @sincePackFormat 18
* @since 1.2.0
*/
@Contract("_ -> this")
default @NotNull Builder add(final @NotNull GuiMeta meta) {
return add(GuiMeta.class, meta);
}

/**
* Adds an overlay meta part.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of creative, licensed under the MIT license
*
* Copyright (c) 2021-2023 Unnamed Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package team.unnamed.creative.metadata.gui;

import net.kyori.examination.Examinable;
import org.jetbrains.annotations.NotNull;

public interface GuiBorder extends Examinable {

int top();
int bottom();
int left();
int right();

static @NotNull GuiBorder of(int top, int bottom, int left, int right) {
return new GuiBorderImpl(top, bottom, left, right);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* This file is part of creative, licensed under the MIT license
*
* Copyright (c) 2021-2023 Unnamed Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package team.unnamed.creative.metadata.gui;

import net.kyori.examination.ExaminableProperty;
import net.kyori.examination.string.StringExaminer;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;
import java.util.stream.Stream;

final class GuiBorderImpl implements GuiBorder {

private final int top;
private final int bottom;
private final int left;
private final int right;

GuiBorderImpl(int top, int bottom, int left, int right) {
this.top = top;
this.bottom = bottom;
this.left = left;
this.right = right;
}

public int top() {
return top;
}

public int bottom() {
return bottom;
}

public int left() {
return left;
}

public int right() {
return right;
}

@Override
public @NotNull Stream<? extends ExaminableProperty> examinableProperties() {
return Stream.of(
ExaminableProperty.of("top", top),
ExaminableProperty.of("bottom", bottom),
ExaminableProperty.of("left", left),
ExaminableProperty.of("right", right)
);
}

@Override
public String toString() {
return examine(StringExaminer.simpleEscaping());
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof GuiBorderImpl)) return false;
GuiBorderImpl guiBorder = (GuiBorderImpl) o;
return top == guiBorder.top && bottom == guiBorder.bottom && left == guiBorder.left && right == guiBorder.right;
}

@Override
public int hashCode() {
return Objects.hash(top, bottom, left, right);
}


}
71 changes: 71 additions & 0 deletions api/src/main/java/team/unnamed/creative/metadata/gui/GuiMeta.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* This file is part of creative, licensed under the MIT license
*
* Copyright (c) 2021-2023 Unnamed Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package team.unnamed.creative.metadata.gui;

import org.jetbrains.annotations.NotNull;
import team.unnamed.creative.metadata.MetadataPart;

/**
* Represents meta-data applicable to gui-elements
*
* @since 1.2.0
* @sinceMinecraft 1.20.2
* @sincePackFormat 18
*/
public interface GuiMeta extends MetadataPart {

GuiScaling scaling();

/**
* Creates a new {@link GuiMeta} instance
* from the given values
*
* @param scaling Scaling instance
* @return A new instance of {@link GuiMeta}
* @since 1.0.0
*/
static @NotNull GuiMeta of(GuiScaling scaling) {
return new GuiMetaImpl(scaling);
}

static @NotNull GuiMeta.Builder builder() {
return new GuiMeta.Builder();
}

class Builder {
private GuiScaling scaling;

private Builder() {
}

public Builder scaling(GuiScaling scaling) {
this.scaling = scaling;
return this;
}

public GuiMeta build() {
return new GuiMetaImpl(scaling);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* This file is part of creative, licensed under the MIT license
*
* Copyright (c) 2021-2023 Unnamed Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package team.unnamed.creative.metadata.gui;

import net.kyori.examination.ExaminableProperty;
import net.kyori.examination.string.StringExaminer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;

import java.util.Objects;
import java.util.stream.Stream;

import static java.util.Objects.requireNonNull;

final class GuiMetaImpl implements GuiMeta {
@Unmodifiable private final GuiScaling scaling;

GuiMetaImpl(GuiScaling scaling) {
requireNonNull(scaling, "scaling");
this.scaling = scaling;
}

public GuiScaling scaling() {
return scaling;
}

@Override
public @NotNull Stream<? extends ExaminableProperty> examinableProperties() {
return Stream.of(ExaminableProperty.of("scaling", scaling));
}

@Override
public String toString() {
return examine(StringExaminer.simpleEscaping());
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GuiMetaImpl that = (GuiMetaImpl) o;
return Objects.equals(scaling, that.scaling);
}

@Override
public int hashCode() {
return Objects.hash(scaling);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of creative, licensed under the MIT license
*
* Copyright (c) 2021-2023 Unnamed Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package team.unnamed.creative.metadata.gui;

import net.kyori.examination.Examinable;

public interface GuiScaling extends Examinable {

ScalingType type();
int width();
int height();
GuiBorder border();

static GuiScaling of(ScalingType type, int width, int height, GuiBorder border) {
return new GuiScalingImpl(type, width, height, border);
}

static GuiScaling of(ScalingType type, int width, int height, int border) {
return new GuiScalingImpl(type, width, height, GuiBorder.of(border, border, border, border));
}

enum ScalingType {
STRETCH, TILE, NINE_SLICE
}
}
Loading
Loading