mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-27 23:45:57 +00:00
86 lines
2.6 KiB
Java
86 lines
2.6 KiB
Java
/**
|
|
* This class was created by <Vazkii>. It's distributed as
|
|
* part of the Botania Mod. Get the Source Code in github:
|
|
* https://github.com/Vazkii/Botania
|
|
*
|
|
* Botania is Open Source and distributed under the
|
|
* Botania License: http://botaniamod.net/license.php
|
|
*
|
|
* File Created @ [Jun 26, 2014, 7:32:16 PM (GMT)]
|
|
*/
|
|
package vazkii.botania.common.entity;
|
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockVine;
|
|
import net.minecraft.block.properties.PropertyBool;
|
|
import net.minecraft.block.state.IBlockState;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.entity.projectile.EntityThrowable;
|
|
import net.minecraft.network.datasync.DataParameter;
|
|
import net.minecraft.network.datasync.DataSerializers;
|
|
import net.minecraft.network.datasync.EntityDataManager;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.EnumFacing;
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
import net.minecraft.world.World;
|
|
import vazkii.botania.common.block.ModBlocks;
|
|
|
|
import java.util.Map;
|
|
|
|
public class EntityVineBall extends EntityThrowable {
|
|
|
|
private static final DataParameter<Float> GRAVITY = EntityDataManager.createKey(EntityVineBall.class, DataSerializers.FLOAT);
|
|
private final boolean gravity;
|
|
|
|
public EntityVineBall(World par1World) {
|
|
super(par1World);
|
|
gravity = false;
|
|
}
|
|
|
|
public EntityVineBall(EntityLivingBase thrower, boolean gravity) {
|
|
super(thrower.worldObj, thrower);
|
|
this.gravity = gravity;
|
|
}
|
|
|
|
@Override
|
|
protected void entityInit() {
|
|
super.entityInit();
|
|
dataManager.register(GRAVITY, gravity ? 0.03F : 0F);
|
|
}
|
|
|
|
@Override
|
|
protected void onImpact(RayTraceResult var1) {
|
|
if(var1 != null) {
|
|
EnumFacing dir = var1.sideHit;
|
|
|
|
Map<EnumFacing, PropertyBool> propMap = ImmutableMap.of(EnumFacing.NORTH, BlockVine.NORTH, EnumFacing.SOUTH, BlockVine.SOUTH,
|
|
EnumFacing.WEST, BlockVine.WEST, EnumFacing.EAST, BlockVine.EAST);
|
|
|
|
if(dir != null && dir.getAxis() != EnumFacing.Axis.Y) {
|
|
BlockPos pos = var1.getBlockPos().offset(dir);
|
|
while(pos.getY() > 0) {
|
|
IBlockState state = worldObj.getBlockState(pos);
|
|
Block block = state.getBlock();
|
|
if(block.isAir(state, worldObj, pos)) {
|
|
IBlockState stateSet = ModBlocks.solidVines.getDefaultState().withProperty(propMap.get(dir.getOpposite()), true);
|
|
worldObj.setBlockState(pos, stateSet, 1 | 2);
|
|
worldObj.playAuxSFX(2001, pos, Block.getStateId(stateSet));
|
|
pos = pos.down();
|
|
} else break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
setDead();
|
|
}
|
|
|
|
@Override
|
|
protected float getGravityVelocity() {
|
|
return dataManager.get(GRAVITY);
|
|
}
|
|
|
|
}
|