@@ -140,6 +140,29 @@ public static BlockPos getActualTopSolidOrLiquidBlock(World world, BlockPos pos)
140
140
return blockPos ;
141
141
}
142
142
143
+ /**
144
+ * Finds a safe location to put entities when they are dismounted from a player's head, or being spawned into the world through other means.
145
+ */
146
+ public static BlockPos getSafeMobPos (EntityLivingBase entity , BlockPos near , Boolean addHeight ) {
147
+ int radius = 6 ;
148
+ int maxTries = 24 ;
149
+ BlockPos testing ;
150
+ for (int i = 0 ; i < maxTries ; i ++) {
151
+ int x = near .getX () + entity .getEntityWorld ().rand .nextInt (radius * 2 ) - radius ;
152
+ int z = near .getZ () + entity .getEntityWorld ().rand .nextInt (radius * 2 ) - radius ;
153
+ int y = entity .getEntityWorld ().getHeight (x , z ) + (addHeight ? 16 : 0 );
154
+ testing = new BlockPos (x , y , z );
155
+ while (entity .getEntityWorld ().isAirBlock (testing ) && testing .getY () > 0 ) {
156
+ testing = testing .down (1 );
157
+ }
158
+ IBlockState iblockstate = entity .getEntityWorld ().getBlockState (testing );
159
+ if (iblockstate .canEntitySpawn (entity )) {
160
+ return testing .up (1 );
161
+ }
162
+ }
163
+ return null ;
164
+ }
165
+
143
166
/**
144
167
* spawns tiny slimes
145
168
*/
@@ -1228,7 +1251,15 @@ public static void dismountPassengerFromEntity(Entity passenger, Entity entity,
1228
1251
if (force || (passenger instanceof EntityLivingBase && entity .isSneaking ())) {
1229
1252
System .out .println ("Forcing dismount from " + entity + " for passenger " + passenger );
1230
1253
passenger .dismountRidingEntity ();
1231
- passenger .setPositionAndUpdate (entity .posX , entity .posY + 1D , entity .posZ );
1254
+ double dist = (-1.5D );
1255
+ double newPosX = entity .posX + (dist * Math .sin (((EntityLivingBase ) entity ).renderYawOffset / 57.29578F ));
1256
+ double newPosZ = entity .posZ - (dist * Math .cos (((EntityLivingBase ) entity ).renderYawOffset / 57.29578F ));
1257
+ BlockPos safeSpawnPos = getSafeMobPos ((EntityLivingBase ) passenger , new BlockPos (newPosX , entity .posY , newPosZ ), false );
1258
+ if (safeSpawnPos != null ) {
1259
+ passenger .setPositionAndUpdate (safeSpawnPos .getX (), safeSpawnPos .getY () + 1D , safeSpawnPos .getZ ());
1260
+ } else {
1261
+ passenger .setPositionAndUpdate (entity .posX , entity .posY + 1D , entity .posZ );
1262
+ }
1232
1263
MoCTools .playCustomSound (passenger , SoundEvents .ENTITY_CHICKEN_EGG );
1233
1264
if (entity instanceof EntityPlayer ) {
1234
1265
NBTTagCompound tag = entity .getEntityData ();
0 commit comments