Skip to content

Commit

Permalink
Finished the pigment shifter
Browse files Browse the repository at this point in the history
  • Loading branch information
N1nn1 committed May 13, 2024
1 parent c5d3551 commit d2a87b5
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 155 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/ninni/spawn/block/PigmentShifterBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
//player.awardStat(Stats.INTERACT_WITH_CRAFTING_TABLE);
return InteractionResult.CONSUME;
}
} else return InteractionResult.SUCCESS;
} else {
player.displayClientMessage(Component.translatable("container.spawn.pigment_shifter.no_water"), true);
return InteractionResult.SUCCESS;
}
}

public MenuProvider getMenuProvider(BlockState blockState, Level level, BlockPos blockPos) {
Expand Down
242 changes: 154 additions & 88 deletions src/main/java/com/ninni/spawn/client/inventory/PigmentShifterMenu.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.ninni.spawn.client.inventory;

import com.google.common.collect.Lists;
import com.mojang.blaze3d.systems.RenderSystem;
import com.ninni.spawn.Spawn;
import com.ninni.spawn.entity.Clam;
import com.ninni.spawn.entity.variant.ClamVariant;
import com.ninni.spawn.registry.SpawnTags;
import com.ninni.spawn.entity.Seahorse;
import com.ninni.spawn.mixin.accessor.TropicalFishAccessor;
Expand All @@ -11,9 +12,6 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.client.renderer.GameRenderer;
Expand All @@ -24,24 +22,22 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.TropicalFish;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.inventory.SmithingMenu;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.SmithingTemplateItem;
import net.minecraft.world.level.Level;
import org.joml.Quaternionf;

import java.util.List;
import java.util.Optional;

@Environment(EnvType.CLIENT)
public class PigmentShifterScreen extends AbstractContainerScreen<PigmentShifterMenu> {
private static final ResourceLocation RESOURCE_LOCATION = new ResourceLocation(Spawn.MOD_ID, "textures/gui/container/fish.png");
private static final Component BODY_PLAN_TOOLTIP = Component.translatable("container.spawn.pigment_shifter.body_plan");
private static final Component BODY_PLAN_TOOLTIP_PRESET_COLOR = Component.translatable("container.spawn.pigment_shifter.body_plan.color");
private static final Component PATTERN_TOOLTIP = Component.translatable("container.spawn.pigment_shifter.pattern");
private static final Component BODY_DYE_TOOLTIP = Component.translatable("container.spawn.pigment_shifter.body_dye");
private static final Component PATTERN_DYE_TOOLTIP = Component.translatable("container.spawn.pigment_shifter.pattern_dye");
private final PigmentShifterMenu menu;
private final Level level;
private double rotationY = 0;
Expand Down Expand Up @@ -80,34 +76,55 @@ protected void renderBg(GuiGraphics poseStack, float partialTicks, int x, int y)
if (!patternDyeSlot.hasItem()) poseStack.blit(RESOURCE_LOCATION, imgX + patternDyeSlot.x, imgY + patternDyeSlot.y, this.imageWidth, 0, 16, 16);
if (!bucketSlot.hasItem()) poseStack.blit(RESOURCE_LOCATION, imgX + bucketSlot.x, imgY + bucketSlot.y, this.imageWidth + 16, 0, 16, 16);
if (!bodyPlanSlot.hasItem()) poseStack.blit(RESOURCE_LOCATION, imgX + bodyPlanSlot.x, imgY + bodyPlanSlot.y, this.imageWidth + 32, 0, 16, 16);
if (!patternSlot.hasItem()) poseStack.blit(RESOURCE_LOCATION, imgX + patternSlot.x, imgY + patternSlot.y, this.imageWidth + 32, 0, 16, 16);
if (!patternSlot.hasItem()) poseStack.blit(RESOURCE_LOCATION, imgX + patternSlot.x, imgY + patternSlot.y, this.imageWidth + 48, 0, 16, 16);
if (bodyDyeSlot instanceof PigmentShifterSlot pigmentShifterSlot && pigmentShifterSlot.isDisabled()) poseStack.blit(RESOURCE_LOCATION, imgX + bodyDyeSlot.x, imgY + bodyDyeSlot.y, this.imageWidth + 64, 0, 16, 16);
if (patternDyeSlot instanceof PigmentShifterSlot pigmentShifterSlot && pigmentShifterSlot.isDisabled()) poseStack.blit(RESOURCE_LOCATION, imgX + patternDyeSlot.x, imgY + patternDyeSlot.y, this.imageWidth + 64, 0, 16, 16);
if (patternSlot instanceof PigmentShifterSlot pigmentShifterSlot && pigmentShifterSlot.isDisabled()) poseStack.blit(RESOURCE_LOCATION, imgX + patternSlot.x, imgY + patternSlot.y, this.imageWidth + 64, 0, 16, 16);
if (bodyPlanSlot instanceof PigmentShifterSlot pigmentShifterSlot && pigmentShifterSlot.isDisabled()) poseStack.blit(RESOURCE_LOCATION, imgX + bodyPlanSlot.x, imgY + bodyPlanSlot.y, this.imageWidth + 64, 0, 16, 16);


if (menu.resultSlot.hasItem() && item.is(SpawnTags.CUSTOMIZABLE_MOB_ITEMS)) {

CompoundTag compoundTag = item.getTag();

if (compoundTag != null && compoundTag.contains("ItemVariantTag", 3) && item.is(SpawnItems.CLAM)) {
int tag = compoundTag.getInt("ItemVariantTag");
Clam clam = SpawnEntityType.SpawnAquaticCreature.CLAM.create(this.level);
clam.noPhysics = true;
ClamVariant.Variant variant = new ClamVariant.Variant(Clam.getBaseColor(tag), Clam.getPattern(tag), Clam.getDyeColor(tag));
clam.setPackedVariant(variant.getPackedId());
int id = clam.getBaseColor().base().getId();
int i = id + 2;
int scale = 40;
if (id == 2) scale = 30;
int h = id == 0 ? 54 : id == 1 ? 50 : 60;

renderMovableEntity(poseStack, imgX + 107, imgY + h, scale, clam, i);
clam.discard();
}

if (compoundTag != null && compoundTag.contains("BucketVariantTag", 3)) {
int tag = compoundTag.getInt("BucketVariantTag");

if (item.is(Items.TROPICAL_FISH_BUCKET)) {
TropicalFish tropicalFish = EntityType.TROPICAL_FISH.create(this.level);
tropicalFish.noPhysics = true;
TropicalFish.Variant variant = new TropicalFish.Variant(TropicalFish.getPattern(tag), TropicalFish.getBaseColor(tag), TropicalFish.getPatternColor(tag));
((TropicalFishAccessor) tropicalFish).callSetPackedVariant(variant.getPackedId());

renderMovableEntity(poseStack, imgX + 107, imgY + 54, 40, tropicalFish, true);
renderMovableEntity(poseStack, imgX + 107, imgY + 54, 40, tropicalFish, 1);
tropicalFish.discard();
}

if (item.is(SpawnItems.SEAHORSE_BUCKET)) {
int h;

Seahorse seahorse = SpawnEntityType.SpawnFish.SEAHORSE.create(this.level);
seahorse.noPhysics = true;
Seahorse.Pattern pattern = Seahorse.getPattern(tag);
Seahorse.Variant variant = new Seahorse.Variant(pattern, Seahorse.getBaseColor(tag), Seahorse.getPatternColor(tag));
seahorse.setPackedVariant(variant.getPackedId());
if (pattern.base() == Seahorse.Base.LARGE) h = -10;
else h = 0;
renderMovableEntity(poseStack, imgX + 107, imgY + 64 + h, 40, seahorse, false);
renderMovableEntity(poseStack, imgX + 107, imgY + 64 + h, 40, seahorse, 0);
seahorse.discard();
}

Expand All @@ -120,16 +137,25 @@ private void renderOnboardingTooltips(GuiGraphics guiGraphics, int i, int j) {
Optional<Component> optional = Optional.empty();

if (this.hoveredSlot != null) {
ItemStack itemStack = this.menu.getSlot(this.menu.patternSlot.index).getItem();
ItemStack itemStack2 = this.menu.getSlot(this.menu.bodyPlanSlot.index).getItem();
if (itemStack.isEmpty()) {
if (this.menu.getSlot(this.menu.patternSlot.index).getItem().isEmpty() && !((PigmentShifterSlot)this.menu.patternSlot).isDisabled()) {
if (this.hoveredSlot.index == this.menu.patternSlot.index) {
optional = Optional.of(PATTERN_TOOLTIP);
}
}
if (itemStack2.isEmpty()) {
if (this.menu.getSlot(this.menu.bodyPlanSlot.index).getItem().isEmpty() && !((PigmentShifterSlot)this.menu.bodyPlanSlot).isDisabled()) {
if (this.hoveredSlot.index == this.menu.bodyPlanSlot.index) {
optional = Optional.of(BODY_PLAN_TOOLTIP);
if (this.menu.bucketSlot.getItem().is(SpawnItems.CLAM)) optional = Optional.of(BODY_PLAN_TOOLTIP_PRESET_COLOR);
else optional = Optional.of(BODY_PLAN_TOOLTIP);
}
}
if (this.menu.getSlot(this.menu.bodyDyeSlot.index).getItem().isEmpty() && !((PigmentShifterSlot)this.menu.bodyDyeSlot).isDisabled()) {
if (this.hoveredSlot.index == this.menu.bodyDyeSlot.index) {
optional = Optional.of(BODY_DYE_TOOLTIP);
}
}
if (this.menu.getSlot(this.menu.patternDyeSlot.index).getItem().isEmpty() && !((PigmentShifterSlot)this.menu.patternDyeSlot).isDisabled()) {
if (this.hoveredSlot.index == this.menu.patternDyeSlot.index) {
optional = Optional.of(PATTERN_DYE_TOOLTIP);
}
}
}
Expand All @@ -140,19 +166,23 @@ private void renderOnboardingTooltips(GuiGraphics guiGraphics, int i, int j) {
}


public void renderMovableEntity(GuiGraphics poseStack, int x, int y, int scale, LivingEntity entity, boolean rotate) {
public void renderMovableEntity(GuiGraphics poseStack, int x, int y, int scale, LivingEntity entity, int rotate) {
rotationY += rotateY;
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);

Quaternionf quaternionf = new Quaternionf().rotateX((float) Math.toRadians(180f));
Quaternionf quaternionf1 = new Quaternionf().rotateY( ((float) rotationY));
Quaternionf quaternionf2 = new Quaternionf().rotateZ((float) Math.toRadians(90f));
Quaternionf quaternionf3 = new Quaternionf().rotateX((float) rotationY);

if (rotate) {
quaternionf.mul(quaternionf2);
quaternionf.mul(quaternionf3);
if (rotate == 1) {
quaternionf.mul(new Quaternionf().rotateZ((float) Math.toRadians(90f)));
quaternionf.mul(new Quaternionf().rotateX((float) rotationY));
} else if (rotate == 2) {
quaternionf.mul( new Quaternionf().rotateX((float) Math.toRadians(90f)));
quaternionf.mul(new Quaternionf().rotateZ((float) -rotationY));
} else if (rotate == 3) {
quaternionf.mul(new Quaternionf().rotateX((float) Math.toRadians(-90f)));
quaternionf.mul(new Quaternionf().rotateZ((float) rotationY));
} else quaternionf.mul(quaternionf1);

InventoryScreen.renderEntityInInventory(poseStack, x, y, scale, quaternionf, quaternionf1, entity);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.ninni.spawn.client.inventory;

import net.minecraft.world.Container;
import net.minecraft.world.inventory.Slot;

public class PigmentShifterSlot extends Slot {
public boolean disabled;
public PigmentShifterSlot(Container container, int i, int j, int k) {
super(container, i, j, k);
}

public boolean isDisabled() {
return disabled;
}

public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/ninni/spawn/entity/variant/ClamVariant.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,9 @@ public enum Base {
this.id = j;
this.name = name;
}

public int getId() {
return id;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,39 @@ public void init(ModelPart modelPart, CallbackInfo ci) {
@Inject(method = "setupAnim", at = @At("HEAD"), cancellable = true)
private void setupAnim(T tropicalFish, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch, CallbackInfo ci) {
float pi = ((float)Math.PI);

if (SpawnRPTweaks.isPresent(SpawnRPTweaks.Tweaks.TROPICAL_FISH_ANIMATIONS)) {
if (tropicalFish.noPhysics) {
ci.cancel();
this.all.xRot = 0;
this.all.yRot = 0;
} else {
if (SpawnRPTweaks.isPresent(SpawnRPTweaks.Tweaks.TROPICAL_FISH_ANIMATIONS) && !tropicalFish.noPhysics) {
ci.cancel();

float speed = tropicalFish.isInWater() ? 1 : 4;
float speed = tropicalFish.isInWater() ? 1 : 4;

SpawnRPTweaks.addTilting(SpawnRPTweaks.Tweaks.TROPICAL_FISH_TILTING, this.all, headYaw, headPitch);
SpawnRPTweaks.addTilting(SpawnRPTweaks.Tweaks.TROPICAL_FISH_TILTING, this.all, headYaw, headPitch);

this.all.y = Mth.cos(animationProgress * 0.3f + 3) * 2.4F * 0.25F + 21.5F;
this.all.z = -1.0F;
this.all.xRot += Mth.sin(animationProgress * 0.15f + 1) * 0.2F * -0.25F;
this.tailFin.yRot = Mth.cos(animationProgress * 0.15f * speed + 1) * 2.8F * 0.25F;
this.tailFin.yRot += Mth.cos(limbAngle * 2f + 1) * 2.8F * limbDistance;
this.rightFin.yRot = Mth.cos(animationProgress * 0.3f + 1f + pi) * 2 * 0.25F + 0.6F;
this.leftFin.yRot = Mth.cos(animationProgress * 0.3f + 1.5f) * 2F * 0.25F - 0.6F;
} else {
ci.cancel();
SpawnRPTweaks.addTilting(SpawnRPTweaks.Tweaks.TROPICAL_FISH_TILTING, this.all, headYaw, headPitch);
this.all.z = -1.0F;
this.all.y = Mth.cos(animationProgress * 0.3f + 3) * 2.4F * 0.25F + 21.5F;
this.all.z = -1.0F;
this.all.xRot += Mth.sin(animationProgress * 0.15f + 1) * 0.2F * -0.25F;
this.tailFin.yRot = Mth.cos(animationProgress * 0.15f * speed + 1) * 2.8F * 0.25F;
this.tailFin.yRot += Mth.cos(limbAngle * 2f + 1) * 2.8F * limbDistance;
this.rightFin.yRot = Mth.cos(animationProgress * 0.3f + 1f + pi) * 2 * 0.25F + 0.6F;
this.leftFin.yRot = Mth.cos(animationProgress * 0.3f + 1.5f) * 2F * 0.25F - 0.6F;
} else {
ci.cancel();
SpawnRPTweaks.addTilting(SpawnRPTweaks.Tweaks.TROPICAL_FISH_TILTING, this.all, headYaw, headPitch);
this.all.z = -1.0F;

float k = 1.0f;
if (!tropicalFish.isInWater()) {
k = 1.5f;
float k = 1.0f;
if (!tropicalFish.isInWater()) {
k = 1.5f;
}
this.tailFin.yRot = -k * 0.45f * Mth.sin(0.6f * animationProgress);
}
this.tailFin.yRot = -k * 0.45f * Mth.sin(0.6f * animationProgress);
}
}

@Inject(method = "createBodyLayer", at = @At("HEAD"), cancellable = true)
private static void createBodyLayer(CallbackInfoReturnable<LayerDefinition> cir) {
MeshDefinition meshdefinition = new MeshDefinition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,41 @@ public void init(ModelPart modelPart, CallbackInfo ci) {
private void setupAnim(T tropicalFish, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch, CallbackInfo ci) {
float pi = ((float)Math.PI);

if (SpawnRPTweaks.isPresent(SpawnRPTweaks.Tweaks.TROPICAL_FISH_ANIMATIONS)) {
if (tropicalFish.noPhysics) {
ci.cancel();
this.all.xRot = 0;
this.all.yRot = 0;
} else {
if (SpawnRPTweaks.isPresent(SpawnRPTweaks.Tweaks.TROPICAL_FISH_ANIMATIONS)) {
ci.cancel();

float speed = tropicalFish.isInWater() ? 1 : 4;
float speed = tropicalFish.isInWater() ? 1 : 4;

SpawnRPTweaks.addTilting(SpawnRPTweaks.Tweaks.TROPICAL_FISH_TILTING, this.all, headYaw, headPitch);
SpawnRPTweaks.addTilting(SpawnRPTweaks.Tweaks.TROPICAL_FISH_TILTING, this.all, headYaw, headPitch);

this.all.y = Mth.cos(animationProgress * 0.3f + 3) * 2.4F * 0.25F + 21.5F;
this.all.z = -1.0F;
this.all.xRot += Mth.sin(animationProgress * 0.15f + 1) * 0.2F * -0.25F;
this.tailFin.yRot = Mth.cos(animationProgress * 0.15f * speed + 1) * 2.8F * 0.25F;
this.tailFin.yRot += Mth.cos(limbAngle * 2f + 1) * 2.8F * limbDistance;
this.rightFin.yRot = Mth.cos(animationProgress * 0.3f + 1f + pi) * 2 * 0.25F + 0.6F;
this.leftFin.yRot = Mth.cos(animationProgress * 0.3f + 1.5f) * 2F * 0.25F - 0.6F;
} else {
ci.cancel();
SpawnRPTweaks.addTilting(SpawnRPTweaks.Tweaks.TROPICAL_FISH_TILTING, this.all, headYaw, headPitch);
this.all.z = -1.0F;
this.all.y = Mth.cos(animationProgress * 0.3f + 3) * 2.4F * 0.25F + 21.5F;
this.all.z = -1.0F;
this.all.xRot += Mth.sin(animationProgress * 0.15f + 1) * 0.2F * -0.25F;
this.tailFin.yRot = Mth.cos(animationProgress * 0.15f * speed + 1) * 2.8F * 0.25F;
this.tailFin.yRot += Mth.cos(limbAngle * 2f + 1) * 2.8F * limbDistance;
this.rightFin.yRot = Mth.cos(animationProgress * 0.3f + 1f + pi) * 2 * 0.25F + 0.6F;
this.leftFin.yRot = Mth.cos(animationProgress * 0.3f + 1.5f) * 2F * 0.25F - 0.6F;
} else {
ci.cancel();
SpawnRPTweaks.addTilting(SpawnRPTweaks.Tweaks.TROPICAL_FISH_TILTING, this.all, headYaw, headPitch);
this.all.z = -1.0F;

float k = 1.0f;
if (!tropicalFish.isInWater()) {
k = 1.5f;
float k = 1.0f;
if (!tropicalFish.isInWater()) {
k = 1.5f;
}
this.tailFin.yRot = -k * 0.45f * Mth.sin(0.6f * animationProgress);
}
this.tailFin.yRot = -k * 0.45f * Mth.sin(0.6f * animationProgress);
}


}

@Inject(method = "createBodyLayer", at = @At("HEAD"), cancellable = true)
private static void createBodyLayer(CallbackInfoReturnable<LayerDefinition> cir) {
MeshDefinition meshdefinition = new MeshDefinition();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ninni/spawn/registry/SpawnTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public interface SpawnTags {

//Item tags
TagKey<Item> CUSTOMIZABLE_MOB_ITEMS = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "customizable_mob_items"));
TagKey<Item> CHANGES_BODY_PLAN = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "changes_body_plan"));
TagKey<Item> CHANGES_PATTERN = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "changes_pattern"));
TagKey<Item> ANGLER_FISH_TEMPTS = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "angler_fish_tempts"));
TagKey<Item> ANGLER_FISH_LIKES = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "angler_fish_likes"));
TagKey<Item> TUNA_TEMPTS = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "tuna_tempts"));
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/assets/spawn/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,12 @@
"block.spawn.clam_launcher": "Clam Launcher",
"block.spawn.pigment_shifter": "Pigment Shifter",
"container.spawn.pigment_shifter": "Customize",
"container.spawn.pigment_shifter.body_plan": "Cycle Body Plan",
"container.spawn.pigment_shifter.pattern": "Cycle Pattern",
"container.spawn.pigment_shifter.no_water": "Block Needs to be in Water to work",
"container.spawn.pigment_shifter.body_plan": "Cycle Body Plans",
"container.spawn.pigment_shifter.body_plan.color": "Cycle Body Colors",
"container.spawn.pigment_shifter.pattern": "Cycle Patterns",
"container.spawn.pigment_shifter.body_dye": "Change Body Color",
"container.spawn.pigment_shifter.pattern_dye": "Change Pattern Color",

"entity.spawn.sea_cow": "Sea Cow",
"item.spawn.sea_cow_spawn_egg": "Sea Cow Spawn Egg",
Expand Down
Binary file modified src/main/resources/assets/spawn/textures/gui/container/fish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d2a87b5

Please sign in to comment.