Skip to content

Commit

Permalink
Axolotl compat
Browse files Browse the repository at this point in the history
  • Loading branch information
N1nn1 committed May 13, 2024
1 parent d2a87b5 commit b7de2f1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.TropicalFish;
import net.minecraft.world.entity.animal.axolotl.Axolotl;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
Expand Down Expand Up @@ -171,8 +172,23 @@ public void slotsChanged(Container container) {
resultCopy.getOrCreateTag().putInt("ItemVariantTag", clam.getPackedVariant());
clam.discard();

this.outputContainer.setItem(4, resultCopy);
} else if (bucketSlotItem.is(Items.AXOLOTL_BUCKET) && compoundTag.contains("Variant", 3)) {
int variantId = bucketSlotItem.getTag().getInt("Variant");

if (variantId != 4) {
((PigmentShifterSlot)this.bodyDyeSlot).setDisabled(true);
((PigmentShifterSlot)this.patternSlot).setDisabled(true);
((PigmentShifterSlot)this.patternDyeSlot).setDisabled(true);

int shiftedId = variantId + 1;
if (variantId == 3) shiftedId = 0;

if (bodyPlanSlotItem.is(SpawnTags.CHANGES_BODY_PLAN)) resultCopy.getOrCreateTag().putInt("Variant", shiftedId);
this.outputContainer.setItem(4, resultCopy);
}
} else {
((PigmentShifterSlot)this.bodyDyeSlot).setDisabled(false);
setAllSlotsDisabled(false);

if (bucketSlotItem.is(SpawnItems.SEAHORSE_BUCKET) && compoundTag.contains("BucketVariantTag", 3)) {
int tag = bucketSlotItem.getTag().getInt("BucketVariantTag");
Expand Down Expand Up @@ -210,8 +226,9 @@ public void slotsChanged(Container container) {
resultCopy.getOrCreateTag().putInt("BucketVariantTag", ((TropicalFishAccessor) tropicalFish).callGetPackedVariant());
tropicalFish.discard();
}

this.outputContainer.setItem(4, resultCopy);
}
this.outputContainer.setItem(4, resultCopy);
} else {
setAllSlotsDisabled(false);
this.outputContainer.removeItemNoUpdate(4);
Expand Down Expand Up @@ -264,9 +281,9 @@ public ItemStack quickMoveStack(Player player, int i) {
(((PigmentShifterSlot)this.patternDyeSlot).isDisabled() || !this.moveItemStackTo(itemStack2, this.patternDyeSlot.index, this.patternDyeSlot.index + 1, false))

: itemStack2.is(SpawnTags.CHANGES_BODY_PLAN) ?
!this.moveItemStackTo(itemStack2, this.bodyPlanSlot.index, this.bodyPlanSlot.index + 1, false)
(((PigmentShifterSlot)this.bodyPlanSlot).isDisabled() || !this.moveItemStackTo(itemStack2, this.bodyPlanSlot.index, this.bodyPlanSlot.index + 1, false))
: itemStack2.is(SpawnTags.CHANGES_PATTERN) ?
!this.moveItemStackTo(itemStack2, this.patternSlot.index, this.patternSlot.index + 1, false)
(((PigmentShifterSlot)this.patternSlot).isDisabled() || !this.moveItemStackTo(itemStack2, this.patternSlot.index, this.patternSlot.index + 1, false))

: itemStack2.is(SpawnTags.CUSTOMIZABLE_MOB_ITEMS) ?
!this.moveItemStackTo(itemStack2, this.bucketSlot.index, this.bucketSlot.index + 1, false) : i >= 4 && i < 31 ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.TropicalFish;
import net.minecraft.world.entity.animal.axolotl.Axolotl;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -102,6 +103,16 @@ protected void renderBg(GuiGraphics poseStack, float partialTicks, int x, int y)
clam.discard();
}

if (compoundTag != null && compoundTag.contains("Variant", 3) && item.is(Items.AXOLOTL_BUCKET) && compoundTag.getInt("Variant") != 4) {
int variant = compoundTag.getInt("Variant");

Axolotl axolotl = EntityType.AXOLOTL.create(this.level);
axolotl.noPhysics = true;
axolotl.setVariant(Axolotl.Variant.byId(variant));
renderMovableEntity(poseStack, imgX + 107, imgY + 60, 30, axolotl, 0);
axolotl.discard();
}

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

Expand Down Expand Up @@ -144,7 +155,7 @@ private void renderOnboardingTooltips(GuiGraphics guiGraphics, int i, int j) {
}
if (this.menu.getSlot(this.menu.bodyPlanSlot.index).getItem().isEmpty() && !((PigmentShifterSlot)this.menu.bodyPlanSlot).isDisabled()) {
if (this.hoveredSlot.index == this.menu.bodyPlanSlot.index) {
if (this.menu.bucketSlot.getItem().is(SpawnItems.CLAM)) optional = Optional.of(BODY_PLAN_TOOLTIP_PRESET_COLOR);
if (this.menu.bucketSlot.getItem().is(SpawnItems.CLAM) || this.menu.bucketSlot.getItem().is(Items.AXOLOTL_BUCKET)) optional = Optional.of(BODY_PLAN_TOOLTIP_PRESET_COLOR);
else optional = Optional.of(BODY_PLAN_TOOLTIP);
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/com/ninni/spawn/entity/common/BoidFishEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public abstract class BoidFishEntity extends AbstractFish {
public BoidFishEntity leader;
public List<BoidFishEntity> ownSchool = new ArrayList<>();
private int maxSchoolSize;
public int cantSwimTimer = 40;
public int cantFollowTimer;

public BoidFishEntity(EntityType<? extends AbstractFish> entityType, Level level) {
Expand All @@ -35,11 +34,11 @@ public BoidFishEntity(EntityType<? extends AbstractFish> entityType, Level level

@Override
protected void registerGoals() {
this.goalSelector.addGoal(4, new FishSwimGoal(this));
this.goalSelector.addGoal(5, new BoidFishSchoolingGoal(this, 0.2f, 0.4f, 8 / 20f, 1 / 20f));
this.goalSelector.addGoal(3, new HeightBoundsGoal(this));
this.goalSelector.addGoal(2, new LimitSpeedAndLookInVelocityDirectionGoal(this, 0.65f));
this.goalSelector.addGoal(5, new OrganizeBoidSchoolingGoal(this));
this.goalSelector.addGoal(0, new BoidFishSchoolingGoal(this, 0.2f, 0.4f, 8 / 20f, 1 / 20f));
this.goalSelector.addGoal(0, new HeightBoundsGoal(this));
this.goalSelector.addGoal(0, new LimitSpeedAndLookInVelocityDirectionGoal(this, 0.65f));
this.goalSelector.addGoal(0, new OrganizeBoidSchoolingGoal(this));
this.goalSelector.addGoal(6, new FishSwimGoal(this));
}

public int getMaxSchoolSize() {
Expand Down Expand Up @@ -74,7 +73,6 @@ protected SoundEvent getSwimSound() {

private void addToOwnSchoolFollower(BoidFishEntity entity) {
if (entity.cantFollowTimer == 0) this.ownSchool.add(entity);
if (entity.cantSwimTimer > 0) this.cantSwimTimer--;
}

private void removeFollowerFromOwnSchool(BoidFishEntity entity) {
Expand Down Expand Up @@ -110,13 +108,13 @@ static class FishSwimGoal extends RandomSwimmingGoal {
private final BoidFishEntity fish;

public FishSwimGoal(BoidFishEntity boidFish) {
super(boidFish, 1.0, 40);
super(boidFish, 1.0, 120);
this.fish = boidFish;
}

@Override
public boolean canUse() {
return !this.fish.isFollower() && !this.fish.hasFollowers() && fish.cantSwimTimer == 0 && super.canUse();
return !this.fish.isFollower() && !this.fish.hasFollowers() && super.canUse();
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/ninni/spawn/mixin/client/AxolotlModelMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ninni.spawn.mixin.client;

import net.minecraft.client.model.AgeableListModel;
import net.minecraft.client.model.AxolotlModel;
import net.minecraft.world.entity.LerpingModel;
import net.minecraft.world.entity.animal.axolotl.Axolotl;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(AxolotlModel.class)
public abstract class AxolotlModelMixin<T extends Axolotl & LerpingModel> extends AgeableListModel<T> {

@Inject(method = "setupAnim(Lnet/minecraft/world/entity/animal/axolotl/Axolotl;FFFFF)V", at = @At("HEAD"), cancellable = true)
private void setupAnim(T axolotl, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch, CallbackInfo ci) {
if (axolotl.noPhysics) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"replace": false,
"values": [
"minecraft:tropical_fish_bucket",
"minecraft:axolotl_bucket",
"spawn:seahorse_bucket",
"spawn:clam"
]
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/spawn.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"accessor.TropicalFishAccessor"
],
"client": [
"client.AxolotlModelMixin",
"client.BatRendererMixin",
"client.BlockEntityWithoutLevelRendererMixin",
"client.CodModelMixin",
Expand Down

0 comments on commit b7de2f1

Please sign in to comment.