Skip to content
Closed
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
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ loader_version_range=[1,)

# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
# Must match the String constant located in the main mod class annotated with @Mod.
mod_id=7\
/.*-+****************************rainbowsheep
mod_id=rainbowsheep
# The human-readable display name for the mod.
mod_name=Rainbow Sheep
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.gmail.sheepingtoninc.rainbowsheep.block.FlagWoolBlock;
import com.gmail.sheepingtoninc.rainbowsheep.item.RainbowDyeItem;
import com.mojang.serialization.Codec;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -136,8 +137,8 @@ public class RainbowSheep {
public static final DeferredItem<RainbowDyeItem> ASEXUAL_DYE_ITEM = ITEMS.register("asexual_dye", () -> new RainbowDyeItem(new Item.Properties(), FlagWool.ASEXUAL));
public static final DeferredItem<RainbowDyeItem> NONBINARY_DYE_ITEM = ITEMS.register("nonbinary_dye", () -> new RainbowDyeItem(new Item.Properties(), FlagWool.NONBINARY));

public static final Supplier<AttachmentType<Integer>> FLAG = ATTACHMENT_TYPES.register(
"flag", () -> AttachmentType.builder(() -> 0).serialize(Codec.INT).build()
public static final Supplier<AttachmentType<Integer>> WOOL_FLAG = ATTACHMENT_TYPES.register(
"flag", () -> AttachmentType.builder(() -> 0).serialize(Codec.INT).sync(ByteBufCodecs.INT).build()
);


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gmail.sheepingtoninc.rainbowsheep.item;

import com.gmail.sheepingtoninc.rainbowsheep.RainbowSheep;
import com.gmail.sheepingtoninc.rainbowsheep.api.FlagWool;
import com.gmail.sheepingtoninc.rainbowsheep.api.IFlagSheep;
import net.minecraft.sounds.SoundEvents;
Expand All @@ -27,7 +26,6 @@ public InteractionResult interactLivingEntity(ItemStack stack, Player player, Li
sheep.level().playSound(player, sheep, SoundEvents.DYE_USE, SoundSource.PLAYERS, 1.0F, 1.0F);
((IFlagSheep) sheep).rainbowSheep$setFlagWool(flagWool.ordinal());
if (!player.level().isClientSide) {
RainbowSheep.LOGGER.info("Current flag int is " + sheep.getData(RainbowSheep.FLAG));
stack.shrink(1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.animal.Sheep;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.storage.loot.LootTable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import static com.gmail.sheepingtoninc.rainbowsheep.RainbowSheep.FLAG;
import static com.gmail.sheepingtoninc.rainbowsheep.RainbowSheep.LOGGER;
import static com.gmail.sheepingtoninc.rainbowsheep.RainbowSheep.WOOL_FLAG;


@Mixin(Sheep.class)
Expand All @@ -29,36 +30,37 @@ public abstract class SheepMixin implements IFlagSheep {

@Shadow @Final private static EntityDataAccessor<Byte> DATA_WOOL_ID;

private static final ResourceLocation RAINBOW_LOOT_LOCATION = ResourceLocation.fromNamespaceAndPath("rainbowsheep", "entities/sheep/rainbow");
private static final ResourceKey<LootTable> RAINBOW_LOOT_KEY = ResourceKey.create(Registries.LOOT_TABLE, RAINBOW_LOOT_LOCATION);
@Unique
private static final ResourceKey<LootTable> RAINBOW_LOOT_KEY = ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.fromNamespaceAndPath("rainbowsheep", "entities/sheep/rainbow"));

private static final ResourceLocation TRANSGENDER_LOOT_LOCATION = ResourceLocation.fromNamespaceAndPath("rainbowsheep", "entities/sheep/transgender");
private static final ResourceKey<LootTable> TRANSGENDER_LOOT_KEY = ResourceKey.create(Registries.LOOT_TABLE, TRANSGENDER_LOOT_LOCATION);
@Unique
private static final ResourceKey<LootTable> TRANSGENDER_LOOT_KEY = ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.fromNamespaceAndPath("rainbowsheep", "entities/sheep/transgender"));

private static final ResourceLocation BISEXUAL_LOOT_LOCATION = ResourceLocation.fromNamespaceAndPath("rainbowsheep", "entities/sheep/bisexual");
private static final ResourceKey<LootTable> BISEXUAL_LOOT_KEY = ResourceKey.create(Registries.LOOT_TABLE, BISEXUAL_LOOT_LOCATION);
@Unique
private static final ResourceKey<LootTable> BISEXUAL_LOOT_KEY = ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.fromNamespaceAndPath("rainbowsheep", "entities/sheep/bisexual"));

private static final ResourceLocation LESBIAN_LOOT_LOCATION = ResourceLocation.fromNamespaceAndPath("rainbowsheep", "entities/sheep/lesbian");
private static final ResourceKey<LootTable> LESBIAN_LOOT_KEY = ResourceKey.create(Registries.LOOT_TABLE, LESBIAN_LOOT_LOCATION);
@Unique
private static final ResourceKey<LootTable> LESBIAN_LOOT_KEY = ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.fromNamespaceAndPath("rainbowsheep", "entities/sheep/lesbian"));

private static final ResourceLocation ASEXUAL_LOOT_LOCATION = ResourceLocation.fromNamespaceAndPath("rainbowsheep", "entities/sheep/asexual");
private static final ResourceKey<LootTable> ASEXUAL_LOOT_KEY = ResourceKey.create(Registries.LOOT_TABLE, ASEXUAL_LOOT_LOCATION);
@Unique
private static final ResourceKey<LootTable> ASEXUAL_LOOT_KEY = ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.fromNamespaceAndPath("rainbowsheep", "entities/sheep/asexual"));

private static final ResourceLocation NONBINARY_LOOT_LOCATION = ResourceLocation.fromNamespaceAndPath("rainbowsheep", "entities/sheep/nonbinary");
private static final ResourceKey<LootTable> NONBINARY_LOOT_KEY = ResourceKey.create(Registries.LOOT_TABLE, NONBINARY_LOOT_LOCATION);
@Unique
private static final ResourceKey<LootTable> NONBINARY_LOOT_KEY = ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.fromNamespaceAndPath("rainbowsheep", "entities/sheep/nonbinary"));


