2018-09-16 00:45:44 +02:00
|
|
|
package com.minelittlepony.unicopia.block;
|
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.CloudType;
|
2019-01-30 11:26:00 +01:00
|
|
|
import com.minelittlepony.unicopia.UClient;
|
|
|
|
import com.minelittlepony.unicopia.forgebullshit.FUF;
|
2018-09-16 00:45:44 +02:00
|
|
|
|
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;
|
|
|
|
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) {
|
2019-01-30 11:26:00 +01:00
|
|
|
EntityPlayer player = UClient.instance().getPlayer();
|
2019-01-13 21:06:27 +01:00
|
|
|
|
|
|
|
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) {
|
2019-01-30 11:26:00 +01:00
|
|
|
// @FUF(reason = "There is no TickEvents.EntityTickEvent. Waiting on mixins...")
|
2019-01-27 16:35:39 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-01-30 11:26:00 +01:00
|
|
|
/**
|
|
|
|
* Determines whether falling sand entities should fall through this block.
|
|
|
|
* @param state Our block state
|
|
|
|
* @param world The current world
|
|
|
|
* @param pos The current position
|
|
|
|
*
|
|
|
|
* @return True to allow blocks to pass.
|
|
|
|
*/
|
|
|
|
@FUF(reason = "Hacked until we can get mixins to implement a proper hook")
|
2018-09-19 09:07:39 +02:00
|
|
|
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
|
|
|
}
|