Skip to content

Commit 6411276

Browse files
authored
Merge pull request #2 from CampioneBase/master
铁傀儡的自动生锈,修改了部分数据类型
2 parents f7871de + 1f2fa13 commit 6411276

3 files changed

Lines changed: 48 additions & 51 deletions

File tree

src/main/java/com/adccadc/rust/RustConfig.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ public class RustConfig {
4747

4848
private static boolean affectEntity = true; // 是否影响实体
4949
// 各种铁傀儡的生物属性
50-
private static final List<?> default_IG = new ArrayList<>(Arrays.asList((double) 0.25F, (double) 15.0F)); //原版铁傀儡属性(移动速度,攻击伤害)
51-
private static List<?> exposed_IG = new ArrayList<>(Arrays.asList((double) 0.22F, (double) 14.0F));
52-
private static List<?> weathered_IG = new ArrayList<>(Arrays.asList((double) 0.19F, (double) 13.0F));
53-
private static List<?> oxidized_IG = new ArrayList<>(Arrays.asList((double) 0.16F, (double) 12.0F));
54-
private static List<?> waxed_IG = new ArrayList<>(Arrays.asList((double) 0.23F, (double) 14.5F));
55-
private static List<?> waxed_exposed_IG = new ArrayList<>(Arrays.asList((double) 0.20F, (double) 13.5F));
56-
private static List<?> waxed_weathered_IG = new ArrayList<>(Arrays.asList((double) 0.17F, (double) 12.5F));
57-
private static List<?> waxed_oxidized_IG = new ArrayList<>(Arrays.asList((double) 0.14F, (double) 11.5F));
50+
private static final List<Float> default_IG = new ArrayList<Float>(Arrays.asList(0.25F, 15.0F)); //原版铁傀儡属性(移动速度,攻击伤害)
51+
private static List<Float> exposed_IG = new ArrayList<Float>(Arrays.asList(0.22F, 14.0F));
52+
private static List<Float> weathered_IG = new ArrayList<Float>(Arrays.asList(0.19F, 13.0F));
53+
private static List<Float> oxidized_IG = new ArrayList<Float>(Arrays.asList(0.16F, 12.0F));
54+
private static List<Float> waxed_IG = new ArrayList<Float>(Arrays.asList(0.23F, 14.5F));
55+
private static List<Float> waxed_exposed_IG = new ArrayList<Float>(Arrays.asList(0.20F, 13.5F));
56+
private static List<Float> waxed_weathered_IG = new ArrayList<Float>(Arrays.asList(0.17F, 12.5F));
57+
private static List<Float> waxed_oxidized_IG = new ArrayList<Float>(Arrays.asList(0.14F, 11.5F));
5858

5959
private RustConfig() {}
6060

@@ -75,7 +75,7 @@ protected static List<Float> convertWithRegex(String input) {
7575
return result;
7676
}
7777

78-
protected static String formatWithF(List<?> list) {
78+
protected static String formatWithF(List<Float> list) {
7979
return list.stream()
8080
.map(obj -> {
8181
if (obj instanceof Number) {
@@ -195,11 +195,11 @@ private static void createDefaultConfig(File configFile) {
195195
public static Integer getWaxed_weathered_WPPB() {return affectRedstone ? waxed_weathered_WPPB : 150;}
196196
public static Integer getWaxed_oxidized_WPPB() {return affectRedstone ? waxed_oxidized_WPPB : 150;}
197197

198-
public static List<?> getExposed_IG() {return affectEntity ? exposed_IG : default_IG;}
199-
public static List<?> getWeathered_IG() {return affectEntity ? weathered_IG : default_IG;}
200-
public static List<?> getOxidized_IG() {return affectEntity ? oxidized_IG : default_IG;}
201-
public static List<?> getWaxed_IG() {return affectEntity ? waxed_IG : default_IG;}
202-
public static List<?> getWaxed_exposed_IG() {return affectEntity ? waxed_exposed_IG : default_IG;}
203-
public static List<?> getWaxed_weathered_IG() {return affectEntity ? waxed_weathered_IG : default_IG;}
204-
public static List<?> getWaxed_oxidized_IG() {return affectEntity ? waxed_oxidized_IG : default_IG;}
198+
public static List<Float> getExposed_IG() {return affectEntity ? exposed_IG : default_IG;}
199+
public static List<Float> getWeathered_IG() {return affectEntity ? weathered_IG : default_IG;}
200+
public static List<Float> getOxidized_IG() {return affectEntity ? oxidized_IG : default_IG;}
201+
public static List<Float> getWaxed_IG() {return affectEntity ? waxed_IG : default_IG;}
202+
public static List<Float> getWaxed_exposed_IG() {return affectEntity ? waxed_exposed_IG : default_IG;}
203+
public static List<Float> getWaxed_weathered_IG() {return affectEntity ? waxed_weathered_IG : default_IG;}
204+
public static List<Float> getWaxed_oxidized_IG() {return affectEntity ? waxed_oxidized_IG : default_IG;}
205205
}

src/main/java/com/adccadc/rust/manager/RustManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public boolean tryWaxed(){
7373
return true;
7474
}
7575

76+
public boolean canRusted(){
77+
return !this.state.isWaxed && this.state.level < this.maxLevel;
78+
}
79+
7680
public RustState getState(){
7781
return state;
7882
}

src/main/java/com/adccadc/rust/mixin/entity/iromGolem/IronGolemEntityMixin.java

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@ public abstract class IronGolemEntityMixin extends GolemEntity implements IronGo
4343
@Unique
4444
public RustManager rust = new RustManager(new ItemStack(Moditems.IRON_RUST, 4), 3);
4545

46+
@Unique
47+
public int rustLayTime = 9000;
48+
4649
public IronGolemEntityMixin(EntityType<? extends IronGolemEntity> entityType, World world) {
4750
super(entityType, world);
4851
}
4952

50-
@Unique
51-
public IronGolemEntityProxy proxy(){
52-
return this;
53-
}
54-
5553
@Unique
5654
public RustManager getRust(){
5755
return this.rust;
@@ -109,7 +107,7 @@ private void readCustomDataWithRust(ReadView view, CallbackInfo info){
109107
)
110108
protected void interactMobWithRustActions(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir){
111109
ItemStack itemStack = player.getStackInHand(hand);
112-
/*
110+
113111
if (itemStack.isOf(Items.WATER_BUCKET)){
114112
// 处理物品
115113
if(!player.isCreative()){
@@ -126,7 +124,7 @@ protected void interactMobWithRustActions(PlayerEntity player, Hand hand, Callba
126124
}
127125

128126
}
129-
*/
127+
130128
// 物品是否含有斧头标签
131129
if (itemStack.isIn(ItemTags.AXES)){
132130
// 执行一次除锈
@@ -206,6 +204,7 @@ private void getAttackDamage(CallbackInfoReturnable<Float> cir) {
206204
public void tryAttack(ServerWorld world, Entity target, CallbackInfoReturnable<Boolean> cir) {
207205
float f1 = AttackDamage();
208206
float g1 = (int)f1 > 0 ? f1 / 2.0F + (float)this.random.nextInt((int)f1) : f1;
207+
Rust.LOGGER.info("铁傀儡伤害:{}", g1);
209208
DamageSource damageSource = this.getDamageSources().mobAttack(this);
210209
boolean bl1 = target.damage(world, damageSource, g1);
211210
if (bl1 && target instanceof LivingEntity livingEntity) {
@@ -229,36 +228,30 @@ protected Text getDefaultName(){
229228

230229
@Override
231230
public float getMovementSpeed() {
232-
float movementspeed = super.getMovementSpeed();
233-
if (!this.rust.getState().isWaxed) {
234-
switch (this.rust.getState().level) {
235-
case 0 -> movementspeed = (float) this.getAttributeValue(EntityAttributes.MOVEMENT_SPEED);
236-
case 1 -> movementspeed = (float) (this.getAttributeValue(EntityAttributes.MOVEMENT_SPEED) - (0.25F - (float) RustConfig.getExposed_IG().getFirst()));
237-
case 2 -> movementspeed = (float) (this.getAttributeValue(EntityAttributes.MOVEMENT_SPEED) - (0.25F - (float) RustConfig.getWeathered_IG().getFirst()));
238-
case 3 -> movementspeed = (float) (this.getAttributeValue(EntityAttributes.MOVEMENT_SPEED) - (0.25F - (float) RustConfig.getOxidized_IG().getFirst()));
239-
}
240-
} else {
241-
switch (this.rust.getState().level) {
242-
case 0 -> movementspeed = (float) (this.getAttributeValue(EntityAttributes.MOVEMENT_SPEED) - (0.25F - (float) RustConfig.getWaxed_IG().getFirst()));
243-
case 1 -> movementspeed = (float) (this.getAttributeValue(EntityAttributes.MOVEMENT_SPEED) - (0.25F - (float) RustConfig.getWaxed_exposed_IG().getFirst()));
244-
case 2 -> movementspeed = (float) (this.getAttributeValue(EntityAttributes.MOVEMENT_SPEED) - (0.25F - (float) RustConfig.getWaxed_weathered_IG().getFirst()));
245-
case 3 -> movementspeed = (float) (this.getAttributeValue(EntityAttributes.MOVEMENT_SPEED) - (0.25F - (float) RustConfig.getWaxed_oxidized_IG().getFirst()));
246-
}
247-
}
248-
return movementspeed;
231+
float[] speed = {
232+
(float) this.getAttributeValue(EntityAttributes.MOVEMENT_SPEED),
233+
RustConfig.getExposed_IG().getFirst(),
234+
RustConfig.getWeathered_IG().getFirst(),
235+
RustConfig.getOxidized_IG().getFirst()
236+
};
237+
float[] waxed_speed = {
238+
RustConfig.getWaxed_IG().getFirst(),
239+
RustConfig.getWaxed_exposed_IG().getFirst(),
240+
RustConfig.getWaxed_weathered_IG().getFirst(),
241+
RustConfig.getWaxed_oxidized_IG().getFirst(),
242+
};
243+
return this.rust.getState().isWaxed ? waxed_speed[this.rust.getState().level] : speed[this.rust.getState().level];
249244
}
250245

251-
@Override
252-
public void tick() {
253-
super.tick();
254-
if (!this.getWorld().isClient && this.age % 5 == 0) {
255-
this.updateGoalControls();
256-
}
257-
if (this.getWorld().isClient) {
258-
if (RustTick.CanRusty("client_entity")) {RustTick.Client_Entity_Can_Rusty = false ;this.rust.tryRusted();}
259-
}
260-
if (!this.getWorld().isClient) {
261-
if (RustTick.CanRusty("server_entity")) {RustTick.Server_Entity_Can_Rusty = false ;this.rust.tryRusted();}
246+
@Inject(
247+
method = "tickMovement",
248+
at = @At("TAIL")
249+
)
250+
public void tickMovementWithRust(CallbackInfo ci){
251+
int multiply = this.isTouchingWater() ? 2 : 1;
252+
if(this.rust.canRusted() && (this.rustLayTime -= multiply) <= 0){
253+
this.rust.tryRusted();
254+
this.rustLayTime = 9000;
262255
}
263256
}
264257
}

0 commit comments

Comments
 (0)