@Override
public void rainbowSheep$setFlagWool(int flag) {
SynchedEntityData data = ((Sheep)(Object)this).getEntityData();
Sheep sheep = ((Sheep)(Object)this);
SynchedEntityData data = sheep.getEntityData();
byte woolByte = data.get(DATA_WOOL_ID);
data.set(DATA_WOOL_ID, (byte)(woolByte & 240));
((Sheep)(Object)this).setData(FLAG, flag);
sheep.setData(WOOL_FLAG, flag);
}

@Override
public int rainbowSheep$getFlagWool() {
return ((Sheep)(Object) this).getData(FLAG);
return ((Sheep)(Object) this).getData(WOOL_FLAG);
}

@ModifyArg(method = "shear", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Sheep;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;I)Lnet/minecraft/world/entity/item/ItemEntity;"))
Expand Down Expand Up @@ -88,8 +90,10 @@ protected void setFlagLootTable(CallbackInfoReturnable<ResourceKey<LootTable>> c
}
}

@Inject(method = "setColor", at = @At(value="HEAD"))
private void removeFlagOnColor(CallbackInfo ci) {
this.rainbowSheep$setFlagWool(0);
@Inject(method = "setColor", at = @At("HEAD"))
private void removeFlagOnColor(DyeColor newColor, CallbackInfo ci) {
if (!((Sheep)(Object)this).level().isClientSide && ((Sheep)(Object)this).tickCount > 0) { //setColor is called when loading sheep, this ensures that first call does not remove flag wool
this.rainbowSheep$setFlagWool(0);
}
}
}