Skip to content

Commit f7871de

Browse files
committed
add rusting logic
1 parent 37ff20d commit f7871de

3 files changed

Lines changed: 34 additions & 23 deletions

File tree

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

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public void onInitialize() {
122122

123123
// 氧化过程
124124
ServerTickEvents.END_WORLD_TICK.register(world -> {
125+
RustTick.Judge_Rusty(world);
125126
if(RustConfig.useLegacyOxidizeLogic()) {
126127
if (world.getTime() % 6000 == 0) { // 5min一次
127128
if (world instanceof ServerWorld serverWorld) {
@@ -151,7 +152,8 @@ public void onInitialize() {
151152
}
152153
} else {
153154
// 新版氧化过程
154-
if (RustTick.tick(world)) {
155+
if (RustTick.CanRusty("item")) {
156+
RustTick.Item_Can_Rusty = false;
155157
// 新版物品氧化机制
156158
for (PlayerEntity player : world.getPlayers()) {
157159
ItemReplace.OxidizationItemWithAttribute(player, 3);
@@ -220,26 +222,5 @@ public void onInitialize() {
220222
}
221223
return ActionResult.PASS;
222224
});
223-
/*
224-
UseEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
225-
Rust.LOGGER.info(world.toString());
226-
if (world.isClient) return ActionResult.PASS;
227-
if (entity.getType() == EntityType.IRON_GOLEM) {
228-
if (player.getStackInHand(hand).getItem() == Items.GUNPOWDER) {
229-
//Rust.LOGGER.info("1");
230-
return ActionResult.SUCCESS;
231-
}
232-
}
233-
234-
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
235-
String caller = "";
236-
for (int i = 1; i < Math.min(5, stackTrace.length); i++) {
237-
caller += stackTrace[i].getMethodName() + " <-";
238-
}
239-
Rust.LOGGER.info("调用链:{}",caller);
240-
241-
return ActionResult.PASS;
242-
});
243-
*/
244225
}
245226
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ public class RustTick {
1010
private static long lastTrueTime = System.nanoTime();
1111
private static double nextInterval = generateNextInterval();
1212

13+
public static boolean Item_Can_Rusty = false;
14+
public static boolean Server_Entity_Can_Rusty = false;
15+
public static boolean Client_Entity_Can_Rusty = false;
16+
1317
// 生成下一个间隔时间(秒)
1418
private static double generateNextInterval() {
1519
if (random.nextDouble() < 0.0138) {
@@ -38,4 +42,22 @@ public static boolean tick(ServerWorld serverWorld) {
3842
}
3943
return false;
4044
}
45+
46+
public static void Judge_Rusty(ServerWorld serverWorld) {
47+
if (tick(serverWorld)) {
48+
// item
49+
if (random.nextDouble() < 0.5) {Item_Can_Rusty = true;}
50+
// entity
51+
if (random.nextDouble() < 0.6) {Server_Entity_Can_Rusty = true; Client_Entity_Can_Rusty = true;}
52+
}
53+
}
54+
55+
public static boolean CanRusty(String type) {
56+
switch (type) {
57+
case "item" -> {;return Item_Can_Rusty;}
58+
case "server_entity" -> {return Server_Entity_Can_Rusty;}
59+
case "client_entity" -> {return Client_Entity_Can_Rusty;}
60+
default -> throw new RuntimeException("RustTick.CanRusty Type Error");
61+
}
62+
}
4163
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import com.adccadc.rust.Rust;
44
import com.adccadc.rust.RustConfig;
5+
import com.adccadc.rust.RustTick;
56
import com.adccadc.rust.effect.ModEffects;
67
import com.adccadc.rust.item.Moditems;
78
import com.adccadc.rust.manager.RustManager;
89
import com.adccadc.rust.proxy.IronGolemEntityProxy;
10+
import net.minecraft.client.world.ClientWorld;
911
import net.minecraft.entity.Entity;
1012
import net.minecraft.entity.EntityType;
1113
import net.minecraft.entity.ItemEntity;
@@ -138,7 +140,7 @@ protected void interactMobWithRustActions(PlayerEntity player, Hand hand, Callba
138140
// 生成掉落物
139141
ItemEntity drop = this.dropStack(serverWorld, dropStack, 1.5F);
140142
// 播放音效
141-
this.playSound(SoundEvents.ITEM_AXE_WAX_OFF, 1.0F, 1.0F);
143+
this.playSound(SoundEvents.ITEM_AXE_SCRAPE, 1.0F, 1.0F);
142144
// 播放粒子
143145
serverWorld.spawnParticles(
144146
ParticleTypes.WAX_OFF,
@@ -252,5 +254,11 @@ public void tick() {
252254
if (!this.getWorld().isClient && this.age % 5 == 0) {
253255
this.updateGoalControls();
254256
}
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();}
262+
}
255263
}
256264
}

0 commit comments

Comments
 (0)