Skip to content

Commit 1ea1e76

Browse files
committed
Change invulnerable logic
1 parent 8436108 commit 1ea1e76

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

common/src/main/java/cn/zbx1425/minopp/entity/EntityAutoPlayer.java

+14-24
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ public void tick() {
8181
}
8282

8383
// Rate limiting
84-
if (!entityData.get(ACTIVE)) {
85-
if (noPush) heal(10);
84+
if (!getActive()) {
85+
tablePos = null;
86+
heal(10);
8687
return;
8788
}
8889
if (autoPlayer.aiNoDelay < 2 && level().getGameTime() - lastTickGameTime < 10) {
@@ -120,11 +121,7 @@ public void tick() {
120121
if (tableFound) break;
121122
}
122123
if (!tableFound) {
123-
if (!noPush) {
124-
kill();
125-
} else {
126-
entityData.set(ACTIVE, false);
127-
}
124+
setActive(false);
128125
return;
129126
}
130127
}
@@ -134,7 +131,6 @@ public void tick() {
134131
BlockEntity blockEntity = level().getBlockEntity(tablePos);
135132
if (blockEntity instanceof BlockEntityMinoTable tableEntity) {
136133
if (tableEntity.game != null) {
137-
setInvulnerable(true);
138134
heal(10);
139135
if (tableEntity.game.players.get(tableEntity.game.currentPlayerIndex).equals(cardPlayer)) {
140136
if (autoPlayer.aiNoDelay > 0) {
@@ -164,7 +160,6 @@ public void tick() {
164160
isThinking = false;
165161
}
166162
} else {
167-
setInvulnerable(false);
168163
if (gameEndTime == -1L) {
169164
gameEndTime = level().getGameTime() + 100;
170165
} else if (level().getGameTime() - gameEndTime <= 20 * 3) {
@@ -189,21 +184,6 @@ public void tick() {
189184
}
190185
}
191186

192-
@Override
193-
public boolean hurt(DamageSource source, float amount) {
194-
if (source.getEntity() instanceof Player) {
195-
if (!entityData.get(ACTIVE)) {
196-
entityData.set(ACTIVE, true);
197-
} else {
198-
if (((Player)source.getEntity()).getMainHandItem().is(net.minecraft.world.item.Items.STICK)) {
199-
entityData.set(ACTIVE, false);
200-
tablePos = null;
201-
}
202-
}
203-
}
204-
return super.hurt(source, amount);
205-
}
206-
207187
@Override
208188
public @NotNull InteractionResult interact(Player player, InteractionHand hand) {
209189
if (level().isClientSide) {
@@ -248,6 +228,16 @@ public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
248228
return HumanoidArm.RIGHT;
249229
}
250230

231+
@Override
232+
public boolean isInvulnerable() {
233+
return true;
234+
}
235+
236+
@Override
237+
public boolean isInvulnerableTo(DamageSource source) {
238+
return true;
239+
}
240+
251241
@Override
252242
public void addAdditionalSaveData(CompoundTag compound) {
253243
super.addAdditionalSaveData(compound);

0 commit comments

Comments
 (0)