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

feat: begin impl for Equipment #71

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
106 changes: 106 additions & 0 deletions api/src/main/java/team/unnamed/creative/equipment/Equipment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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.equipment;


import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.Keyed;
import net.kyori.examination.Examinable;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import team.unnamed.creative.overlay.ResourceContainer;
import team.unnamed.creative.part.ResourcePackPart;

/**
* Represents a Minecraft equipment model for 1.21.2+.
*
* @since 1.7.4
*/
@ApiStatus.NonExtendable
public interface Equipment extends ResourcePackPart, Keyed, Examinable {
@Contract("-> new")
static @NotNull Builder equipment() {
return new EquipmentImpl.BuilderImpl();
}

@Override
@NotNull Key key();

@Nullable Key humanoid();

@Nullable Key humanoidLeggings();

@Nullable Key wings();

@Nullable Key horseBody();

@Nullable Key llamaBody();

@Nullable Key wolfBody();

@Contract("-> new")
@NotNull default Builder toBuilder() {
return Equipment.equipment().key(key())
.humanoid(humanoid())
.humanoidLeggings(humanoidLeggings())
.wings(wings())
.horseBody(horseBody())
.llamaBody(llamaBody())
.wolfBody(wolfBody());
}

@Override
default void addTo(final @NotNull ResourceContainer resourceContainer) {
resourceContainer.equipment(this);
}

interface Builder {
@Contract("_ -> this")
@NotNull Builder key(final @Nullable Key key);

@Contract("_ -> this")
@NotNull Builder humanoid(final @Nullable Key humanoid);

@Contract("_ -> this")
@NotNull Builder humanoidLeggings(final @Nullable Key humanoidLeggings);

@Contract("_ -> this")
@NotNull Builder wings(final @Nullable Key wings);

@Contract("_ -> this")
@NotNull Builder horseBody(final @Nullable Key horseBody);

@Contract("_ -> this")
@NotNull Builder llamaBody(final @Nullable Key llamaBody);

@Contract("_ -> this")
@NotNull Builder wolfBody(final @Nullable Key wolfBody);

@Contract("-> new")
@NotNull Equipment build();

}
}
195 changes: 195 additions & 0 deletions api/src/main/java/team/unnamed/creative/equipment/EquipmentImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
* 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.equipment;

import net.kyori.adventure.key.Key;
import net.kyori.examination.ExaminableProperty;
import net.kyori.examination.string.StringExaminer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

import static java.util.Objects.requireNonNull;

