2018-09-12 01:29:49 +02:00
|
|
|
package com.minelittlepony.unicopia.power;
|
|
|
|
|
|
|
|
import org.lwjgl.input.Keyboard;
|
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.Race;
|
2019-02-17 00:08:19 +01:00
|
|
|
import com.minelittlepony.unicopia.init.UParticles;
|
2018-09-12 01:29:49 +02:00
|
|
|
import com.minelittlepony.unicopia.player.IPlayer;
|
|
|
|
import com.minelittlepony.unicopia.power.data.Location;
|
2019-02-07 12:32:55 +01:00
|
|
|
import com.minelittlepony.util.WorldEvent;
|
2018-09-12 01:29:49 +02:00
|
|
|
import com.minelittlepony.util.vector.VecHelper;
|
|
|
|
|
|
|
|
import net.minecraft.block.BlockDoublePlant;
|
|
|
|
import net.minecraft.block.BlockGrass;
|
|
|
|
import net.minecraft.block.IGrowable;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.init.Items;
|
|
|
|
import net.minecraft.item.ItemDye;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public class PowerGrow implements IPower<Location> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getKeyName() {
|
|
|
|
return "unicopia.power.grow";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getKeyCode() {
|
|
|
|
return Keyboard.KEY_N;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getWarmupTime(IPlayer player) {
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCooldownTime(IPlayer player) {
|
|
|
|
return 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canUse(Race playerSpecies) {
|
|
|
|
return playerSpecies == Race.EARTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-03 10:45:45 +01:00
|
|
|
public Location tryActivate(IPlayer player) {
|
|
|
|
RayTraceResult ray = VecHelper.getObjectMouseOver(player.getOwner(), 3, 1);
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
if (ray != null && ray.typeOfHit == RayTraceResult.Type.BLOCK) {
|
|
|
|
return new Location(ray.getBlockPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<Location> getPackageType() {
|
|
|
|
return Location.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-03 10:45:45 +01:00
|
|
|
public void apply(IPlayer player, Location data) {
|
2018-09-12 01:29:49 +02:00
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (BlockPos pos : BlockPos.getAllInBox(
|
|
|
|
new BlockPos(data.x - 2, data.y - 2, data.z - 2),
|
|
|
|
new BlockPos(data.x + 2, data.y + 2, data.z + 2))) {
|
2019-02-03 10:45:45 +01:00
|
|
|
count += applySingle(player.getWorld(), player.getWorld().getBlockState(pos), pos);
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 0) {
|
2019-02-03 10:45:45 +01:00
|
|
|
IPower.takeFromPlayer(player.getOwner(), count * 5);
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int applySingle(World w, IBlockState state, BlockPos pos) {
|
|
|
|
if (state.getBlock() instanceof IGrowable
|
|
|
|
&& !(state.getBlock() instanceof BlockGrass)) {
|
|
|
|
|
|
|
|
IGrowable g = ((IGrowable)state.getBlock());
|
|
|
|
|
|
|
|
if (g.canGrow(w, pos, state, w.isRemote) && g.canUseBonemeal(w, w.rand, pos, state)) {
|
2018-09-12 22:37:06 +02:00
|
|
|
if (ItemDye.applyBonemeal(new ItemStack(Items.DYE, 1), w, pos)) {
|
2019-02-07 12:38:42 +01:00
|
|
|
WorldEvent.BONEMEAL.play(w, pos);
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2018-09-12 22:37:06 +02:00
|
|
|
if (g instanceof BlockDoublePlant) {
|
2019-02-07 12:38:42 +01:00
|
|
|
WorldEvent.BONEMEAL.play(w, pos.up());
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
2018-09-12 22:37:06 +02:00
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-13 14:04:24 +02:00
|
|
|
public void preApply(IPlayer player) {
|
|
|
|
player.addExertion(3);
|
2019-01-27 19:22:47 +01:00
|
|
|
|
|
|
|
if (player.getWorld().isRemote) {
|
2019-02-07 12:32:55 +01:00
|
|
|
player.spawnParticles(UParticles.UNICORN_MAGIC, 1);
|
2019-01-27 19:22:47 +01:00
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-13 14:04:24 +02:00
|
|
|
public void postApply(IPlayer player) {
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|