11package com .adccadc .rust .mixin .entity .iromGolem ;
22
33import com .adccadc .rust .Rust ;
4- import com .adccadc .rust .RustTick ;
4+ import com .adccadc .rust .RustConfig ;
5+ import com .adccadc .rust .effect .ModEffects ;
56import com .adccadc .rust .item .Moditems ;
67import com .adccadc .rust .manager .RustManager ;
78import com .adccadc .rust .proxy .IronGolemEntityProxy ;
8- import net .fabricmc .api .EnvType ;
9- import net .fabricmc .api .Environment ;
10- import net .fabricmc .fabric .api .event .player .UseEntityCallback ;
11- import net .minecraft .block .Blocks ;
9+ import net .minecraft .entity .Entity ;
1210import net .minecraft .entity .EntityType ;
1311import net .minecraft .entity .ItemEntity ;
12+ import net .minecraft .entity .LivingEntity ;
13+ import net .minecraft .entity .attribute .EntityAttributes ;
14+ import net .minecraft .entity .damage .DamageSource ;
15+ import net .minecraft .entity .effect .StatusEffectInstance ;
1416import net .minecraft .entity .passive .GolemEntity ;
1517import net .minecraft .entity .passive .IronGolemEntity ;
1618import net .minecraft .entity .player .PlayerEntity ;
1719import net .minecraft .item .*;
1820import net .minecraft .particle .ParticleTypes ;
1921import net .minecraft .registry .tag .ItemTags ;
20- import net .minecraft .registry .tag .TagKey ;
2122import net .minecraft .server .world .ServerWorld ;
2223import net .minecraft .sound .SoundEvents ;
2324import net .minecraft .storage .ReadView ;
2728import net .minecraft .util .Hand ;
2829import net .minecraft .world .World ;
2930import org .spongepowered .asm .mixin .Mixin ;
30- import org .spongepowered .asm .mixin .Overwrite ;
3131import org .spongepowered .asm .mixin .Unique ;
3232import org .spongepowered .asm .mixin .injection .At ;
3333import org .spongepowered .asm .mixin .injection .Inject ;
@@ -39,7 +39,7 @@ public abstract class IronGolemEntityMixin extends GolemEntity implements IronGo
3939{
4040 // 锈蚀控制器
4141 @ Unique
42- public RustManager rust = new RustManager (new ItemStack (Moditems .IRON_RUST , 2 ), 3 );
42+ public RustManager rust = new RustManager (new ItemStack (Moditems .IRON_RUST , 4 ), 3 );
4343
4444 public IronGolemEntityMixin (EntityType <? extends IronGolemEntity > entityType , World world ) {
4545 super (entityType , world );
@@ -55,6 +55,27 @@ public RustManager getRust(){
5555 return this .rust ;
5656 }
5757
58+ @ Unique
59+ protected Float AttackDamage () {
60+ float damage = (float ) this .getAttributeValue (EntityAttributes .ATTACK_DAMAGE );
61+ if (!this .rust .getState ().isWaxed ) {
62+ switch (this .rust .getState ().level ) {
63+ case 0 -> damage = (float ) this .getAttributeValue (EntityAttributes .ATTACK_DAMAGE );
64+ case 1 -> damage = (float ) (this .getAttributeValue (EntityAttributes .ATTACK_DAMAGE ) - (15.0F - (float ) RustConfig .getExposed_IG ().get (1 )));
65+ case 2 -> damage = (float ) (this .getAttributeValue (EntityAttributes .ATTACK_DAMAGE ) - (15.0F - (float ) RustConfig .getWeathered_IG ().get (1 )));
66+ case 3 -> damage = (float ) (this .getAttributeValue (EntityAttributes .ATTACK_DAMAGE ) - (15.0F - (float ) RustConfig .getOxidized_IG ().get (1 )));
67+ }
68+ } else {
69+ switch (this .rust .getState ().level ) {
70+ case 0 -> damage = (float ) (this .getAttributeValue (EntityAttributes .ATTACK_DAMAGE ) - (15.0F - (float ) RustConfig .getWaxed_IG ().get (1 )));
71+ case 1 -> damage = (float ) (this .getAttributeValue (EntityAttributes .ATTACK_DAMAGE ) - (15.0F - (float ) RustConfig .getWaxed_exposed_IG ().get (1 )));
72+ case 2 -> damage = (float ) (this .getAttributeValue (EntityAttributes .ATTACK_DAMAGE ) - (15.0F - (float ) RustConfig .getWaxed_weathered_IG ().get (1 )));
73+ case 3 -> damage = (float ) (this .getAttributeValue (EntityAttributes .ATTACK_DAMAGE ) - (15.0F - (float ) RustConfig .getWaxed_oxidized_IG ().get (1 )));
74+ }
75+ }
76+ return damage ;
77+ }
78+
5879 @ Inject (method = "writeCustomData" ,
5980 /*at = @At(value = "INVOKE",
6081 target = "Lnet/minecraft/iromGolem/mob/Angerable;writeAngerToData(Lnet/minecraft/world/World;Lnet/minecraft/storage/WriteView;)V",
@@ -86,7 +107,7 @@ private void readCustomDataWithRust(ReadView view, CallbackInfo info){
86107 )
87108 protected void interactMobWithRustActions (PlayerEntity player , Hand hand , CallbackInfoReturnable <ActionResult > cir ){
88109 ItemStack itemStack = player .getStackInHand (hand );
89- // 是否为水桶
110+ /*
90111 if (itemStack.isOf(Items.WATER_BUCKET)){
91112 // 处理物品
92113 if(!player.isCreative()){
@@ -101,8 +122,11 @@ protected void interactMobWithRustActions(PlayerEntity player, Hand hand, Callba
101122 }else{
102123 cir.setReturnValue(ActionResult.SUCCESS);
103124 }
125+
126+ }
127+ */
104128 // 物品是否含有斧头标签
105- } else if (itemStack .isIn (ItemTags .AXES )){
129+ if (itemStack .isIn (ItemTags .AXES )){
106130 // 执行一次除锈
107131 ItemStack dropStack ;
108132 if (((dropStack = this .rust .tryDerusted ()) == null )){
@@ -128,12 +152,12 @@ protected void interactMobWithRustActions(PlayerEntity player, Hand hand, Callba
128152 0.1F
129153 );
130154 // 处理物品
131- itemStack .damage (1 , player );
155+ itemStack .damage (4 , player );
132156 cir .setReturnValue (ActionResult .SUCCESS );
133157 }
134158 }
135159 // 物品是否为蜜脾
136- } else if (itemStack .isOf (Items .HONEYCOMB ) && itemStack .getCount () >= 2 ) {
160+ } else if (itemStack .isOf (Items .HONEYCOMB ) && itemStack .getCount () >= 4 ) {
137161 // 尝试上蜡
138162 if (!this .rust .tryWaxed ()){
139163 // 上蜡失败
@@ -156,30 +180,77 @@ protected void interactMobWithRustActions(PlayerEntity player, Hand hand, Callba
156180 0.1F
157181 );
158182 // 处理物品
159- itemStack .decrementUnlessCreative (2 , player );
183+ itemStack .decrementUnlessCreative (4 , player );
160184 cir .setReturnValue (ActionResult .SUCCESS );
161185 }
162186 }
163187 }
164188 }
165189
190+ @ Inject (
191+ method = "getAttackDamage" ,
192+ at = @ At ("HEAD" ),
193+ cancellable = true
194+ )
195+ private void getAttackDamage (CallbackInfoReturnable <Float > cir ) {
196+ cir .setReturnValue (AttackDamage ());
197+ cir .cancel ();
198+ }
199+
200+ @ Inject (
201+ method = "tryAttack" ,
202+ at = @ At ("RETURN" )
203+ )
204+ public void tryAttack (ServerWorld world , Entity target , CallbackInfoReturnable <Boolean > cir ) {
205+ float f1 = AttackDamage ();
206+ float g1 = (int )f1 > 0 ? f1 / 2.0F + (float )this .random .nextInt ((int )f1 ) : f1 ;
207+ DamageSource damageSource = this .getDamageSources ().mobAttack (this );
208+ boolean bl1 = target .damage (world , damageSource , g1 );
209+ if (bl1 && target instanceof LivingEntity livingEntity ) {
210+ StatusEffectInstance tetanusEffect = livingEntity .getStatusEffect (ModEffects .TETANUS );
211+ if (tetanusEffect == null ) {
212+ // 给与破伤风1级 10s
213+ livingEntity .addStatusEffect (new StatusEffectInstance (
214+ ModEffects .TETANUS ,
215+ 200 ,
216+ 0
217+ ));
218+ }
219+ }
220+ }
221+
166222 @ Override
167223 // 在名称前添加锈蚀状态
168224 protected Text getDefaultName (){
169225 return Text .of (this .rust .getName () + this .getType ().getName ().getString ());
170226 }
171- /*
227+
228+ @ Override
229+ public float getMovementSpeed () {
230+ float movementspeed = super .getMovementSpeed ();
231+ if (!this .rust .getState ().isWaxed ) {
232+ switch (this .rust .getState ().level ) {
233+ case 0 -> movementspeed = (float ) this .getAttributeValue (EntityAttributes .MOVEMENT_SPEED );
234+ case 1 -> movementspeed = (float ) (this .getAttributeValue (EntityAttributes .MOVEMENT_SPEED ) - (0.25F - (float ) RustConfig .getExposed_IG ().getFirst ()));
235+ case 2 -> movementspeed = (float ) (this .getAttributeValue (EntityAttributes .MOVEMENT_SPEED ) - (0.25F - (float ) RustConfig .getWeathered_IG ().getFirst ()));
236+ case 3 -> movementspeed = (float ) (this .getAttributeValue (EntityAttributes .MOVEMENT_SPEED ) - (0.25F - (float ) RustConfig .getOxidized_IG ().getFirst ()));
237+ }
238+ } else {
239+ switch (this .rust .getState ().level ) {
240+ case 0 -> movementspeed = (float ) (this .getAttributeValue (EntityAttributes .MOVEMENT_SPEED ) - (0.25F - (float ) RustConfig .getWaxed_IG ().getFirst ()));
241+ case 1 -> movementspeed = (float ) (this .getAttributeValue (EntityAttributes .MOVEMENT_SPEED ) - (0.25F - (float ) RustConfig .getWaxed_exposed_IG ().getFirst ()));
242+ case 2 -> movementspeed = (float ) (this .getAttributeValue (EntityAttributes .MOVEMENT_SPEED ) - (0.25F - (float ) RustConfig .getWaxed_weathered_IG ().getFirst ()));
243+ case 3 -> movementspeed = (float ) (this .getAttributeValue (EntityAttributes .MOVEMENT_SPEED ) - (0.25F - (float ) RustConfig .getWaxed_oxidized_IG ().getFirst ()));
244+ }
245+ }
246+ return movementspeed ;
247+ }
248+
172249 @ Override
173250 public void tick () {
174251 super .tick ();
175252 if (!this .getWorld ().isClient && this .age % 5 == 0 ) {
176253 this .updateGoalControls ();
177254 }
178- if (!this.getWorld().isClient()) {
179- if (random.nextDouble() < 1 && RustTick.tick((ServerWorld) this.getWorld())) {
180- this.rust.tryRusted();
181- }
182- }
183255 }
184- */
185256}
0 commit comments