Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
- Merge simple inject annotation into one line
- Prefix @unique with modid

Signed-off-by: Hendrix-Shen <[email protected]>
  • Loading branch information
Hendrix-Shen committed Aug 2, 2024
1 parent 92e6988 commit 09d6a82
Show file tree
Hide file tree
Showing 42 changed files with 114 additions and 203 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.plusls.MasaGadget.impl.feature.entityInfo;

import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
import com.plusls.MasaGadget.game.Configs;
import com.plusls.MasaGadget.util.MiscUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class VillagerNextRestockTimeInfo {
nextWorkTime = timeOfDay < 2000 ? 2000 - timeOfDay : 24000 - timeOfDay + 2000;
}

int numberOfRestocksToday = ((AccessorVillager) villager).getNumberOfRestocksToday();
long lastRestockGameTime = ((AccessorVillager) villager).getLastRestockGameTime();
int numberOfRestocksToday = ((AccessorVillager) villager).masa_gadget_mod$getNumberOfRestocksToday();
long lastRestockGameTime = ((AccessorVillager) villager).masa_gadget_mod$getLastRestockGameTime();

if (numberOfRestocksToday == 0) {
nextRestockTime = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ZombieVillagerConvertTimeInfo {
return ComponentUtil.tr("masa_gadget_mod.message.no_data").withStyle(ChatFormatting.YELLOW).get();
}

int villagerConversionTime = ((AccessorZombieVillager) zombieVillager).getVillagerConversionTime();
int villagerConversionTime = ((AccessorZombieVillager) zombieVillager).masa_gadget_mod$$getVillagerConversionTime();

if (villagerConversionTime > 0) {
return ComponentUtil.simple(String.format("%d", villagerConversionTime)).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

//#if MC > 11904
//$$ import net.minecraft.client.gui.GuiGraphics;
//$$ import net.minecraft.client.gui.screens.Screen;
//#endif

//#if MC > 11605
Expand Down Expand Up @@ -267,10 +268,10 @@ private void renderSlotHighlight(@NotNull RenderContext renderContext, int x, in
}

private void renderTooltip(RenderContext renderContext, @NotNull ItemStack itemStack, int x, int y) {
Minecraft mc = Minecraft.getInstance();
//#if MC > 11904
//$$ renderContext.getGuiComponent().renderTooltip(Minecraft.getInstance().font, itemStack, x, y);
//$$ renderContext.getGuiComponent().renderTooltip(mc.font, Screen.getTooltipFromItem(mc, itemStack), itemStack.getTooltipImage(), x, y);
//#else
Minecraft mc = Minecraft.getInstance();
List<Component> tooltipLines = itemStack.getTooltipLines(mc.player, mc.options.advancedItemTooltips ?
TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

@Mixin(AbstractMinecartContainer.class)
public interface AccessorAbstractMinecartContainer {
@Accessor
NonNullList<ItemStack> getItemStacks();
@Accessor("itemStacks")
NonNullList<ItemStack> masa_gadget_mod$getItemStacks();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

@Mixin(AbstractVillager.class)
public interface AccessorAbstractVillager {
@Accessor
void setOffers(MerchantOffers offers);
@Accessor("offers")
void masa_gadget_mod$setOffers(MerchantOffers offers);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

@Mixin(value = GuiListBase.class, remap = false)
public interface AccessorGuiListBase {
@Invoker
WidgetListBase<?, ?> invokeGetListWidget();
@Invoker("getListWidget")
WidgetListBase<?, ?> masa_gadget_mod$getListWidget();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

@Mixin(LivingEntity.class)
public interface AccessorLivingEntity {
@Accessor
void setBrain(Brain<?> brain);
@Accessor("brain")
void masa_gadget_mod$setBrain(Brain<?> brain);

@Invoker
Brain<?> invokeMakeBrain(Dynamic<?> dynamic);
@Invoker("makeBrain")
Brain<?> masa_gadget_mod$makeBrain(Dynamic<?> dynamic);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

@Mixin(Villager.class)
public interface AccessorVillager {
@Accessor
int getNumberOfRestocksToday();
@Accessor("numberOfRestocksToday")
int masa_gadget_mod$getNumberOfRestocksToday();

@Accessor
void setNumberOfRestocksToday(int numberOfRestocksToday);
@Accessor("numberOfRestocksToday")
void masa_gadget_mod$setNumberOfRestocksToday(int numberOfRestocksToday);

@Accessor
long getLastRestockGameTime();
@Accessor("lastRestockGameTime")
long masa_gadget_mod$getLastRestockGameTime();

@Accessor
void setLastRestockGameTime(long lastRestockGameTime);
@Accessor("lastRestockGameTime")
void masa_gadget_mod$setLastRestockGameTime(long lastRestockGameTime);

@Invoker
boolean invokeNeedsToRestock();
@Invoker("needsToRestock")
boolean masa_gadget_mod$needsToRestock();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

@Mixin(ZombieVillager.class)
public interface AccessorZombieVillager {
@Accessor
int getVillagerConversionTime();
@Accessor("villagerConversionTime")
int masa_gadget_mod$$getVillagerConversionTime();

@Invoker
void invokeStartConverting(@Nullable UUID uUID, int i);
@Invoker("startConverting")
void masa_gadget_mod$startConverting(@Nullable UUID uUID, int i);
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public abstract class MixinMinecraftClient {
//#else
method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V",
//#endif
at = @At(
value = "HEAD"
)
at = @At("HEAD")
)
private void onDisconnect(CallbackInfo ci) {
if (!Minecraft.getInstance().hasSingleplayerServer()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.world.entity.npc.Villager;
import net.minecraft.world.phys.AABB;
import org.spongepowered.asm.mixin.Mixin;
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.callback.CallbackInfo;
Expand All @@ -21,8 +22,8 @@

@Mixin(ClientPacketListener.class)
public class MixinClientPlayNetworkHandler {

private static final List<SoundEvent> WORK_SOUNDS = ImmutableList.of(
@Unique
private static final List<SoundEvent> masa_gadget_mod$WORK_SOUNDS = ImmutableList.of(
SoundEvents.VILLAGER_WORK_ARMORER,
SoundEvents.VILLAGER_WORK_BUTCHER,
SoundEvents.VILLAGER_WORK_CARTOGRAPHER,
Expand All @@ -38,21 +39,24 @@ public class MixinClientPlayNetworkHandler {
SoundEvents.VILLAGER_WORK_WEAPONSMITH
);

@Inject(method = "handleSoundEvent", at = @At(value = "RETURN"))
@Inject(method = "handleSoundEvent", at = @At("RETURN"))
private void syncVillagerData(ClientboundSoundPacket packet, CallbackInfo ci) {
if (!Configs.autoSyncEntityData.getBooleanValue() ||
Minecraft.getInstance().hasSingleplayerServer() ||
!PcaSyncProtocol.enable) {
return;
}
ClientLevel clientWorld = Minecraft.getInstance().level;
if (clientWorld == null || (!WORK_SOUNDS.contains(packet.getSound()))) {

ClientLevel clientLevel = Minecraft.getInstance().level;

if (clientLevel == null || (!MixinClientPlayNetworkHandler.masa_gadget_mod$WORK_SOUNDS.contains(packet.getSound()))) {
return;
}

// 工作后可能会发生补货,因此在播放工作声音后需要同步村民数据
clientWorld.getEntitiesOfClass(Villager.class,
clientLevel.getEntitiesOfClass(Villager.class,
new AABB(packet.getX() - 1, packet.getY() - 1, packet.getZ() - 1, packet.getX() + 1, packet.getY() + 1, packet.getZ() + 1),
villager -> ((AccessorVillager) villager).invokeNeedsToRestock()).forEach(
villager -> ((AccessorVillager) villager).masa_gadget_mod$needsToRestock()).forEach(
villagerEntity -> {
PcaSyncProtocol.syncEntity(villagerEntity.getId());
PcaSyncProtocol.cancelSyncEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import net.minecraft.world.entity.npc.Villager;
import net.minecraft.world.entity.npc.VillagerProfession;
import org.spongepowered.asm.mixin.Mixin;
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.callback.CallbackInfo;

@Mixin(Villager.class)
public abstract class MixinVillagerEntity {

private VillagerProfession oldVillagerProfession;
@Unique
private VillagerProfession masa_gadget_mod$oldVillagerProfession;

@SuppressWarnings("ConstantConditions")
@Inject(method = "tick", at = @At(value = "RETURN"))
Expand All @@ -23,27 +24,28 @@ private void syncVillagerData(CallbackInfo ci) {
!PcaSyncProtocol.enable) {
return;
}

VillagerProfession currentVillagerProfession = ((Villager) (Object) this).getVillagerData().getProfession();
if (oldVillagerProfession != currentVillagerProfession) {

if (this.masa_gadget_mod$oldVillagerProfession != currentVillagerProfession) {
PcaSyncProtocol.syncEntity(((Villager) (Object) this).getId());
PcaSyncProtocol.cancelSyncEntity();
oldVillagerProfession = currentVillagerProfession;
this.masa_gadget_mod$oldVillagerProfession = currentVillagerProfession;
}
}

@SuppressWarnings("ConstantConditions")
@Inject(method = "handleEntityEvent", at = @At(value = "RETURN"))
@Inject(method = "handleEntityEvent", at = @At("RETURN"))
private void syncVillagerData(byte status, CallbackInfo ci) {
if (!Configs.autoSyncEntityData.getBooleanValue() ||
Minecraft.getInstance().hasSingleplayerServer() ||
!PcaSyncProtocol.enable) {
return;
}

if (status == 14) {
PcaSyncProtocol.syncEntity(((Villager) (Object) this).getId());
PcaSyncProtocol.cancelSyncEntity();
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import top.hendrixshen.magiclib.api.compat.minecraft.world.entity.EntityCompat;

@Mixin(ZombieVillager.class)
public abstract class MixinZombieVillagerEntity extends Zombie {

public MixinZombieVillagerEntity(EntityType<? extends Zombie> entityType, Level level) {
super(entityType, level);
}
Expand All @@ -29,37 +29,34 @@ public MixinZombieVillagerEntity(EntityType<? extends Zombie> entityType, Level
@Shadow
private int villagerConversionTime;

@Inject(method = "handleEntityEvent", at = @At(value = "RETURN"))
@Inject(method = "handleEntityEvent", at = @At("RETURN"))
private void syncVillagerData(byte status, CallbackInfo ci) {
if (!Configs.autoSyncEntityData.getBooleanValue() ||
Minecraft.getInstance().hasSingleplayerServer() ||
!PcaSyncProtocol.enable) {
return;
}

if (status == 16) {
PcaSyncProtocol.syncEntity(this.getId());
PcaSyncProtocol.cancelSyncEntity();
}
}

@Inject(method = "tick", at = @At(value = "RETURN"))
@Inject(method = "tick", at = @At("RETURN"))
private void syncConvertingData(CallbackInfo ci) {
//#if MC > 11904
//$$ if (this.level().isClientSide() && this.isAlive() && this.isConverting()) {
//#elseif MC > 11701
//$$ if (this.getLevel().isClientSide() && this.isAlive() && this.isConverting()) {
//#else
if (this.level.isClientSide() && this.isAlive() && this.isConverting()) {
//#endif
if (EntityCompat.of(this).getLevelCompat().get().get().isClientSide() && this.isAlive() && this.isConverting()) {
int i = this.getConversionProgress();
this.villagerConversionTime -= i;

if (this.villagerConversionTime <= 0) {
// 如果这里为负,应该是没有同步数据
if (!Configs.autoSyncEntityData.getBooleanValue() ||
Minecraft.getInstance().hasSingleplayerServer() ||
!PcaSyncProtocol.enable) {
return;
}

PcaSyncProtocol.syncEntity(this.getId());
PcaSyncProtocol.cancelSyncEntity();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@

@Mixin(ClientPacketListener.class)
public class MixinClientPacketListener {
@Inject(
method = "handleOpenScreen",
at = @At(
value = "RETURN"
)
)
@Inject(method = "handleOpenScreen", at = @At("RETURN"))
private void postHandleOpenScreen(ClientboundOpenScreenPacket clientboundOpenScreenPacket, CallbackInfo ci) {
Minecraft minecraft = Minecraft.getInstance();

Expand All @@ -41,12 +36,7 @@ private void postHandleOpenScreen(ClientboundOpenScreenPacket clientboundOpenScr
}
}

@Inject(
method = "handleContainerSetSlot",
at = @At(
value = "RETURN"
)
)
@Inject(method = "handleContainerSetSlot", at = @At("RETURN"))
private void postHandleContainerSetSlot(ClientboundContainerSetSlotPacket clientboundContainerSetSlotPacket,
CallbackInfo ci) {
Minecraft minecraft = Minecraft.getInstance();
Expand Down Expand Up @@ -77,7 +67,7 @@ private void postHandleContainerSetSlot(ClientboundContainerSetSlotPacket client
}
}

@Inject(method = "handleContainerContent", at = @At(value = "RETURN"))
@Inject(method = "handleContainerContent", at = @At("RETURN"))
private void postHandleContainerContent(ClientboundContainerSetContentPacket clientboundContainerSetContentPacket, CallbackInfo ci) {
Minecraft minecraft = Minecraft.getInstance();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@

@Mixin(LocalPlayer.class)
public class MixinLocalPlayer {
@Inject(
method = "closeContainer",
at = @At(
value = "RETURN"
)
)
@Inject(method = "closeContainer", at = @At("RETURN"))
private void postCloseContainer(CallbackInfo ci) {
CacheContainerMenuHandler.getInstance().clearLastClickData();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@

@Mixin(MultiPlayerGameMode.class)
public class MixinMultiPlayerGameMode {
@Inject(
method = "useItemOn",
at = @At(
value = "HEAD"
)
)
@Inject(method = "useItemOn", at = @At("HEAD"))
private void prevUseItemOn(LocalPlayer localPlayer,
//#if MC < 11900
ClientLevel clientLevel,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.plusls.MasaGadget.mixin.mod_tweak.litematica.fixCarpetAccurateProtocol;

import com.plusls.MasaGadget.SharedConstants;
import com.plusls.MasaGadget.game.Configs;
import com.plusls.MasaGadget.util.BlockPlacer;
import com.plusls.MasaGadget.util.ModId;
Expand Down Expand Up @@ -41,7 +42,7 @@ private void preGetPlacementState(BlockPlaceContext context, CallbackInfoReturna
try {
blockState = BlockPlacer.alternativeBlockPlacement(this.getBlock(), context);
} catch (Exception e) {
e.printStackTrace();
SharedConstants.getLogger().throwing(e);
}

if (blockState != null && this.canPlace(context, blockState)) {
Expand Down
Loading

0 comments on commit 09d6a82

Please sign in to comment.