Skip to content

Commit

Permalink
修正与宠物革新模组的兼容
Browse files Browse the repository at this point in the history
fix: #426
  • Loading branch information
TartaricAcid committed Nov 7, 2023
1 parent 1604f20 commit 5a3fd1c
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 20 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ dependencies {

implementation fg.deobf("me.shedaniel.cloth:cloth-config-forge:${cloth_config_forge}")

implementation fg.deobf("curse.maven:citadel-331936:${citadel_id}")
implementation fg.deobf("curse.maven:domestication-innovation-591149:${domestication_innovation_id}")

annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
}

Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ patchouli_version=1.20.1-80-FORGE
twilight_forest_version=4.3.1850
jade_id=4768593
top_id=4629624
cloth_config_forge=11.1.106
cloth_config_forge=11.1.106
citadel_id=4576429
domestication_innovation_id=4578807
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,31 @@

import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.eventbus.api.Cancelable;

public class MaidAttackEvent extends LivingAttackEvent {
@Cancelable
public class MaidAttackEvent extends LivingEvent {
private final EntityMaid maid;
private final DamageSource source;
private final float amount;

public MaidAttackEvent(EntityMaid maid, DamageSource source, float amount) {
super(maid, source, amount);
super(maid);
this.source = source;
this.amount = amount;
this.maid = maid;
}

public EntityMaid getMaid() {
return maid;
}

public DamageSource getSource() {
return source;
}

public float getAmount() {
return amount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@

import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraftforge.event.entity.living.LivingDamageEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.eventbus.api.Cancelable;

public class MaidDamageEvent extends LivingDamageEvent {
@Cancelable
public class MaidDamageEvent extends LivingEvent {
private final EntityMaid maid;
private final DamageSource source;
private float amount;

public MaidDamageEvent(EntityMaid maid, DamageSource source, float amount) {
super(maid, source, amount);
super(maid);
this.maid = maid;
this.source = source;
this.amount = amount;
}

public EntityMaid getMaid() {
return maid;
}

public DamageSource getSource() {
return source;
}

public float getAmount() {
return amount;
}

public void setAmount(float amount) {
this.amount = amount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@

import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.eventbus.api.Cancelable;

public class MaidDeathEvent extends LivingDeathEvent {
@Cancelable
public class MaidDeathEvent extends LivingEvent {
private final EntityMaid maid;
private final DamageSource source;

public MaidDeathEvent(EntityMaid maid, DamageSource source) {
super(maid, source);
super(maid);
this.maid = maid;
this.source = source;
}

public EntityMaid getMaid() {
return maid;
}

public DamageSource getSource() {
return source;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@

import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.eventbus.api.Cancelable;

public class MaidHurtEvent extends LivingHurtEvent {
@Cancelable
public class MaidHurtEvent extends LivingEvent {
private final EntityMaid maid;
private final DamageSource source;
private float amount;

public MaidHurtEvent(EntityMaid maid, DamageSource source, float amount) {
super(maid, source, amount);
super(maid);
this.maid = maid;
this.source = source;
this.amount = amount;
}

public EntityMaid getMaid() {
return maid;
}

public DamageSource getSource() {
return source;
}

public float getAmount() {
return amount;
}

public void setAmount(float amount) {
this.amount = amount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.eventbus.api.Cancelable;

public class MaidTickEvent extends LivingEvent.LivingTickEvent {
@Cancelable
public class MaidTickEvent extends LivingEvent {
private final EntityMaid maid;

public MaidTickEvent(EntityMaid maid) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.github.tartaricacid.touhoulittlemaid.compat.domesticationinnovation;

import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.Map;

@Mod.EventBusSubscriber
public class EnchantmentRefuse {
private static final String DOMESTICATION_INNOVATION = "domesticationinnovation";
private static final ResourceLocation COLLAR_TAG_ID = new ResourceLocation(DOMESTICATION_INNOVATION, "collar_tag");
private static final ResourceLocation UNDEAD_CURSE_ENCHANTMENT_ID = new ResourceLocation(DOMESTICATION_INNOVATION, "undead_curse");
private static final ResourceLocation BLAZING_PROTECTION_ENCHANTMENT_ID = new ResourceLocation(DOMESTICATION_INNOVATION, "blazing_protection");

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onInteractMaid(PlayerInteractEvent.EntityInteract event) {
if (!ModList.get().isLoaded(DOMESTICATION_INNOVATION)) {
return;
}
if (!(event.getTarget() instanceof EntityMaid maid)) {
return;
}
if (maid.level.isClientSide) {
return;
}
Player player = event.getEntity();
if (!maid.isOwnedBy(player)) {
return;
}
ItemStack stack = event.getItemStack();
ResourceLocation itemsKey = ForgeRegistries.ITEMS.getKey(stack.getItem());
if (!COLLAR_TAG_ID.equals(itemsKey)) {
return;
}
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(stack);
for (Enchantment enchantment : enchantments.keySet()) {
ResourceLocation enchantmentsKey = ForgeRegistries.ENCHANTMENTS.getKey(enchantment);
if (UNDEAD_CURSE_ENCHANTMENT_ID.equals(enchantmentsKey)) {
event.setCanceled(true);
player.sendSystemMessage(Component.translatable("domesticationinnovation.touhou_little_maid.enchantment.undead_curse"));
return;
}
if (BLAZING_PROTECTION_ENCHANTMENT_ID.equals(enchantmentsKey)) {
event.setCanceled(true);
player.sendSystemMessage(Component.translatable("domesticationinnovation.touhou_little_maid.enchantment.blazing_protection"));
return;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.tags.TagKey;
import net.minecraft.util.Mth;
import net.minecraft.world.*;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.Brain;
Expand Down Expand Up @@ -877,8 +880,7 @@ public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Dir
@Override
protected void dropEquipment() {
ItemsUtil.dropEntityItems(this, new CombinedInvWrapper(armorInvWrapper, handsInvWrapper, maidInv, maidBauble));
ItemMaidBackpack.getInstance(getBackpackLevel()).ifPresent(backpack ->
Containers.dropItemStack(level, getX(), getY(), getZ(), backpack.getDefaultInstance()));
ItemMaidBackpack.getInstance(getBackpackLevel()).ifPresent(backpack -> spawnAtLocation(backpack.getDefaultInstance()));
spawnAtLocation(ItemFilm.maidToFilm(this), 0.2f);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.EventPriority;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.github.tartaricacid.touhoulittlemaid.inventory.handler.BaubleItemHandler;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.world.Containers;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
Expand All @@ -22,7 +21,7 @@ private ItemsUtil() {
*/
public static void dropEntityItems(Entity entity, IItemHandler itemHandler, int startIndex, int endIndex) {
for (int i = startIndex; i < endIndex; i++) {
Containers.dropItemStack(entity.level, entity.getX(), entity.getY(), entity.getZ(), itemHandler.getStackInSlot(i));
entity.spawnAtLocation(itemHandler.getStackInSlot(i));
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/touhou_little_maid/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
"top.touhou_little_maid.entity_maid.task": "Mode: ",
"top.touhou_little_maid.entity_maid.invulnerable": "Invulnerable",
"top.touhou_little_maid.entity_maid.schedule": "Schedule: ",
"domesticationinnovation.touhou_little_maid.enchantment.undead_curse": "§4Undead Curse enchantment cannot be applied to maids!",
"domesticationinnovation.touhou_little_maid.enchantment.blazing_protection": "§4Blazing Protection enchantment cannot be applied to maids!",
"config.jade.plugin_touhou_little_maid.maid": "Show Maid's Extra Info",
"patchouli.touhou_little_maid.book.name": "Memorizable Gensokyo",
"patchouli.touhou_little_maid.book.landing_text": "A mod about the maid and the touhou project.$(br2)Thanks to Snownee for help in coding. $(br)Thanks to Succinum, Pajinyi, ZeniCrow, Tian_mi, Paulzzh, Yuriscat and other artists for producing excellent models and textures.$(br)Thanks to Verclene, the author of little maid mob mod.",
Expand Down

0 comments on commit 5a3fd1c

Please sign in to comment.