public class EquipmentImpl implements Equipment {
private final Key key;
private final Key humanoid;
private final Key humanoidLeggings;
private final Key wings;
private final Key horseBody;
private final Key llamaBody;
private final Key wolfBody;

EquipmentImpl(
final Key key,
final @Nullable Key humanoid,
final @Nullable Key humanoidLeggings,
final @Nullable Key wings,
final @Nullable Key horseBody,
final @Nullable Key llamaBody,
final @Nullable Key wolfBody
) {
this.key = key;
this.humanoid = humanoid;
this.humanoidLeggings = humanoidLeggings;
this.wings = wings;
this.horseBody = horseBody;
this.llamaBody = llamaBody;
this.wolfBody = wolfBody;
}

@Override
public @NotNull Key key() {
return key;
}

@Override
public @Nullable Key humanoid() {
return humanoid;
}

@Override
public @Nullable Key humanoidLeggings() {
return humanoidLeggings;
}

@Override
public @Nullable Key wings() {
return wings;
}

@Override
public @Nullable Key horseBody() {
return horseBody;
}

@Override
public @Nullable Key llamaBody() {
return llamaBody;
}

@Override
public @Nullable Key wolfBody() {
return wolfBody;
}

@Override
public @NotNull Stream<? extends ExaminableProperty> examinableProperties() {
return Stream.of(
ExaminableProperty.of("key", key),
ExaminableProperty.of("humanoid", humanoid),
ExaminableProperty.of("humanoidLeggings", humanoidLeggings),
ExaminableProperty.of("wings", wings),
ExaminableProperty.of("horseBody", horseBody),
ExaminableProperty.of("llamaBody", llamaBody),
ExaminableProperty.of("wolfBody", wolfBody)
);
}

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

@Override
public boolean equals(final @Nullable Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final EquipmentImpl that = (EquipmentImpl) o;
return key.equals(that.key)
&& Objects.equals(humanoid, that.humanoid)
&& Objects.equals(humanoidLeggings, that.humanoidLeggings)
&& Objects.equals(wings, that.wings)
&& Objects.equals(horseBody, that.horseBody)
&& Objects.equals(llamaBody, that.llamaBody)
&& Objects.equals(wolfBody, that.wolfBody);
}

@Override
public int hashCode() {
return Objects.hash(key, humanoid, humanoidLeggings, horseBody, wings);
}



static final class BuilderImpl implements Equipment.Builder {
private Key key;
private Key humanoid;
private Key humanoidLeggings;
private Key wings;
private Key horseBody;
private Key llamaBody;
private Key wolfBody;

@Override
public @NotNull Builder key(final @NotNull Key key) {
this.key = requireNonNull(key, "key");
return this;
}

@Override
public @NotNull Builder humanoid(final @Nullable Key humanoid) {
this.humanoid = humanoid;
return this;
}

@Override
public @NotNull Builder humanoidLeggings(final @Nullable Key humanoidLeggings) {
this.humanoidLeggings = humanoidLeggings;
return this;
}

@Override
public @NotNull Builder wings(final @Nullable Key wings) {
this.wings = wings;
return this;
}

@Override
public @NotNull Builder horseBody(final @Nullable Key horseBody) {
this.horseBody = horseBody;
return this;
}

@Override
public @NotNull Builder llamaBody(final @Nullable Key llamaBody) {
this.llamaBody = llamaBody;
return this;
}

@Override
public @NotNull Builder wolfBody(final @Nullable Key wolfBody) {
this.wolfBody = wolfBody;
return this;
}

@Override
public @NotNull Equipment build() {
return new EquipmentImpl(key, humanoid, humanoidLeggings, wings, horseBody, llamaBody, wolfBody);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import team.unnamed.creative.atlas.Atlas;
import team.unnamed.creative.base.Writable;
import team.unnamed.creative.blockstate.BlockState;
import team.unnamed.creative.equipment.Equipment;
import team.unnamed.creative.font.Font;
import team.unnamed.creative.font.FontProvider;
import team.unnamed.creative.lang.Language;
Expand Down Expand Up @@ -304,6 +305,14 @@ default void font(final @NotNull Key key, final @NotNull List<FontProvider> prov
@NotNull Collection<Model> models();
//#endregion

//#region Equipment Models

void equipment(final @NotNull Equipment equipmentModel);
@Nullable Equipment equipment(final @NotNull Key key);
boolean removeEquipment(final @NotNull Key key);
@NotNull Collection<Equipment> equipments();
//#endregion

//#region Sound Registries (Namespaced)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import team.unnamed.creative.atlas.AtlasSource;
import team.unnamed.creative.base.Writable;
import team.unnamed.creative.blockstate.BlockState;
import team.unnamed.creative.equipment.Equipment;
import team.unnamed.creative.font.Font;
import team.unnamed.creative.font.FontProvider;
import team.unnamed.creative.lang.Language;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class ResourceContainerImpl implements ResourceContainer {
private final Map<String, SoundRegistry> soundRegistries = new LinkedHashMap<>();
private final Map<Key, Sound> sounds = new LinkedHashMap<>();
private final Map<Key, Texture> textures = new LinkedHashMap<>();
private final Map<Key, Equipment> equipments = new LinkedHashMap<>();

// Unknown files we don't know how to parse
private final Map<String, Writable> files = new LinkedHashMap<>();
Expand Down Expand Up @@ -268,6 +270,31 @@ public boolean removeTexture(final @NotNull Key key) {
}
//#endregion

//#region Fonts (Keyed)
@Override
public void equipment(final @NotNull Equipment equipment) {
requireNonNull(equipment, "equipment");
equipments.put(equipment.key(), equipment);
}

@Override
public @Nullable Equipment equipment(final @NotNull Key key) {
requireNonNull(key, "key");
return equipments.get(key);
}

@Override
public boolean removeEquipment(final @NotNull Key key) {
requireNonNull(key, "key");
return equipments.remove(key) != null;
}

@Override
public @NotNull Collection<Equipment> equipments() {
return equipments.values();
}
//#endregion

//#region Unknown Files (By absolute path)
@Override
public void unknownFile(final @NotNull String path, final @NotNull Writable data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jetbrains.annotations.Nullable;
import team.unnamed.creative.serialize.minecraft.atlas.AtlasSerializer;
import team.unnamed.creative.serialize.minecraft.blockstate.BlockStateSerializer;
import team.unnamed.creative.serialize.minecraft.equipment.EquipmentSerializer;
import team.unnamed.creative.serialize.minecraft.font.FontSerializer;
import team.unnamed.creative.serialize.minecraft.language.LanguageSerializer;
import team.unnamed.creative.serialize.minecraft.model.ModelSerializer;
Expand All @@ -47,6 +48,7 @@ public class ResourceCategories {
registerCategory(LanguageSerializer.CATEGORY);
registerCategory(BlockStateSerializer.CATEGORY);
registerCategory(FontSerializer.CATEGORY);
registerCategory(EquipmentSerializer.CATEGORY);
}

private ResourceCategories() {
Expand Down
Loading