-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/github/ptom76/tutorialfabricmod/enchantment/Enchantments.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.github.ptom76.tutorialfabricmod.enchantment; | ||
|
||
import com.github.ptom76.tutorialfabricmod.TutorialFabricMod; | ||
import net.minecraft.enchantment.Enchantment; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
|
||
public class Enchantments { | ||
public static Enchantment FREEZE = new FreezeEnchantment(); | ||
|
||
public static void init() { | ||
// エンチャント登録 | ||
Registry.register(Registries.ENCHANTMENT, TutorialFabricMod.id("freeze"), FREEZE); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/com/github/ptom76/tutorialfabricmod/enchantment/FreezeEnchantment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.github.ptom76.tutorialfabricmod.enchantment; | ||
|
||
import com.github.ptom76.tutorialfabricmod.timer.StuffTimerAccess; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.enchantment.Enchantment; | ||
import net.minecraft.enchantment.EnchantmentTarget; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EquipmentSlot; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.damage.DamageSource; | ||
import net.minecraft.entity.effect.StatusEffectInstance; | ||
import net.minecraft.entity.effect.StatusEffects; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
public class FreezeEnchantment extends Enchantment { | ||
public FreezeEnchantment() { | ||
super(Rarity.UNCOMMON, EnchantmentTarget.WEAPON, new EquipmentSlot[]{EquipmentSlot.MAINHAND}); | ||
} | ||
|
||
@Override | ||
public int getMaxPower(int level) { | ||
return super.getMinPower(level) + 50; | ||
} | ||
|
||
@Override | ||
public int getMinPower(int level) { | ||
return level * 10; | ||
} | ||
|
||
@Override | ||
public int getMaxLevel() { | ||
return 3; | ||
} | ||
|
||
@Override | ||
public void onTargetDamaged(LivingEntity user, Entity target, int level) { | ||
if (target instanceof LivingEntity) { | ||
LivingEntity entity = (LivingEntity) target; | ||
BlockPos pos = entity.getBlockPos(); | ||
World world = entity.getWorld(); | ||
// ブロックが空気のとき | ||
if (world.getBlockState(pos).isAir()) { | ||
// 音の再生 | ||
target.playSound(SoundEvents.BLOCK_GLASS_BREAK, 1f, 1f); | ||
|
||
// 薄氷の設置 | ||
world.setBlockState(pos, Blocks.ICE.getDefaultState()); | ||
} | ||
if (world.getBlockState(pos.up()).isAir()) { | ||
world.setBlockState(pos.up(), Blocks.ICE.getDefaultState()); | ||
} | ||
|
||
// 移動速度低下の追加 | ||
entity.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 500, 255, false, false, false)); | ||
|
||
StuffTimerAccess stuffTimerAccess = (StuffTimerAccess) world.getServer(); | ||
|
||
stuffTimerAccess.tutorialFabricMod_addTimer(5, () -> { | ||
// エンティティの場所を設定 | ||
entity.teleport(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5); | ||
return true; | ||
}); | ||
|
||
stuffTimerAccess.tutorialFabricMod_addTimer(45, () -> { | ||
// ブロックが薄氷のとき、 | ||
if (world.getBlockState(pos).getBlock() == Blocks.ICE) { | ||
|
||
// ブロック破壊 | ||
world.breakBlock(pos, false); | ||
|
||
// 攻撃 | ||
entity.damage(DamageSource.FREEZE, level * 2); | ||
} | ||
return true; | ||
}); | ||
stuffTimerAccess.tutorialFabricMod_addTimer(50, () -> { | ||
// pos.up()はY座標に+1 | ||
if (world.getBlockState(pos.up()).getBlock() == Blocks.ICE) { | ||
world.breakBlock(pos.up(), false); | ||
entity.damage(DamageSource.FREEZE, level * 3); | ||
} | ||
|
||
// 移動速度低下の除去 | ||
entity.removeStatusEffect(StatusEffects.SLOWNESS); | ||
|
||
return true; | ||
}); | ||
|
||
|
||
} | ||
super.onTargetDamaged(user, target, level); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/github/ptom76/tutorialfabricmod/mixin/StuffTimer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.github.ptom76.tutorialfabricmod.mixin; | ||
|
||
import com.github.ptom76.tutorialfabricmod.timer.StuffTimerAccess; | ||
import com.github.ptom76.tutorialfabricmod.timer.TickTimer; | ||
import net.minecraft.server.MinecraftServer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
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 java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
@Mixin(MinecraftServer.class) | ||
public class StuffTimer implements StuffTimerAccess { | ||
@Unique | ||
private final List<TickTimer> tickTimers = new ArrayList<>(); | ||
|
||
@Inject(method = "tick", at = @At("TAIL")) | ||
private void onTick(CallbackInfo ci) { | ||
if (tickTimers.isEmpty()) return; | ||
|
||
for (TickTimer tickTimer : tickTimers) { | ||
if (--tickTimer.ticksUntilSomething == 0) { | ||
tickTimer.supplier.get(); | ||
} | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void tutorialFabricMod_addTimer(long ticksUntilSomething, Supplier<Boolean> supplier) { | ||
tickTimers.add(new TickTimer(ticksUntilSomething, supplier)); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/github/ptom76/tutorialfabricmod/timer/StuffTimerAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.github.ptom76.tutorialfabricmod.timer; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public interface StuffTimerAccess { | ||
void tutorialFabricMod_addTimer(long ticksUntilSomething, Supplier<Boolean> supplier); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/github/ptom76/tutorialfabricmod/timer/TickTimer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.ptom76.tutorialfabricmod.timer; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class TickTimer { | ||
public long ticksUntilSomething; | ||
public Supplier<Boolean> supplier; | ||
|
||
public TickTimer(long ticksUntilSomething, Supplier<Boolean> supplier) { | ||
this.ticksUntilSomething = ticksUntilSomething; | ||
this.supplier = supplier; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters