Skip to content

Commit

Permalink
dirty tricks for the nose, tested
Browse files Browse the repository at this point in the history
  • Loading branch information
commandblock2 committed Jul 30, 2023
1 parent c9c6b66 commit 0786402
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 22 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Coffee Mod <img src="coffee-mod-hsds/src/main/resources/assets/coffee_mod/icon.png" width="64"> (WIP)
A fabric implementation of the coffee mod, idea by hsds. The link of the video https://www.bilibili.com/video/BV1JD4y1579K/.

# It is known that `Villager Shit Coffee` DOES NOT work properly right now in multiplayer

## Features
- [x] Can brew coffee with brewing stand with water bottle and cocoa bean.
- Consuming coffee gives a potion effect (Coffee Buzz) which
Expand Down
2 changes: 0 additions & 2 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# 咖啡模组 <img src="coffee-mod-hsds/src/main/resources/assets/coffee_mod/icon.png" width="64"> (开发中)
这是一个基于 Fabric 的咖啡模组,灵感来自 hsds。视频链接为 https://www.bilibili.com/video/BV1JD4y1579K/。

# 村民屎咖啡在目前版本的多人游戏中工作不大正常

## 特性
- [x] 可以在酿造台上用水瓶和可可豆酿制咖啡
- 喝咖啡会获得药水效果 "咖啡刺激",其中包括:
Expand Down
2 changes: 1 addition & 1 deletion coffee-mod-hsds/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ loom_version=1.2-SNAPSHOT
java_version=17
##########################################################################
# Mod Properties
mod_version=0.7.1
mod_version=0.7.3
maven_group=github.commandblock2
archives_base_name=coffee-mod
mod_id=coffee_mod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class MixinAbstractClientPlayerEntity {
void addNoseToSkin(CallbackInfoReturnable<Identifier> cir) {
final var originalSkin = cir.getReturnValue();

cir.setReturnValue(PlayerSkinTextureWithNose.INSTANCE.add(
cir.setReturnValue(PlayerSkinTextureWithNose.INSTANCE.get(
MinecraftClient.getInstance().getTextureManager(),
MinecraftClient.getInstance().getResourceManager(),
originalSkin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,13 @@
package github.commandblock2.coffee_mod.mixins.minecraft.entity;

import github.commandblock2.coffee_mod.entity.effect.CoffeeModEffects;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.TargetPredicate;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.mob.PhantomEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
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.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(LivingEntity.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* This file is part of CoffeeMod (https://github.com/commandblock2/coffee-mod-hsds)
*
* Copyright (c) 2023 commandblock2
*
* CoffeeMod is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CoffeeMod is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CoffeeMod. If not, see <https://www.gnu.org/licenses/>.
*/

package github.commandblock2.coffee_mod.mixins.minecraft.server;

import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.s2c.play.EntityStatusEffectS2CPacket;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
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(PlayerManager.class)
public class MixinPlayerManager {
@Inject(method = "onPlayerConnect", at = @At("TAIL"))
private void sendAllPlayerEffect(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci){
player
.getServerWorld()
.getPlayers()
.forEach(p ->
p.getStatusEffects().forEach(
effect ->
player
.networkHandler
.sendPacket(
new EntityStatusEffectS2CPacket(
p.getId(), effect
)
)
)
);

player
.getServerWorld()
.getPlayers()
.forEach(p ->
player.getStatusEffects().forEach(
effect ->
p
.networkHandler
.sendPacket(
new EntityStatusEffectS2CPacket(
player.getId(), effect
)
)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@

import github.commandblock2.coffee_mod.CoffeeMod;
import github.commandblock2.coffee_mod.entity.CoffeeModEntitySupport;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.network.packet.s2c.play.DeathMessageS2CPacket;
import net.minecraft.network.packet.s2c.play.EntityStatusEffectS2CPacket;
import net.minecraft.scoreboard.AbstractTeam;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -66,4 +69,39 @@ void sendDeathMessage(DamageSource damageSource, CallbackInfo ci) {
ci.cancel();
}
}


@Inject(method = "onStatusEffectApplied", at = @At("HEAD"))
void sendToAllPlayers(StatusEffectInstance effect, Entity source, CallbackInfo ci) {
final var this_ = (ServerPlayerEntity) (Object) this;
this_
.getServerWorld()
.getPlayers()
.forEach(player ->
player
.networkHandler
.sendPacket(
new EntityStatusEffectS2CPacket(
this_.getId(), effect
)
)
);
}

@Inject(method = "onStatusEffectUpgraded", at = @At("HEAD"))
void sendToAllPlayers(StatusEffectInstance effect, boolean reapplyEffect, Entity source, CallbackInfo ci) {
final var this_ = (ServerPlayerEntity) (Object) this;
this_
.getServerWorld()
.getPlayers()
.forEach(player ->
player
.networkHandler
.sendPacket(
new EntityStatusEffectS2CPacket(
this_.getId(), effect
)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import github.commandblock2.coffee_mod.CoffeeMod
import net.minecraft.client.render.entity.VillagerEntityRenderer
import net.minecraft.client.texture.AbstractTexture
import net.minecraft.client.texture.NativeImage
import net.minecraft.client.texture.NativeImageBackedTexture
import net.minecraft.client.texture.PlayerSkinTexture
import net.minecraft.client.texture.ResourceTexture
import net.minecraft.client.texture.SpriteAtlasTexture
import net.minecraft.client.texture.TextureManager
import net.minecraft.resource.ResourceManager
import net.minecraft.util.Identifier
Expand All @@ -38,7 +35,7 @@ object PlayerSkinTextureWithNose {
private val skinCache = HashMap<Identifier, Identifier>()
val nativeImageCache = HashMap<PlayerSkinTexture, NativeImage>()

fun add(
fun get(
textureManager: TextureManager,
resourceManager: ResourceManager,
playerSkinIdentifier: Identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ class CoffeeBuzzStatusEffect : StatusEffect(StatusEffectCategory.NEUTRAL, 0x6c4c

override fun onApplied(entity: LivingEntity?, attributes: AttributeContainer?, amplifier: Int) {
super.onApplied(entity, attributes, amplifier)
if (entity != null) {
CoffeeModEntitySupport.addToCoffeeDeathTracker(entity)
}
entity ?: return
val world = entity.entityWorld
if (world !is ServerWorld)
return

CoffeeModEntitySupport.addToCoffeeDeathTracker(entity)
if (entity is VillagerEntity && entity.world is ServerWorld) {
entity.reinitializeBrain(entity.world as ServerWorld)
}
Expand Down
1 change: 1 addition & 0 deletions coffee-mod-hsds/src/main/resources/coffee_mod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"minecraft.entity.MixinLivingEntity",
"minecraft.entity.passive.MixinVillagerEntity",
"minecraft.recipe.MixinBrewingRecipeRegistry",
"minecraft.server.MixinPlayerManager",
"minecraft.server.network.MixinServerPlayerEntity",
"minecraft.server.world.MixinSleepManager",
"minecraft.server.world.spawner.MixinPhantomSpawner"
Expand Down

0 comments on commit 0786402

Please sign in to comment.