2018-11-23 17:11:35 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.Helper;
|
2019-01-28 15:43:21 +01:00
|
|
|
import de.ellpeck.naturesaura.api.render.IVisualizable;
|
2018-11-23 17:11:35 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityPickupStopper;
|
|
|
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
|
|
|
import net.minecraft.block.SoundType;
|
|
|
|
import net.minecraft.block.material.Material;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.entity.item.ItemEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2019-01-27 13:57:34 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2018-11-23 17:11:35 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2019-01-27 13:57:34 +01:00
|
|
|
import net.minecraft.world.World;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2018-11-23 17:11:35 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2018-11-23 17:11:35 +01:00
|
|
|
|
2019-01-28 15:43:21 +01:00
|
|
|
public class BlockPickupStopper extends BlockContainerImpl implements IVisualizable {
|
2018-11-23 17:11:35 +01:00
|
|
|
public BlockPickupStopper() {
|
2019-11-04 19:08:49 +01:00
|
|
|
super("pickup_stopper", TileEntityPickupStopper.class, "pickup_stopper", ModBlocks.prop(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE));
|
2018-11-23 17:11:35 +01:00
|
|
|
|
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onPickup(EntityItemPickupEvent event) {
|
2019-10-20 22:30:49 +02:00
|
|
|
PlayerEntity player = event.getEntityPlayer();
|
2018-11-23 17:11:35 +01:00
|
|
|
if (player != null && !player.isSneaking()) {
|
2019-10-20 22:30:49 +02:00
|
|
|
ItemEntity item = event.getItem();
|
2018-11-23 17:11:35 +01:00
|
|
|
BlockPos pos = item.getPosition();
|
|
|
|
Helper.getTileEntitiesInArea(item.world, pos, 8, tile -> {
|
|
|
|
if (!(tile instanceof TileEntityPickupStopper))
|
|
|
|
return false;
|
|
|
|
TileEntityPickupStopper stopper = (TileEntityPickupStopper) tile;
|
|
|
|
float radius = stopper.getRadius();
|
|
|
|
if (radius <= 0F)
|
|
|
|
return false;
|
|
|
|
BlockPos stopperPos = stopper.getPos();
|
2020-01-21 21:04:44 +01:00
|
|
|
if (!new AxisAlignedBB(stopperPos).grow(radius).intersects(item.getBoundingBox()))
|
2018-11-23 17:11:35 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
/* if (item.world.getGameTime() % 3 == 0) TODO particles
|
2018-11-23 17:11:35 +01:00
|
|
|
PacketHandler.sendToAllAround(item.world, pos, 32,
|
2020-01-21 21:04:44 +01:00
|
|
|
new PacketParticles((float) item.posX, (float) item.posY, (float) item.posZ, 14));*/
|
2018-11-23 17:11:35 +01:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-01-27 13:57:34 +01:00
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-01-27 13:57:34 +01:00
|
|
|
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if (tile instanceof TileEntityPickupStopper) {
|
|
|
|
double radius = ((TileEntityPickupStopper) tile).getRadius();
|
|
|
|
if (radius > 0)
|
|
|
|
return new AxisAlignedBB(pos).grow(radius);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-01-27 13:57:34 +01:00
|
|
|
public int getVisualizationColor(World world, BlockPos pos) {
|
|
|
|
return 0xf4aa42;
|
|
|
|
}
|
2018-11-23 17:11:35 +01:00
|
|
|
}
|