Skip to content
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
27 changes: 26 additions & 1 deletion api/src/main/java/team/unnamed/creative/item/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public interface Item extends Keyed, ResourcePackPart, Examinable {
@ApiStatus.Internal
boolean DEFAULT_HAND_ANIMATION_ON_SWAP = true;

@ApiStatus.Internal
boolean DEFAULT_OVERSIZED_IN_GUI = false;

/**
* Describes if down-and-up animation should be played in first-person view
* when item stack is changed (either type, count or components).
Expand All @@ -58,13 +61,35 @@ public interface Item extends Keyed, ResourcePackPart, Examinable {
*/
boolean handAnimationOnSwap();

/**
* Determines whether the item should be rendered oversized or clipped in the inventory.
*
* @return If clipping should not be applied
*/
boolean oversizedInGui();

@NotNull ItemModel model();

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

/**
* Creates a new {@link Item} instance with the given key, model and hand animation on swap.
*
* @param key The item key
* @param model The item model
* @param handAnimationOnSwap If hand animation should be played
* @param oversizedInGui If item clipping should not be applied
* @return The item
* @since 1.8.4
*/
@Contract(value = "_, _, _, _ -> new", pure = true)
static @NotNull Item item(final @NotNull Key key, final @NotNull ItemModel model, final boolean handAnimationOnSwap, final boolean oversizedInGui) {
return new ItemImpl(key, model, handAnimationOnSwap, oversizedInGui);
}

/**
* Creates a new {@link Item} instance with the given key, model and hand animation on swap.
*
Expand All @@ -76,7 +101,7 @@ default void addTo(final @NotNull ResourceContainer resourceContainer) {
*/
@Contract(value = "_, _, _ -> new", pure = true)
static @NotNull Item item(final @NotNull Key key, final @NotNull ItemModel model, final boolean handAnimationOnSwap) {
return new ItemImpl(key, model, handAnimationOnSwap);
return new ItemImpl(key, model, handAnimationOnSwap, DEFAULT_OVERSIZED_IN_GUI);
}

/**
Expand Down
19 changes: 15 additions & 4 deletions api/src/main/java/team/unnamed/creative/item/ItemImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ final class ItemImpl implements Item {
private final Key key;
private final ItemModel model;
private final boolean handAnimationOnSwap;
private final boolean oversizedInGui;

ItemImpl(final @NotNull Key key, final @NotNull ItemModel model, final boolean handAnimationOnSwap) {
ItemImpl(final @NotNull Key key, final @NotNull ItemModel model, final boolean handAnimationOnSwap, final boolean oversizedInGui) {
this.key = requireNonNull(key, "key");
this.model = requireNonNull(model, "model");
this.handAnimationOnSwap = handAnimationOnSwap;
this.oversizedInGui = oversizedInGui;
}

@Override
Expand All @@ -54,6 +56,11 @@ public boolean handAnimationOnSwap() {
return handAnimationOnSwap;
}

@Override
public boolean oversizedInGui() {
return oversizedInGui;
}

@Override
public @NotNull ItemModel model() {
return model;
Expand All @@ -64,20 +71,24 @@ public boolean handAnimationOnSwap() {
return Stream.of(
ExaminableProperty.of("key", key),
ExaminableProperty.of("model", model),
ExaminableProperty.of("handAnimationOnSwap", handAnimationOnSwap)
ExaminableProperty.of("handAnimationOnSwap", handAnimationOnSwap),
ExaminableProperty.of("oversized_in_gui", oversizedInGui)
);
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
ItemImpl item = (ItemImpl) o;
return key.equals(item.key) && model.equals(item.model) && handAnimationOnSwap == item.handAnimationOnSwap;
return key.equals(item.key)
&& model.equals(item.model)
&& handAnimationOnSwap == item.handAnimationOnSwap
&& oversizedInGui == item.oversizedInGui;
}

@Override
public int hashCode() {
return Objects.hash(key, model, handAnimationOnSwap);
return Objects.hash(key, model, handAnimationOnSwap, oversizedInGui);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import team.unnamed.creative.base.HeadType;

/**
* Represents a special render for heads. Uses profile from {@code minecraft:profile} component
* when applicable.
* Represents a special render for heads.
*
* @since 1.8.0
* @sinceMinecraft 1.21.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ final class NoFieldSpecialRenderImpl implements NoFieldSpecialRender {
static final NoFieldSpecialRender DECORATED_POT = new NoFieldSpecialRenderImpl("decorated_pot"); // renders a decorated pot, uses values from minecraft:pot_decorations component
static final NoFieldSpecialRender SHIELD = new NoFieldSpecialRenderImpl("shield"); // renders a shield, uses patterns from the minecraft:banner_patterns component and color from the minecraft:base_color component
static final NoFieldSpecialRender TRIDENT = new NoFieldSpecialRenderImpl("trident"); // renders a trident
static final NoFieldSpecialRender PLAYER_HEAD = new NoFieldSpecialRenderImpl("player_head"); // renders a player head

private final Key key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,18 @@ public interface SpecialRender extends Examinable {
return head(kind, null, HeadSpecialRender.DEFAULT_ANIMATION);
}

/**
* Returns a special renderer which renders a player head using the item profile component
*
* @return A player head special renderer
* @since 1.8.4
* @sinceMinecraft 1.21.6
* @sincePackFormat 63
*/
static @NotNull NoFieldSpecialRender playerHead() {
return NoFieldSpecialRenderImpl.PLAYER_HEAD;
}

/**
* Returns a special renderer which renders a shulker box with the given texture, openness
* and orientation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ private ElementRotation(

private void validate() {
float absAngle = Math.abs(angle);
if (angle != 0F && absAngle != 22.5F && absAngle != 45F)
throw new IllegalArgumentException("Angle must be multiple of 22.5, in range of -45 to 45");
if (absAngle > 45.0f)
throw new IllegalArgumentException("Angle must be between [-45.0, 45.0] (inclusive), but was " + absAngle);
}

/**
Expand All @@ -91,8 +91,7 @@ public Axis3D axis() {
}

/**
* Returns the actual rotation angle,
* must a multiple of 22.5 and exist in
* Returns the actual rotation angle in the
* range of [-45.0, 45.0]
*
* @return The rotation angle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import team.unnamed.creative.sound.SoundEvent;
import team.unnamed.creative.sound.SoundRegistry;
import team.unnamed.creative.texture.Texture;
import team.unnamed.creative.waypoint.WaypointStyle;
import team.unnamed.creative.waypoint.WaypointStyleImpl;

import java.util.Collection;
import java.util.HashSet;
Expand Down Expand Up @@ -666,6 +668,47 @@ default void texture(final @NotNull Key key, final @NotNull Writable data, final
//#endregion
//#endregion

//#region Waypoint Styles (Keyed)

/**
* Sets the style of the waypoint to the specified {@code WaypointStyle}.
*
* @param style the desired waypoint style to be applied; must not be null
* @since 1.8.4
* @sinceMinecraft 1.21.6
*/
void waypointStyle(final @NotNull WaypointStyle style);

/**
* Retrieves the waypoint style associated with the specified key.
*
* @param key the non-null key used to fetch the corresponding waypoint style
* @return the waypoint style associated with the given key, or null if no style is found
* @since 1.8.4
* @sinceMinecraft 1.21.6
*/
@Nullable WaypointStyle waypointStyle(final @NotNull Key key);

/**
* Removes the waypoint style associated with the specified key.
*
* @param key the key representing the waypoint style to be removed, must not be null
* @return true if the waypoint style was successfully removed, false otherwise
* @since 1.8.4
* @sinceMinecraft 1.21.6
*/
boolean removeWaypointStyle(final @NotNull Key key);

/**
* Retrieves a collection of waypoint styles.
*
* @return A non-null collection of {@link WaypointStyle} objects representing the styles of waypoints.
* @since 1.8.4
* @sinceMinecraft 1.21.6
*/
@NotNull Collection<WaypointStyle> waypointStyles();
//#endregion

/**
* Adds the given resource pack part to this resource container.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
import team.unnamed.creative.sound.SoundEvent;
import team.unnamed.creative.sound.SoundRegistry;
import team.unnamed.creative.texture.Texture;
import team.unnamed.creative.waypoint.WaypointStyle;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
Expand All @@ -70,6 +72,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<String, WaypointStyle> waypointStyles = new LinkedHashMap<>();

// Unknown files we don't know how to parse
private final Map<String, Writable> files = new LinkedHashMap<>();
Expand Down Expand Up @@ -322,6 +325,29 @@ public boolean removeTexture(final @NotNull Key key) {
public @NotNull Collection<Texture> textures() {
return textures.values();
}

@Override
public void waypointStyle(@NotNull WaypointStyle style) {
requireNonNull(style, "style");
waypointStyles.put(style.key().asString(), style);
}

@Override
public @Nullable WaypointStyle waypointStyle(@NotNull Key key) {
requireNonNull(key, "key");
return waypointStyles.get(key.asString());
}

@Override
public boolean removeWaypointStyle(@NotNull Key key) {
requireNonNull(key, "key");
return waypointStyles.remove(key.asString()) != null;
}

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

//#region Unknown Files (By absolute path)
Expand Down
Loading