mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 07:17:58 +01:00
You can now soak clouds using bottles of water
This commit is contained in:
parent
c89f7209e9
commit
c877016ac7
4 changed files with 48 additions and 10 deletions
|
@ -29,6 +29,7 @@ public class NaturalCloudBlock extends PoreousCloudBlock {
|
||||||
this.compactedBlock = compactedBlock;
|
this.compactedBlock = compactedBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||||
ItemStack stack = player.getStackInHand(hand);
|
ItemStack stack = player.getStackInHand(hand);
|
||||||
|
@ -41,6 +42,6 @@ public class NaturalCloudBlock extends PoreousCloudBlock {
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActionResult.PASS;
|
return super.onUse(state, world, pos, player, hand, hit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,14 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import com.minelittlepony.unicopia.block.state.StateUtil;
|
import com.minelittlepony.unicopia.block.state.StateUtil;
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.random.Random;
|
import net.minecraft.util.math.random.Random;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class PoreousCloudBlock extends CloudBlock implements Soakable {
|
public class PoreousCloudBlock extends CloudBlock implements Soakable {
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -20,6 +25,12 @@ public class PoreousCloudBlock extends CloudBlock implements Soakable {
|
||||||
this.soggyBlock = soggyBlock;
|
this.soggyBlock = soggyBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@Override
|
||||||
|
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||||
|
return Soakable.tryDepositMoisture(state, world, pos, player, hand, hit);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BlockState getStateWithMoisture(BlockState state, int moisture) {
|
public BlockState getStateWithMoisture(BlockState state, int moisture) {
|
||||||
|
|
|
@ -7,6 +7,12 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import com.minelittlepony.unicopia.block.state.StateUtil;
|
import com.minelittlepony.unicopia.block.state.StateUtil;
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class PoreousCloudStairsBlock extends CloudStairsBlock implements Soakable {
|
public class PoreousCloudStairsBlock extends CloudStairsBlock implements Soakable {
|
||||||
|
|
||||||
|
@ -17,6 +23,12 @@ public class PoreousCloudStairsBlock extends CloudStairsBlock implements Soakabl
|
||||||
this.soggyBlock = soggyBlock;
|
this.soggyBlock = soggyBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@Override
|
||||||
|
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||||
|
return Soakable.tryDepositMoisture(state, world, pos, player, hand, hit);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BlockState getStateWithMoisture(BlockState state, int moisture) {
|
public BlockState getStateWithMoisture(BlockState state, int moisture) {
|
||||||
|
|
|
@ -9,8 +9,11 @@ import com.minelittlepony.unicopia.USounds;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.ItemUsage;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.particle.ParticleTypes;
|
import net.minecraft.particle.ParticleTypes;
|
||||||
|
import net.minecraft.potion.PotionUtil;
|
||||||
|
import net.minecraft.potion.Potions;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.sound.SoundCategory;
|
import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
|
@ -50,15 +53,8 @@ public interface Soakable {
|
||||||
static ActionResult tryCollectMoisture(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
static ActionResult tryCollectMoisture(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||||
if (state.getBlock() instanceof Soakable soakable) {
|
if (state.getBlock() instanceof Soakable soakable) {
|
||||||
ItemStack stack = player.getStackInHand(hand);
|
ItemStack stack = player.getStackInHand(hand);
|
||||||
if (stack.getItem() == Items.GLASS_BOTTLE) {
|
if (stack.isOf(Items.GLASS_BOTTLE)) {
|
||||||
if (!player.isCreative()) {
|
player.setStackInHand(hand, ItemUsage.exchangeStack(stack, player, Items.POTION.getDefaultStack(), false));
|
||||||
stack.split(1);
|
|
||||||
}
|
|
||||||
if (stack.isEmpty()) {
|
|
||||||
player.setStackInHand(hand, Items.POTION.getDefaultStack());
|
|
||||||
} else {
|
|
||||||
player.giveItemStack(Items.POTION.getDefaultStack());
|
|
||||||
}
|
|
||||||
world.playSound(player, player.getX(), player.getY(), player.getZ(), USounds.Vanilla.ITEM_BOTTLE_FILL, SoundCategory.NEUTRAL, 1, 1);
|
world.playSound(player, player.getX(), player.getY(), player.getZ(), USounds.Vanilla.ITEM_BOTTLE_FILL, SoundCategory.NEUTRAL, 1, 1);
|
||||||
world.emitGameEvent(player, GameEvent.FLUID_PICKUP, pos);
|
world.emitGameEvent(player, GameEvent.FLUID_PICKUP, pos);
|
||||||
updateMoisture(soakable, state, world, pos, soakable.getMoisture(state) - 1);
|
updateMoisture(soakable, state, world, pos, soakable.getMoisture(state) - 1);
|
||||||
|
@ -67,6 +63,24 @@ public interface Soakable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return tryDepositMoisture(state, world, pos, player, hand, hit);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ActionResult tryDepositMoisture(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||||
|
if (state.getBlock() instanceof Soakable soakable) {
|
||||||
|
ItemStack stack = player.getStackInHand(hand);
|
||||||
|
if (soakable.getMoisture(state) < 7
|
||||||
|
&& stack.isOf(Items.POTION)
|
||||||
|
&& PotionUtil.getPotion(stack) == Potions.WATER) {
|
||||||
|
player.setStackInHand(hand, ItemUsage.exchangeStack(stack, player, Items.GLASS_BOTTLE.getDefaultStack(), false));
|
||||||
|
world.playSound(player, player.getX(), player.getY(), player.getZ(), USounds.Vanilla.ITEM_BUCKET_EMPTY, SoundCategory.NEUTRAL, 1, 1);
|
||||||
|
world.emitGameEvent(player, GameEvent.FLUID_PLACE, pos);
|
||||||
|
updateMoisture(soakable, state, world, pos, soakable.getMoisture(state) + 1);
|
||||||
|
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue