2018-09-16 00:45:44 +02:00
|
|
|
package com.minelittlepony.unicopia.block;
|
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.CloudType;
|
|
|
|
|
2018-09-19 09:07:39 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockFalling;
|
2019-01-13 21:06:27 +01:00
|
|
|
import net.minecraft.block.BlockTorch;
|
2018-09-16 00:45:44 +02:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2019-01-13 21:06:27 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2018-09-16 00:45:44 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
2019-01-27 16:35:39 +01:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2019-01-13 21:06:27 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2018-09-19 09:07:39 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.IBlockAccess;
|
2019-01-13 21:06:27 +01:00
|
|
|
import net.minecraft.world.World;
|
2018-09-16 00:45:44 +02:00
|
|
|
|
|
|
|
public interface ICloudBlock {
|
|
|
|
|
|
|
|
CloudType getCloudMaterialType(IBlockState blockState);
|
|
|
|
|
2019-01-13 21:06:27 +01:00
|
|
|
default boolean handleRayTraceSpecialCases(World world, BlockPos pos, IBlockState state) {
|
|
|
|
if (world.isRemote) {
|
|
|
|
EntityPlayer player = Minecraft.getMinecraft().player;
|
|
|
|
|
|
|
|
if (!getCanInteract(state, player)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack main = player.getHeldItemMainhand();
|
|
|
|
if (main.isEmpty()) {
|
|
|
|
main = player.getHeldItemOffhand();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!main.isEmpty() && main.getItem() instanceof ItemBlock) {
|
|
|
|
Block block = ((ItemBlock)main.getItem()).getBlock();
|
|
|
|
|
|
|
|
if (block == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block instanceof BlockTorch && getCloudMaterialType(state) != CloudType.NORMAL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block != Blocks.AIR && !(block instanceof ICloudBlock)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
default boolean getCanInteract(IBlockState state, Entity e) {
|
2019-01-27 16:35:39 +01:00
|
|
|
if (getCloudMaterialType(state).canInteract(e)) {
|
|
|
|
if (e instanceof EntityItem) {
|
|
|
|
e.setNoGravity(true);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2018-09-16 00:45:44 +02:00
|
|
|
}
|
|
|
|
|
2018-09-19 09:07:39 +02:00
|
|
|
default boolean isDense(IBlockState blockState) {
|
|
|
|
return getCloudMaterialType(blockState) != CloudType.NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
default boolean allowsFallingBlockToPass(IBlockState state, IBlockAccess world, BlockPos pos) {
|
|
|
|
if (isDense(state)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Block above = world.getBlockState(pos.up()).getBlock();
|
|
|
|
return !(above instanceof ICloudBlock) && above instanceof BlockFalling;
|
|
|
|
}
|
2018-09-16 00:45:44 +02:00
|
|
|
}
|